Search in sources :

Example 41 with LogicalVariable

use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.

the class DataSourceScanPOperator method contributeRuntimeOperator.

@SuppressWarnings("unchecked")
@Override
public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op, IOperatorSchema opSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema) throws AlgebricksException {
    DataSourceScanOperator scan = (DataSourceScanOperator) op;
    IMetadataProvider mp = context.getMetadataProvider();
    IVariableTypeEnvironment typeEnv = context.getTypeEnvironment(op);
    List<LogicalVariable> vars = scan.getVariables();
    List<LogicalVariable> projectVars = scan.getProjectVariables();
    Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> p = mp.getScannerRuntime(dataSource, vars, projectVars, scan.isProjectPushed(), scan.getMinFilterVars(), scan.getMaxFilterVars(), opSchema, typeEnv, context, builder.getJobSpec(), implConfig);
    builder.contributeHyracksOperator(scan, p.first);
    if (p.second != null) {
        builder.contributeAlgebricksPartitionConstraint(p.first, p.second);
    }
    ILogicalOperator srcExchange = scan.getInputs().get(0).getValue();
    builder.contributeGraphEdge(srcExchange, 0, scan, 0);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) DataSourceScanOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator) IOperatorDescriptor(org.apache.hyracks.api.dataflow.IOperatorDescriptor) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) AlgebricksPartitionConstraint(org.apache.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint) IMetadataProvider(org.apache.hyracks.algebricks.core.algebra.metadata.IMetadataProvider) IVariableTypeEnvironment(org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment)

Example 42 with LogicalVariable

use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.

the class JoinMultiComparator method contributeRuntimeOperator.

@Override
public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op, IOperatorSchema propagatedSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema) throws AlgebricksException {
    int[] keysLeft = JobGenHelper.variablesToFieldIndexes(keysLeftBranch, inputSchemas[0]);
    int[] keysRight = JobGenHelper.variablesToFieldIndexes(keysRightBranch, inputSchemas[1]);
    IVariableTypeEnvironment env = context.getTypeEnvironment(op);
    IBinaryHashFunctionFactory[] hashFunFactories = JobGenHelper.variablesToBinaryHashFunctionFactories(keysLeftBranch, env, context);
    IBinaryHashFunctionFamily[] hashFunFamilies = JobGenHelper.variablesToBinaryHashFunctionFamilies(keysLeftBranch, env, context);
    IBinaryComparatorFactory[] comparatorFactories = new IBinaryComparatorFactory[keysLeft.length];
    int i = 0;
    IBinaryComparatorFactoryProvider bcfp = context.getBinaryComparatorFactoryProvider();
    for (LogicalVariable v : keysLeftBranch) {
        Object t = env.getVarType(v);
        comparatorFactories[i++] = bcfp.getBinaryComparatorFactory(t, true);
    }
    IPredicateEvaluatorFactoryProvider predEvaluatorFactoryProvider = context.getPredicateEvaluatorFactoryProvider();
    IPredicateEvaluatorFactory predEvaluatorFactory = predEvaluatorFactoryProvider == null ? null : predEvaluatorFactoryProvider.getPredicateEvaluatorFactory(keysLeft, keysRight);
    RecordDescriptor recDescriptor = JobGenHelper.mkRecordDescriptor(context.getTypeEnvironment(op), propagatedSchema, context);
    IOperatorDescriptorRegistry spec = builder.getJobSpec();
    IOperatorDescriptor opDesc;
    boolean optimizedHashJoin = true;
    for (IBinaryHashFunctionFamily family : hashFunFamilies) {
        if (family == null) {
            optimizedHashJoin = false;
            break;
        }
    }
    if (optimizedHashJoin) {
        opDesc = generateOptimizedHashJoinRuntime(context, inputSchemas, keysLeft, keysRight, hashFunFamilies, comparatorFactories, predEvaluatorFactory, recDescriptor, spec);
    } else {
        opDesc = generateHashJoinRuntime(context, inputSchemas, keysLeft, keysRight, hashFunFactories, comparatorFactories, predEvaluatorFactory, recDescriptor, spec);
    }
    contributeOpDesc(builder, (AbstractLogicalOperator) op, opDesc);
    ILogicalOperator src1 = op.getInputs().get(0).getValue();
    builder.contributeGraphEdge(src1, 0, op, 0);
    ILogicalOperator src2 = op.getInputs().get(1).getValue();
    builder.contributeGraphEdge(src2, 0, op, 1);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) IPredicateEvaluatorFactoryProvider(org.apache.hyracks.api.dataflow.value.IPredicateEvaluatorFactoryProvider) IPredicateEvaluatorFactory(org.apache.hyracks.api.dataflow.value.IPredicateEvaluatorFactory) RecordDescriptor(org.apache.hyracks.api.dataflow.value.RecordDescriptor) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) IBinaryComparatorFactory(org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory) IOperatorDescriptorRegistry(org.apache.hyracks.api.job.IOperatorDescriptorRegistry) IBinaryHashFunctionFactory(org.apache.hyracks.api.dataflow.value.IBinaryHashFunctionFactory) IBinaryComparatorFactoryProvider(org.apache.hyracks.algebricks.data.IBinaryComparatorFactoryProvider) IOperatorDescriptor(org.apache.hyracks.api.dataflow.IOperatorDescriptor) IVariableTypeEnvironment(org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment) IBinaryHashFunctionFamily(org.apache.hyracks.api.dataflow.value.IBinaryHashFunctionFamily)

