use of org.apache.asterix.lang.common.struct.OperatorType in project asterixdb by apache.
the class OperatorExpressionVisitor method visit.
@Override
public Expression visit(OperatorExpr operatorExpr, ILangExpression arg) throws CompilationException {
List<Expression> newExprList = new ArrayList<>();
for (Expression expr : operatorExpr.getExprList()) {
newExprList.add(expr.accept(this, operatorExpr));
}
operatorExpr.setExprList(newExprList);
OperatorType opType = operatorExpr.getOpList().get(0);
switch(opType) {
// There can only be one LIKE/NOT_LIKE/IN/NOT_IN in an operator expression (according to the grammar).
case LIKE:
case NOT_LIKE:
return processLikeOperator(operatorExpr, opType);
case IN:
case NOT_IN:
return processInOperator(operatorExpr, opType);
case CONCAT:
// There can be multiple "||"s in one operator expression (according to the grammar).
return processConcatOperator(operatorExpr);
case BETWEEN:
case NOT_BETWEEN:
return processBetweenOperator(operatorExpr, opType);
default:
break;
}
return operatorExpr;
}
use of org.apache.asterix.lang.common.struct.OperatorType in project asterixdb by apache.
the class LangExpressionToPlanTranslator method visit.
@Override
public Pair<ILogicalOperator, LogicalVariable> visit(OperatorExpr op, Mutable<ILogicalOperator> tupSource) throws CompilationException {
List<OperatorType> ops = op.getOpList();
int nOps = ops.size();
if (nOps > 0 && (ops.get(0) == OperatorType.AND || ops.get(0) == OperatorType.OR)) {
return visitAndOrOperator(op, tupSource);
}
List<Expression> exprs = op.getExprList();
Mutable<ILogicalOperator> topOp = tupSource;
ILogicalExpression currExpr = null;
for (int i = 0; i <= nOps; i++) {
Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = langExprToAlgExpression(exprs.get(i), topOp);
topOp = p.second;
ILogicalExpression e = p.first;
// now look at the operator
if (i < nOps) {
if (OperatorExpr.opIsComparison(ops.get(i))) {
AbstractFunctionCallExpression c = createComparisonExpression(ops.get(i));
// chain the operators
if (i == 0) {
c.getArguments().add(new MutableObject<>(e));
currExpr = c;
if (op.isBroadcastOperand(i)) {
BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
bcast.setObject(BroadcastSide.LEFT);
c.getAnnotations().put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
}
} else {
((AbstractFunctionCallExpression) currExpr).getArguments().add(new MutableObject<>(e));
c.getArguments().add(new MutableObject<>(currExpr));
currExpr = c;
if (i == 1 && op.isBroadcastOperand(i)) {
BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
bcast.setObject(BroadcastSide.RIGHT);
c.getAnnotations().put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
}
}
} else {
AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(ops.get(i));
if (i == 0) {
f.getArguments().add(new MutableObject<>(e));
currExpr = f;
} else {
((AbstractFunctionCallExpression) currExpr).getArguments().add(new MutableObject<>(e));
f.getArguments().add(new MutableObject<>(currExpr));
currExpr = f;
}
}
} else {
// don't forget the last expression...
((AbstractFunctionCallExpression) currExpr).getArguments().add(new MutableObject<>(e));
if (i == 1 && op.isBroadcastOperand(i)) {
BroadcastExpressionAnnotation bcast = new BroadcastExpressionAnnotation();
bcast.setObject(BroadcastSide.RIGHT);
((AbstractFunctionCallExpression) currExpr).getAnnotations().put(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY, bcast);
}
}
}
// Add hints as annotations.
if (op.hasHints() && (currExpr instanceof AbstractFunctionCallExpression)) {
AbstractFunctionCallExpression currFuncExpr = (AbstractFunctionCallExpression) currExpr;
for (IExpressionAnnotation hint : op.getHints()) {
currFuncExpr.getAnnotations().put(hint, hint);
}
}
LogicalVariable assignedVar = context.newVar();
AssignOperator a = new AssignOperator(assignedVar, new MutableObject<>(currExpr));
a.getInputs().add(topOp);
return new Pair<>(a, assignedVar);
}
use of org.apache.asterix.lang.common.struct.OperatorType in project asterixdb by apache.
the class LangExpressionToPlanTranslator method visitAndOrOperator.
protected Pair<ILogicalOperator, LogicalVariable> visitAndOrOperator(OperatorExpr op, Mutable<ILogicalOperator> tupSource) throws CompilationException {
List<OperatorType> ops = op.getOpList();
int nOps = ops.size();
List<Expression> exprs = op.getExprList();
Mutable<ILogicalOperator> topOp = tupSource;
OperatorType opLogical = ops.get(0);
AbstractFunctionCallExpression f = createFunctionCallExpressionForBuiltinOperator(opLogical);
for (int i = 0; i <= nOps; i++) {
Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = langExprToAlgExpression(exprs.get(i), topOp);
topOp = p.second;
// now look at the operator
if (i < nOps && ops.get(i) != opLogical) {
throw new TranslationException("Unexpected operator " + ops.get(i) + " in an OperatorExpr starting with " + opLogical);
}
f.getArguments().add(new MutableObject<>(p.first));
}
LogicalVariable assignedVar = context.newVar();
AssignOperator a = new AssignOperator(assignedVar, new MutableObject<>(f));
a.getInputs().add(topOp);
return new Pair<>(a, assignedVar);
}
use of org.apache.asterix.lang.common.struct.OperatorType in project asterixdb by apache.
the class FormatPrintVisitor method visit.
@Override
public Void visit(OperatorExpr operatorExpr, Integer step) throws CompilationException {
List<Expression> exprList = operatorExpr.getExprList();
List<OperatorType> opList = operatorExpr.getOpList();
if (operatorExpr.isCurrentop()) {
out.print("(");
exprList.get(0).accept(this, step + 1);
for (int i = 1; i < exprList.size(); i++) {
OperatorType opType = opList.get(i - 1);
;
if (i == 1) {
printHints(operatorExpr.getHints(), step + 1);
}
out.print(" " + opType + " ");
exprList.get(i).accept(this, step + 1);
}
out.print(")");
} else {
exprList.get(0).accept(this, step);
}
return null;
}
Aggregations