use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.
the class PushAggregateIntoNestedSubplanRule method collectOneVarPerAggFromOpWithNestedPlans.
private List<LogicalVariable> collectOneVarPerAggFromOpWithNestedPlans(AbstractOperatorWithNestedPlans op) {
List<ILogicalPlan> nPlans = op.getNestedPlans();
if (nPlans == null || nPlans.isEmpty()) {
return Collections.emptyList();
}
List<LogicalVariable> aggVars = new ArrayList<>();
// test that the operator computes a "listify" aggregate
for (int i = 0; i < nPlans.size(); i++) {
AbstractLogicalOperator topOp = (AbstractLogicalOperator) nPlans.get(i).getRoots().get(0).getValue();
if (topOp.getOperatorTag() != LogicalOperatorTag.AGGREGATE) {
continue;
}
AggregateOperator agg = (AggregateOperator) topOp;
if (agg.getVariables().size() != 1) {
continue;
}
ILogicalExpression expr = agg.getExpressions().get(0).getValue();
if (expr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
continue;
}
AbstractFunctionCallExpression fceAgg = (AbstractFunctionCallExpression) expr;
if (fceAgg.getFunctionIdentifier() != BuiltinFunctions.LISTIFY) {
continue;
}
aggVars.add(agg.getVariables().get(0));
}
return aggVars;
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression 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);
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.
the class IntroduceEnforcedListTypeRule method rewriteExpressions.
private boolean rewriteExpressions(List<Mutable<ILogicalExpression>> expressions, IVariableTypeEnvironment env) throws AlgebricksException {
boolean changed = false;
for (Mutable<ILogicalExpression> exprRef : expressions) {
ILogicalExpression expr = exprRef.getValue();
if (expr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
AbstractFunctionCallExpression argFuncExpr = (AbstractFunctionCallExpression) expr;
IAType exprType = (IAType) env.getType(argFuncExpr);
if (StaticTypeCastUtil.rewriteListExpr(argFuncExpr, exprType, exprType, env)) {
TypeCastUtils.resetRequiredAndInputTypes(argFuncExpr);
changed = true;
}
}
}
return changed;
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.
the class IntroduceMaterializationForInsertWithSelfScanRule method checkIfInsertAndScanDatasetsSame.
private boolean checkIfInsertAndScanDatasetsSame(AbstractLogicalOperator op, String insertDatasetName) {
boolean sameDataset = false;
for (int i = 0; i < op.getInputs().size(); ++i) {
AbstractLogicalOperator descendantOp = (AbstractLogicalOperator) op.getInputs().get(i).getValue();
if (descendantOp.getOperatorTag() == LogicalOperatorTag.UNNEST_MAP) {
UnnestMapOperator unnestMapOp = (UnnestMapOperator) descendantOp;
ILogicalExpression unnestExpr = unnestMapOp.getExpressionRef().getValue();
if (unnestExpr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) {
AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) unnestExpr;
FunctionIdentifier fid = f.getFunctionIdentifier();
if (!fid.equals(BuiltinFunctions.INDEX_SEARCH)) {
throw new IllegalStateException();
}
AccessMethodJobGenParams jobGenParams = new AccessMethodJobGenParams();
jobGenParams.readFromFuncArgs(f.getArguments());
boolean isPrimaryIndex = jobGenParams.isPrimaryIndex();
String indexName = jobGenParams.getIndexName();
if (isPrimaryIndex && indexName.compareTo(insertDatasetName) == 0) {
return true;
}
}
} else if (descendantOp.getOperatorTag() == LogicalOperatorTag.DATASOURCESCAN) {
DataSourceScanOperator dataSourceScanOp = (DataSourceScanOperator) descendantOp;
DataSource ds = (DataSource) dataSourceScanOp.getDataSource();
if ((ds.getDatasourceType() == Type.INTERNAL_DATASET || ds.getDatasourceType() == Type.EXTERNAL_DATASET) && ((DatasetDataSource) ds).getDataset().getDatasetName().compareTo(insertDatasetName) == 0) {
return true;
}
}
sameDataset = checkIfInsertAndScanDatasetsSame(descendantOp, insertDatasetName);
if (sameDataset) {
break;
}
}
return sameDataset;
}
use of org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression in project asterixdb by apache.
the class LoadRecordFieldsRule method findFieldByNameFromRecordConstructor.
// Resolves field expression by name-based access.
private static ILogicalExpression findFieldByNameFromRecordConstructor(Object fldName, AbstractFunctionCallExpression fce) {
Iterator<Mutable<ILogicalExpression>> fldIter = fce.getArguments().iterator();
while (fldIter.hasNext()) {
ILogicalExpression fldExpr = fldIter.next().getValue();
if (fldName.equals(ConstantExpressionUtil.getStringConstant(fldExpr))) {
return fldIter.next().getValue();
}
fldIter.next();
}
return null;
}
Aggregations