Example 43 with LogicalVariable

use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.

the class JoinMultiComparator method deliveredLocalProperties.

@Override
protected List<ILocalStructuralProperty> deliveredLocalProperties(ILogicalOperator op, IOptimizationContext context) throws AlgebricksException {
    List<ILocalStructuralProperty> deliveredLocalProperties = new ArrayList<>();
    // Inner join can kick off the "role reversal" optimization, which can kill data properties for the probe side.
    if (kind != JoinKind.LEFT_OUTER) {
        return deliveredLocalProperties;
    }
    AbstractLogicalOperator probeOp = (AbstractLogicalOperator) op.getInputs().get(0).getValue();
    IPhysicalPropertiesVector probeSideProperties = probeOp.getPhysicalOperator().getDeliveredProperties();
    List<ILocalStructuralProperty> probeSideLocalProperties = probeSideProperties.getLocalProperties();
    if (probeSideLocalProperties != null) {
        // is destroyed.
        for (ILocalStructuralProperty property : probeSideLocalProperties) {
            Set<LogicalVariable> groupingVars = new ListSet<>();
            Set<LogicalVariable> leftBranchVars = new ListSet<>();
            property.getVariables(groupingVars);
            leftBranchVars.addAll(getKeysLeftBranch());
            if (groupingVars.containsAll(leftBranchVars)) {
                deliveredLocalProperties.add(new LocalGroupingProperty(groupingVars));
            }
        }
    }
    return deliveredLocalProperties;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) ListSet(org.apache.hyracks.algebricks.common.utils.ListSet) LocalGroupingProperty(org.apache.hyracks.algebricks.core.algebra.properties.LocalGroupingProperty) ArrayList(java.util.ArrayList) IPhysicalPropertiesVector(org.apache.hyracks.algebricks.core.algebra.properties.IPhysicalPropertiesVector) ILocalStructuralProperty(org.apache.hyracks.algebricks.core.algebra.properties.ILocalStructuralProperty)

Example 44 with LogicalVariable

use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.

the class AggregatePOperator method contributeRuntimeOperator.

@Override
public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op, IOperatorSchema opSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema) throws AlgebricksException {
    AggregateOperator aggOp = (AggregateOperator) op;
    List<LogicalVariable> variables = aggOp.getVariables();
    List<Mutable<ILogicalExpression>> expressions = aggOp.getExpressions();
    int[] outColumns = new int[variables.size()];
    for (int i = 0; i < outColumns.length; i++) {
        outColumns[i] = opSchema.findVariable(variables.get(i));
    }
    IAggregateEvaluatorFactory[] aggFactories = new IAggregateEvaluatorFactory[expressions.size()];
    IExpressionRuntimeProvider expressionRuntimeProvider = context.getExpressionRuntimeProvider();
    for (int i = 0; i < aggFactories.length; i++) {
        AggregateFunctionCallExpression aggFun = (AggregateFunctionCallExpression) expressions.get(i).getValue();
        aggFactories[i] = expressionRuntimeProvider.createAggregateFunctionFactory(aggFun, context.getTypeEnvironment(op.getInputs().get(0).getValue()), inputSchemas, context);
    }
    AggregateRuntimeFactory runtime = new AggregateRuntimeFactory(aggFactories);
    // contribute one Asterix framewriter
    RecordDescriptor recDesc = JobGenHelper.mkRecordDescriptor(context.getTypeEnvironment(op), opSchema, context);
    builder.contributeMicroOperator(aggOp, runtime, recDesc);
    // and contribute one edge from its child
    ILogicalOperator src = aggOp.getInputs().get(0).getValue();
    builder.contributeGraphEdge(src, 0, aggOp, 0);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) AggregateFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AggregateFunctionCallExpression) AggregateRuntimeFactory(org.apache.hyracks.algebricks.runtime.operators.aggreg.AggregateRuntimeFactory) RecordDescriptor(org.apache.hyracks.api.dataflow.value.RecordDescriptor) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) IAggregateEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluatorFactory) Mutable(org.apache.commons.lang3.mutable.Mutable) IExpressionRuntimeProvider(org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionRuntimeProvider) AggregateOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator)

