use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.
the class LangExpressionToPlanTranslator method processReturningExpression.
// Stitches the translated operators for the returning expression into the query plan.
private ILogicalOperator processReturningExpression(ILogicalOperator inputOperator, InsertDeleteUpsertOperator insertOp, CompiledInsertStatement compiledInsert) throws AlgebricksException {
Expression returnExpression = compiledInsert.getReturnExpression();
if (returnExpression == null) {
return inputOperator;
}
ILogicalOperator rootOperator = inputOperator;
//Makes the id of the insert var point to the record variable.
context.newVarFromExpression(compiledInsert.getVar());
context.setVar(compiledInsert.getVar(), ((VariableReferenceExpression) insertOp.getPayloadExpression().getValue()).getVariableReference());
Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = langExprToAlgExpression(returnExpression, new MutableObject<>(rootOperator));
// Adds an assign operator for the returning expression.
LogicalVariable resultVar = context.newVar();
AssignOperator assignOperator = new AssignOperator(resultVar, new MutableObject<>(p.first));
assignOperator.getInputs().add(p.second);
// Adds a distribute result operator.
List<Mutable<ILogicalExpression>> expressions = new ArrayList<>();
expressions.add(new MutableObject<>(new VariableReferenceExpression(resultVar)));
ResultSetSinkId rssId = new ResultSetSinkId(metadataProvider.getResultSetId());
ResultSetDataSink sink = new ResultSetDataSink(rssId, null);
rootOperator = new DistributeResultOperator(expressions, sink);
rootOperator.getInputs().add(new MutableObject<>(assignOperator));
return rootOperator;
}
use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.
the class AqlExpressionToPlanTranslator method visit.
@Override
public Pair<ILogicalOperator, LogicalVariable> visit(DistinctClause dc, Mutable<ILogicalOperator> tupSource) throws CompilationException {
List<Mutable<ILogicalExpression>> exprList = new ArrayList<>();
Mutable<ILogicalOperator> input = null;
for (Expression expr : dc.getDistinctByExpr()) {
Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = langExprToAlgExpression(expr, tupSource);
exprList.add(new MutableObject<ILogicalExpression>(p.first));
input = p.second;
}
DistinctOperator opDistinct = new DistinctOperator(exprList);
opDistinct.getInputs().add(input);
return new Pair<>(opDistinct, null);
}
use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.
the class AqlExpressionToPlanTranslator method visit.
@Override
public Pair<ILogicalOperator, LogicalVariable> visit(ForClause fc, Mutable<ILogicalOperator> tupSource) throws CompilationException {
LogicalVariable v = context.newVarFromExpression(fc.getVarExpr());
Expression inExpr = fc.getInExpr();
Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(inExpr, tupSource);
ILogicalOperator returnedOp;
if (fc.getPosVarExpr() == null) {
returnedOp = new UnnestOperator(v, new MutableObject<ILogicalExpression>(makeUnnestExpression(eo.first)));
} else {
LogicalVariable pVar = context.newVarFromExpression(fc.getPosVarExpr());
// We set the positional variable type as INT64 type.
returnedOp = new UnnestOperator(v, new MutableObject<ILogicalExpression>(makeUnnestExpression(eo.first)), pVar, BuiltinType.AINT64, new PositionWriter());
}
returnedOp.getInputs().add(eo.second);
return new Pair<>(returnedOp, v);
}
use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.
the class LangExpressionToPlanTranslator method visit.
@Override
public Pair<ILogicalOperator, LogicalVariable> visit(ListConstructor lc, Mutable<ILogicalOperator> tupSource) throws CompilationException {
FunctionIdentifier fid = (lc.getType() == ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR) ? BuiltinFunctions.ORDERED_LIST_CONSTRUCTOR : BuiltinFunctions.UNORDERED_LIST_CONSTRUCTOR;
AbstractFunctionCallExpression f = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(fid));
LogicalVariable v1 = context.newVar();
AssignOperator a = new AssignOperator(v1, new MutableObject<>(f));
Mutable<ILogicalOperator> topOp = tupSource;
for (Expression expr : lc.getExprList()) {
Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(expr, topOp);
f.getArguments().add(new MutableObject<>(eo.first));
topOp = eo.second;
}
a.getInputs().add(topOp);
return new Pair<>(a, v1);
}
use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.
the class SqlppExpressionToPlanTranslator method generateUnnestForBinaryCorrelateRightBranch.
private Pair<ILogicalOperator, LogicalVariable> generateUnnestForBinaryCorrelateRightBranch(AbstractBinaryCorrelateClause binaryCorrelate, Mutable<ILogicalOperator> inputOpRef, boolean innerUnnest) throws CompilationException {
LogicalVariable rightVar = context.newVarFromExpression(binaryCorrelate.getRightVariable());
Expression rightExpr = binaryCorrelate.getRightExpression();
Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(rightExpr, inputOpRef);
ILogicalOperator unnestOp;
if (binaryCorrelate.hasPositionalVariable()) {
LogicalVariable pVar = context.newVarFromExpression(binaryCorrelate.getPositionalVariable());
// We set the positional variable type as BIGINT type.
unnestOp = innerUnnest ? new UnnestOperator(rightVar, new MutableObject<>(makeUnnestExpression(eo.first)), pVar, BuiltinType.AINT64, new PositionWriter()) : new LeftOuterUnnestOperator(rightVar, new MutableObject<>(makeUnnestExpression(eo.first)), pVar, BuiltinType.AINT64, new PositionWriter());
} else {
unnestOp = innerUnnest ? new UnnestOperator(rightVar, new MutableObject<>(makeUnnestExpression(eo.first))) : new LeftOuterUnnestOperator(rightVar, new MutableObject<>(makeUnnestExpression(eo.first)));
}
unnestOp.getInputs().add(eo.second);
return new Pair<>(unnestOp, rightVar);
}
Aggregations