/** * Converts a {@link SqlValidatorScope} into a {@link RelOptTable}. This is only possible if the * scope represents an identifier, such as "sales.emp". Otherwise, returns null. * * @param namespace Namespace * @param catalogReader Schema * @param datasetName Name of sample dataset to substitute, or null to use the regular table * @param usedDataset Output parameter which is set to true if a sample dataset is found; may be * null */ public static RelOptTable getRelOptTable( SqlValidatorNamespace namespace, Prepare.CatalogReader catalogReader, String datasetName, boolean[] usedDataset) { if (namespace.isWrapperFor(IdentifierNamespace.class)) { IdentifierNamespace identifierNamespace = namespace.unwrap(IdentifierNamespace.class); final List<String> names = identifierNamespace.getId().names; if ((datasetName != null) && (catalogReader instanceof RelOptSchemaWithSampling)) { return ((RelOptSchemaWithSampling) catalogReader) .getTableForMember(names, datasetName, usedDataset); } else { // Schema does not support substitution. Ignore the dataset, // if any. return catalogReader.getTableForMember(names); } } else { return null; } }