public static DataSource lookupSourceInMetadata(IClusterStateManager clusterStateManager,
MetadataTransactionContext mdTxnCtx, DataSourceId aqlId) throws AlgebricksException {
Dataset dataset = findDataset(mdTxnCtx, aqlId.getDataverseName(), aqlId.getDatasourceName());
if (dataset == null) {
throw new AlgebricksException("Datasource with id " + aqlId + " was not found.");
}
IAType itemType = findType(mdTxnCtx, dataset.getItemTypeDataverseName(), dataset.getItemTypeName());
IAType metaItemType = findType(mdTxnCtx, dataset.getMetaItemTypeDataverseName(), dataset.getMetaItemTypeName());
INodeDomain domain = findNodeDomain(clusterStateManager, mdTxnCtx, dataset.getNodeGroupName());
byte datasourceType = dataset.getDatasetType().equals(DatasetType.EXTERNAL) ? DataSource.Type.EXTERNAL_DATASET
: DataSource.Type.INTERNAL_DATASET;
return new DatasetDataSource(aqlId, dataset, itemType, metaItemType, datasourceType,
dataset.getDatasetDetails(), domain);
}
}