Search in sources :

Example 71 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project drill by apache.

the class JdbcCatalogSchema method setHolder.

void setHolder(SchemaPlus plusOfThis) {
    for (String s : getSubSchemaNames()) {
        CapitalizingJdbcSchema inner = getSubSchema(s);
        SchemaPlus holder = plusOfThis.add(s, inner);
        inner.setHolder(holder);
    }
}
Also used : SchemaPlus(org.apache.calcite.schema.SchemaPlus)

Example 72 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project drill by apache.

the class UserSession method setDefaultSchemaPath.

/**
 * Update the schema path for the session.
 * @param newDefaultSchemaPath New default schema path to set. It could be relative to the current default schema or
 *                             absolute schema.
 * @param currentDefaultSchema Current default schema.
 * @throws ValidationException If the given default schema path is invalid in current schema tree.
 */
public void setDefaultSchemaPath(String newDefaultSchemaPath, SchemaPlus currentDefaultSchema) throws ValidationException {
    final List<String> newDefaultPathAsList = SchemaUtilites.getSchemaPathAsList(newDefaultSchemaPath);
    SchemaPlus newDefault;
    // First try to find the given schema relative to the current default schema.
    newDefault = SchemaUtilites.findSchema(currentDefaultSchema, newDefaultPathAsList);
    if (newDefault == null) {
        // If we fail to find the schema relative to current default schema, consider the given new default schema path as
        // absolute schema path.
        newDefault = SchemaUtilites.findSchema(currentDefaultSchema, newDefaultPathAsList);
    }
    if (newDefault == null) {
        SchemaUtilites.throwSchemaNotFoundException(currentDefaultSchema, newDefaultSchemaPath);
    }
    properties.setProperty(DrillProperties.SCHEMA, SchemaUtilites.getSchemaPath(newDefault));
}
Also used : SchemaPlus(org.apache.calcite.schema.SchemaPlus)

Example 73 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project drill by apache.

the class SplunkSchemaFactory method registerSchemas.

@Override
public void registerSchemas(SchemaConfig schemaConfig, SchemaPlus parent) {
    SplunkSchema schema = new SplunkSchema(plugin);
    SchemaPlus plusOfThis = parent.add(schema.getName(), schema);
}
Also used : SchemaPlus(org.apache.calcite.schema.SchemaPlus)

Example 74 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project drill by apache.

the class BaseQueryRunner method applyDefaultSchema.

protected void applyDefaultSchema(String defaultSchema) throws ValidationException {
    if (!Strings.isNullOrEmpty(defaultSchema)) {
        SessionOptionManager options = webUserConnection.getSession().getOptions();
        @SuppressWarnings("resource") SchemaTreeProvider schemaTreeProvider = new SchemaTreeProvider(workManager.getContext());
        SchemaPlus rootSchema = schemaTreeProvider.createRootSchema(options);
        webUserConnection.getSession().setDefaultSchemaPath(defaultSchema, rootSchema);
    }
}
Also used : SessionOptionManager(org.apache.drill.exec.server.options.SessionOptionManager) SchemaPlus(org.apache.calcite.schema.SchemaPlus) SchemaTreeProvider(org.apache.drill.exec.store.SchemaTreeProvider)

Example 75 with SchemaPlus

use of org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus in project drill by apache.

the class DynamicRootSchema method loadSchemaFactory.

/**
 * Loads schema factory(storage plugin) for specified {@code schemaName}
 * @param schemaName the name of the schema
 * @param caseSensitive whether matching for the schema name is case sensitive
 */
