Search in sources :

Example 1 with RTreeJobGenParams

use of org.apache.asterix.optimizer.rules.am.RTreeJobGenParams in project asterixdb by apache.

the class RTreeSearchPOperator method contributeRuntimeOperator.

@Override
public void contributeRuntimeOperator(IHyracksJobBuilder builder, JobGenContext context, ILogicalOperator op, IOperatorSchema opSchema, IOperatorSchema[] inputSchemas, IOperatorSchema outerPlanSchema) throws AlgebricksException {
    AbstractUnnestMapOperator unnestMap = (AbstractUnnestMapOperator) op;
    ILogicalExpression unnestExpr = unnestMap.getExpressionRef().getValue();
    if (unnestExpr.getExpressionTag() != LogicalExpressionTag.FUNCTION_CALL) {
        throw new IllegalStateException();
    }
    AbstractFunctionCallExpression unnestFuncExpr = (AbstractFunctionCallExpression) unnestExpr;
    FunctionIdentifier funcIdent = unnestFuncExpr.getFunctionIdentifier();
    if (!funcIdent.equals(BuiltinFunctions.INDEX_SEARCH)) {
        return;
    }
    RTreeJobGenParams jobGenParams = new RTreeJobGenParams();
    jobGenParams.readFromFuncArgs(unnestFuncExpr.getArguments());
    int[] keyIndexes = getKeyIndexes(jobGenParams.getKeyVarList(), inputSchemas);
    int[] minFilterFieldIndexes = getKeyIndexes(unnestMap.getMinFilterVars(), inputSchemas);
    int[] maxFilterFieldIndexes = getKeyIndexes(unnestMap.getMaxFilterVars(), inputSchemas);
    MetadataProvider mp = (MetadataProvider) context.getMetadataProvider();
    Dataset dataset = mp.findDataset(jobGenParams.getDataverseName(), jobGenParams.getDatasetName());
    IVariableTypeEnvironment typeEnv = context.getTypeEnvironment(unnestMap);
    List<LogicalVariable> outputVars = unnestMap.getVariables();
    if (jobGenParams.getRetainInput()) {
        outputVars = new ArrayList<LogicalVariable>();
        VariableUtilities.getLiveVariables(unnestMap, outputVars);
    }
    boolean retainNull = false;
    if (op.getOperatorTag() == LogicalOperatorTag.LEFT_OUTER_UNNEST_MAP) {
        // By nature, LEFT_OUTER_UNNEST_MAP should generate null values for non-matching tuples.
        retainNull = true;
    }
    Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> rtreeSearch = mp.buildRtreeRuntime(builder.getJobSpec(), outputVars, opSchema, typeEnv, context, jobGenParams.getRetainInput(), retainNull, dataset, jobGenParams.getIndexName(), keyIndexes, minFilterFieldIndexes, maxFilterFieldIndexes);
    builder.contributeHyracksOperator(unnestMap, rtreeSearch.first);
    builder.contributeAlgebricksPartitionConstraint(rtreeSearch.first, rtreeSearch.second);
    ILogicalOperator srcExchange = unnestMap.getInputs().get(0).getValue();
    builder.contributeGraphEdge(srcExchange, 0, unnestMap, 0);
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) Dataset(org.apache.asterix.metadata.entities.Dataset) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) FunctionIdentifier(org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) RTreeJobGenParams(org.apache.asterix.optimizer.rules.am.RTreeJobGenParams) MetadataProvider(org.apache.asterix.metadata.declared.MetadataProvider) IOperatorDescriptor(org.apache.hyracks.api.dataflow.IOperatorDescriptor) AbstractUnnestMapOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractUnnestMapOperator) AlgebricksPartitionConstraint(org.apache.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint) IVariableTypeEnvironment(org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment)

Aggregations

MetadataProvider (org.apache.asterix.metadata.declared.MetadataProvider)1 Dataset (org.apache.asterix.metadata.entities.Dataset)1 RTreeJobGenParams (org.apache.asterix.optimizer.rules.am.RTreeJobGenParams)1 AlgebricksPartitionConstraint (org.apache.hyracks.algebricks.common.constraints.AlgebricksPartitionConstraint)1 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)1 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)1 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)1 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)1 IVariableTypeEnvironment (org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment)1 FunctionIdentifier (org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier)1 AbstractUnnestMapOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractUnnestMapOperator)1 IOperatorDescriptor (org.apache.hyracks.api.dataflow.IOperatorDescriptor)1