use of org.apache.calcite.jdbc.CalciteSchema in project calcite by apache.
the class SqlValidatorUtil method getTableEntry.
/**
* Finds a {@link org.apache.calcite.jdbc.CalciteSchema.TableEntry} in a
* given catalog reader whose table has the given name, possibly qualified.
*
* <p>Uses the case-sensitivity policy of the specified catalog reader.
*
* <p>If not found, returns null.
*
* @param catalogReader accessor to the table metadata
* @param names Name of table, may be qualified or fully-qualified
*
* @return TableEntry with a table with the given name, or null
*/
public static CalciteSchema.TableEntry getTableEntry(SqlValidatorCatalogReader catalogReader, List<String> names) {
// If not found, look in the root schema.
for (List<String> schemaPath : catalogReader.getSchemaPaths()) {
CalciteSchema schema = getSchema(catalogReader.getRootSchema(), Iterables.concat(schemaPath, Util.skipLast(names)), catalogReader.nameMatcher());
if (schema == null) {
continue;
}
CalciteSchema.TableEntry entry = getTableEntryFrom(schema, Util.last(names), catalogReader.nameMatcher().isCaseSensitive());
if (entry != null) {
return entry;
}
}
return null;
}
use of org.apache.calcite.jdbc.CalciteSchema in project drill by apache.
the class DrillValidator method replaceAliasWithActualName.
private void replaceAliasWithActualName(SqlIdentifier tempNode) {
CalciteSchema schema = getCatalogReader().getRootSchema();
if (schema instanceof DynamicRootSchema) {
DynamicRootSchema rootSchema = (DynamicRootSchema) schema;
String alias = SchemaPath.getCompoundPath(tempNode.names.toArray(new String[0])).toExpr();
SchemaPath actualPath = rootSchema.resolveTableAlias(alias);
if (actualPath != null) {
List<String> names = new ArrayList<>();
PathSegment pathSegment = actualPath.getRootSegment();
while (pathSegment != null) {
names.add(pathSegment.getNameSegment().getPath());
pathSegment = pathSegment.getChild();
}
changeNames(tempNode, names);
}
}
}
Aggregations