Search in sources :

Example 1 with IdentifierNamespace

use of org.apache.calcite.sql.validate.IdentifierNamespace in project druid by druid-io.

the class SqlResourceCollectorShuttle method visit.

@Override
public SqlNode visit(SqlIdentifier id) {
    // raw tables and views and such will have a IdentifierNamespace
    // since we are scoped to identifiers here, we should only pick up these
    SqlValidatorNamespace namespace = validator.getNamespace(id);
    if (namespace != null && namespace.isWrapperFor(IdentifierNamespace.class)) {
        SqlValidatorTable validatorTable = namespace.getTable();
        // this should not probably be null if the namespace was not null,
        if (validatorTable != null) {
            List<String> qualifiedNameParts = validatorTable.getQualifiedName();
            // 'schema'.'identifier'
            if (qualifiedNameParts.size() == 2) {
                final String schema = qualifiedNameParts.get(0);
                final String resourceName = qualifiedNameParts.get(1);
                final String resourceType = plannerContext.getSchemaResourceType(schema, resourceName);
                if (resourceType != null) {
                    resourceActions.add(new ResourceAction(new Resource(resourceName, resourceType), Action.READ));
                }
            } else if (qualifiedNameParts.size() > 2) {
                // Don't expect to see more than 2 names (catalog?).
                throw new ISE("Cannot analyze table idetifier %s", qualifiedNameParts);
            }
        }
    }
    return super.visit(id);
}
Also used : SqlValidatorTable(org.apache.calcite.sql.validate.SqlValidatorTable) Resource(org.apache.druid.server.security.Resource) ISE(org.apache.druid.java.util.common.ISE) SqlValidatorNamespace(org.apache.calcite.sql.validate.SqlValidatorNamespace) IdentifierNamespace(org.apache.calcite.sql.validate.IdentifierNamespace) ResourceAction(org.apache.druid.server.security.ResourceAction)

Aggregations

IdentifierNamespace (org.apache.calcite.sql.validate.IdentifierNamespace)1 SqlValidatorNamespace (org.apache.calcite.sql.validate.SqlValidatorNamespace)1 SqlValidatorTable (org.apache.calcite.sql.validate.SqlValidatorTable)1 ISE (org.apache.druid.java.util.common.ISE)1 Resource (org.apache.druid.server.security.Resource)1 ResourceAction (org.apache.druid.server.security.ResourceAction)1