Java Code Examples for org.apache.calcite.schema.SchemaPlus#getSubSchemaNames()
The following examples show how to use
org.apache.calcite.schema.SchemaPlus#getSubSchemaNames() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InfoSchemaRecordGenerator.java From Bats with Apache License 2.0 | 6 votes |
/** * 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); } }
Example 2
Source File: MycatCalciteDataContext.java From Mycat2 with GNU General Public License v3.0 | 6 votes |
public MycatLogicTable getLogicTable(String targetName, String schema, String table) { String uniqueName = targetName + "." + schema + "." + table; SchemaPlus rootSchema = getRootSchema(); Set<String> subSchemaNames = rootSchema.getSubSchemaNames(); for (String subSchemaName : subSchemaNames) { SchemaPlus subSchema = rootSchema.getSubSchema(subSchemaName); log.debug("schemaName:{}", subSchemaName); Set<String> tableNames = subSchema.getTableNames(); log.debug("tableNames:{}", tableNames); for (String tableName : tableNames) { Table table1 = subSchema.getTable(tableName); if (table1 instanceof MycatLogicTable) { Map<String, MycatPhysicalTable> dataNodeMap = ((MycatLogicTable) table1).getDataNodeMap(); log.debug("dataNodeMap:{}", dataNodeMap); if (dataNodeMap.containsKey(uniqueName)) { return Objects.requireNonNull((MycatLogicTable) table1); } } } } return null; }
Example 3
Source File: SchemaTreeProvider.java From Bats with Apache License 2.0 | 5 votes |
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. } }
Example 4
Source File: DynamicRootSchema.java From Bats with Apache License 2.0 | 4 votes |
/** * 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 */ public void loadSchemaFactory(String schemaName, boolean caseSensitive) { try { SchemaPlus schemaPlus = this.plus(); StoragePlugin plugin = getSchemaFactories().getPlugin(schemaName); if (plugin != null && plugin.getConfig().isEnabled()) { 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 = getSchemaFactories().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(org.apache.drill.exec.store.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(ExecutionSetupException | 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(UserExceptionUtils.getUserHint(ex)); //Provide hint if it exists throw exceptBuilder.build(logger); } }