@Override public Object[] apply(final String schemaName) { final SchemaPlus subSchema = rootSchema.getSubSchema(schemaName); return new Object[]{ CATALOG_NAME, // CATALOG_NAME subSchema.getName(), // SCHEMA_NAME null, // SCHEMA_OWNER null, // DEFAULT_CHARACTER_SET_CATALOG null, // DEFAULT_CHARACTER_SET_SCHEMA null, // DEFAULT_CHARACTER_SET_NAME null // SQL_PATH }; } }
private static void addSchemasToCloseList(final SchemaPlus tree, final List<AutoCloseable> toClose) { for(String subSchemaName : tree.getSubSchemaNames()) { addSchemasToCloseList(tree.getSubSchema(subSchemaName), toClose); } try { AbstractSchema drillSchemaImpl = tree.unwrap(AbstractSchema.class); toClose.add(drillSchemaImpl); } catch (ClassCastException e) { // Ignore as the SchemaPlus is not an implementation of Drill schema. } } }
@Override public Iterable<Object[]> apply(final String schemaName) final SchemaPlus subSchema = rootSchema.getSubSchema(schemaName);
@Override public Iterable<Object[]> apply(final String schemaName) final SchemaPlus subSchema = rootSchema.getSubSchema(schemaName); final JavaTypeFactoryImpl typeFactory = new JavaTypeFactoryImpl(TYPE_SYSTEM);
.context(Contexts.EMPTY_CONTEXT) .typeSystem(DruidTypeSystem.INSTANCE) .defaultSchema(rootSchema.getSubSchema(DruidSchema.NAME)) .sqlToRelConverterConfig(sqlToRelConverterConfig) .context(new Context()
public SchemaPlus getDefaultSchema() { SchemaPlus defaultSchemaPlus = this.rootSchema; for (String schemaName : this.defaultSchema) { defaultSchemaPlus = defaultSchemaPlus.getSubSchema(schemaName); } return defaultSchemaPlus; }
/** Utility method to search for schema path starting from the given <i>schema</i> reference */ private static SchemaPlus searchSchemaTree(SchemaPlus schema, final List<String> schemaPath) { for (String schemaName : schemaPath) { // schemas in Drill are case insensitive and stored in lower case schema = schema.getSubSchema(schemaName.toLowerCase()); if (schema == null) { return null; } } return schema; }
@Override public Object[] apply(final String schemaName) { final SchemaPlus subSchema = rootSchema.getSubSchema(schemaName); return new Object[]{ EMPTY_CATALOG, // CATALOG_NAME subSchema.getName(), // SCHEMA_NAME null, // SCHEMA_OWNER null, // DEFAULT_CHARACTER_SET_CATALOG null, // DEFAULT_CHARACTER_SET_SCHEMA null, // DEFAULT_CHARACTER_SET_NAME null // SQL_PATH }; } }
/** Returns a {@link Queryable}, given a fully-qualified table name as an * iterable. */ public static <E> Queryable<E> queryable(DataContext root, Class<E> clazz, Iterable<? extends String> names) { SchemaPlus schema = root.getRootSchema(); for (Iterator<? extends String> iterator = names.iterator();;) { String name = iterator.next(); if (iterator.hasNext()) { schema = schema.getSubSchema(name); } else { return queryable(root, schema, clazz, name); } } }
/** Returns an {@link org.apache.calcite.linq4j.Enumerable} over object * arrays, given a fully-qualified table name which leads to a * {@link ScannableTable}. */ public static Table table(DataContext root, String... names) { SchemaPlus schema = root.getRootSchema(); final List<String> nameList = Arrays.asList(names); for (Iterator<? extends String> iterator = nameList.iterator();;) { String name = iterator.next(); if (iterator.hasNext()) { schema = schema.getSubSchema(name); } else { return schema.getTable(name); } } }
/** Returns a {@link Queryable}, given a fully-qualified table name as an * iterable. */ public static <E> Queryable<E> queryable(DataContext root, Class<E> clazz, Iterable<? extends String> names) { SchemaPlus schema = root.getRootSchema(); for (Iterator<? extends String> iterator = names.iterator();;) { String name = iterator.next(); if (iterator.hasNext()) { schema = schema.getSubSchema(name); } else { return queryable(root, schema, clazz, name); } } }
@Override public Iterable<String> getSubPartitions(String schema, String table, List<String> partitionColumns, List<String> partitionValues ) throws PartitionNotFoundException { AbstractSchema subSchema = rootSchema.getSubSchema(schema.toLowerCase()).unwrap(AbstractSchema.class); return subSchema.getSubPartitions(table, partitionColumns, partitionValues); } }
/** Returns an {@link org.apache.calcite.linq4j.Enumerable} over object * arrays, given a fully-qualified table name which leads to a * {@link ScannableTable}. */ public static Table table(DataContext root, String... names) { SchemaPlus schema = root.getRootSchema(); final List<String> nameList = Arrays.asList(names); for (Iterator<? extends String> iterator = nameList.iterator();;) { String name = iterator.next(); if (iterator.hasNext()) { schema = schema.getSubSchema(name); } else { return schema.getTable(name); } } }
public List<List<String>> getCalciteReaderDefaultPaths(SchemaPlus defaultSchema) { List<List<String>> paths = new ArrayList<>(); // Add both catalog and catalog.db, if there's a default db, as default schema paths paths.add(new ArrayList<>(CalciteSchema.from(defaultSchema).path(getDefaultCatalogName()))); if (getDefaultDatabaseName() != null && defaultSchema.getSubSchema(getDefaultCatalogName()) != null) { paths.add(new ArrayList<>( CalciteSchema.from(defaultSchema.getSubSchema(getDefaultCatalogName())).path(getDefaultDatabaseName()))); } return paths; } }
private static SchemaPlus addSchemaIfNotExists(SchemaPlus rootSchema, SchemaSpec schemaSpec) { final SchemaPlus schema = rootSchema.getSubSchema(schemaSpec.schemaName); if (schema != null) { return schema; } return addSchema(rootSchema, schemaSpec); }
private static SchemaPlus addSchemaIfNotExists(SchemaPlus rootSchema, SchemaSpec schemaSpec) { final SchemaPlus schema = rootSchema.getSubSchema(schemaSpec.schemaName); if (schema != null) { return schema; } return addSchema(rootSchema, schemaSpec); }
public static void registerCatalog( SchemaPlus parentSchema, String catalogName, ReadableCatalog catalog) { LOGGER.info("Register catalog '{}' to Calcite", catalogName); SchemaPlus catalogSchema = parentSchema.getSubSchema(catalogName); if (catalogSchema != null) { throw new CatalogAlreadyExistException(catalogName); } else { CatalogCalciteSchema newCatalog = new CatalogCalciteSchema(catalogName, catalog); SchemaPlus schemaPlusOfNewCatalog = parentSchema.add(catalogName, newCatalog); newCatalog.registerSubSchemas(schemaPlusOfNewCatalog); } }
public Table getTable(SchemaPlus rootSchema){ List<FolderName> components = this.getFolderPath(); SchemaPlus schema = rootSchema.getSubSchema(this.getRoot().getName()); if(schema == null){ throw new IllegalStateException(String.format("Failure finding schema path %s in position 0 of path %s", getRoot().getName(), toPathString())); } int i = 1; for(FolderName folder : components){ schema = schema.getSubSchema(folder.getName()); if(schema == null){ throw new IllegalStateException(String.format("Failure finding schema path %s in position %d of path %s", folder.getName(), i, toPathString())); } i++; } Table table = schema.getTable(getLeaf().getName()); if(table == null){ throw new IllegalStateException(String.format("Failure finding table in path %s. The schema exists but no table in that schema matches %s", toPathString(), getLeaf().getName())); } return table; }
@Test public void testCloneSchema() throws ClassNotFoundException, SQLException { final Connection connection = CalciteAssert.that(CalciteAssert.Config.JDBC_FOODMART).connect(); final CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class); final SchemaPlus rootSchema = calciteConnection.getRootSchema(); final SchemaPlus foodmart = rootSchema.getSubSchema("foodmart"); rootSchema.add("foodmart2", new CloneSchema(foodmart)); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery( "select count(*) from \"foodmart2\".\"time_by_day\""); assertTrue(resultSet.next()); assertEquals(730, resultSet.getInt(1)); resultSet.close(); connection.close(); }
@Test public void testCloneSchema() throws ClassNotFoundException, SQLException { final Connection connection = CalciteAssert.that(CalciteAssert.Config.JDBC_FOODMART).connect(); final CalciteConnection calciteConnection = connection.unwrap(CalciteConnection.class); final SchemaPlus rootSchema = calciteConnection.getRootSchema(); final SchemaPlus foodmart = rootSchema.getSubSchema("foodmart"); rootSchema.add("foodmart2", new CloneSchema(foodmart)); Statement statement = connection.createStatement(); ResultSet resultSet = statement.executeQuery( "select count(*) from \"foodmart2\".\"time_by_day\""); assertTrue(resultSet.next()); assertEquals(730, resultSet.getInt(1)); resultSet.close(); connection.close(); }