Search in sources :

Example 1 with DynamicRootSchema

use of org.apache.calcite.jdbc.DynamicRootSchema 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

ArrayList (java.util.ArrayList)1 CalciteSchema (org.apache.calcite.jdbc.CalciteSchema)1 DynamicRootSchema (org.apache.calcite.jdbc.DynamicRootSchema)1 PathSegment (org.apache.drill.common.expression.PathSegment)1 SchemaPath (org.apache.drill.common.expression.SchemaPath)1