Search in sources :

Example 1 with ExternalDataLookupPOperator

use of org.apache.asterix.algebra.operators.physical.ExternalDataLookupPOperator in project asterixdb by apache.

the class AccessMethodUtils method createExternalDataLookupUnnestMap.

public static UnnestMapOperator createExternalDataLookupUnnestMap(AbstractDataSourceOperator dataSourceOp, Dataset dataset, ARecordType recordType, ILogicalOperator inputOp, IOptimizationContext context, boolean retainInput, boolean retainNull) throws AlgebricksException {
    List<LogicalVariable> primaryKeyVars = AccessMethodUtils.getPrimaryKeyVarsFromSecondaryUnnestMap(dataset, inputOp);
    // add a sort on the RID fields before fetching external data.
    OrderOperator order = new OrderOperator();
    for (LogicalVariable pkVar : primaryKeyVars) {
        Mutable<ILogicalExpression> vRef = new MutableObject<>(new VariableReferenceExpression(pkVar));
        order.getOrderExpressions().add(new Pair<>(OrderOperator.ASC_ORDER, vRef));
    }
    // The secondary-index search feeds into the sort.
    order.getInputs().add(new MutableObject<>(inputOp));
    order.setExecutionMode(ExecutionMode.LOCAL);
    context.computeAndSetTypeEnvironmentForOperator(order);
    List<Mutable<ILogicalExpression>> externalLookupArgs = new ArrayList<>();
    //Add dataverse to the arguments
    AccessMethodUtils.addStringArg(dataset.getDataverseName(), externalLookupArgs);
    //Add dataset to the arguments
    AccessMethodUtils.addStringArg(dataset.getDatasetName(), externalLookupArgs);
    //Add PK vars to the arguments
    AccessMethodUtils.writeVarList(primaryKeyVars, externalLookupArgs);
    // Variables and types coming out of the external access.
    List<LogicalVariable> externalUnnestVars = new ArrayList<>();
    List<Object> outputTypes = new ArrayList<>();
    // Append output variables/types generated by the data scan (not forwarded from input).
    externalUnnestVars.addAll(dataSourceOp.getVariables());
    appendExternalRecTypes(dataset, recordType, outputTypes);
    IFunctionInfo externalLookup = FunctionUtil.getFunctionInfo(BuiltinFunctions.EXTERNAL_LOOKUP);
    AbstractFunctionCallExpression externalLookupFunc = new ScalarFunctionCallExpression(externalLookup, externalLookupArgs);
    UnnestMapOperator unnestOp = new UnnestMapOperator(externalUnnestVars, new MutableObject<ILogicalExpression>(externalLookupFunc), outputTypes, retainInput);
    // Fed by the order operator or the secondaryIndexUnnestOp.
    unnestOp.getInputs().add(new MutableObject<ILogicalOperator>(order));
    context.computeAndSetTypeEnvironmentForOperator(unnestOp);
    unnestOp.setExecutionMode(ExecutionMode.PARTITIONED);
    //set the physical operator
    DataSourceId dataSourceId = new DataSourceId(dataset.getDataverseName(), dataset.getDatasetName());
    unnestOp.setPhysicalOperator(new ExternalDataLookupPOperator(dataSourceId, dataset, recordType, primaryKeyVars, false, retainInput, retainNull));
    return unnestOp;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) IFunctionInfo(org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo) LeftOuterUnnestMapOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.LeftOuterUnnestMapOperator) UnnestMapOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.UnnestMapOperator) AbstractUnnestMapOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractUnnestMapOperator) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) ArrayList(java.util.ArrayList) OrderOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator) Mutable(org.apache.commons.lang3.mutable.Mutable) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) ExternalDataLookupPOperator(org.apache.asterix.algebra.operators.physical.ExternalDataLookupPOperator) MutableObject(org.apache.commons.lang3.mutable.MutableObject) IAObject(org.apache.asterix.om.base.IAObject) DataSourceId(org.apache.asterix.metadata.declared.DataSourceId) MutableObject(org.apache.commons.lang3.mutable.MutableObject) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)

Aggregations

ArrayList (java.util.ArrayList)1 ExternalDataLookupPOperator (org.apache.asterix.algebra.operators.physical.ExternalDataLookupPOperator)1 DataSourceId (org.apache.asterix.metadata.declared.DataSourceId)1 IAObject (org.apache.asterix.om.base.IAObject)1 Mutable (org.apache.commons.lang3.mutable.Mutable)1 MutableObject (org.apache.commons.lang3.mutable.MutableObject)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 ScalarFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)1 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)1 IFunctionInfo (org.apache.hyracks.algebricks.core.algebra.functions.IFunctionInfo)1 AbstractUnnestMapOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractUnnestMapOperator)1 LeftOuterUnnestMapOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.LeftOuterUnnestMapOperator)1 OrderOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.OrderOperator)1 UnnestMapOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.UnnestMapOperator)1