Search in sources :

Example 36 with CalciteSchema

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;
}
Also used : CalciteSchema(org.apache.calcite.jdbc.CalciteSchema)

Example 37 with CalciteSchema

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);
        }
    }
}
Also used : DynamicRootSchema(org.apache.calcite.jdbc.DynamicRootSchema) SchemaPath(org.apache.drill.common.expression.SchemaPath) CalciteSchema(org.apache.calcite.jdbc.CalciteSchema) ArrayList(java.util.ArrayList) PathSegment(org.apache.drill.common.expression.PathSegment)

Aggregations

CalciteSchema (org.apache.calcite.jdbc.CalciteSchema)31 SchemaPlus (org.apache.calcite.schema.SchemaPlus)8 CalciteSchema (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.jdbc.CalciteSchema)6 ArrayList (java.util.ArrayList)5 RelDataType (org.apache.calcite.rel.type.RelDataType)5 Schema (org.apache.calcite.schema.Schema)4 Table (org.apache.calcite.schema.Table)4 SqlIdentifier (org.apache.calcite.sql.SqlIdentifier)4 SqlNode (org.apache.calcite.sql.SqlNode)4 ImmutableList (com.google.common.collect.ImmutableList)3 BeamCalciteSchema (org.apache.beam.sdk.extensions.sql.impl.BeamCalciteSchema)3 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)3 TableFunction (org.apache.calcite.schema.TableFunction)3 TranslatableTable (org.apache.calcite.schema.TranslatableTable)3 AbstractSchema (org.apache.calcite.schema.impl.AbstractSchema)3 ViewTableMacro (org.apache.calcite.schema.impl.ViewTableMacro)3 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 JdbcSchema (org.apache.calcite.adapter.jdbc.JdbcSchema)2 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)2