use of org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation in project asterixdb by apache.
the class LogicalExpressionDeepCopyWithNewVariablesVisitor method deepCopyAnnotations.
private void deepCopyAnnotations(AbstractFunctionCallExpression src, AbstractFunctionCallExpression dest) {
Map<Object, IExpressionAnnotation> srcAnnotations = src.getAnnotations();
Map<Object, IExpressionAnnotation> destAnnotations = dest.getAnnotations();
for (Map.Entry<Object, IExpressionAnnotation> annotationEntry : srcAnnotations.entrySet()) {
IExpressionAnnotation annotation = annotationEntry.getValue().copy();
destAnnotations.put(annotationEntry.getKey(), annotation);
}
}
use of org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation 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.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation 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.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation in project asterixdb by apache.
the class OperatorExpressionVisitor method createLessThanExpression.
private Expression createLessThanExpression(Expression lhs, Expression rhs, List<IExpressionAnnotation> hints) throws CompilationException {
OperatorExpr comparison = new OperatorExpr();
comparison.addOperand(lhs);
comparison.addOperand(rhs);
comparison.addOperator("<=");
if (hints != null) {
for (IExpressionAnnotation hint : hints) {
comparison.addHint(hint);
}
}
return comparison;
}
use of org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionAnnotation in project asterixdb by apache.
the class JoinUtils method getBroadcastJoinSide.
private static BroadcastSide getBroadcastJoinSide(ILogicalExpression e, List<LogicalVariable> varsLeft, List<LogicalVariable> varsRight) {
if (e.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
return null;
}
AbstractFunctionCallExpression fexp = (AbstractFunctionCallExpression) e;
IExpressionAnnotation ann = fexp.getAnnotations().get(BroadcastExpressionAnnotation.BROADCAST_ANNOTATION_KEY);
if (ann == null) {
return null;
}
BroadcastSide side = (BroadcastSide) ann.getObject();
if (side == null) {
return null;
}
int i;
switch(side) {
case LEFT:
i = 0;
break;
case RIGHT:
i = 1;
break;
default:
return null;
}
ArrayList<LogicalVariable> vars = new ArrayList<>();
fexp.getArguments().get(i).getValue().getUsedVariables(vars);
if (varsLeft.containsAll(vars)) {
return BroadcastSide.LEFT;
} else if (varsRight.containsAll(vars)) {
return BroadcastSide.RIGHT;
} else {
return null;
}
}
Aggregations