Search in sources :

Example 6 with DataSourceId

use of org.apache.asterix.metadata.declared.DataSourceId 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

DataSourceId (org.apache.asterix.metadata.declared.DataSourceId)6 Dataset (org.apache.asterix.metadata.entities.Dataset)5 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)5 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)5 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)5 ArrayList (java.util.ArrayList)4 MetadataProvider (org.apache.asterix.metadata.declared.MetadataProvider)4 IAType (org.apache.asterix.om.types.IAType)4 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)4 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)4 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)4 List (java.util.List)3 AString (org.apache.asterix.om.base.AString)3 ARecordType (org.apache.asterix.om.types.ARecordType)3 Mutable (org.apache.commons.lang3.mutable.Mutable)3 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)3 DataSourceScanOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator)3 DataSource (org.apache.asterix.metadata.declared.DataSource)2 IAObject (org.apache.asterix.om.base.IAObject)2 AsterixConstantValue (org.apache.asterix.om.constants.AsterixConstantValue)2