@Override public AbstractLogicalExpression cloneExpression() { Map<Object, IExpressionAnnotation> m = new HashMap<>(); annotationMap.forEach((key, value1) -> m.put(key, value1.copy())); ConstantExpression c = new ConstantExpression(value); c.annotationMap = m; c.setSourceLocation(sourceLoc); return c; }
/** * Whether the condition expression always returns true. * * @param cond * @return true if the condition always holds; false otherwise. */ private boolean alwaysHold(ILogicalExpression cond) { if (cond.equals(ConstantExpression.TRUE)) { return true; } if (cond.equals(new ConstantExpression(new AsterixConstantValue(ABoolean.TRUE)))) { return true; } return false; } }
@Override public ILogicalExpression visitConstantExpression(ConstantExpression expr, Void arg) throws AlgebricksException { ConstantExpression exprCopy = new ConstantExpression(expr.getValue()); copySourceLocation(expr, exprCopy); return exprCopy; }
private static Mutable<ILogicalExpression> constantToMutableLogicalExpression(IAObject constantObject) { return new MutableObject<>(new ConstantExpression(new AsterixConstantValue(constantObject))); }
private ConstantExpression createConstantExpression(IAObject value, SourceLocation sourceLoc) { ConstantExpression constExpr = new ConstantExpression(new AsterixConstantValue(value)); constExpr.setSourceLocation(sourceLoc); return constExpr; } }
protected void writeVarList(List<LogicalVariable> varList, List<Mutable<ILogicalExpression>> funcArgs) { Mutable<ILogicalExpression> numKeysRef = new MutableObject<>(new ConstantExpression(new AsterixConstantValue(new AInt32(varList.size())))); funcArgs.add(numKeysRef); for (LogicalVariable keyVar : varList) { VariableReferenceExpression keyVarRef = new VariableReferenceExpression(keyVar); funcArgs.add(new MutableObject<>(keyVarRef)); } }
public static ConstantExpression createBooleanConstant(boolean b) { return new ConstantExpression(new AsterixConstantValue(ABoolean.valueOf(b))); }
private static void addStringArg(String argument, List<Mutable<ILogicalExpression>> funcArgs) { Mutable<ILogicalExpression> stringRef = new MutableObject<>(new ConstantExpression(new AsterixConstantValue(new AString(argument)))); funcArgs.add(stringRef); }
private static void writeVarList(List<LogicalVariable> varList, List<Mutable<ILogicalExpression>> funcArgs) { Mutable<ILogicalExpression> numKeysRef = new MutableObject<>(new ConstantExpression(new AsterixConstantValue(new AInt32(varList.size())))); funcArgs.add(numKeysRef); for (LogicalVariable keyVar : varList) { Mutable<ILogicalExpression> keyVarRef = new MutableObject<>(new VariableReferenceExpression(keyVar)); funcArgs.add(keyVarRef); } }
private static ScalarFunctionCallExpression createFieldAccessExpression(ILogicalExpression target, List<String> field, SourceLocation sourceLoc) { FunctionIdentifier functionIdentifier; IAObject value; if (field.size() > 1) { functionIdentifier = BuiltinFunctions.FIELD_ACCESS_NESTED; value = new AOrderedList(field); } else { functionIdentifier = BuiltinFunctions.FIELD_ACCESS_BY_NAME; value = new AString(field.get(0)); } IFunctionInfo finfoAccess = FunctionUtil.getFunctionInfo(functionIdentifier); ScalarFunctionCallExpression faExpr = new ScalarFunctionCallExpression(finfoAccess, new MutableObject<>(target), new MutableObject<>(new ConstantExpression(new AsterixConstantValue(value)))); faExpr.setSourceLocation(sourceLoc); return faExpr; } }
/** * Sets the default option value(s) when a user doesn't provide any option. */ void setDefaultValueForThirdParameter(List<Mutable<ILogicalExpression>> newArgs) throws AlgebricksException { // Sets the search mode option: the default option is conjunctive search. ILogicalExpression searchModeOptionExpr = new ConstantExpression( new AsterixConstantValue(new AString(FullTextContainsDescriptor.SEARCH_MODE_OPTION))); ILogicalExpression searchModeValExpr = new ConstantExpression( new AsterixConstantValue(new AString(FullTextContainsDescriptor.CONJUNCTIVE_SEARCH_MODE_OPTION))); // Add this option as arguments to the ftcontains(). newArgs.add(new MutableObject<ILogicalExpression>(searchModeOptionExpr)); newArgs.add(new MutableObject<ILogicalExpression>(searchModeValExpr)); }
public static ConstantExpression createInt32Constant(int i) { return new ConstantExpression(new AsterixConstantValue(new AInt32(i))); }
public static void prepareMetaKeyAccessExpression(List<String> field, LogicalVariable resVar, List<Mutable<ILogicalExpression>> assignExpressions, List<LogicalVariable> vars, List<Mutable<ILogicalExpression>> varRefs, IVariableContext context, SourceLocation sourceLoc) { IAObject value = (field.size() > 1) ? new AOrderedList(field) : new AString(field.get(0)); ScalarFunctionCallExpression metaKeyFunction = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.META_KEY)); metaKeyFunction.setSourceLocation(sourceLoc); VariableReferenceExpression resVarRef = new VariableReferenceExpression(resVar); resVarRef.setSourceLocation(sourceLoc); metaKeyFunction.getArguments().add(new MutableObject<ILogicalExpression>(resVarRef)); metaKeyFunction.getArguments() .add(new MutableObject<>(new ConstantExpression(new AsterixConstantValue(value)))); assignExpressions.add(new MutableObject<ILogicalExpression>(metaKeyFunction)); LogicalVariable v = context.newVar(); vars.add(v); if (varRefs != null) { VariableReferenceExpression vRef = new VariableReferenceExpression(v); vRef.setSourceLocation(sourceLoc); varRefs.add(new MutableObject<ILogicalExpression>(vRef)); } }
private static AbstractFunctionCallExpression getClosedFieldAccessFunction(Mutable<ILogicalExpression> varRef, int position, SourceLocation sourceLoc) { Mutable<ILogicalExpression> indexRef = new MutableObject<>(new ConstantExpression(new AsterixConstantValue(new AInt32(position)))); ScalarFunctionCallExpression fnExpr = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_INDEX), varRef, indexRef); fnExpr.setSourceLocation(sourceLoc); return fnExpr; }
public static ConstantExpression createStringConstant(String str) { return new ConstantExpression(new AsterixConstantValue(new AString(str))); }
@SuppressWarnings("unchecked") private static ILogicalExpression createFieldAccessByIndex(ARecordType recType, AbstractFunctionCallExpression fce) { String s = ConstantExpressionUtil.getStringArgument(fce, 1); if (s == null) { return null; } int k = recType.getFieldIndex(s); if (k < 0) { return null; } ScalarFunctionCallExpression faExpr = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_INDEX), fce.getArguments().get(0), new MutableObject<>(new ConstantExpression(new AsterixConstantValue(new AInt32(k))))); faExpr.setSourceLocation(fce.getSourceLocation()); return faExpr; } }
@Override public Pair<ILogicalOperator, LogicalVariable> visit(LiteralExpr l, Mutable<ILogicalOperator> tupSource) { SourceLocation sourceLoc = l.getSourceLocation(); LogicalVariable var = context.newVar(); AsterixConstantValue cValue = new AsterixConstantValue(ConstantHelper.objectFromLiteral(l.getValue())); ConstantExpression cExpr = new ConstantExpression(cValue); cExpr.setSourceLocation(sourceLoc); AssignOperator a = new AssignOperator(var, new MutableObject<>(cExpr)); a.setSourceLocation(sourceLoc); if (tupSource != null) { a.getInputs().add(tupSource); } return new Pair<>(a, var); }
private ILogicalExpression translateConstantValue(IAObject value, SourceLocation sourceLoc) throws CompilationException { ConstantExpression constExpr = new ConstantExpression(new AsterixConstantValue(value)); constExpr.setSourceLocation(sourceLoc); IAType valueType = value.getType(); if (valueType.getTypeTag().isDerivedType()) { ScalarFunctionCallExpression castExpr = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.CAST_TYPE)); castExpr.setSourceLocation(sourceLoc); castExpr.getArguments().add(new MutableObject<>(constExpr)); TypeCastUtils.setRequiredAndInputTypes(castExpr, BuiltinType.ANY, valueType); return castExpr; } else { return constExpr; } }
private AssignOperator processExists(ILogicalExpression inputExpr, LogicalVariable v1, boolean not, SourceLocation sourceLoc) { AbstractFunctionCallExpression count = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.SCALAR_COUNT)); count.getArguments().add(new MutableObject<>(inputExpr)); count.setSourceLocation(sourceLoc); AbstractFunctionCallExpression comparison = new ScalarFunctionCallExpression( FunctionUtil.getFunctionInfo(not ? BuiltinFunctions.EQ : BuiltinFunctions.NEQ)); ConstantExpression eZero = new ConstantExpression(new AsterixConstantValue(new AInt64(0L))); eZero.setSourceLocation(sourceLoc); comparison.getArguments().add(new MutableObject<>(count)); comparison.getArguments().add(new MutableObject<>(eZero)); comparison.setSourceLocation(sourceLoc); AssignOperator a = new AssignOperator(v1, new MutableObject<>(comparison)); a.setSourceLocation(sourceLoc); return a; }
@Override public Pair<ILogicalOperator, LogicalVariable> visit(FieldAccessor fa, Mutable<ILogicalOperator> tupSource) throws CompilationException { SourceLocation sourceLoc = fa.getSourceLocation(); Pair<ILogicalExpression, Mutable<ILogicalOperator>> p = langExprToAlgExpression(fa.getExpr(), tupSource); LogicalVariable v = context.newVarFromExpression(fa); AbstractFunctionCallExpression fldAccess = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_NAME)); fldAccess.setSourceLocation(sourceLoc); fldAccess.getArguments().add(new MutableObject<>(p.first)); ConstantExpression faExpr = new ConstantExpression(new AsterixConstantValue(new AString(fa.getIdent().getValue()))); faExpr.setSourceLocation(sourceLoc); fldAccess.getArguments().add(new MutableObject<>(faExpr)); AssignOperator a = new AssignOperator(v, new MutableObject<>(fldAccess)); a.getInputs().add(p.second); a.setSourceLocation(sourceLoc); return new Pair<>(a, v); }