Example 45 with LogicalVariable

use of org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable in project asterixdb by apache.

the class AssignPOperator method contributeRuntimeOperator.

@Override
public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op, IOperatorSchema opSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema) throws AlgebricksException {
    AssignOperator assign = (AssignOperator) op;
    List<LogicalVariable> variables = assign.getVariables();
    List<Mutable<ILogicalExpression>> expressions = assign.getExpressions();
    int[] outColumns = new int[variables.size()];
    for (int i = 0; i < outColumns.length; i++) {
        outColumns[i] = opSchema.findVariable(variables.get(i));
    }
    IScalarEvaluatorFactory[] evalFactories = new IScalarEvaluatorFactory[expressions.size()];
    IExpressionRuntimeProvider expressionRuntimeProvider = context.getExpressionRuntimeProvider();
    for (int i = 0; i < evalFactories.length; i++) {
        evalFactories[i] = expressionRuntimeProvider.createEvaluatorFactory(expressions.get(i).getValue(), context.getTypeEnvironment(op.getInputs().get(0).getValue()), inputSchemas, context);
    }
    // TODO push projections into the operator
    int[] projectionList = JobGenHelper.projectAllVariables(opSchema);
    AssignRuntimeFactory runtime = new AssignRuntimeFactory(outColumns, evalFactories, projectionList, flushFramesRapidly);
    // contribute one Asterix framewriter
    RecordDescriptor recDesc = JobGenHelper.mkRecordDescriptor(context.getTypeEnvironment(op), opSchema, context);
    if (cardinalityConstraint > 0) {
        AlgebricksCountPartitionConstraint countConstraint = new AlgebricksCountPartitionConstraint(cardinalityConstraint);
        builder.contributeMicroOperator(assign, runtime, recDesc, countConstraint);
    } else {
        builder.contributeMicroOperator(assign, runtime, recDesc);
    }
    // and contribute one edge from its child
    ILogicalOperator src = assign.getInputs().get(0).getValue();
    builder.contributeGraphEdge(src, 0, assign, 0);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) RecordDescriptor(org.apache.hyracks.api.dataflow.value.RecordDescriptor) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) AlgebricksCountPartitionConstraint(org.apache.hyracks.algebricks.common.constraints.AlgebricksCountPartitionConstraint) AssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator) AssignRuntimeFactory(org.apache.hyracks.algebricks.runtime.operators.std.AssignRuntimeFactory) AlgebricksCountPartitionConstraint(org.apache.hyracks.algebricks.common.constraints.AlgebricksCountPartitionConstraint) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) Mutable(org.apache.commons.lang3.mutable.Mutable) IExpressionRuntimeProvider(org.apache.hyracks.algebricks.core.algebra.expressions.IExpressionRuntimeProvider)

Aggregations

LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)376 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)196 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)182 ArrayList (java.util.ArrayList)171 Mutable (org.apache.commons.lang3.mutable.Mutable)136 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)127 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)92 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)79 Pair (org.apache.hyracks.algebricks.common.utils.Pair)75 HashSet (java.util.HashSet)60 MutableObject (org.apache.commons.lang3.mutable.MutableObject)60 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)60 ILogicalPlan (org.apache.hyracks.algebricks.core.algebra.base.ILogicalPlan)54 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)46 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)36 GroupByOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.GroupByOperator)33 ConstantExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ConstantExpression)32 AggregateOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator)28 FunctionalDependency (org.apache.hyracks.algebricks.core.algebra.properties.FunctionalDependency)28 IAType (org.apache.asterix.om.types.IAType)27