Search in sources :

Example 11 with DataSource

use of org.apache.asterix.metadata.declared.DataSource in project asterixdb by apache.

the class IntroduceLSMComponentFilterRule method changePlan.

private void changePlan(List<IOptimizableFuncExpr> optFuncExprs, AbstractLogicalOperator op, Dataset dataset, IOptimizationContext context) throws AlgebricksException {
    Queue<Mutable<ILogicalOperator>> queue = new LinkedList<>(op.getInputs());
    while (!queue.isEmpty()) {
        AbstractLogicalOperator descendantOp = (AbstractLogicalOperator) queue.poll().getValue();
        if (descendantOp == null) {
            continue;
        }
        if (descendantOp.getOperatorTag() == LogicalOperatorTag.DATASOURCESCAN) {
            DataSourceScanOperator dataSourceScanOp = (DataSourceScanOperator) descendantOp;
            DataSource ds = (DataSource) dataSourceScanOp.getDataSource();
            if (dataset.getDatasetName().compareTo(((DatasetDataSource) ds).getDataset().getDatasetName()) == 0) {
                List<LogicalVariable> minFilterVars = new ArrayList<>();
                List<LogicalVariable> maxFilterVars = new ArrayList<>();
                AssignOperator assignOp = createAssignOperator(optFuncExprs, minFilterVars, maxFilterVars, context);
                dataSourceScanOp.setMinFilterVars(minFilterVars);
                dataSourceScanOp.setMaxFilterVars(maxFilterVars);
                List<Mutable<ILogicalExpression>> additionalFilteringExpressions = new ArrayList<>();
                for (LogicalVariable var : assignOp.getVariables()) {
                    additionalFilteringExpressions.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(var)));
                }
                dataSourceScanOp.setAdditionalFilteringExpressions(additionalFilteringExpressions);
                assignOp.getInputs().add(new MutableObject<>(dataSourceScanOp.getInputs().get(0).getValue()));
                dataSourceScanOp.getInputs().get(0).setValue(assignOp);
            }
        } else 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());
                if (dataset.getDatasetName().compareTo(jobGenParams.datasetName) == 0) {
                    List<LogicalVariable> minFilterVars = new ArrayList<>();
                    List<LogicalVariable> maxFilterVars = new ArrayList<>();
                    AssignOperator assignOp = createAssignOperator(optFuncExprs, minFilterVars, maxFilterVars, context);
                    unnestMapOp.setMinFilterVars(minFilterVars);
                    unnestMapOp.setMaxFilterVars(maxFilterVars);
                    List<Mutable<ILogicalExpression>> additionalFilteringExpressions = new ArrayList<>();
                    for (LogicalVariable var : assignOp.getVariables()) {
                        additionalFilteringExpressions.add(new MutableObject<ILogicalExpression>(new VariableReferenceExpression(var)));
                    }
                    unnestMapOp.setAdditionalFilteringExpressions(additionalFilteringExpressions);
                    assignOp.getInputs().add(new MutableObject<>(unnestMapOp.getInputs().get(0).getValue()));
                    unnestMapOp.getInputs().get(0).setValue(assignOp);
                }
            }
        }
        queue.addAll(descendantOp.getInputs());
    }
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) AbstractLogicalOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator) UnnestMapOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.UnnestMapOperator) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) ArrayList(java.util.ArrayList) AssignOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator) LinkedList(java.util.LinkedList) DataSource(org.apache.asterix.metadata.declared.DataSource) DatasetDataSource(org.apache.asterix.metadata.declared.DatasetDataSource) Mutable(org.apache.commons.lang3.mutable.Mutable) FunctionIdentifier(org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier) ILogicalExpression(org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression) DataSourceScanOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator) VariableReferenceExpression(org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) MutableObject(org.apache.commons.lang3.mutable.MutableObject)

Example 12 with DataSource

use of org.apache.asterix.metadata.declared.DataSource in project asterixdb by apache.

the class ExternalDataLookupPOperator method computeDeliveredProperties.

@Override
public void computeDeliveredProperties(ILogicalOperator op, IOptimizationContext context) throws AlgebricksException {
    DataSource ds = new DatasetDataSource(datasetId, dataset, recordType, null, /*external dataset doesn't have meta records.*/
    Type.EXTERNAL_DATASET, dataset.getDatasetDetails(), context.getComputationNodeDomain());
    IDataSourcePropertiesProvider dspp = ds.getPropertiesProvider();
    AbstractScanOperator as = (AbstractScanOperator) op;
    deliveredProperties = dspp.computePropertiesVector(as.getVariables());
}
Also used : AbstractScanOperator(org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractScanOperator) DatasetDataSource(org.apache.asterix.metadata.declared.DatasetDataSource) DataSource(org.apache.asterix.metadata.declared.DataSource) DatasetDataSource(org.apache.asterix.metadata.declared.DatasetDataSource) IDataSourcePropertiesProvider(org.apache.hyracks.algebricks.core.algebra.metadata.IDataSourcePropertiesProvider)

Aggregations

DataSource (org.apache.asterix.metadata.declared.DataSource)12 ILogicalExpression (org.apache.hyracks.algebricks.core.algebra.base.ILogicalExpression)9 ArrayList (java.util.ArrayList)8 AbstractLogicalOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractLogicalOperator)8 DataSourceScanOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.DataSourceScanOperator)8 LogicalVariable (org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable)7 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)7 IAType (org.apache.asterix.om.types.IAType)6 List (java.util.List)5 ARecordType (org.apache.asterix.om.types.ARecordType)5 Mutable (org.apache.commons.lang3.mutable.Mutable)5 ILogicalOperator (org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator)5 AssignOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator)5 DatasetDataSource (org.apache.asterix.metadata.declared.DatasetDataSource)4 Dataset (org.apache.asterix.metadata.entities.Dataset)4 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)4 VariableReferenceExpression (org.apache.hyracks.algebricks.core.algebra.expressions.VariableReferenceExpression)4 FunctionIdentifier (org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier)4 UnnestMapOperator (org.apache.hyracks.algebricks.core.algebra.operators.logical.UnnestMapOperator)4 CommitOperator (org.apache.asterix.algebra.operators.CommitOperator)3