@Override public Enumerable<Object[]> scan(final DataContext root) { final FluentIterable<Object[]> results = FluentIterable .from(rootSchema.getSubSchemaNames()) .transform( new Function<String, Object[]>() { @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 }; } } ); return Linq4j.asEnumerable(results); }
.from(rootSchema.getSubSchemaNames()) .transformAndConcat( new Function<String, Iterable<Object[]>>()
.from(rootSchema.getSubSchemaNames()) .transformAndConcat( new Function<String, Iterable<Object[]>>()
@Override public Enumerable<Object[]> scan(final DataContext root) { final FluentIterable<Object[]> results = FluentIterable .from(rootSchema.getSubSchemaNames()) .transform( new Function<String, Object[]>() { @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 }; } } ); return Linq4j.asEnumerable(results); }
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. } } }
.from(rootSchema.getSubSchemaNames()) .transformAndConcat( new Function<String, Iterable<Object[]>>()
.from(rootSchema.getSubSchemaNames()) .transformAndConcat( new Function<String, Iterable<Object[]>>()
/** Unit test to test create root schema which has no "metadata" schema. */ @Test public void testCreateRootSchemaWithNoMetadataSchema() { SchemaPlus rootSchema = Frameworks.createRootSchema(false); assertThat(rootSchema.getSubSchemaNames().size(), equalTo(0)); }
/** Unit test to test create root schema which has no "metadata" schema. */ @Test public void testCreateRootSchemaWithNoMetadataSchema() { SchemaPlus rootSchema = Frameworks.createRootSchema(false); assertThat(rootSchema.getSubSchemaNames().size(), equalTo(0)); }
for (String firstLevelSchemaName : parent.getSubSchemaNames()) { SchemaPlus firstLevelSchema = parent.getSubSchema(firstLevelSchemaName); for (String secondLevelSchemaName : firstLevelSchema.getSubSchemaNames()) { secondLevelSchemas.add(firstLevelSchema.getSubSchema(secondLevelSchemaName));
/** * Recursively scans the given schema, invoking the visitor as appropriate. * @param schemaPath the path to the given schema, so far * @param schema the given schema */ private void scanSchema(String schemaPath, SchemaPlus schema) { // Recursively scan any subschema. for (String name: schema.getSubSchemaNames()) { scanSchema(schemaPath + ("".equals(schemaPath) ? "" : ".") + // If we have an empty schema path, then don't insert a leading dot. name, schema.getSubSchema(name)); } // Visit this schema and if requested ... if (shouldVisitSchema(schemaPath, schema) && visitSchema(schemaPath, schema)) { visitTables(schemaPath, schema); } if (shouldVisitFiles(schemaPath, schema)) { visitFiles(schemaPath, schema); } }
for (String secondLevelSchemaName : firstLevelSchema.getSubSchemaNames()) { secondLevelSchemas.add(firstLevelSchema.getSubSchema(secondLevelSchemaName));
assertThat(aSchema.getSubSchemaNames().size(), is(0)); assertThat(aSchema.getSubSchemaNames().size(), is(0)); assertThat(aSchema.getSubSchemaNames().size(), is(0)); assertThat(aSchema.getSubSchema("b1"), nullValue()); aSchema.setCacheEnabled(false); assertThat(aSchema.getSubSchemaNames().size(), is(1)); assertThat(aSchema.getSubSchema("b1"), notNullValue()); assertThat(aSchema.getSubSchemaNames().size(), is(2)); assertThat(aSchema.getSubSchemaNames().size(), is(2)); aSchema.add("b3", new AbstractSchema()); // explicit aSubSchemaMap.put("b4", new AbstractSchema()); // implicit assertThat(aSchema.getSubSchemaNames().size(), is(3)); aSchema.setCacheEnabled(false); assertThat(aSchema.getSubSchemaNames().size(), is(4)); for (String name : aSchema.getSubSchemaNames()) { assertThat(aSchema.getSubSchema(name), notNullValue()); assertThat(a2Schema.getSubSchemaNames().size(), is(0)); assertThat(a2Schema.getSubSchemaNames().size(), is(0)); Thread.sleep(1); assertThat(a2Schema.getSubSchemaNames().size(), is(0)); assertThat(a2Schema.getSubSchemaNames().size(), is(1)); a2SubSchemaMap.put("b4", new AbstractSchema());
@Test public void testExplicitImplicitSchemaSameName() throws Exception { final SchemaPlus rootSchema = CalciteSchema.createRootSchema(false).plus(); // create schema "/a" final Map<String, Schema> aSubSchemaMap = new HashMap<>(); final SchemaPlus aSchema = rootSchema.add("a", new AbstractSchema() { @Override protected Map<String, Schema> getSubSchemaMap() { return aSubSchemaMap; } }); // add explicit schema "/a/b". aSchema.add("b", new AbstractSchema()); // add implicit schema "/a/b" aSubSchemaMap.put("b", new AbstractSchema()); aSchema.setCacheEnabled(true); // explicit should win implicit. assertThat(aSchema.getSubSchemaNames().size(), is(1)); }
assertThat(aSchema.getSubSchemaNames().size(), is(0)); assertThat(aSchema.getSubSchemaNames().size(), is(0)); assertThat(aSchema.getSubSchemaNames().size(), is(0)); assertThat(aSchema.getSubSchema("b1"), nullValue()); aSchema.setCacheEnabled(false); assertThat(aSchema.getSubSchemaNames().size(), is(1)); assertThat(aSchema.getSubSchema("b1"), notNullValue()); assertThat(aSchema.getSubSchemaNames().size(), is(2)); assertThat(aSchema.getSubSchemaNames().size(), is(2)); aSchema.add("b3", new AbstractSchema()); // explicit aSubSchemaMap.put("b4", new AbstractSchema()); // implicit assertThat(aSchema.getSubSchemaNames().size(), is(3)); aSchema.setCacheEnabled(false); assertThat(aSchema.getSubSchemaNames().size(), is(4)); for (String name : aSchema.getSubSchemaNames()) { assertThat(aSchema.getSubSchema(name), notNullValue()); assertThat(a2Schema.getSubSchemaNames().size(), is(0)); assertThat(a2Schema.getSubSchemaNames().size(), is(0)); Thread.sleep(1); assertThat(a2Schema.getSubSchemaNames().size(), is(0)); assertThat(a2Schema.getSubSchemaNames().size(), is(1)); a2SubSchemaMap.put("b4", new AbstractSchema());
@Test public void testSimpleCalciteSchema() throws Exception { final SchemaPlus rootSchema = CalciteSchema.createRootSchema(false, false).plus(); // create schema "/a" final Map<String, Schema> aSubSchemaMap = new HashMap<>(); final SchemaPlus aSchema = rootSchema.add("a", new AbstractSchema() { @Override protected Map<String, Schema> getSubSchemaMap() { return aSubSchemaMap; } }); // add explicit schema "/a/b". aSchema.add("b", new AbstractSchema()); // add implicit schema "/a/c" aSubSchemaMap.put("c", new AbstractSchema()); assertThat(aSchema.getSubSchema("c"), notNullValue()); assertThat(aSchema.getSubSchema("b"), notNullValue()); // add implicit schema "/a/b" aSubSchemaMap.put("b", new AbstractSchema()); // explicit should win implicit. assertThat(aSchema.getSubSchemaNames().size(), is(2)); }
@Test public void testExplicitImplicitSchemaSameName() throws Exception { final SchemaPlus rootSchema = CalciteSchema.createRootSchema(false).plus(); // create schema "/a" final Map<String, Schema> aSubSchemaMap = new HashMap<>(); final SchemaPlus aSchema = rootSchema.add("a", new AbstractSchema() { @Override protected Map<String, Schema> getSubSchemaMap() { return aSubSchemaMap; } }); // add explicit schema "/a/b". aSchema.add("b", new AbstractSchema()); // add implicit schema "/a/b" aSubSchemaMap.put("b", new AbstractSchema()); aSchema.setCacheEnabled(true); // explicit should win implicit. assertThat(aSchema.getSubSchemaNames().size(), is(1)); }
@Test public void testSimpleCalciteSchema() throws Exception { final SchemaPlus rootSchema = CalciteSchema.createRootSchema(false, false).plus(); // create schema "/a" final Map<String, Schema> aSubSchemaMap = new HashMap<>(); final SchemaPlus aSchema = rootSchema.add("a", new AbstractSchema() { @Override protected Map<String, Schema> getSubSchemaMap() { return aSubSchemaMap; } }); // add explicit schema "/a/b". aSchema.add("b", new AbstractSchema()); // add implicit schema "/a/c" aSubSchemaMap.put("c", new AbstractSchema()); assertThat(aSchema.getSubSchema("c"), notNullValue()); assertThat(aSchema.getSubSchema("b"), notNullValue()); // add implicit schema "/a/b" aSubSchemaMap.put("b", new AbstractSchema()); // explicit should win implicit. assertThat(aSchema.getSubSchemaNames().size(), is(2)); }