use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.
the class RemoveLeftOuterUnnestForLeftOuterJoinRule method checkSelect.
// Checks the expression for the nested select operator inside the group-by operator.
private Pair<Boolean, ILogicalExpression> checkSelect(SelectOperator select) {
ILogicalExpression condition = select.getCondition().getValue();
if (condition.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
return new Pair<>(false, null);
}
AbstractFunctionCallExpression conditionFunc = (AbstractFunctionCallExpression) condition;
if (!conditionFunc.getFunctionIdentifier().equals(BuiltinFunctions.NOT)) {
return new Pair<>(false, null);
}
condition = conditionFunc.getArguments().get(0).getValue();
if (condition.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
return new Pair<>(false, null);
}
conditionFunc = (AbstractFunctionCallExpression) condition;
if (!conditionFunc.getFunctionIdentifier().equals(BuiltinFunctions.IS_MISSING)) {
return new Pair<>(false, null);
}
ILogicalExpression conditionArg = conditionFunc.getArguments().get(0).getValue();
return new Pair<>(true, conditionArg);
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.
the class RemoveLeftOuterUnnestForLeftOuterJoinRule method checkGroupBy.
// Checks the group-by operator on top of the left outer join operator.
private Triple<Boolean, ILogicalExpression, ILogicalExpression> checkGroupBy(GroupByOperator gbyOperator, LogicalVariable varToUnnest) {
Pair<Boolean, ILogicalOperator> checkNestedPlanResult = checkNestedPlan(gbyOperator);
if (!checkNestedPlanResult.first) {
return new Triple<>(false, null, null);
}
ILogicalOperator root = checkNestedPlanResult.second;
if (root.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
return new Triple<>(false, null, null);
}
// Checks aggregate.
AggregateOperator agg = (AggregateOperator) root;
Pair<Boolean, ILogicalExpression> listifyArgPair = checksAggregate(agg, varToUnnest);
if (!listifyArgPair.first) {
return new Triple<>(false, null, null);
}
// Checks select.
ILogicalOperator rootInputOp = root.getInputs().get(0).getValue();
if (rootInputOp.getOperatorTag() != LogicalOperatorTag.SELECT) {
return new Triple<>(false, null, null);
}
SelectOperator select = (SelectOperator) rootInputOp;
Pair<Boolean, ILogicalExpression> conditionArgPair = checkSelect(select);
return new Triple<>(true, listifyArgPair.second, conditionArgPair.second);
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.
the class OpenRecordConstructorResultType method computeType.
@Override
public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env, IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expression;
/**
* if type has been top-down propagated, use the enforced type
*/
ARecordType type = (ARecordType) TypeCastUtils.getRequiredType(f);
if (type != null) {
return type;
}
Iterator<Mutable<ILogicalExpression>> argIter = f.getArguments().iterator();
List<String> namesList = new ArrayList<>();
List<IAType> typesList = new ArrayList<>();
// The following set of names do not belong to the closed part,
// but are additional possible field names. For example, a field "foo" with type
// ANY cannot be in the closed part, but "foo" is a possible field name.
Set<String> allPossibleAdditionalFieldNames = new HashSet<>();
boolean canProvideAdditionFieldInfo = true;
boolean isOpen = false;
while (argIter.hasNext()) {
ILogicalExpression e1 = argIter.next().getValue();
ILogicalExpression e2 = argIter.next().getValue();
IAType t2 = (IAType) env.getType(e2);
String fieldName = ConstantExpressionUtil.getStringConstant(e1);
if (fieldName != null && t2 != null && TypeHelper.isClosed(t2)) {
namesList.add(fieldName);
if (t2.getTypeTag() == ATypeTag.UNION) {
AUnionType unionType = (AUnionType) t2;
t2 = AUnionType.createUnknownableType(unionType.getActualType());
}
typesList.add(t2);
} else {
if (canProvideAdditionFieldInfo && fieldName != null) {
allPossibleAdditionalFieldNames.add(fieldName);
} else {
canProvideAdditionFieldInfo = false;
}
isOpen = true;
}
}
String[] fieldNames = namesList.toArray(new String[0]);
IAType[] fieldTypes = typesList.toArray(new IAType[0]);
return canProvideAdditionFieldInfo ? new ARecordType(null, fieldNames, fieldTypes, isOpen, allPossibleAdditionalFieldNames) : new ARecordType(null, fieldNames, fieldTypes, isOpen);
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.
the class RecordAddFieldsTypeComputer method containsVariable.
// Handle variable as input
private boolean containsVariable(ILogicalExpression expression) {
if (expression.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expression;
List<Mutable<ILogicalExpression>> args = f.getArguments();
for (Mutable<ILogicalExpression> arg : args) {
ILogicalExpression subExpression = arg.getValue();
switch(subExpression.getExpressionTag()) {
case VARIABLE:
return true;
case CONSTANT:
return false;
default:
//FUNCTION_CALL
return containsVariable(subExpression);
}
}
}
return true;
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.
the class AbstractUnnestPOperator method contributeRuntimeOperator.
@Override
public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op, IOperatorSchema opSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema) throws AlgebricksException {
AbstractUnnestNonMapOperator unnest = (AbstractUnnestNonMapOperator) op;
int outCol = opSchema.findVariable(unnest.getVariable());
ILogicalExpression unnestExpr = unnest.getExpressionRef().getValue();
IExpressionRuntimeProvider expressionRuntimeProvider = context.getExpressionRuntimeProvider();
boolean exit = false;
if (unnestExpr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
exit = true;
} else {
AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) unnestExpr;
if (fce.getKind() != FunctionKind.UNNEST) {
exit = true;
}
}
if (exit) {
throw new AlgebricksException("Unnest expression " + unnestExpr + " is not an unnesting function call.");
}
UnnestingFunctionCallExpression agg = (UnnestingFunctionCallExpression) unnestExpr;
IUnnestingEvaluatorFactory unnestingFactory = expressionRuntimeProvider.createUnnestingFunctionFactory(agg, context.getTypeEnvironment(op.getInputs().get(0).getValue()), inputSchemas, context);
int[] projectionList = JobGenHelper.projectAllVariables(opSchema);
UnnestRuntimeFactory unnestRuntime = new UnnestRuntimeFactory(outCol, unnestingFactory, projectionList, unnest.getPositionWriter(), leftOuter, context.getMissingWriterFactory());
RecordDescriptor recDesc = JobGenHelper.mkRecordDescriptor(context.getTypeEnvironment(op), opSchema, context);
builder.contributeMicroOperator(unnest, unnestRuntime, recDesc);
ILogicalOperator src = unnest.getInputs().get(0).getValue();
builder.contributeGraphEdge(src, 0, unnest, 0);
}
Aggregations