use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractUnnestOperator in project asterixdb by apache.
the class IntroduceEnforcedListTypeRule method rewritePost.
@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException {
if (context.checkIfInDontApplySet(this, opRef.getValue()))
return false;
AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue();
context.addToDontApplySet(this, opRef.getValue());
/**
* rewrite list constructor types for list constructor functions
*/
List<Mutable<ILogicalExpression>> expressions;
switch(op.getOperatorTag()) {
case ASSIGN:
AbstractAssignOperator assignOp = (AbstractAssignOperator) op;
expressions = assignOp.getExpressions();
break;
case UNNEST:
AbstractUnnestOperator unnestOp = (AbstractUnnestOperator) op;
expressions = Collections.singletonList(unnestOp.getExpressionRef());
break;
default:
return false;
}
IVariableTypeEnvironment env = op.computeOutputTypeEnvironment(context);
return rewriteExpressions(expressions, env);
}
use of org.apache.hyracks.algebricks.core.algebra.operators.logical.AbstractUnnestOperator in project asterixdb by apache.
the class OptimizableOperatorSubTree method setDatasetAndTypeMetadata.
/**
* Find the dataset corresponding to the datasource scan in the metadata.
* Also sets recordType to be the type of that dataset.
*/
public boolean setDatasetAndTypeMetadata(MetadataProvider metadataProvider) throws AlgebricksException {
String dataverseName = null;
String datasetName = null;
Dataset ds = null;
ARecordType rType = null;
List<Mutable<ILogicalOperator>> sourceOpRefs = new ArrayList<>();
List<DataSourceType> dsTypes = new ArrayList<>();
sourceOpRefs.add(getDataSourceRef());
dsTypes.add(getDataSourceType());
// If there are multiple datasources in the subtree, we need to find the dataset for these.
if (getIxJoinOuterAdditionalDataSourceRefs() != null) {
for (int i = 0; i < getIxJoinOuterAdditionalDataSourceRefs().size(); i++) {
sourceOpRefs.add(getIxJoinOuterAdditionalDataSourceRefs().get(i));
dsTypes.add(getIxJoinOuterAdditionalDataSourceTypes().get(i));
}
}
for (int i = 0; i < sourceOpRefs.size(); i++) {
switch(dsTypes.get(i)) {
case DATASOURCE_SCAN:
DataSourceScanOperator dataSourceScan = (DataSourceScanOperator) sourceOpRefs.get(i).getValue();
IDataSource<?> datasource = dataSourceScan.getDataSource();
if (datasource instanceof DataSource) {
byte dsType = ((DataSource) datasource).getDatasourceType();
if (dsType != DataSource.Type.INTERNAL_DATASET && dsType != DataSource.Type.EXTERNAL_DATASET) {
return false;
}
}
Pair<String, String> datasetInfo = AnalysisUtil.getDatasetInfo(dataSourceScan);
dataverseName = datasetInfo.first;
datasetName = datasetInfo.second;
break;
case PRIMARY_INDEX_LOOKUP:
AbstractUnnestOperator unnestMapOp = (AbstractUnnestOperator) sourceOpRefs.get(i).getValue();
ILogicalExpression unnestExpr = unnestMapOp.getExpressionRef().getValue();
AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) unnestExpr;
AccessMethodJobGenParams jobGenParams = new AccessMethodJobGenParams();
jobGenParams.readFromFuncArgs(f.getArguments());
datasetName = jobGenParams.getDatasetName();
dataverseName = jobGenParams.getDataverseName();
break;
case EXTERNAL_SCAN:
UnnestMapOperator externalScan = (UnnestMapOperator) sourceOpRefs.get(i).getValue();
datasetInfo = AnalysisUtil.getExternalDatasetInfo(externalScan);
dataverseName = datasetInfo.first;
datasetName = datasetInfo.second;
break;
case COLLECTION_SCAN:
if (i != 0) {
getIxJoinOuterAdditionalDatasets().add(null);
getIxJoinOuterAdditionalRecordTypes().add(null);
}
continue;
case NO_DATASOURCE:
default:
return false;
}
if (dataverseName == null || datasetName == null) {
return false;
}
// Find the dataset corresponding to the datasource in the metadata.
ds = metadataProvider.findDataset(dataverseName, datasetName);
if (ds == null) {
throw CompilationException.create(ErrorCode.NO_METADATA_FOR_DATASET, datasetName);
}
// Get the record type for that dataset.
IAType itemType = metadataProvider.findType(ds.getItemTypeDataverseName(), ds.getItemTypeName());
if (itemType.getTypeTag() != ATypeTag.OBJECT) {
if (i == 0) {
return false;
} else {
getIxJoinOuterAdditionalDatasets().add(null);
getIxJoinOuterAdditionalRecordTypes().add(null);
}
}
rType = (ARecordType) itemType;
// Get the meta record type for that dataset.
IAType metaItemType = metadataProvider.findType(ds.getMetaItemTypeDataverseName(), ds.getMetaItemTypeName());
// First index is always the primary datasource in this subtree.
if (i == 0) {
setDataset(ds);
setRecordType(rType);
setMetaRecordType((ARecordType) metaItemType);
} else {
getIxJoinOuterAdditionalDatasets().add(ds);
getIxJoinOuterAdditionalRecordTypes().add(rType);
}
dataverseName = null;
datasetName = null;
ds = null;
rType = null;
}
return true;
}
Aggregations