本文整理汇总了Java中org.apache.calcite.schema.SchemaPlus.getTable方法的典型用法代码示例。如果您正苦于以下问题:Java SchemaPlus.getTable方法的具体用法?Java SchemaPlus.getTable怎么用?Java SchemaPlus.getTable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.schema.SchemaPlus
的用法示例。
在下文中一共展示了SchemaPlus.getTable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTable
import org.apache.calcite.schema.SchemaPlus; //导入方法依赖的package包/类
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;
}
示例2: scanSchema
import org.apache.calcite.schema.SchemaPlus; //导入方法依赖的package包/类
/**
* 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 +
(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)) {
// ... do for each of the schema's tables.
for (String tableName: schema.getTableNames()) {
Table table = schema.getTable(tableName);
if (table == null) {
// Schema may return NULL for table if the query user doesn't have permissions to load the table. Ignore such
// tables as INFO SCHEMA is about showing tables which the use has access to query.
continue;
}
// Visit the table, and if requested ...
if (shouldVisitTable(schemaPath, tableName) && visitTable(schemaPath, tableName, table)) {
// ... do for each of the table's fields.
RelDataType tableRow = table.getRowType(new JavaTypeFactoryImpl());
for (RelDataTypeField field: tableRow.getFieldList()) {
visitField(schemaPath, tableName, field);
}
}
}
}
}
示例3: getPlan
import org.apache.calcite.schema.SchemaPlus; //导入方法依赖的package包/类
@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException, ForemanSetupException {
final SqlRefreshMetadata refreshTable = unwrap(sqlNode, SqlRefreshMetadata.class);
try {
final SchemaPlus schema = findSchema(context.getNewDefaultSchema(),
refreshTable.getSchemaPath());
final String tableName = refreshTable.getName();
if (tableName.contains("*") || tableName.contains("?")) {
return direct(false, "Glob path %s not supported for metadata refresh", tableName);
}
final Table table = schema.getTable(tableName);
if(table == null){
return direct(false, "Table %s does not exist.", tableName);
}
if(! (table instanceof DrillTable) ){
return notSupported(tableName);
}
final DrillTable drillTable = (DrillTable) table;
final Object selection = drillTable.getSelection();
if( !(selection instanceof FormatSelection) ){
return notSupported(tableName);
}
FormatSelection formatSelection = (FormatSelection) selection;
FormatPluginConfig formatConfig = formatSelection.getFormat();
if (!((formatConfig instanceof ParquetFormatConfig) ||
((formatConfig instanceof NamedFormatPluginConfig) && ((NamedFormatPluginConfig) formatConfig).name.equals("parquet")))) {
return notSupported(tableName);
}
FileSystemPlugin plugin = (FileSystemPlugin) drillTable.getPlugin();
DrillFileSystem fs = new DrillFileSystem(plugin.getFormatPlugin(formatSelection.getFormat()).getFsConf());
String selectionRoot = formatSelection.getSelection().selectionRoot;
if (!fs.getFileStatus(new Path(selectionRoot)).isDirectory()) {
return notSupported(tableName);
}
Metadata.createMeta(fs, selectionRoot);
return direct(true, "Successfully updated metadata for table %s.", tableName);
} catch(Exception e) {
logger.error("Failed to update metadata for table '{}'", refreshTable.getName(), e);
return DirectPlan.createDirectPlan(context, false, String.format("Error: %s", e.getMessage()));
}
}
示例4: rewrite
import org.apache.calcite.schema.SchemaPlus; //导入方法依赖的package包/类
/** Rewrite the parse tree as SELECT ... FROM INFORMATION_SCHEMA.COLUMNS ... */
@Override
public SqlNode rewrite(SqlNode sqlNode) throws RelConversionException, ForemanSetupException {
SqlDescribeTable node = unwrap(sqlNode, SqlDescribeTable.class);
try {
List<SqlNode> selectList =
ImmutableList.of((SqlNode) new SqlIdentifier(COLS_COL_COLUMN_NAME, SqlParserPos.ZERO),
new SqlIdentifier(COLS_COL_DATA_TYPE, SqlParserPos.ZERO),
new SqlIdentifier(COLS_COL_IS_NULLABLE, SqlParserPos.ZERO));
SqlNode fromClause = new SqlIdentifier(
ImmutableList.of(IS_SCHEMA_NAME, TAB_COLUMNS), null, SqlParserPos.ZERO, null);
final SqlIdentifier table = node.getTable();
final SchemaPlus defaultSchema = context.getNewDefaultSchema();
final List<String> schemaPathGivenInCmd = Util.skipLast(table.names);
final SchemaPlus schema = SchemaUtilites.findSchema(defaultSchema, schemaPathGivenInCmd);
if (schema == null) {
SchemaUtilites.throwSchemaNotFoundException(defaultSchema,
SchemaUtilites.SCHEMA_PATH_JOINER.join(schemaPathGivenInCmd));
}
if (SchemaUtilites.isRootSchema(schema)) {
throw UserException.validationError()
.message("No schema selected.")
.build(logger);
}
final String tableName = Util.last(table.names);
// find resolved schema path
final String schemaPath = SchemaUtilites.unwrapAsDrillSchemaInstance(schema).getFullSchemaName();
if (schema.getTable(tableName) == null) {
throw UserException.validationError()
.message("Unknown table [%s] in schema [%s]", tableName, schemaPath)
.build(logger);
}
SqlNode schemaCondition = null;
if (!SchemaUtilites.isRootSchema(schema)) {
schemaCondition = DrillParserUtil.createCondition(
new SqlIdentifier(SHRD_COL_TABLE_SCHEMA, SqlParserPos.ZERO),
SqlStdOperatorTable.EQUALS,
SqlLiteral.createCharString(schemaPath, CHARSET, SqlParserPos.ZERO)
);
}
SqlNode where = DrillParserUtil.createCondition(
new SqlIdentifier(SHRD_COL_TABLE_NAME, SqlParserPos.ZERO),
SqlStdOperatorTable.EQUALS,
SqlLiteral.createCharString(tableName, CHARSET, SqlParserPos.ZERO));
where = DrillParserUtil.createCondition(schemaCondition, SqlStdOperatorTable.AND, where);
SqlNode columnFilter = null;
if (node.getColumn() != null) {
columnFilter =
DrillParserUtil.createCondition(
new SqlIdentifier(COLS_COL_COLUMN_NAME, SqlParserPos.ZERO),
SqlStdOperatorTable.EQUALS,
SqlLiteral.createCharString(node.getColumn().toString(), CHARSET, SqlParserPos.ZERO));
} else if (node.getColumnQualifier() != null) {
columnFilter =
DrillParserUtil.createCondition(
new SqlIdentifier(COLS_COL_COLUMN_NAME, SqlParserPos.ZERO),
SqlStdOperatorTable.LIKE, node.getColumnQualifier());
}
where = DrillParserUtil.createCondition(where, SqlStdOperatorTable.AND, columnFilter);
return new SqlSelect(SqlParserPos.ZERO, null, new SqlNodeList(selectList, SqlParserPos.ZERO),
fromClause, where, null, null, null, null, null, null);
} catch (Exception ex) {
throw UserException.planError(ex)
.message("Error while rewriting DESCRIBE query: %d", ex.getMessage())
.build(logger);
}
}