use of org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression 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.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression in project asterixdb by apache.
the class IntroduceAutogenerateIDRule method createRecordMergeFunction.
private AbstractFunctionCallExpression createRecordMergeFunction(ILogicalExpression rec0, ILogicalExpression rec1) {
List<Mutable<ILogicalExpression>> recordMergeFnArgs = new ArrayList<>();
recordMergeFnArgs.add(new MutableObject<>(rec0));
recordMergeFnArgs.add(new MutableObject<>(rec1));
AbstractFunctionCallExpression recordMergeFn = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.RECORD_MERGE), recordMergeFnArgs);
return recordMergeFn;
}
use of org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression in project asterixdb by apache.
the class IntroduceAutogenerateIDRule method createNotNullFunction.
private ILogicalExpression createNotNullFunction(ILogicalExpression mergedRec) {
List<Mutable<ILogicalExpression>> args = new ArrayList<>();
args.add(new MutableObject<ILogicalExpression>(mergedRec));
AbstractFunctionCallExpression notNullFn = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.CHECK_UNKNOWN), args);
return notNullFn;
}
use of org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression in project asterixdb by apache.
the class IntroduceDynamicTypeCastForExternalFunctionRule method rewriteFunctionArgs.
private boolean rewriteFunctionArgs(ILogicalOperator op, Mutable<ILogicalExpression> expRef, IOptimizationContext context) throws AlgebricksException {
ILogicalExpression expr = expRef.getValue();
if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL || !(expr instanceof ScalarFunctionCallExpression)) {
return false;
}
ScalarFunctionCallExpression funcCallExpr = (ScalarFunctionCallExpression) expr;
boolean changed = false;
IAType inputRecordType;
ARecordType requiredRecordType;
for (int iter1 = 0; iter1 < funcCallExpr.getArguments().size(); iter1++) {
inputRecordType = (IAType) op.computeOutputTypeEnvironment(context).getType(funcCallExpr.getArguments().get(iter1).getValue());
if (!(((ExternalScalarFunctionInfo) funcCallExpr.getFunctionInfo()).getArgumenTypes().get(iter1) instanceof ARecordType)) {
continue;
}
requiredRecordType = (ARecordType) ((ExternalScalarFunctionInfo) funcCallExpr.getFunctionInfo()).getArgumenTypes().get(iter1);
/**
* the input record type can be an union type
* for the case when it comes from a subplan or left-outer join
*/
boolean checkUnknown = false;
while (NonTaggedFormatUtil.isOptional(inputRecordType)) {
/** while-loop for the case there is a nested multi-level union */
inputRecordType = ((AUnionType) inputRecordType).getActualType();
checkUnknown = true;
}
boolean castFlag = !IntroduceDynamicTypeCastRule.compatible(requiredRecordType, inputRecordType);
if (castFlag || checkUnknown) {
AbstractFunctionCallExpression castFunc = new ScalarFunctionCallExpression(FunctionUtil.getFunctionInfo(BuiltinFunctions.CAST_TYPE));
castFunc.getArguments().add(funcCallExpr.getArguments().get(iter1));
TypeCastUtils.setRequiredAndInputTypes(castFunc, requiredRecordType, inputRecordType);
funcCallExpr.getArguments().set(iter1, new MutableObject<>(castFunc));
changed = changed || true;
}
}
return changed;
}
use of org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression in project asterixdb by apache.
the class AsterixIntroduceGroupByCombinerRule method processNullTest.
@SuppressWarnings("unchecked")
@Override
protected void processNullTest(IOptimizationContext context, GroupByOperator nestedGby, List<LogicalVariable> aggregateVarsProducedByCombiner) {
IFunctionInfo finfoEq = context.getMetadataProvider().lookupFunction(BuiltinFunctions.IS_SYSTEM_NULL);
SelectOperator selectNonSystemNull;
if (aggregateVarsProducedByCombiner.size() == 1) {
ILogicalExpression isSystemNullTest = new ScalarFunctionCallExpression(finfoEq, new MutableObject<ILogicalExpression>(new VariableReferenceExpression(aggregateVarsProducedByCombiner.get(0))));
IFunctionInfo finfoNot = context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.NOT);
ScalarFunctionCallExpression nonSystemNullTest = new ScalarFunctionCallExpression(finfoNot, new MutableObject<ILogicalExpression>(isSystemNullTest));
selectNonSystemNull = new SelectOperator(new MutableObject<ILogicalExpression>(nonSystemNullTest), false, null);
} else {
List<Mutable<ILogicalExpression>> isSystemNullTestList = new ArrayList<Mutable<ILogicalExpression>>();
for (LogicalVariable aggVar : aggregateVarsProducedByCombiner) {
ILogicalExpression isSystemNullTest = new ScalarFunctionCallExpression(finfoEq, new MutableObject<ILogicalExpression>(new VariableReferenceExpression(aggVar)));
IFunctionInfo finfoNot = context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.NOT);
ScalarFunctionCallExpression nonSystemNullTest = new ScalarFunctionCallExpression(finfoNot, new MutableObject<ILogicalExpression>(isSystemNullTest));
isSystemNullTestList.add(new MutableObject<ILogicalExpression>(nonSystemNullTest));
}
IFunctionInfo finfoAnd = context.getMetadataProvider().lookupFunction(AlgebricksBuiltinFunctions.AND);
selectNonSystemNull = new SelectOperator(new MutableObject<ILogicalExpression>(new ScalarFunctionCallExpression(finfoAnd, isSystemNullTestList)), false, null);
}
//add the not-system-null check into the nested pipeline
Mutable<ILogicalOperator> ntsBeforeNestedGby = nestedGby.getInputs().get(0);
nestedGby.getInputs().set(0, new MutableObject<ILogicalOperator>(selectNonSystemNull));
selectNonSystemNull.getInputs().add(ntsBeforeNestedGby);
}
Aggregations