use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.
the class GatherFunctionCallsVisitor method visit.
@Override
public Void visit(InsertStatement wc, Void arg) throws CompilationException {
wc.getQuery().accept(this, arg);
Expression returnExpression = wc.getReturnExpression();
if (returnExpression != null) {
returnExpression.accept(this, arg);
}
return null;
}
use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.
the class QueryPrintVisitor method visit.
@Override
public Void visit(GroupbyClause gc, Integer step) throws CompilationException {
out.println(skip(step) + "Groupby");
for (GbyVariableExpressionPair pair : gc.getGbyPairList()) {
if (pair.getVar() != null) {
pair.getVar().accept(this, step + 1);
out.println(skip(step + 1) + ":=");
}
pair.getExpr().accept(this, step + 1);
}
if (gc.hasDecorList()) {
out.println(skip(step + 1) + "Decor");
for (GbyVariableExpressionPair pair : gc.getDecorPairList()) {
if (pair.getVar() != null) {
pair.getVar().accept(this, step + 1);
out.println(skip(step + 1) + ":=");
}
pair.getExpr().accept(this, step + 1);
}
}
if (gc.hasWithMap()) {
out.println(skip(step + 1) + "With");
for (Entry<Expression, VariableExpr> entry : gc.getWithVarMap().entrySet()) {
Expression key = entry.getKey();
VariableExpr value = entry.getValue();
key.accept(this, step + 1);
if (!key.equals(value)) {
out.println(skip(step + 1) + "AS");
value.accept(this, step + 1);
}
}
}
out.println();
return null;
}
use of org.apache.asterix.lang.common.base.Expression in project asterixdb by apache.
the class QueryPrintVisitor method visit.
@Override
public Void visit(CallExpr pf, Integer step) throws CompilationException {
out.println(skip(step) + "FunctionCall " + pf.getFunctionSignature().toString() + "[");
for (Expression expr : pf.getExprList()) {
expr.accept(this, step + 1);
}
out.println(skip(step) + "]");
return null;
}
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(CallExpr fcall, Mutable<ILogicalOperator> tupSource) throws CompilationException {
LogicalVariable v = context.newVar();
FunctionSignature signature = fcall.getFunctionSignature();
List<Mutable<ILogicalExpression>> args = new ArrayList<>();
Mutable<ILogicalOperator> topOp = tupSource;
for (Expression expr : fcall.getExprList()) {
switch(expr.getKind()) {
case VARIABLE_EXPRESSION:
LogicalVariable var = context.getVar(((VariableExpr) expr).getVar().getId());
args.add(new MutableObject<>(new VariableReferenceExpression(var)));
break;
case LITERAL_EXPRESSION:
LiteralExpr val = (LiteralExpr) expr;
args.add(new MutableObject<>(new ConstantExpression(new AsterixConstantValue(ConstantHelper.objectFromLiteral(val.getValue())))));
break;
default:
Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(expr, topOp);
AbstractLogicalOperator o1 = (AbstractLogicalOperator) eo.second.getValue();
args.add(new MutableObject<>(eo.first));
if (o1 != null && !(o1.getOperatorTag() == LogicalOperatorTag.ASSIGN && hasOnlyChild(o1, topOp))) {
topOp = eo.second;
}
break;
}
}
AbstractFunctionCallExpression f;
if ((f = lookupUserDefinedFunction(signature, args)) == null) {
f = lookupBuiltinFunction(signature.getName(), signature.getArity(), args);
}
if (f == null) {
throw new CompilationException(" Unknown function " + signature.getName() + "@" + signature.getArity());
}
// Put hints into function call expr.
if (fcall.hasHints()) {
for (IExpressionAnnotation hint : fcall.getHints()) {
f.getAnnotations().put(hint, hint);
}
}
AssignOperator op = new AssignOperator(v, new MutableObject<>(f));
if (topOp != null) {
op.getInputs().add(topOp);
}
return new Pair<>(op, 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(OrderbyClause oc, Mutable<ILogicalOperator> tupSource) throws CompilationException {
OrderOperator ord = new OrderOperator();
Iterator<OrderModifier> modifIter = oc.getModifierList().iterator();
Mutable<ILogicalOperator> topOp = tupSource;
for (Expression e : oc.getOrderbyList()) {
Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = langExprToAlgExpression(e, topOp);
OrderModifier m = modifIter.next();
OrderOperator.IOrder comp = (m == OrderModifier.ASC) ? OrderOperator.ASC_ORDER : OrderOperator.DESC_ORDER;
ord.getOrderExpressions().add(new Pair<>(comp, new MutableObject<>(p.first)));
topOp = p.second;
}
ord.getInputs().add(topOp);
if (oc.getNumTuples() > 0) {
ord.getAnnotations().put(OperatorAnnotations.CARDINALITY, oc.getNumTuples());
}
if (oc.getNumFrames() > 0) {
ord.getAnnotations().put(OperatorAnnotations.MAX_NUMBER_FRAMES, oc.getNumFrames());
}
if (oc.getRangeMap() != null) {
Iterator<OrderModifier> orderModifIter = oc.getModifierList().iterator();
boolean ascending = (orderModifIter.next() == OrderModifier.ASC);
RangeMapBuilder.verifyRangeOrder(oc.getRangeMap(), ascending);
ord.getAnnotations().put(OperatorAnnotations.USE_RANGE_CONNECTOR, oc.getRangeMap());
}
return new Pair<>(ord, null);
}
Aggregations