/** * 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(TableNamespace.class)) { return null; } final TableNamespace tableNamespace = namespace.unwrap(TableNamespace.class); final List<String> names = tableNamespace.getTable().getQualifiedName(); RelOptTable table; if (datasetName != null && catalogReader instanceof RelOptSchemaWithSampling) { final RelOptSchemaWithSampling reader = (RelOptSchemaWithSampling) catalogReader; table = reader.getTableForMember(names, datasetName, usedDataset); } else { // Schema does not support substitution. Ignore the data set, if any. table = catalogReader.getTableForMember(names); } if (!tableNamespace.extendedFields.isEmpty()) { table = table.extend(tableNamespace.extendedFields); } return table; }