use of org.apache.hyracks.algebricks.common.utils.Triple in project asterixdb by apache.
the class PushUnnestDownThroughUnionRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
AbstractLogicalOperator unnest = (AbstractLogicalOperator) opRef.getValue();
if (unnest.getOperatorTag() != LogicalOperatorTag.UNNEST) {
return false;
}
UnnestOperator unnestOpRef = (UnnestOperator) opRef.getValue();
Mutable<ILogicalOperator> unionOp = unnest.getInputs().get(0);
AbstractLogicalOperator unionAbstractOp = (AbstractLogicalOperator) unionOp.getValue();
if (unionAbstractOp.getOperatorTag() != LogicalOperatorTag.UNIONALL) {
return false;
}
LogicalVariable unnestVar1 = context.newVar();
UnnestOperator unnest1 = new UnnestOperator(unnestVar1, new MutableObject<ILogicalExpression>(unnestOpRef.getExpressionRef().getValue().cloneExpression()));
LogicalVariable unnestVar2 = context.newVar();
UnnestOperator unnest2 = new UnnestOperator(unnestVar2, new MutableObject<ILogicalExpression>(unnestOpRef.getExpressionRef().getValue().cloneExpression()));
//Getting the two topmost branched and adding them as an input to the unnests:
Mutable<ILogicalOperator> branch1 = unionAbstractOp.getInputs().get(0);
ILogicalOperator agg1 = branch1.getValue();
List<LogicalVariable> agg1_var = new ArrayList<LogicalVariable>();
VariableUtilities.getLiveVariables(agg1, agg1_var);
Mutable<ILogicalOperator> branch2 = unionAbstractOp.getInputs().get(1);
ILogicalOperator agg2 = branch2.getValue();
List<LogicalVariable> agg2_var = new ArrayList<LogicalVariable>();
VariableUtilities.getLiveVariables(agg2, agg2_var);
//Modifying the unnest so it has the right variable
List<LogicalVariable> var_unnest_1 = new ArrayList<LogicalVariable>();
unnest1.getExpressionRef().getValue().getUsedVariables(var_unnest_1);
unnest1.getExpressionRef().getValue().substituteVar(var_unnest_1.get(0), agg1_var.get(0));
List<LogicalVariable> var_unnest2 = new ArrayList<LogicalVariable>();
unnest2.getExpressionRef().getValue().getUsedVariables(var_unnest2);
unnest2.getExpressionRef().getValue().substituteVar(var_unnest2.get(0), agg2_var.get(0));
unnest1.getInputs().add(branch1);
unnest2.getInputs().add(branch2);
context.computeAndSetTypeEnvironmentForOperator(unnest1);
context.computeAndSetTypeEnvironmentForOperator(unnest2);
//creating a new union operator with the updated logical variables
List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> varMap = new ArrayList<Triple<LogicalVariable, LogicalVariable, LogicalVariable>>(1);
Triple<LogicalVariable, LogicalVariable, LogicalVariable> union_triple_vars = new Triple<LogicalVariable, LogicalVariable, LogicalVariable>(unnestVar1, unnestVar2, unnestOpRef.getVariables().get(0));
varMap.add(union_triple_vars);
UnionAllOperator unionOpFinal = new UnionAllOperator(varMap);
unionOpFinal.getInputs().add(new MutableObject<ILogicalOperator>(unnest1));
unionOpFinal.getInputs().add(new MutableObject<ILogicalOperator>(unnest2));
context.computeAndSetTypeEnvironmentForOperator(unionOpFinal);
opRef.setValue(unionOpFinal);
return true;
}
use of org.apache.hyracks.algebricks.common.utils.Triple in project asterixdb by apache.
the class NonTaggedDataFormat method partitioningEvaluatorFactory.
@SuppressWarnings("unchecked")
@Override
public Triple<IScalarEvaluatorFactory, ScalarFunctionCallExpression, IAType> partitioningEvaluatorFactory(ARecordType recType, List<String> fldName) throws AlgebricksException {
String[] names = recType.getFieldNames();
int n = names.length;
if (fldName.size() > 1) {
for (int i = 0; i < n; i++) {
if (names[i].equals(fldName.get(0))) {
IScalarEvaluatorFactory recordEvalFactory = new ColumnAccessEvalFactory(GlobalConfig.DEFAULT_INPUT_DATA_COLUMN);
ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
DataOutput dos = abvs.getDataOutput();
try {
AInt32 ai = new AInt32(i);
SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(ai.getType()).serialize(ai, dos);
} catch (HyracksDataException e) {
throw new AlgebricksException(e);
}
IScalarEvaluatorFactory fldIndexEvalFactory = new ConstantEvalFactory(Arrays.copyOf(abvs.getByteArray(), abvs.getLength()));
IScalarEvaluatorFactory evalFactory = new FieldAccessByIndexEvalFactory(recordEvalFactory, fldIndexEvalFactory, recType);
IFunctionInfo finfoAccess = BuiltinFunctions.getAsterixFunctionInfo(BuiltinFunctions.FIELD_ACCESS_BY_INDEX);
ScalarFunctionCallExpression partitionFun = new ScalarFunctionCallExpression(finfoAccess, new MutableObject<ILogicalExpression>(new VariableReferenceExpression(METADATA_DUMMY_VAR)), new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(new AInt32(i)))));
return new Triple<IScalarEvaluatorFactory, ScalarFunctionCallExpression, IAType>(evalFactory, partitionFun, recType.getFieldTypes()[i]);
}
}
} else {
IScalarEvaluatorFactory recordEvalFactory = new ColumnAccessEvalFactory(GlobalConfig.DEFAULT_INPUT_DATA_COLUMN);
ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
DataOutput dos = abvs.getDataOutput();
AOrderedList as = new AOrderedList(fldName);
try {
SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(as.getType()).serialize(as, dos);
} catch (HyracksDataException e) {
throw new AlgebricksException(e);
}
IScalarEvaluatorFactory evalFactory = new FieldAccessNestedEvalFactory(recordEvalFactory, recType, fldName);
IFunctionInfo finfoAccess = BuiltinFunctions.getAsterixFunctionInfo(BuiltinFunctions.FIELD_ACCESS_NESTED);
ScalarFunctionCallExpression partitionFun = new ScalarFunctionCallExpression(finfoAccess, new MutableObject<ILogicalExpression>(new VariableReferenceExpression(METADATA_DUMMY_VAR)), new MutableObject<ILogicalExpression>(new ConstantExpression(new AsterixConstantValue(as))));
return new Triple<IScalarEvaluatorFactory, ScalarFunctionCallExpression, IAType>(evalFactory, partitionFun, recType.getSubFieldType(fldName));
}
throw new AlgebricksException("Could not find field " + fldName + " in the schema.");
}
use of org.apache.hyracks.algebricks.common.utils.Triple 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.common.utils.Triple in project asterixdb by apache.
the class IsomorphismOperatorVisitor method visitUnionOperator.
@Override
public Boolean visitUnionOperator(UnionAllOperator op, ILogicalOperator arg) throws AlgebricksException {
AbstractLogicalOperator aop = (AbstractLogicalOperator) arg;
if (aop.getOperatorTag() != LogicalOperatorTag.UNIONALL) {
return Boolean.FALSE;
}
UnionAllOperator unionOpArg = (UnionAllOperator) copyAndSubstituteVar(op, arg);
List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> mapping = op.getVariableMappings();
List<Triple<LogicalVariable, LogicalVariable, LogicalVariable>> mappingArg = unionOpArg.getVariableMappings();
if (mapping.size() != mappingArg.size()) {
return Boolean.FALSE;
}
return VariableUtilities.varListEqualUnordered(mapping, mappingArg);
}
use of org.apache.hyracks.algebricks.common.utils.Triple in project asterixdb by apache.
the class RemoveLeftOuterUnnestForLeftOuterJoinRule method checkUnnestAndGby.
// Checks left outer unnest and gby.
private Triple<Boolean, ILogicalExpression, ILogicalExpression> checkUnnestAndGby(LeftOuterUnnestOperator outerUnnest, GroupByOperator gbyOperator) {
// Checks left outer unnest.
Pair<Boolean, LogicalVariable> checkUnnestResult = checkUnnest(outerUnnest);
if (!checkUnnestResult.first) {
return new Triple<>(false, null, null);
}
// Checks group-by.
LogicalVariable varToUnnest = checkUnnestResult.second;
Triple<Boolean, ILogicalExpression, ILogicalExpression> checkGbyResult = checkGroupBy(gbyOperator, varToUnnest);
if (!checkGbyResult.first) {
return new Triple<>(false, null, null);
}
return checkGbyResult;
}
Aggregations