use of org.apache.asterix.om.constants.AsterixConstantValue in project asterixdb by apache.
the class IntroduceAutogenerateIDRule method createPrimaryKeyRecordExpression.
private AbstractFunctionCallExpression createPrimaryKeyRecordExpression(List<String> pkFieldName) {
//Create lowest level of nested uuid
AbstractFunctionCallExpression uuidFn = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.CREATE_UUID));
List<Mutable<ILogicalExpression>> openRecordConsArgs = new ArrayList<>();
Mutable<ILogicalExpression> pkFieldNameExpression = new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(new AString(pkFieldName.get(pkFieldName.size() - 1)))));
openRecordConsArgs.add(pkFieldNameExpression);
Mutable<ILogicalExpression> pkFieldValueExpression = new MutableObject<ILogicalExpression>(uuidFn);
openRecordConsArgs.add(pkFieldValueExpression);
AbstractFunctionCallExpression openRecFn = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR), openRecordConsArgs);
//Create higher levels
for (int i = pkFieldName.size() - 2; i > -1; i--) {
AString fieldName = new AString(pkFieldName.get(i));
openRecordConsArgs = new ArrayList<>();
openRecordConsArgs.add(new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(fieldName))));
openRecordConsArgs.add(new MutableObject<ILogicalExpression>(openRecFn));
openRecFn = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.OPEN_RECORD_CONSTRUCTOR), openRecordConsArgs);
}
return openRecFn;
}
use of org.apache.asterix.om.constants.AsterixConstantValue in project asterixdb by apache.
the class LoadRecordFieldsRule method findAndEliminateRedundantFieldAccess.
/**
* Rewrite
* assign $x := field-access($y, "field")
* assign $y := record-constructor { "field": Expr, ... }
* into
* assign $x := Expr
* assign $y := record-constructor { "field": Expr, ... }
*/
private static boolean findAndEliminateRedundantFieldAccess(AssignOperator assign, IOptimizationContext context) throws AlgebricksException {
ILogicalExpression expr = getFirstExpr(assign);
AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expr;
ILogicalExpression arg0 = f.getArguments().get(0).getValue();
if (arg0.getExpressionTag() != LogicalExpressionTag.VARIABLE) {
return false;
}
VariableReferenceExpression vre = (VariableReferenceExpression) arg0;
LogicalVariable recordVar = vre.getVariableReference();
ILogicalExpression arg1 = f.getArguments().get(1).getValue();
if (arg1.getExpressionTag() != LogicalExpressionTag.CONSTANT) {
return false;
}
IVariableTypeEnvironment typeEnvironment = context.getOutputTypeEnvironment(assign);
ConstantExpression ce = (ConstantExpression) arg1;
ILogicalExpression fldExpr;
if (f.getFunctionIdentifier().equals(BuiltinFunctions.FIELD_ACCESS_BY_NAME)) {
String fldName = ((AString) ((AsterixConstantValue) ce.getValue()).getObject()).getStringValue();
fldExpr = findFieldExpression(assign, recordVar, fldName, typeEnvironment, (name, expression, env) -> findFieldByNameFromRecordConstructor(name, expression));
} else if (f.getFunctionIdentifier().equals(BuiltinFunctions.FIELD_ACCESS_BY_INDEX)) {
Integer fldIdx = ((AInt32) ((AsterixConstantValue) ce.getValue()).getObject()).getIntegerValue();
fldExpr = findFieldExpression(assign, recordVar, fldIdx, typeEnvironment, LoadRecordFieldsRule::findFieldByIndexFromRecordConstructor);
} else if (f.getFunctionIdentifier().equals(BuiltinFunctions.FIELD_ACCESS_NESTED)) {
return false;
} else {
throw new IllegalStateException();
}
if (fldExpr == null) {
return false;
}
// check the liveness of the new expression
List<LogicalVariable> usedVariables = new ArrayList<>();
fldExpr.getUsedVariables(usedVariables);
List<LogicalVariable> liveInputVars = new ArrayList<>();
VariableUtilities.getLiveVariables(assign, liveInputVars);
usedVariables.removeAll(liveInputVars);
if (usedVariables.isEmpty()) {
assign.getExpressions().get(0).setValue(fldExpr);
return true;
} else {
return false;
}
}
use of org.apache.asterix.om.constants.AsterixConstantValue in project asterixdb by apache.
the class PlanTranslationUtil method createFieldAccessExpression.
private static ScalarFunctionCallExpression createFieldAccessExpression(ILogicalExpression target, List<String> field) {
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);
return new ScalarFunctionCallExpression(finfoAccess, new MutableObject<>(target), new MutableObject<>(new ConstantExpression(new AsterixConstantValue(value))));
}
use of org.apache.asterix.om.constants.AsterixConstantValue in project asterixdb by apache.
the class LangExpressionToPlanTranslator method processExists.
// Processes EXISTS and NOT EXISTS.
private AssignOperator processExists(ILogicalExpression inputExpr, LogicalVariable v1, boolean not) {
AbstractFunctionCallExpression count = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.SCALAR_COUNT));
count.getArguments().add(new MutableObject<>(inputExpr));
AbstractFunctionCallExpression comparison = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(not ? BuiltinFunctions.EQ : BuiltinFunctions.NEQ));
comparison.getArguments().add(new MutableObject<>(count));
comparison.getArguments().add(new MutableObject<>(new ConstantExpression(new AsterixConstantValue(new AInt64(0L)))));
return new AssignOperator(v1, new MutableObject<>(comparison));
}
use of org.apache.asterix.om.constants.AsterixConstantValue in project asterixdb by apache.
the class LangExpressionToPlanTranslator method visit.
@Override
public Pair<ILogicalOperator, LogicalVariable> visit(FieldAccessor fa, Mutable<ILogicalOperator> tupSource) throws CompilationException {
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.getArguments().add(new MutableObject<>(p.first));
ILogicalExpression faExpr = new ConstantExpression(new AsterixConstantValue(new AString(fa.getIdent().getValue())));
fldAccess.getArguments().add(new MutableObject<>(faExpr));
AssignOperator a = new AssignOperator(v, new MutableObject<>(fldAccess));
a.getInputs().add(p.second);
return new Pair<>(a, v);
}
Aggregations