use of org.apache.asterix.metadata.declared.IMutationDataSource in project asterixdb by apache.
the class MetaKeyExpressionReferenceTransform method visit.
private ILogicalExpressionReferenceTransformWithCondition visit(Mutable<ILogicalOperator> opRef) throws AlgebricksException {
ILogicalOperator op = opRef.getValue();
// Reaches NTS or ETS.
if (op.getInputs().size() == 0) {
return NoOpExpressionReferenceTransform.INSTANCE;
}
// Datascan returns an useful transform if the meta part presents in the dataset.
if (op.getOperatorTag() == LogicalOperatorTag.DATASOURCESCAN) {
DataSourceScanOperator scanOp = (DataSourceScanOperator) op;
ILogicalExpressionReferenceTransformWithCondition inputTransfomer = visit(op.getInputs().get(0));
DataSource dataSource = (DataSource) scanOp.getDataSource();
List<ILogicalExpressionReferenceTransformWithCondition> transformers = null;
List<LogicalVariable> allVars = scanOp.getVariables();
LogicalVariable dataVar = dataSource.getDataRecordVariable(allVars);
LogicalVariable metaVar = dataSource.getMetaVariable(allVars);
LogicalExpressionReferenceTransform currentTransformer = null;
// https://issues.apache.org/jira/browse/ASTERIXDB-1618
if (dataSource.getDatasourceType() != DataSource.Type.EXTERNAL_DATASET && dataSource.getDatasourceType() != DataSource.Type.INTERNAL_DATASET && dataSource.getDatasourceType() != DataSource.Type.LOADABLE) {
IMutationDataSource mds = (IMutationDataSource) dataSource;
if (mds.isChange()) {
transformers = new ArrayList<>();
transformers.add(new MetaKeyExpressionReferenceTransform(mds.getPkVars(allVars), mds.getKeyAccessExpression()));
} else if (metaVar != null) {
transformers = new ArrayList<>();
transformers.add(new MetaKeyToFieldAccessTransform(metaVar));
}
}
if (!dataSource.hasMeta() && transformers == null) {
return inputTransfomer;
}
if (metaVar != null) {
currentTransformer = new LogicalExpressionReferenceTransform(dataVar, metaVar);
}
if (inputTransfomer.equals(NoOpExpressionReferenceTransform.INSTANCE) && transformers == null) {
return currentTransformer;
} else if (inputTransfomer.equals(NoOpExpressionReferenceTransform.INSTANCE) && currentTransformer == null) {
return transformers.get(0);
} else {
// Requires an argument variable to resolve ambiguity.
if (transformers == null) {
transformers = new ArrayList<>();
}
if (!inputTransfomer.equals(NoOpExpressionReferenceTransform.INSTANCE)) {
inputTransfomer.setVariableRequired();
transformers.add(inputTransfomer);
}
currentTransformer.setVariableRequired();
transformers.add(currentTransformer);
return new CompositeExpressionReferenceTransform(transformers);
}
}
// Visits children in the depth-first order.
List<ILogicalExpressionReferenceTransformWithCondition> transformers = new ArrayList<>();
for (Mutable<ILogicalOperator> childRef : op.getInputs()) {
ILogicalExpressionReferenceTransformWithCondition transformer = visit(childRef);
if (!transformer.equals(NoOpExpressionReferenceTransform.INSTANCE)) {
transformers.add(transformer);
}
}
ILogicalExpressionReferenceTransformWithCondition currentTransformer = null;
if (transformers.size() == 0) {
currentTransformer = NoOpExpressionReferenceTransform.INSTANCE;
} else if (transformers.size() == 1) {
currentTransformer = transformers.get(0);
} else {
// Transformers in a CompositeTransformer should require argument variable check.
for (ILogicalExpressionReferenceTransformWithCondition transformer : transformers) {
transformer.setVariableRequired();
}
currentTransformer = new CompositeExpressionReferenceTransform(transformers);
}
rewritten |= op.acceptExpressionTransform(currentTransformer);
return currentTransformer;
}
Aggregations