- Fixed Type Casting issue
- Reorganized duplicated internal class in the DelimitedDataParser and DelimitedDataParserFactory
- Prevented a user from creating an inverted index on a dataset with a variable-length PK
- INT64 is now the default type
- Issue 852 fixed
Change-Id: I2d71e8a21da4f709c3259a3d3f678c640f9e1160
Reviewed-on: http://fulliautomatix.ics.uci.edu:8443/192
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Till Westmann <westmann@gmail.com>
diff --git a/asterix-aql/src/main/javacc/AQL.jj b/asterix-aql/src/main/javacc/AQL.jj
index ac4f527..e85b56b 100644
--- a/asterix-aql/src/main/javacc/AQL.jj
+++ b/asterix-aql/src/main/javacc/AQL.jj
@@ -1,8 +1,8 @@
options {
-
+
STATIC = false;
-
+
}
@@ -36,6 +36,7 @@
import edu.uci.ics.asterix.common.config.DatasetConfig.IndexType;
import edu.uci.ics.asterix.aql.expression.visitor.AQLPrintVisitor;
import edu.uci.ics.asterix.aql.expression.UnaryExpr.Sign;
+import edu.uci.ics.asterix.aql.expression.TypeExpression.TypeExprKind;
import edu.uci.ics.asterix.aql.base.Statement.Kind;
import edu.uci.ics.asterix.aql.context.Scope;
import edu.uci.ics.asterix.aql.context.RootScopeFactory;
@@ -70,49 +71,49 @@
private static final String DATETIME_BETWEEN_YEARS_HINT = "datetime-between-years";
private static final String DATE_BETWEEN_YEARS_HINT = "date-between-years";
private static final String DATETIME_ADD_RAND_HOURS_HINT = "datetime-add-rand-hours";
- private static final String AUTO_HINT = "auto";
-
- private static final String GEN_FIELDS_HINT = "gen-fields";
-
+ private static final String AUTO_HINT = "auto";
+
+ private static final String GEN_FIELDS_HINT = "gen-fields";
+
// data generator hints
private static final String DGEN_HINT = "dgen";
-
+
private static class IndexParams {
public IndexType type;
public int gramLength;
-
+
public IndexParams(IndexType type, int gramLength) {
this.type = type;
this.gramLength = gramLength;
}
- };
-
+ };
+
private static class FunctionName {
- public String dataverse = null;
- public String library = null;
- public String function = null;
- }
+ public String dataverse = null;
+ public String library = null;
+ public String function = null;
+ }
private static String getHint(Token t) {
if (t.specialToken == null) {
return null;
- }
+ }
String s = t.specialToken.image;
int n = s.length();
if (n < 2) {
return null;
- }
+ }
return s.substring(1).trim();
}
-
+
private static IRecordFieldDataGen parseFieldDataGen(String hint) throws ParseException {
IRecordFieldDataGen rfdg = null;
String splits[] = hint.split(" +");
- if (splits[0].equals(VAL_FILE_HINT)) {
+ if (splits[0].equals(VAL_FILE_HINT)) {
File[] valFiles = new File[splits.length - 1];
for (int k=1; k<splits.length; k++) {
valFiles[k-1] = new File(splits[k]);
- }
+ }
rfdg = new FieldValFileDataGen(valFiles);
} else if (splits[0].equals(VAL_FILE_SAME_INDEX_HINT)) {
rfdg = new FieldValFileSameIndexDataGen(new File(splits[1]), splits[2]);
@@ -133,7 +134,7 @@
} else {
throw new ParseException("Unknown type for interval data gen: " + splits[1]);
}
- rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
+ rfdg = new FieldIntervalDataGen(vt, splits[2], splits[3]);
} else if (splits[0].equals(INSERT_RAND_INT_HINT)) {
rfdg = new InsertRandIntDataGen(splits[1], splits[2]);
} else if (splits[0].equals(DATE_BETWEEN_YEARS_HINT)) {
@@ -189,7 +190,7 @@
)*
<EOF>
{
- return decls;
+ return decls;
}
}
@@ -208,7 +209,7 @@
| stmt = SetStatement()
| stmt = InsertStatement()
| stmt = DeleteStatement()
- | stmt = UpdateStatement()
+ | stmt = UpdateStatement()
| stmt = FeedStatement()
| stmt = CompactStatement()
| stmt = Query()
@@ -245,16 +246,16 @@
hint = getHint(token);
if (hint != null && hint.startsWith(DGEN_HINT)) {
dgen = true;
- }
+ }
}
stmt = TypeSpecification(hint, dgen)
| stmt = NodegroupSpecification()
- | stmt = DatasetSpecification()
+ | stmt = DatasetSpecification()
| stmt = IndexSpecification()
| stmt = DataverseSpecification()
| stmt = FunctionSpecification()
| stmt = FeedSpecification()
- )
+ )
{
return stmt;
}
@@ -272,14 +273,14 @@
{
long numValues = -1;
String filename = null;
- if (dgen) {
+ if (dgen) {
String splits[] = hint.split(" +");
if (splits.length != 3) {
throw new ParseException("Expecting /*+ dgen <filename> <numberOfItems> */");
- }
+ }
filename = splits[1];
numValues = Long.parseLong(splits[2]);
- }
+ }
TypeDataGen tddg = new TypeDataGen(dgen, filename, numValues);
return new TypeDecl(nameComponents.first, nameComponents.second, typeExpr, tddg, ifNotExists);
}
@@ -312,7 +313,7 @@
DatasetDecl DatasetSpecification() throws ParseException:
{
- Pair<Identifier,Identifier> nameComponents = null;
+ Pair<Identifier,Identifier> nameComponents = null;
boolean ifNotExists = false;
String typeName = null;
String adapterName = null;
@@ -321,7 +322,7 @@
FunctionSignature appliedFunction = null;
List<String> primaryKeyFields = null;
String nodeGroupName = null;
- Map<String,String> hints = new HashMap<String,String>();
+ Map<String,String> hints = new HashMap<String,String>();
DatasetDecl dsetDecl = null;
boolean autogenerated = false;
String compactionPolicy = null;
@@ -350,13 +351,13 @@
DatasetType.EXTERNAL,
edd,
ifNotExists);
- }
+ }
| ("internal")? <DATASET> nameComponents = QualifiedName()
<LEFTPAREN> typeName = Identifier() <RIGHTPAREN>
ifNotExists = IfNotExists()
- primaryKeyFields = PrimaryKey()
- ("autogenerated" { autogenerated = true; } )?
+ primaryKeyFields = PrimaryKey()
+ ("autogenerated" { autogenerated = true; } )?
("on" nodeGroupName = Identifier() )?
( "hints" hints = Properties() )?
( "using" "compaction" "policy" compactionPolicy = CompactionPolicy() (compactionPolicyProperties = Configuration())? )?
@@ -391,12 +392,12 @@
String datasetName = null;
}
{
- "refresh external" <DATASET> nameComponents = QualifiedName()
- {
- redss.setDataverseName(nameComponents.first);
- redss.setDatasetName(nameComponents.second);
- return redss;
- }
+ "refresh external" <DATASET> nameComponents = QualifiedName()
+ {
+ redss.setDataverseName(nameComponents.first);
+ redss.setDatasetName(nameComponents.second);
+ return redss;
+ }
}
RunStatement RunStatement() throws ParseException:
@@ -414,7 +415,7 @@
}
)*<RIGHTPAREN>
<FROM> <DATASET> nameComponentsFrom = QualifiedName()
- "to" <DATASET> nameComponentsTo = QualifiedName()
+ "to" <DATASET> nameComponentsTo = QualifiedName()
{
return new RunStatement(system, parameters, nameComponentsFrom.first, nameComponentsFrom.second, nameComponentsTo.first, nameComponentsTo.second);
}
@@ -432,7 +433,7 @@
{
"index" indexName = Identifier()
ifNotExists = IfNotExists()
- "on" nameComponents = QualifiedName()
+ "on" nameComponents = QualifiedName()
<LEFTPAREN> ( fieldExpr = Identifier()
{
cis.addFieldExpr(fieldExpr);
@@ -462,7 +463,7 @@
{
compactionPolicy = Identifier()
{
- return compactionPolicy;
+ return compactionPolicy;
}
}
@@ -473,7 +474,7 @@
{
filterField = Identifier()
{
- return filterField;
+ return filterField;
}
}
@@ -486,7 +487,7 @@
("btree"
{
type = IndexType.BTREE;
- }
+ }
| "rtree"
{
type = IndexType.RTREE;
@@ -532,7 +533,7 @@
Token beginPos;
Token endPos;
FunctionName fctName = null;
-
+
createNewScope();
}
{
@@ -542,7 +543,7 @@
<LEFTBRACE>
{
beginPos = token;
- }
+ }
functionBodyExpr = Expression() <RIGHTBRACE>
{
endPos = token;
@@ -557,7 +558,7 @@
CreateFeedStatement FeedSpecification() throws ParseException:
{
- Pair<Identifier,Identifier> nameComponents = null;
+ Pair<Identifier,Identifier> nameComponents = null;
boolean ifNotExists = false;
String adapterName = null;
Map<String,String> properties = null;
@@ -573,8 +574,8 @@
{
cfs = new CreateFeedStatement(nameComponents.first,
nameComponents.second, adapterName, properties, appliedFunction, ifNotExists);
- }
-
+ }
+
)
{
return cfs;
@@ -641,12 +642,12 @@
String policy = null;
}
{
- "using" "policy" policy = Identifier()
+ "using" "policy" policy = Identifier()
{
return policy;
}
-
-}
+
+}
FunctionSignature FunctionSignature() throws ParseException:
{
@@ -654,15 +655,15 @@
int arity = 0;
}
{
- fctName = FunctionName() "@" <INTEGER_LITERAL>
- {
+ fctName = FunctionName() "@" <INTEGER_LITERAL>
+ {
arity = new Integer(token.image);
if (arity < 0 && arity != FunctionIdentifier.VARARGS) {
throw new ParseException(" invalid arity:" + arity);
}
// TODO use fctName.library
- String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
+ String fqFunctionName = fctName.library == null ? fctName.function : fctName.library + "#" + fctName.function;
return new FunctionSignature(fctName.dataverse, fqFunctionName, arity);
}
}
@@ -726,10 +727,10 @@
| "feed" pairId = QualifiedName() ifExists = IfExists()
{
stmt = new FeedDropStatement(pairId.first, pairId.second, ifExists);
- }
+ }
)
{
- return stmt;
+ return stmt;
}
}
@@ -767,14 +768,14 @@
// This is related to the new metadata lock management
setDataverses(new ArrayList<String>());
setDatasets(new ArrayList<String>());
-
+
}
{
"delete" var = Variable()
{
getCurrentScope().addNewVarSymbolToScope(var.getVar());
}
- <FROM> <DATASET> nameComponents = QualifiedName()
+ <FROM> <DATASET> nameComponents = QualifiedName()
(<WHERE> condition = Expression())?
{
// First we get the dataverses and datasets that we want to lock
@@ -783,8 +784,8 @@
// we remove the pointer to the dataverses and datasets
setDataverses(null);
setDatasets(null);
- return new DeleteStatement(var, nameComponents.first, nameComponents.second,
- condition, getVarCounter(), dataverses, datasets);
+ return new DeleteStatement(var, nameComponents.first, nameComponents.second,
+ condition, getVarCounter(), dataverses, datasets);
}
}
@@ -798,7 +799,7 @@
}
{
"update" vars = Variable() <IN> target = Expression()
- <WHERE> condition = Expression()
+ <WHERE> condition = Expression()
<LEFTPAREN> (uc = UpdateClause()
{
ucs.add(uc);
@@ -816,7 +817,7 @@
UpdateClause UpdateClause() throws ParseException:
{
Expression target = null;
- Expression value = null ;
+ Expression value = null ;
InsertStatement is = null;
DeleteStatement ds = null;
UpdateStatement us = null;
@@ -825,13 +826,13 @@
UpdateClause elsebranch = null;
}
{
- "set" target = Expression() <ASSIGN> value = Expression()
+ "set" target = Expression() <ASSIGN> value = Expression()
| is = InsertStatement()
| ds = DeleteStatement()
| us = UpdateStatement()
| <IF> <LEFTPAREN> condition = Expression() <RIGHTPAREN>
<THEN> ifbranch = UpdateClause()
- [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
+ [LOOKAHEAD(1) <ELSE> elsebranch = UpdateClause()]
{
return new UpdateClause(target, value, is, ds, us, condition, ifbranch, elsebranch);
}
@@ -860,8 +861,8 @@
{
"write" "output" "to" nodeName = Identifier() <COLON> fileName = StringLiteral()
( "using" writerClass = StringLiteral() )?
- {
- return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
+ {
+ return new WriteStatement(new Identifier(nodeName), fileName, writerClass);
}
}
@@ -881,14 +882,14 @@
datasetName = nameComponents.second;
}
"using" adapterName = AdapterName() properties = Configuration()
- ("pre-sorted"
+ ("pre-sorted"
{
alreadySorted = true;
}
)?
{
return new LoadStatement(dataverseName, datasetName, adapterName, properties, alreadySorted);
- }
+ }
}
@@ -899,7 +900,7 @@
{
adapterName = Identifier()
{
- return adapterName;
+ return adapterName;
}
}
@@ -911,10 +912,10 @@
{
"compact" <DATASET> nameComponents = QualifiedName()
{
- stmt = new CompactStatement(nameComponents.first, nameComponents.second);
+ stmt = new CompactStatement(nameComponents.first, nameComponents.second);
}
{
- return stmt;
+ return stmt;
}
}
@@ -922,14 +923,14 @@
{
Pair<Identifier,Identifier> feedNameComponents = null;
Pair<Identifier,Identifier> datasetNameComponents = null;
-
+
Map<String,String> configuration = null;
Statement stmt = null;
String policy = null;
}
{
(
- "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
+ "connect" "feed" feedNameComponents = QualifiedName() "to" <DATASET> datasetNameComponents = QualifiedName() (policy = GetPolicy())?
{
stmt = new ConnectFeedStatement(feedNameComponents, datasetNameComponents, policy, getVarCounter());
}
@@ -945,8 +946,8 @@
Map<String,String> Configuration() throws ParseException :
{
- Map<String,String> configuration = new LinkedHashMap<String,String>();
- Pair<String, String> keyValuePair = null;
+ Map<String,String> configuration = new LinkedHashMap<String,String>();
+ Pair<String, String> keyValuePair = null;
}
{
<LEFTPAREN> ( keyValuePair = KeyValuePair()
@@ -972,7 +973,7 @@
<LEFTPAREN> key = StringLiteral() <EQ> value = StringLiteral() <RIGHTPAREN>
{
return new Pair<String, String>(key, value);
- }
+ }
}
Map<String,String> Properties() throws ParseException:
@@ -985,7 +986,7 @@
{
properties.put(property.first, property.second);
}
- ( <COMMA> property = Property()
+ ( <COMMA> property = Property()
{
properties.put(property.first, property.second);
}
@@ -1006,13 +1007,13 @@
try {
value = "" + Long.valueOf(token.image);
} catch (NumberFormatException nfe) {
- throw new ParseException("inapproriate value: " + token.image);
+ throw new ParseException("inapproriate value: " + token.image);
}
}
)
{
return new Pair<String, String>(key.toUpperCase(), value);
- }
+ }
}
TypeExpression TypeExpr() throws ParseException:
@@ -1024,8 +1025,8 @@
typeExpr = RecordTypeDef()
| typeExpr = TypeReference()
| typeExpr = OrderedListTypeDef()
- | typeExpr = UnorderedListTypeDef()
- )
+ | typeExpr = UnorderedListTypeDef()
+ )
{
return typeExpr;
}
@@ -1034,15 +1035,15 @@
RecordTypeDefinition RecordTypeDef() throws ParseException:
{
RecordTypeDefinition recType = new RecordTypeDefinition();
- RecordTypeDefinition.RecordKind recordKind = null;
+ RecordTypeDefinition.RecordKind recordKind = null;
}
{
- ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
+ ( "closed" { recordKind = RecordTypeDefinition.RecordKind.CLOSED; }
| "open" { recordKind = RecordTypeDefinition.RecordKind.OPEN; } )?
<LEFTBRACE>
{
String hint = getHint(token);
- if (hint != null) {
+ if (hint != null) {
String splits[] = hint.split(" +");
if (splits[0].equals(GEN_FIELDS_HINT)) {
if (splits.length != 5) {
@@ -1050,18 +1051,18 @@
}
if (!splits[1].equals("int")) {
throw new ParseException("The only supported type for gen-fields is int.");
- }
- UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
+ }
+ UndeclaredFieldsDataGen ufdg = new UndeclaredFieldsDataGen(UndeclaredFieldsDataGen.Type.INT,
Integer.parseInt(splits[2]), Integer.parseInt(splits[3]), splits[4]);
- recType.setUndeclaredFieldsDataGen(ufdg);
+ recType.setUndeclaredFieldsDataGen(ufdg);
}
- }
-
+ }
+
}
- (
- RecordField(recType)
- ( <COMMA> RecordField(recType) )*
- )?
+ (
+ RecordField(recType)
+ ( <COMMA> RecordField(recType) )*
+ )?
<RIGHTBRACE>
{
if (recordKind == null) {
@@ -1069,13 +1070,13 @@
}
recType.setRecordKind(recordKind);
return recType;
- }
+ }
}
void RecordField(RecordTypeDefinition recType) throws ParseException:
{
String fieldName;
- TypeExpression type = null;
+ TypeExpression type = null;
boolean nullable = false;
}
{
@@ -1087,7 +1088,7 @@
<COLON> type = TypeExpr() (<QUES> { nullable = true; } )?
{
recType.addField(fieldName, type, nullable, rfdg);
- }
+ }
}
TypeReferenceExpression TypeReference() throws ParseException:
@@ -1097,12 +1098,16 @@
{
id = Identifier()
{
+ if (id.equalsIgnoreCase("int")) {
+ id = "int64";
+ }
+
return new TypeReferenceExpression(new Identifier(id));
}
}
OrderedListTypeDefinition OrderedListTypeDef() throws ParseException:
-{
+{
TypeExpression type = null;
}
{
@@ -1116,7 +1121,7 @@
UnorderedListTypeDefinition UnorderedListTypeDef() throws ParseException:
-{
+{
TypeExpression type = null;
}
{
@@ -1145,25 +1150,29 @@
FunctionName result = new FunctionName();
if (second == null) {
result.dataverse = defaultDataverse;
- result.library = null;
- result.function = first;
+ result.library = null;
+ result.function = first;
} else if (third == null) {
if (secondAfterDot) {
result.dataverse = first;
result.library = null;
- result.function = second;
+ result.function = second;
} else {
result.dataverse = defaultDataverse;
result.library = first;
- result.function = second;
+ result.function = second;
}
} else {
result.dataverse = first;
result.library = second;
result.function = third;
}
+
+ if (result.function.equalsIgnoreCase("int")) {
+ result.function = "int64";
+ }
return result;
- }
+ }
}
@@ -1193,7 +1202,7 @@
| lit = StringLiteral()
{
return lit;
- }
+ }
}
String StringLiteral() throws ParseException:
@@ -1224,9 +1233,9 @@
id2 = new Identifier(second);
}
return new Pair<Identifier,Identifier>(id1, id2);
- }
-}
-
+ }
+}
+
Triple<Identifier,Identifier,Identifier> DoubleQualifiedName() throws ParseException:
{
String first = null;
@@ -1248,8 +1257,8 @@
id3 = new Identifier(third);
}
return new Triple<Identifier,Identifier,Identifier>(id1, id2, id3);
- }
-}
+ }
+}
FunctionDecl FunctionDeclaration() throws ParseException:
{
@@ -1292,7 +1301,7 @@
setDatasets(null);
return query;
}
-
+
}
@@ -1304,18 +1313,18 @@
}
{
(
-
+
//OperatorExpr | IfThenElse | FLWOGRExpression | QuantifiedExpression
expr = OperatorExpr()
| expr = IfThenElse()
| expr = FLWOGR()
| expr = QuantifiedExpression()
-
+
)
- {
- return (exprP==null) ? expr : exprP;
- }
+ {
+ return (exprP==null) ? expr : exprP;
+ }
}
@@ -1326,29 +1335,29 @@
Expression operand = null;
}
{
- operand = AndExpr()
- (
-
- <OR>
- {
- if (op == null) {
- op = new OperatorExpr();
- op.addOperand(operand);
- op.setCurrentop(true);
- }
+ operand = AndExpr()
+ (
+
+ <OR>
+ {
+ if (op == null) {
+ op = new OperatorExpr();
+ op.addOperand(operand);
+ op.setCurrentop(true);
+ }
op.addOperator(token.image);
- }
+ }
- operand = AndExpr()
- {
- op.addOperand(operand);
- }
+ operand = AndExpr()
+ {
+ op.addOperand(operand);
+ }
- )*
-
- {
- return op==null? operand: op;
- }
+ )*
+
+ {
+ return op==null? operand: op;
+ }
}
Expression AndExpr()throws ParseException:
@@ -1357,29 +1366,29 @@
Expression operand = null;
}
{
- operand = RelExpr()
- (
-
- <AND>
- {
- if (op == null) {
- op = new OperatorExpr();
- op.addOperand(operand);
- op.setCurrentop(true);
- }
+ operand = RelExpr()
+ (
+
+ <AND>
+ {
+ if (op == null) {
+ op = new OperatorExpr();
+ op.addOperand(operand);
+ op.setCurrentop(true);
+ }
op.addOperator(token.image);
- }
+ }
- operand = RelExpr()
- {
- op.addOperand(operand);
- }
+ operand = RelExpr()
+ {
+ op.addOperand(operand);
+ }
- )*
-
- {
- return op==null? operand: op;
- }
+ )*
+
+ {
+ return op==null? operand: op;
+ }
}
@@ -1393,83 +1402,83 @@
}
{
operand = AddExpr()
- {
- if (operand instanceof VariableExpr) {
- String hint = getHint(token);
+ {
+ if (operand instanceof VariableExpr) {
+ String hint = getHint(token);
if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
broadcast = true;
}
}
- }
+ }
(
LOOKAHEAD(2)( <LT> | <GT> | <LE> | <GE> | <EQ> | <NE> |<SIMILAR>)
- {
- String mhint = getHint(token);
- if (mhint != null) {
- if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
+ {
+ String mhint = getHint(token);
+ if (mhint != null) {
+ if (mhint.equals(INDEXED_NESTED_LOOP_JOIN_HINT)) {
annotation = IndexedNLJoinExpressionAnnotation.INSTANCE;
} else if (mhint.equals(SKIP_SECONDARY_INDEX_SEARCH_HINT)) {
annotation = SkipSecondaryIndexSearchExpressionAnnotation.INSTANCE;
}
}
- if (op == null) {
- op = new OperatorExpr();
- op.addOperand(operand, broadcast);
+ if (op == null) {
+ op = new OperatorExpr();
+ op.addOperand(operand, broadcast);
op.setCurrentop(true);
broadcast = false;
- }
+ }
op.addOperator(token.image);
- }
-
- operand = AddExpr()
- {
- broadcast = false;
+ }
+
+ operand = AddExpr()
+ {
+ broadcast = false;
if (operand instanceof VariableExpr) {
- String hint = getHint(token);
+ String hint = getHint(token);
if (hint != null && hint.equals(BROADCAST_JOIN_HINT)) {
broadcast = true;
}
}
op.addOperand(operand, broadcast);
- }
+ }
)?
-
- {
- if (annotation != null) {
- op.addHint(annotation);
- }
- return op==null? operand: op;
- }
+
+ {
+ if (annotation != null) {
+ op.addHint(annotation);
+ }
+ return op==null? operand: op;
+ }
}
Expression AddExpr()throws ParseException:
{
OperatorExpr op = null;
- Expression operand = null;
+ Expression operand = null;
}
{
- operand = MultExpr()
+ operand = MultExpr()
- ( (<PLUS> | <MINUS>)
- {
- if (op == null) {
- op = new OperatorExpr();
- op.addOperand(operand);
- op.setCurrentop(true);
- }
- ((OperatorExpr)op).addOperator(token.image);
- }
+ ( (<PLUS> | <MINUS>)
+ {
+ if (op == null) {
+ op = new OperatorExpr();
+ op.addOperand(operand);
+ op.setCurrentop(true);
+ }
+ ((OperatorExpr)op).addOperator(token.image);
+ }
- operand = MultExpr()
- {
- op.addOperand(operand);
- }
- )*
-
- {
- return op==null? operand: op;
- }
+ operand = MultExpr()
+ {
+ op.addOperand(operand);
+ }
+ )*
+
+ {
+ return op==null? operand: op;
+ }
}
Expression MultExpr()throws ParseException:
@@ -1478,26 +1487,26 @@
Expression operand = null;
}
{
- operand = UnionExpr()
+ operand = UnionExpr()
- (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
- {
- if (op == null) {
- op = new OperatorExpr();
+ (( <MUL> | <DIV> | <MOD> | <CARET> | <IDIV>)
+ {
+ if (op == null) {
+ op = new OperatorExpr();
op.addOperand(operand);
- op.setCurrentop(true);
- }
- op.addOperator(token.image);
- }
- operand = UnionExpr()
- {
- op.addOperand(operand);
- }
- )*
-
- {
- return op==null?operand:op;
- }
+ op.setCurrentop(true);
+ }
+ op.addOperator(token.image);
+ }
+ operand = UnionExpr()
+ {
+ op.addOperand(operand);
+ }
+ )*
+
+ {
+ return op==null?operand:op;
+ }
}
Expression UnionExpr() throws ParseException:
@@ -1507,14 +1516,14 @@
Expression operand2 = null;
}
{
- operand1 = UnaryExpr()
- (<UNION>
+ operand1 = UnaryExpr()
+ (<UNION>
(operand2 = UnaryExpr()) {
if (union == null) {
union = new UnionExpr();
- union.addExpr(operand1);
+ union.addExpr(operand1);
}
- union.addExpr(operand2);
+ union.addExpr(operand2);
} )*
{
return (union == null)? operand1: union;
@@ -1523,32 +1532,32 @@
Expression UnaryExpr() throws ParseException:
{
- Expression uexpr = null;
- Expression expr = null;
+ Expression uexpr = null;
+ Expression expr = null;
}
{
- ( (<PLUS> | <MINUS>)
- {
- uexpr = new UnaryExpr();
- if("+".equals(token.image))
- ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
- else if("-".equals(token.image))
- ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
- else
- throw new ParseException();
- }
- )?
-
- expr = ValueExpr()
- {
- if(uexpr!=null){
- ((UnaryExpr)uexpr).setExpr(expr);
- return uexpr;
- }
- else{
- return expr;
- }
- }
+ ( (<PLUS> | <MINUS>)
+ {
+ uexpr = new UnaryExpr();
+ if("+".equals(token.image))
+ ((UnaryExpr)uexpr).setSign(Sign.POSITIVE);
+ else if("-".equals(token.image))
+ ((UnaryExpr)uexpr).setSign(Sign.NEGATIVE);
+ else
+ throw new ParseException();
+ }
+ )?
+
+ expr = ValueExpr()
+ {
+ if(uexpr!=null){
+ ((UnaryExpr)uexpr).setExpr(expr);
+ return uexpr;
+ }
+ else{
+ return expr;
+ }
+ }
}
Expression ValueExpr()throws ParseException:
@@ -1560,8 +1569,8 @@
}
{
expr = PrimaryExpr() ( ident = Field()
- {
- fa = (fa == null ? new FieldAccessor(expr, ident)
+ {
+ fa = (fa == null ? new FieldAccessor(expr, ident)
: new FieldAccessor(fa, ident));
}
| indexExpr = Index()
@@ -1588,29 +1597,29 @@
Expression Index() throws ParseException:
{
- Expression expr = null;
+ Expression expr = null;
}
{
<LEFTBRACKET> ( expr = Expression()
- {
- if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
- {
- Literal lit = ((LiteralExpr)expr).getValue();
- if(lit.getLiteralType() != Literal.Type.INTEGER &&
- lit.getLiteralType() != Literal.Type.LONG) {
- throw new ParseException("Index should be an INTEGER");
+ {
+ if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
+ {
+ Literal lit = ((LiteralExpr)expr).getValue();
+ if(lit.getLiteralType() != Literal.Type.INTEGER &&
+ lit.getLiteralType() != Literal.Type.LONG) {
+ throw new ParseException("Index should be an INTEGER");
}
- }
- }
+ }
+ }
- | <QUES> // ANY
-
- )
+ | <QUES> // ANY
+
+ )
<RIGHTBRACKET>
- {
- return expr;
- }
+ {
+ return expr;
+ }
}
@@ -1619,11 +1628,11 @@
Expression expr = null;
}
{
- ( LOOKAHEAD(2)
+ ( LOOKAHEAD(2)
expr = FunctionCallExpr()
| expr = Literal()
| expr = DatasetAccessExpression()
- | expr = VariableRef()
+ | expr = VariableRef()
{
if(((VariableExpr)expr).getIsNewVar() == true)
throw new ParseException("can't find variable " + ((VariableExpr)expr).getVar());
@@ -1649,11 +1658,7 @@
}
| <INTEGER_LITERAL>
{
- try {
- lit.setValue(new IntegerLiteral(new Integer(token.image)));
- } catch(NumberFormatException ex) {
- lit.setValue(new LongIntegerLiteral(new Long(token.image)));
- }
+ lit.setValue(new LongIntegerLiteral(new Long(token.image)));
}
| <FLOAT_LITERAL>
{
@@ -1670,7 +1675,7 @@
| <TRUE>
{
lit.setValue(TrueLiteral.INSTANCE);
- }
+ }
| <FALSE>
{
lit.setValue(FalseLiteral.INSTANCE);
@@ -1684,24 +1689,24 @@
VariableExpr VariableRef() throws ParseException:
{
- VariableExpr varExp = new VariableExpr();
- VarIdentifier var = new VarIdentifier();
+ VariableExpr varExp = new VariableExpr();
+ VarIdentifier var = new VarIdentifier();
}
{
<VARIABLE>
{
- String varName = token.image;
+ String varName = token.image;
Identifier ident = lookupSymbol(varName);
if (isInForbiddenScopes(varName)) {
throw new ParseException("Inside limit clauses, it is disallowed to reference a variable having the same name as any variable bound in the same scope as the limit clause.");
}
if(ident != null) { // exist such ident
varExp.setIsNewVar(false);
- varExp.setVar((VarIdentifier)ident);
+ varExp.setVar((VarIdentifier)ident);
} else {
- varExp.setVar(var);
+ varExp.setVar(var);
}
- var.setValue(varName);
+ var.setValue(varName);
return varExp;
}
}
@@ -1709,8 +1714,8 @@
VariableExpr Variable() throws ParseException:
{
- VariableExpr varExp = new VariableExpr();
- VarIdentifier var = new VarIdentifier();
+ VariableExpr varExp = new VariableExpr();
+ VarIdentifier var = new VarIdentifier();
}
{
<VARIABLE>
@@ -1718,22 +1723,22 @@
Identifier ident = lookupSymbol(token.image);
if(ident != null) { // exist such ident
varExp.setIsNewVar(false);
- }
- varExp.setVar(var);
- var.setValue(token.image);
+ }
+ varExp.setVar(var);
+ var.setValue(token.image);
return varExp;
}
}
Expression ListConstructor() throws ParseException:
{
- Expression expr = null;
+ Expression expr = null;
}
{
(
- expr = OrderedListConstructor() | expr = UnorderedListConstructor()
+ expr = OrderedListConstructor() | expr = UnorderedListConstructor()
)
-
+
{
return expr;
}
@@ -1742,55 +1747,55 @@
ListConstructor OrderedListConstructor() throws ParseException:
{
- ListConstructor expr = new ListConstructor();
- Expression tmp = null;
- List<Expression> exprList = new ArrayList<Expression>();
- expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
+ ListConstructor expr = new ListConstructor();
+ Expression tmp = null;
+ List<Expression> exprList = new ArrayList<Expression>();
+ expr.setType(ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR);
}
{
- <LEFTBRACKET>
- ( tmp = Expression()
- {
- exprList.add(tmp);
- }
-
- (<COMMA> tmp = Expression() { exprList.add(tmp); })*
- )?
-
+ <LEFTBRACKET>
+ ( tmp = Expression()
+ {
+ exprList.add(tmp);
+ }
+
+ (<COMMA> tmp = Expression() { exprList.add(tmp); })*
+ )?
+
<RIGHTBRACKET>
{
expr.setExprList(exprList);
return expr;
- }
+ }
}
ListConstructor UnorderedListConstructor() throws ParseException:
{
- ListConstructor expr = new ListConstructor();
- Expression tmp = null;
- List<Expression> exprList = new ArrayList<Expression>();
- expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
+ ListConstructor expr = new ListConstructor();
+ Expression tmp = null;
+ List<Expression> exprList = new ArrayList<Expression>();
+ expr.setType(ListConstructor.Type.UNORDERED_LIST_CONSTRUCTOR);
}
{
<LEFTDBLBRACE> ( tmp = Expression()
- {
- exprList.add(tmp);
- }
+ {
+ exprList.add(tmp);
+ }
(<COMMA> tmp = Expression() { exprList.add(tmp); })*)? <RIGHTDBLBRACE>
{
expr.setExprList(exprList);
return expr;
- }
+ }
}
RecordConstructor RecordConstructor() throws ParseException:
{
- RecordConstructor expr = new RecordConstructor();
- FieldBinding tmp = null;
- List<FieldBinding> fbList = new ArrayList<FieldBinding>();
+ RecordConstructor expr = new RecordConstructor();
+ FieldBinding tmp = null;
+ List<FieldBinding> fbList = new ArrayList<FieldBinding>();
}
{
<LEFTBRACE> (tmp = FieldBinding()
@@ -1801,13 +1806,13 @@
{
expr.setFbList(fbList);
return expr;
- }
+ }
}
FieldBinding FieldBinding() throws ParseException:
{
- FieldBinding fb = new FieldBinding();
- Expression left, right;
+ FieldBinding fb = new FieldBinding();
+ Expression left, right;
}
{
left = Expression() <COLON> right = Expression()
@@ -1828,7 +1833,7 @@
FunctionName funcName = null;
String hint = null;
}
-{
+{
funcName = FunctionName()
{
hint = getHint(token);
@@ -1872,25 +1877,25 @@
String arg2 = null;
Expression nameArg;
}
-{
+{
<DATASET>
{
funcName = token.image;
}
- ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
+ ( ( arg1 = Identifier() ( <DOT> arg2 = Identifier() )? )
{
String name = arg2 == null ? arg1 : arg1 + "." + arg2;
LiteralExpr ds = new LiteralExpr();
ds.setValue( new StringLiteral(name) );
nameArg = ds;
if(arg2 != null){
- addDataverse(arg1.toString());
- addDataset(name);
+ addDataverse(arg1.toString());
+ addDataset(name);
} else {
- addDataset(defaultDataverse + "." + name);
+ addDataset(defaultDataverse + "." + name);
}
}
- | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
+ | ( <LEFTPAREN> nameArg = Expression() <RIGHTPAREN> ) )
{
String dataverse = MetadataConstants.METADATA_DATAVERSE_NAME;
FunctionSignature signature = lookupFunctionSignature(dataverse, funcName, 1);
@@ -1934,11 +1939,11 @@
Expression FLWOGR() throws ParseException:
{
- FLWOGRExpression flworg = new FLWOGRExpression();
- List<Clause> clauseList = new ArrayList<Clause>();
- Expression returnExpr;
- Clause tmp;
- createNewScope();
+ FLWOGRExpression flworg = new FLWOGRExpression();
+ List<Clause> clauseList = new ArrayList<Clause>();
+ Expression returnExpr;
+ Clause tmp;
+ createNewScope();
}
{
(tmp = ForClause() {clauseList.add(tmp);} | tmp = LetClause() {clauseList.add(tmp);})
@@ -1958,11 +1963,11 @@
}
{
(
- clause = ForClause()
- | clause = LetClause()
- | clause = WhereClause()
- | clause = OrderbyClause()
- | clause = GroupClause()
+ clause = ForClause()
+ | clause = LetClause()
+ | clause = WhereClause()
+ | clause = OrderbyClause()
+ | clause = GroupClause()
| clause = LimitClause()
| clause = DistinctClause()
)
@@ -1973,11 +1978,11 @@
Clause ForClause()throws ParseException :
{
- ForClause fc = new ForClause();
- VariableExpr varExp;
- VariableExpr varPos = null;
- Expression inExp;
- extendCurrentScope();
+ ForClause fc = new ForClause();
+ VariableExpr varExp;
+ VariableExpr varPos = null;
+ Expression inExp;
+ extendCurrentScope();
}
{
(<FOR>|<FROM>) varExp = Variable() (<AT> varPos = Variable())? <IN> ( inExp = Expression() )
@@ -1987,7 +1992,7 @@
fc.setInExpr(inExp);
if (varPos != null) {
fc.setPosExpr(varPos);
- getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
+ getCurrentScope().addNewVarSymbolToScope(varPos.getVar());
}
return fc;
}
@@ -1995,10 +2000,10 @@
Clause LetClause() throws ParseException:
{
- LetClause lc = new LetClause();
- VariableExpr varExp;
- Expression beExp;
- extendCurrentScope();
+ LetClause lc = new LetClause();
+ VariableExpr varExp;
+ Expression beExp;
+ extendCurrentScope();
}
{
(<LET>|<WITH>) varExp = Variable() <ASSIGN> beExp = Expression()
@@ -2033,28 +2038,28 @@
}
{
(
- <ORDER>
+ <ORDER>
{
String hint = getHint(token);
if (hint != null && hint.startsWith(INMEMORY_HINT)) {
- String splits[] = hint.split(" +");
+ String splits[] = hint.split(" +");
int numFrames = Integer.parseInt(splits[1]);
int numTuples = Integer.parseInt(splits[2]);
oc.setNumFrames(numFrames);
- oc.setNumTuples(numTuples);
- }
- }
+ oc.setNumTuples(numTuples);
+ }
+ }
<BY> orderbyExpr = Expression()
{
orderbyList.add(orderbyExpr);
- OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
+ OrderbyClause.OrderModifier modif = OrderbyClause.OrderModifier.ASC;
}
( (<ASC> { modif = OrderbyClause.OrderModifier.ASC; })
| (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
{
modifierList.add(modif);
}
-
+
(<COMMA> orderbyExpr = Expression()
{
orderbyList.add(orderbyExpr);
@@ -2064,7 +2069,7 @@
| (<DESC> { modif = OrderbyClause.OrderModifier.DESC; }))?
{
modifierList.add(modif);
- }
+ }
)*
)
{
@@ -2075,73 +2080,73 @@
}
Clause GroupClause()throws ParseException :
{
- GroupbyClause gbc = new GroupbyClause();
- // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
- List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
+ GroupbyClause gbc = new GroupbyClause();
+ // GbyVariableExpressionPair pair = new GbyVariableExpressionPair();
+ List<GbyVariableExpressionPair> vePairList = new ArrayList<GbyVariableExpressionPair>();
List<GbyVariableExpressionPair> decorPairList = new ArrayList<GbyVariableExpressionPair>();
- List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
- VariableExpr var = null;
- VariableExpr withVar = null;
- Expression expr = null;
- VariableExpr decorVar = null;
- Expression decorExpr = null;
+ List<VariableExpr> withVarList= new ArrayList<VariableExpr>();
+ VariableExpr var = null;
+ VariableExpr withVar = null;
+ Expression expr = null;
+ VariableExpr decorVar = null;
+ Expression decorExpr = null;
}
{
- {
- Scope newScope = extendCurrentScopeNoPush(true);
- // extendCurrentScope(true);
- }
+ {
+ Scope newScope = extendCurrentScopeNoPush(true);
+ // extendCurrentScope(true);
+ }
<GROUP>
{
String hint = getHint(token);
if (hint != null && hint.equals(HASH_GROUP_BY_HINT)) {
- gbc.setHashGroupByHint(true);
- }
- }
+ gbc.setHashGroupByHint(true);
+ }
+ }
<BY> (LOOKAHEAD(2) var = Variable()
{
newScope.addNewVarSymbolToScope(var.getVar());
} <ASSIGN>)?
- expr = Expression()
+ expr = Expression()
{
- GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
+ GbyVariableExpressionPair pair1 = new GbyVariableExpressionPair(var, expr);
vePairList.add(pair1);
}
(<COMMA> ( LOOKAHEAD(2) var = Variable()
{
newScope.addNewVarSymbolToScope(var.getVar());
} <ASSIGN>)?
- expr = Expression()
- {
- GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
+ expr = Expression()
+ {
+ GbyVariableExpressionPair pair2 = new GbyVariableExpressionPair(var, expr);
vePairList.add(pair2);
}
- )*
+ )*
(<DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
- {
- newScope.addNewVarSymbolToScope(decorVar.getVar());
+ {
+ newScope.addNewVarSymbolToScope(decorVar.getVar());
GbyVariableExpressionPair pair3 = new GbyVariableExpressionPair(decorVar, decorExpr);
decorPairList.add(pair3);
}
(<COMMA> <DECOR> decorVar = Variable() <ASSIGN> decorExpr = Expression()
- {
- newScope.addNewVarSymbolToScope(decorVar.getVar());
+ {
+ newScope.addNewVarSymbolToScope(decorVar.getVar());
GbyVariableExpressionPair pair4 = new GbyVariableExpressionPair(decorVar, decorExpr);
- decorPairList.add(pair4);
+ decorPairList.add(pair4);
}
- )*
- )?
+ )*
+ )?
(<WITH>|<KEEPING>) withVar = VariableRef()
{
if(withVar.getIsNewVar()==true)
- throw new ParseException("can't find variable " + withVar.getVar());
+ throw new ParseException("can't find variable " + withVar.getVar());
withVarList.add(withVar);
newScope.addNewVarSymbolToScope(withVar.getVar());
}
(<COMMA> withVar = VariableRef()
{
if(withVar.getIsNewVar()==true)
- throw new ParseException("can't find variable " + withVar.getVar());
+ throw new ParseException("can't find variable " + withVar.getVar());
withVarList.add(withVar);
newScope.addNewVarSymbolToScope(withVar.getVar());
})*
@@ -2157,16 +2162,16 @@
LimitClause LimitClause() throws ParseException:
{
- LimitClause lc = new LimitClause();
- Expression expr;
- pushForbiddenScope(getCurrentScope());
+ LimitClause lc = new LimitClause();
+ Expression expr;
+ pushForbiddenScope(getCurrentScope());
}
{
<LIMIT> expr = Expression() { lc.setLimitExpr(expr); }
(<OFFSET> expr = Expression() { lc.setOffset(expr); })?
{
- popForbiddenScope();
+ popForbiddenScope();
return lc;
}
}
@@ -2177,17 +2182,17 @@
Expression expr;
}
{
- <DISTINCT> <BY> expr = Expression()
+ <DISTINCT> <BY> expr = Expression()
{
exprs.add(expr);
}
- (<COMMA> expr = Expression()
- {
- exprs.add(expr);
- }
+ (<COMMA> expr = Expression()
+ {
+ exprs.add(expr);
+ }
)*
{
- return new DistinctClause(exprs);
+ return new DistinctClause(exprs);
}
}
@@ -2204,41 +2209,41 @@
{
createNewScope();
}
-
+
( (<SOME> { qc.setQuantifier(QuantifiedExpression.Quantifier.SOME); })
- | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
- var = Variable() <IN> inExpr = Expression()
- {
- pair = new QuantifiedPair(var, inExpr);
- getCurrentScope().addNewVarSymbolToScope(var.getVar());
- quantifiedList.add(pair);
- }
- (
- <COMMA> var = Variable() <IN> inExpr = Expression()
- {
+ | (<EVERY> { qc.setQuantifier(QuantifiedExpression.Quantifier.EVERY); }))
+ var = Variable() <IN> inExpr = Expression()
+ {
pair = new QuantifiedPair(var, inExpr);
getCurrentScope().addNewVarSymbolToScope(var.getVar());
- quantifiedList.add(pair);
- }
- )*
- <SATISFIES> satisfiesExpr = Expression()
- {
- qc.setSatisfiesExpr(satisfiesExpr);
- qc.setQuantifiedList(quantifiedList);
- removeCurrentScope();
- return qc;
- }
+ quantifiedList.add(pair);
+ }
+ (
+ <COMMA> var = Variable() <IN> inExpr = Expression()
+ {
+ pair = new QuantifiedPair(var, inExpr);
+ getCurrentScope().addNewVarSymbolToScope(var.getVar());
+ quantifiedList.add(pair);
+ }
+ )*
+ <SATISFIES> satisfiesExpr = Expression()
+ {
+ qc.setSatisfiesExpr(satisfiesExpr);
+ qc.setQuantifiedList(quantifiedList);
+ removeCurrentScope();
+ return qc;
+ }
}
TOKEN_MGR_DECLS:
{
public int commentDepth = 0;
public IntStack lexerStateStack = new IntStack();
-
+
public void pushState() {
lexerStateStack.push( curLexState );
}
-
+
public void popState(String token) {
if (lexerStateStack.size() > 0) {
SwitchTo( lexerStateStack.pop() );
@@ -2448,7 +2453,7 @@
<DEFAULT,IN_DBL_BRACE>
SKIP:
{
- <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
+ <"//" (~["\n","\r"])* ("\n"|"\r"|"\r\n")?>
}
<DEFAULT,IN_DBL_BRACE>