private void loadSchemaFactory(String schemaName, boolean caseSensitive) {
    try {
        SchemaPlus schemaPlus = this.plus();
        StoragePlugin plugin = storages.getPlugin(schemaName);
        if (plugin != null) {
            plugin.registerSchemas(schemaConfig, schemaPlus);
            return;
        }
        // Could not find the plugin of schemaName. The schemaName could be `dfs.tmp`, a 2nd level schema under 'dfs'
        List<String> paths = SchemaUtilites.getSchemaPathAsList(schemaName);
        if (paths.size() == 2) {
            plugin = storages.getPlugin(paths.get(0));
            if (plugin == null) {
                return;
            }
            // Looking for the SchemaPlus for the top level (e.g. 'dfs') of schemaName (e.g. 'dfs.tmp')
            SchemaPlus firstLevelSchema = schemaPlus.getSubSchema(paths.get(0));
            if (firstLevelSchema == null) {
                // register schema for this storage plugin to 'this'.
                plugin.registerSchemas(schemaConfig, schemaPlus);
                firstLevelSchema = schemaPlus.getSubSchema(paths.get(0));
            }
            // Load second level schemas for this storage plugin
            List<SchemaPlus> secondLevelSchemas = new ArrayList<>();
            for (String secondLevelSchemaName : firstLevelSchema.getSubSchemaNames()) {
                secondLevelSchemas.add(firstLevelSchema.getSubSchema(secondLevelSchemaName));
            }
            for (SchemaPlus schema : secondLevelSchemas) {
                org.apache.drill.exec.store.AbstractSchema drillSchema;
                try {
                    drillSchema = schema.unwrap(AbstractSchema.class);
                } catch (ClassCastException e) {
                    throw new RuntimeException(String.format("Schema '%s' is not expected under root schema", schema.getName()));
                }
                SubSchemaWrapper wrapper = new SubSchemaWrapper(drillSchema);
                schemaPlus.add(wrapper.getName(), wrapper);
            }
        }
    } catch (PluginException | IOException ex) {
        logger.warn("Failed to load schema for \"" + schemaName + "\"!", ex);
        // We can't proceed further without a schema, throw a runtime exception.
        UserException.Builder exceptBuilder = UserException.resourceError(ex).message("Failed to load schema for \"" + schemaName + "\"!").addContext(ex.getClass().getName() + ": " + ex.getMessage()).addContext(// Provide hint if it exists
        UserExceptionUtils.getUserHint(ex));
        throw exceptBuilder.build(logger);
    }
}
Also used : SubSchemaWrapper(org.apache.drill.exec.store.SubSchemaWrapper) PluginException(org.apache.drill.exec.store.StoragePluginRegistry.PluginException) SchemaPlus(org.apache.calcite.schema.SchemaPlus) ArrayList(java.util.ArrayList) IOException(java.io.IOException) StoragePlugin(org.apache.drill.exec.store.StoragePlugin) AbstractSchema(org.apache.drill.exec.store.AbstractSchema) AbstractSchema(org.apache.drill.exec.store.AbstractSchema)

Aggregations

SchemaPlus (org.apache.calcite.schema.SchemaPlus)180 Test (org.junit.Test)56 CalciteConnection (org.apache.calcite.jdbc.CalciteConnection)42 Connection (java.sql.Connection)39 AbstractSchema (org.apache.calcite.schema.impl.AbstractSchema)33 ResultSet (java.sql.ResultSet)26 ReflectiveSchema (org.apache.calcite.adapter.java.ReflectiveSchema)24 Table (org.apache.calcite.schema.Table)20 RelNode (org.apache.calcite.rel.RelNode)19 IOException (java.io.IOException)17 Statement (java.sql.Statement)17 SqlNode (org.apache.calcite.sql.SqlNode)17 PreparedStatement (java.sql.PreparedStatement)16 JavaTypeFactory (org.apache.calcite.adapter.java.JavaTypeFactory)15 AbstractSchema (org.apache.drill.exec.store.AbstractSchema)15 ArrayList (java.util.ArrayList)14 SQLException (java.sql.SQLException)13 SchemaPlus (org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.schema.SchemaPlus)13 JavaTypeFactoryImpl (org.apache.calcite.jdbc.JavaTypeFactoryImpl)13 Properties (java.util.Properties)12