Search in sources :

Example 56 with SchemaPlus

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

the class JdbcStoragePlugin method registerSchemas.

@Override
public void registerSchemas(SchemaConfig config, SchemaPlus parent) {
    JdbcCatalogSchema schema = new JdbcCatalogSchema(name);
    SchemaPlus holder = parent.add(name, schema);
    schema.setHolder(holder);
}
Also used : SchemaPlus(org.apache.calcite.schema.SchemaPlus)

Example 57 with SchemaPlus

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

the class HiveSchemaFactory method registerSchemas.

@Override
public void registerSchemas(SchemaConfig schemaConfig, SchemaPlus parent) throws IOException {
    DrillHiveMetaStoreClient mClientForSchemaTree = processUserMetastoreClient;
    if (isDrillImpersonationEnabled) {
        try {
            mClientForSchemaTree = metaStoreClientLoadingCache.get(schemaConfig.getUserName());
        } catch (final ExecutionException e) {
            throw new IOException("Failure setting up Hive metastore client.", e);
        }
    }
    HiveSchema schema = new HiveSchema(schemaConfig, mClientForSchemaTree, schemaName);
    SchemaPlus hPlus = parent.add(schemaName, schema);
    schema.setHolder(hPlus);
}
Also used : DrillHiveMetaStoreClient(org.apache.drill.exec.store.hive.DrillHiveMetaStoreClient) SchemaPlus(org.apache.calcite.schema.SchemaPlus) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 58 with SchemaPlus

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

the class KuduSchemaFactory method registerSchemas.

@Override
public void registerSchemas(SchemaConfig schemaConfig, SchemaPlus parent) throws IOException {
    KuduTables schema = new KuduTables(schemaName);
    SchemaPlus hPlus = parent.add(schemaName, schema);
    schema.setHolder(hPlus);
}
Also used : SchemaPlus(org.apache.calcite.schema.SchemaPlus)

Example 59 with SchemaPlus

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

the class SchemaUtilites method getTemporaryWorkspace.

/**
 * Looks in schema tree for default temporary workspace instance.
 *
 * @param defaultSchema default schema
 * @param config drill config
 * @return default temporary workspace, null if workspace was not found
 */
public static AbstractSchema getTemporaryWorkspace(SchemaPlus defaultSchema, DrillConfig config) {
    String temporarySchema = config.getString(ExecConstants.DEFAULT_TEMPORARY_WORKSPACE);
    List<String> temporarySchemaPath = Lists.newArrayList(temporarySchema);
    SchemaPlus schema = findSchema(defaultSchema, temporarySchemaPath);
    return schema == null ? null : unwrapAsDrillSchemaInstance(schema);
}
Also used : SchemaPlus(org.apache.calcite.schema.SchemaPlus)

Example 60 with SchemaPlus

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

the class DescribeSchemaHandler method getPlan.

@Override
public PhysicalPlan getPlan(SqlNode sqlNode) {
    SqlIdentifier schema = ((SqlDescribeSchema) sqlNode).getSchema();
    SchemaPlus drillSchema = SchemaUtilites.findSchema(config.getConverter().getDefaultSchema(), schema.names);
    if (drillSchema != null) {
        StoragePlugin storagePlugin;
        try {
            storagePlugin = context.getStorage().getPlugin(schema.names.get(0));
        } catch (ExecutionSetupException e) {
            throw new DrillRuntimeException("Failure while retrieving storage plugin", e);
        }
        String properties;
        try {
            final Map configMap = mapper.convertValue(storagePlugin.getConfig(), Map.class);
            if (storagePlugin instanceof FileSystemPlugin) {
                transformWorkspaces(schema.names, configMap);
            }
            properties = mapper.writeValueAsString(configMap);
        } catch (JsonProcessingException e) {
            throw new DrillRuntimeException("Error while trying to convert storage config to json string", e);
        }
        return DirectPlan.createDirectPlan(context, new DescribeSchemaResult(Joiner.on(".").join(schema.names), properties));
    }
    throw UserException.validationError().message(String.format("Invalid schema name [%s]", Joiner.on(".").join(schema.names))).build(logger);
}
Also used : ExecutionSetupException(org.apache.drill.common.exceptions.ExecutionSetupException) FileSystemPlugin(org.apache.drill.exec.store.dfs.FileSystemPlugin) SchemaPlus(org.apache.calcite.schema.SchemaPlus) SerializableString(com.fasterxml.jackson.core.SerializableString) SqlIdentifier(org.apache.calcite.sql.SqlIdentifier) DrillRuntimeException(org.apache.drill.common.exceptions.DrillRuntimeException) Map(java.util.Map) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SqlDescribeSchema(org.apache.calcite.sql.SqlDescribeSchema) StoragePlugin(org.apache.drill.exec.store.StoragePlugin)

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