Adding support for accessing an item in list using non constant index
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlExpressionToPlanTranslator.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlExpressionToPlanTranslator.java
index 4e82d1c..c52f4d5 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlExpressionToPlanTranslator.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlExpressionToPlanTranslator.java
@@ -427,17 +427,16 @@
Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(ia.getExpr(), tupSource);
LogicalVariable v = context.newVar();
AbstractFunctionCallExpression f;
- int i = ia.getIndex();
- if (i == IndexAccessor.ANY) {
+ if (ia.isAny()) {
f = new ScalarFunctionCallExpression(
FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.ANY_COLLECTION_MEMBER));
f.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
} else {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> indexPair = aqlExprToAlgExpression(ia.getIndexExpr(), tupSource);
f = new ScalarFunctionCallExpression(FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.GET_ITEM));
f.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
f.getArguments().add(
- new MutableObject<ILogicalExpression>(new ConstantExpression(
- new AsterixConstantValue(new AInt32(i)))));
+ new MutableObject<ILogicalExpression>(indexPair.first));
}
AssignOperator a = new AssignOperator(v, new MutableObject<ILogicalExpression>(f));
a.getInputs().add(p.second);
diff --git a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlPlusExpressionToPlanTranslator.java b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlPlusExpressionToPlanTranslator.java
index 1b37303..0c7ff7d 100644
--- a/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlPlusExpressionToPlanTranslator.java
+++ b/asterix-algebra/src/main/java/edu/uci/ics/asterix/translator/AqlPlusExpressionToPlanTranslator.java
@@ -423,17 +423,16 @@
Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = aqlExprToAlgExpression(ia.getExpr(), tupSource);
LogicalVariable v = context.newVar();
AbstractFunctionCallExpression f;
- int i = ia.getIndex();
- if (i == IndexAccessor.ANY) {
+ if (ia.isAny()) {
f = new ScalarFunctionCallExpression(
FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.ANY_COLLECTION_MEMBER));
f.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
} else {
+ Pair<ILogicalExpression, Mutable<ILogicalOperator>> indexPair = aqlExprToAlgExpression(ia.getIndexExpr(), tupSource);
f = new ScalarFunctionCallExpression(FunctionUtils.getFunctionInfo(AsterixBuiltinFunctions.GET_ITEM));
f.getArguments().add(new MutableObject<ILogicalExpression>(p.first));
f.getArguments().add(
- new MutableObject<ILogicalExpression>(new ConstantExpression(
- new AsterixConstantValue(new AInt32(i)))));
+ new MutableObject<ILogicalExpression>(indexPair.first));
}
AssignOperator a = new AssignOperator(v, new MutableObject<ILogicalExpression>(f));
a.getInputs().add(p.second);
diff --git a/asterix-algebra/src/main/javacc/AQLPlus.jj b/asterix-algebra/src/main/javacc/AQLPlus.jj
index 95c6b2d..dd72de4 100644
--- a/asterix-algebra/src/main/javacc/AQLPlus.jj
+++ b/asterix-algebra/src/main/javacc/AQLPlus.jj
@@ -699,7 +699,7 @@
Expression expr = null;
Identifier ident = null;
AbstractAccessor fa = null;
- int index;
+ Expression indexExpr = null;
}
{
@@ -719,12 +719,12 @@
}
)
| (
- index = Index()
+ indexExpr = Index()
{
if(fa == null)
- fa = new IndexAccessor(expr, index);
+ fa = new IndexAccessor(expr, indexExpr);
else
- fa = new IndexAccessor(fa, index);
+ fa = new IndexAccessor(fa, indexExpr);
}
)
)*
@@ -751,10 +751,9 @@
}
}
-int Index() throws ParseException:
+Expression Index() throws ParseException:
{
Expression expr = null;
- int idx = -2;
}
{
"[" ( expr = Expression()
@@ -762,20 +761,15 @@
if(expr.getKind() == Expression.Kind.LITERAL_EXPRESSION)
{
Literal lit = ((LiteralExpr)expr).getValue();
- if(lit.getLiteralType() == Literal.Type.INTEGER ||
- lit.getLiteralType() == Literal.Type.LONG) {
- idx = Integer.valueOf(lit.getStringValue());
- }
- else {
+ if(lit.getLiteralType() != Literal.Type.INTEGER &&
+ lit.getLiteralType() != Literal.Type.LONG) {
throw new ParseException("Index should be an INTEGER");
}
}
-
}
| "?"
{
- idx = IndexAccessor.ANY;
// ANY
}
@@ -783,7 +777,7 @@
"]"
{
- return idx;
+ return expr;
}
}