本文整理汇总了Java中org.apache.calcite.schema.Table.getJdbcTableType方法的典型用法代码示例。如果您正苦于以下问题:Java Table.getJdbcTableType方法的具体用法?Java Table.getJdbcTableType怎么用?Java Table.getJdbcTableType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.calcite.schema.Table
的用法示例。
在下文中一共展示了Table.getJdbcTableType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPlan
import org.apache.calcite.schema.Table; //导入方法依赖的package包/类
@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException, ForemanSetupException {
SqlDropView dropView = unwrap(sqlNode, SqlDropView.class);
final String viewToDrop = dropView.getName();
final AbstractSchema drillSchema =
SchemaUtilites.resolveToMutableDrillSchema(context.getNewDefaultSchema(), dropView.getSchemaPath());
final String schemaPath = drillSchema.getFullSchemaName();
final Table existingTable = SqlHandlerUtil.getTableFromSchema(drillSchema, viewToDrop);
if (existingTable != null && existingTable.getJdbcTableType() != Schema.TableType.VIEW) {
throw UserException.validationError()
.message("[%s] is not a VIEW in schema [%s]", viewToDrop, schemaPath)
.build(logger);
} else if (existingTable == null) {
throw UserException.validationError()
.message("Unknown view [%s] in schema [%s].", viewToDrop, schemaPath)
.build(logger);
}
drillSchema.dropView(viewToDrop);
return DirectPlan.createDirectPlan(context, true,
String.format("View [%s] deleted successfully from schema [%s].", viewToDrop, schemaPath));
}
示例2: visitTables
import org.apache.calcite.schema.Table; //导入方法依赖的package包/类
/**
* Visit the tables in the given schema. The
* @param schemaPath the path to the given schema
* @param schema the given schema
*/
public void visitTables(String schemaPath, SchemaPlus schema) {
final AbstractSchema drillSchema = schema.unwrap(AbstractSchema.class);
final List<String> tableNames = Lists.newArrayList(schema.getTableNames());
for(Pair<String, ? extends Table> tableNameToTable : drillSchema.getTablesByNames(tableNames)) {
final String tableName = tableNameToTable.getKey();
final Table table = tableNameToTable.getValue();
final TableType tableType = table.getJdbcTableType();
// Visit the table, and if requested ...
if(shouldVisitTable(schemaPath, tableName, tableType) && visitTable(schemaPath, tableName, table)) {
// ... do for each of the table's fields.
final RelDataType tableRow = table.getRowType(new JavaTypeFactoryImpl());
for (RelDataTypeField field: tableRow.getFieldList()) {
if (shouldVisitColumn(schemaPath, tableName, field.getName())) {
visitField(schemaPath, tableName, field);
}
}
}
}
}
示例3: validateSequenceValue
import org.apache.calcite.schema.Table; //导入方法依赖的package包/类
public void validateSequenceValue(SqlValidatorScope scope, SqlIdentifier id) {
// Resolve identifier as a table.
final SqlValidatorScope.ResolvedImpl resolved =
new SqlValidatorScope.ResolvedImpl();
scope.resolveTable(id.names, catalogReader.nameMatcher(),
SqlValidatorScope.Path.EMPTY, resolved);
if (resolved.count() != 1) {
throw newValidationError(id, RESOURCE.tableNameNotFound(id.toString()));
}
// We've found a table. But is it a sequence?
final SqlValidatorNamespace ns = resolved.only().namespace;
if (ns instanceof TableNamespace) {
final Table table = ((RelOptTable) ns.getTable()).unwrap(Table.class);
switch (table.getJdbcTableType()) {
case SEQUENCE:
case TEMPORARY_SEQUENCE:
return;
}
}
throw newValidationError(id, RESOURCE.notASequence(id.toString()));
}
示例4: visitTable
import org.apache.calcite.schema.Table; //导入方法依赖的package包/类
@Override
public boolean visitTable(String schemaName, String tableName, Table table) {
if (table.getJdbcTableType() == TableType.VIEW) {
records.add(new Records.View(IS_CATALOG_NAME, schemaName, tableName,
((DrillViewInfoProvider) table).getViewSql()));
}
return false;
}
示例5: toResult
import org.apache.calcite.schema.Table; //导入方法依赖的package包/类
/**
* Function resolves the schema and invokes the drop method
* (while IF EXISTS statement is used function invokes the drop method only if table exists).
* Raises an exception if the schema is immutable.
* @param sqlNode - SqlDropTable (SQL parse tree of drop table [if exists] query)
* @return - Single row indicating drop succeeded or table is not found while IF EXISTS statement is used,
* raise exception otherwise
* @throws ValidationException
* @throws RelConversionException
* @throws IOException
*/
@Override
public List<SimpleCommandResult> toResult(String sql, SqlNode sqlNode) throws ValidationException, ForemanSetupException,
RelConversionException, IOException {
String tableName;
SqlDropTable dropTableNode = ((SqlDropTable) sqlNode);
SqlIdentifier tableIdentifier = dropTableNode.getTableIdentifier();
AbstractSchema schemaInstance = null;
if (tableIdentifier != null) {
schemaInstance = SchemaUtilities.resolveToMutableSchemaInstance(defaultSchema, dropTableNode.getSchema(), systemUser, MutationType.TABLE);
}
tableName = dropTableNode.getName();
if (schemaInstance == null) {
throw UserException.validationError().message("Invalid table_name [%s]", tableName).build(logger);
}
if (dropTableNode.checkTableExistence()) {
final Table tableToDrop = SqlHandlerUtil.getTableFromSchema(schemaInstance, tableName);
if (tableToDrop == null || tableToDrop.getJdbcTableType() != Schema.TableType.TABLE) {
return Collections.singletonList(new SimpleCommandResult(true,
String.format("Table [%s] not found", tableName)));
}
}
schemaInstance.dropTable(tableName);
return Collections.singletonList(SimpleCommandResult.successful("Table [%s] dropped", tableName));
}
示例6: toResult
import org.apache.calcite.schema.Table; //导入方法依赖的package包/类
@Override
public List<SimpleCommandResult> toResult(String sql, SqlNode sqlNode) throws Exception {
final SqlDropView dropView = SqlNodeUtil.unwrap(sqlNode, SqlDropView.class);
final String viewName = dropView.getName();
final AbstractSchema schemaInstance =
SchemaUtilities.resolveToMutableSchemaInstance(defaultSchema, dropView.getSchemaPath(), systemUser, MutationType.VIEW);
final String schemaPath = schemaInstance.getFullSchemaName();
final Table viewToDrop = SqlHandlerUtil.getTableFromSchema(schemaInstance, viewName);
if (dropView.checkViewExistence()) {
if (viewToDrop == null || viewToDrop.getJdbcTableType() != Schema.TableType.VIEW){
return Collections.singletonList(new SimpleCommandResult(true,
String.format("View [%s] not found in schema [%s].", viewName, schemaPath)));
}
} else {
if (viewToDrop != null && viewToDrop.getJdbcTableType() != Schema.TableType.VIEW) {
throw UserException.validationError()
.message("[%s] is not a VIEW in schema [%s]", viewName, schemaPath)
.build(logger);
} else if (viewToDrop == null) {
throw UserException.validationError()
.message("Unknown view [%s] in schema [%s].", viewName, schemaPath)
.build(logger);
}
}
schemaInstance.dropView(viewName);
return Collections.singletonList(SimpleCommandResult.successful("View [%s] deleted successfully from schema [%s].", viewName, schemaPath));
}
示例7: convert
import org.apache.calcite.schema.Table; //导入方法依赖的package包/类
@Override
public RelNode convert(RelNode rel) {
final TableModify tableModify = (TableModify) rel;
final RelNode input = tableModify.getInput();
final RelOptCluster cluster = tableModify.getCluster();
final RelTraitSet traitSet = tableModify.getTraitSet().replace(BeamLogicalConvention.INSTANCE);
final RelOptTable relOptTable = tableModify.getTable();
final Prepare.CatalogReader catalogReader = tableModify.getCatalogReader();
final RelNode convertedInput = convert(input,
input.getTraitSet().replace(BeamLogicalConvention.INSTANCE));
final TableModify.Operation operation = tableModify.getOperation();
final List<String> updateColumnList = tableModify.getUpdateColumnList();
final List<RexNode> sourceExpressionList = tableModify.getSourceExpressionList();
final boolean flattened = tableModify.isFlattened();
final Table table = tableModify.getTable().unwrap(Table.class);
switch (table.getJdbcTableType()) {
case TABLE:
case STREAM:
if (operation != TableModify.Operation.INSERT) {
throw new UnsupportedOperationException(
String.format("Streams doesn't support %s modify operation", operation));
}
return new BeamIOSinkRel(cluster, traitSet,
relOptTable, catalogReader, convertedInput, operation, updateColumnList,
sourceExpressionList, flattened);
default:
throw new IllegalArgumentException(
String.format("Unsupported table type: %s", table.getJdbcTableType()));
}
}
示例8: checkViewCreationPossibility
import org.apache.calcite.schema.Table; //导入方法依赖的package包/类
/**
* Validates if view can be created in indicated schema:
* checks if object (persistent / temporary table) with the same name exists
* or if view with the same name exists but replace flag is not set
* or if object with the same name exists but if not exists flag is set.
*
* @param drillSchema schema where views will be created
* @param view create view call
* @param context query context
* @return if view can be created in indicated schema
* @throws UserException if view cannot be created in indicated schema and no duplicate check requested
*/
private boolean checkViewCreationPossibility(AbstractSchema drillSchema, SqlCreateView view, QueryContext context) {
final String schemaPath = drillSchema.getFullSchemaName();
final String viewName = view.getName();
final Table table = SqlHandlerUtil.getTableFromSchema(drillSchema, viewName);
final boolean isTable = (table != null && table.getJdbcTableType() != Schema.TableType.VIEW)
|| context.getSession().isTemporaryTable(drillSchema, context.getConfig(), viewName);
final boolean isView = (table != null && table.getJdbcTableType() == Schema.TableType.VIEW);
switch (view.getcreateViewType()) {
case SIMPLE:
if (isTable) {
throw UserException
.validationError()
.message("A non-view table with given name [%s] already exists in schema [%s]", viewName, schemaPath)
.build(logger);
} else if (isView) {
throw UserException
.validationError()
.message("A view with given name [%s] already exists in schema [%s]", viewName, schemaPath)
.build(logger);
}
break;
case OR_REPLACE:
if (isTable) {
throw UserException
.validationError()
.message("A non-view table with given name [%s] already exists in schema [%s]", viewName, schemaPath)
.build(logger);
}
break;
case IF_NOT_EXISTS:
if (isTable || isView) {
return false;
}
break;
}
return true;
}
示例9: getPlan
import org.apache.calcite.schema.Table; //导入方法依赖的package包/类
@Override
public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException, ForemanSetupException {
SqlDropView dropView = unwrap(sqlNode, SqlDropView.class);
final String viewName = dropView.getName();
final AbstractSchema drillSchema =
SchemaUtilites.resolveToMutableDrillSchema(context.getNewDefaultSchema(), dropView.getSchemaPath());
final String schemaPath = drillSchema.getFullSchemaName();
final Table viewToDrop = SqlHandlerUtil.getTableFromSchema(drillSchema, viewName);
if (dropView.checkViewExistence()) {
if (viewToDrop == null || viewToDrop.getJdbcTableType() != Schema.TableType.VIEW){
return DirectPlan.createDirectPlan(context, false,
String.format("View [%s] not found in schema [%s].", viewName, schemaPath));
}
} else {
if (viewToDrop != null && viewToDrop.getJdbcTableType() != Schema.TableType.VIEW) {
throw UserException.validationError()
.message("[%s] is not a VIEW in schema [%s]", viewName, schemaPath)
.build(logger);
} else if (viewToDrop == null) {
throw UserException.validationError()
.message("Unknown view [%s] in schema [%s].", viewName, schemaPath)
.build(logger);
}
}
SqlHandlerUtil.dropViewFromSchema(drillSchema, viewName);
return DirectPlan.createDirectPlan(context, true,
String.format("View [%s] deleted successfully from schema [%s].", viewName, schemaPath));
}
示例10: visitTable
import org.apache.calcite.schema.Table; //导入方法依赖的package包/类
@Override
public boolean visitTable(String schemaName, String tableName, Table table) {
Preconditions.checkNotNull(table, "Error. Table %s.%s provided is null.", schemaName, tableName);
// skip over unknown table types
if (table.getJdbcTableType() != null) {
records.add(new Records.Table(IS_CATALOG_NAME, schemaName, tableName,
table.getJdbcTableType().toString()));
}
return false;
}
示例11: toResult
import org.apache.calcite.schema.Table; //导入方法依赖的package包/类
@Override
public List<SimpleCommandResult> toResult(String sql, SqlNode sqlNode) throws Exception {
SqlCreateView createView = SqlNodeUtil.unwrap(sqlNode, SqlCreateView.class);
final String newViewName = createView.getName();
// Store the viewSql as view def SqlNode is modified as part of the resolving the new table definition below.
final String viewSql = createView.getQuery().toSqlString(new SqlDialect(SqlDialect.CALCITE.getDatabaseProduct(), SqlDialect.CALCITE.getDatabaseProduct().name(), ParserConfig.QUOTING.string)).getSql();
final ConvertedRelNode convertedRelNode = PrelTransformer.validateAndConvert(config, createView.getQuery());
final RelDataType validatedRowType = convertedRelNode.getValidatedRowType();
final RelNode queryRelNode = convertedRelNode.getConvertedNode();
final RelNode newViewRelNode = SqlHandlerUtil.resolveNewTableRel(true, createView.getFieldNames(), validatedRowType, queryRelNode);
final SchemaPlus defaultSchema = context.getNewDefaultSchema();
final AbstractSchema schemaInstance = SchemaUtilities.resolveToMutableSchemaInstance(defaultSchema, createView.getSchemaPath(), systemUser, MutationType.VIEW);
final String schemaPath = schemaInstance.getFullSchemaName();
final View view = new View(newViewName, viewSql, newViewRelNode.getRowType(), SchemaUtilities.getSchemaPathAsList(defaultSchema));
final Table existingTable = SqlHandlerUtil.getTableFromSchema(schemaInstance, newViewName);
if (existingTable != null) {
if (existingTable.getJdbcTableType() != Schema.TableType.VIEW) {
// existing table is not a view
throw UserException.validationError()
.message("A non-view table with given name [%s] already exists in schema [%s]",
newViewName, schemaPath
)
.build(logger);
}
if (existingTable.getJdbcTableType() == Schema.TableType.VIEW && !createView.getReplace()) {
// existing table is a view and create view has no "REPLACE" clause
throw UserException.validationError()
.message("A view with given name [%s] already exists in schema [%s]",
newViewName, schemaPath
)
.build(logger);
}
}
final boolean replaced = schemaInstance.createView(view);
return Collections.singletonList(SimpleCommandResult.successful("View '%s' %s successfully in '%s' schema",
createView.getName(), replaced ? "replaced" : "created", schemaPath));
}
示例12: scanSchema
import org.apache.calcite.schema.Table; //导入方法依赖的package包/类
/**
* Scan the schame tree, invoking the visitor as appropriate.
* @param rootSchema the given schema
*/
public void scanSchema(SchemaPlus rootSchema) {
if (!shouldVisitCatalog() || !visitCatalog()) {
return;
}
// Visit this schema and if requested ...
for (String subSchemaName: rootSchema.getSubSchemaNames()) {
final SchemaPlus firstLevelSchema = rootSchema.getSubSchema(subSchemaName);
if (shouldVisitSchema(subSchemaName, firstLevelSchema) && visitSchema(subSchemaName, firstLevelSchema)) {
final AbstractSchema schemaInstance;
try{
schemaInstance = (AbstractSchema) firstLevelSchema.unwrap(AbstractSchema.class).getDefaultSchema();
}catch(Exception ex){
logger.warn("Failure reading schema {}. Skipping inclusion in INFORMATION_SCHEMA.", subSchemaName, ex);
continue;
}
// ... do for each of the schema's tables.
for (String tableName : firstLevelSchema.getTableNames()) {
try {
final TableInfo tableInfo = schemaInstance.getTableInfo(tableName);
if (tableInfo == 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 user has access to query.
continue;
}
final Table table;
if (tableInfo.getTable() == null) {
table = schemaInstance.getTable(tableName);
} else {
table = tableInfo.getTable();
}
final TableType tableType = table.getJdbcTableType();
// Visit the table, and if requested ...
if (shouldVisitTable(subSchemaName, tableName, tableType) && visitTable(subSchemaName, tableName, tableInfo)) {
// ... do for each of the table's fields.
RelDataType tableRow = table.getRowType(new JavaTypeFactoryImpl());
for (RelDataTypeField field : tableRow.getFieldList()) {
if (shouldVisitColumn(subSchemaName, tableName, field.getName())) {
visitField(subSchemaName, tableName, field);
}
}
}
} catch (Exception e) {
Joiner joiner = Joiner.on('.');
String path = joiner.join(joiner.join(firstLevelSchema.getTableNames()), tableName);
logger.warn("Failure while trying to read schema for table {}. Skipping inclusion in INFORMATION_SCHEMA.", path, e);;
continue;
}
}
}
}
}
示例13: TableInfo
import org.apache.calcite.schema.Table; //导入方法依赖的package包/类
public TableInfo(Table table) {
this.type = table.getJdbcTableType();
this.table = table;
}
示例14: CalciteMetaTable
import org.apache.calcite.schema.Table; //导入方法依赖的package包/类
CalciteMetaTable(Table calciteTable, String tableCat,
String tableSchem, String tableName) {
super(tableCat, tableSchem, tableName,
calciteTable.getJdbcTableType().jdbcName);
this.calciteTable = Preconditions.checkNotNull(calciteTable);
}
示例15: isTemporaryTable
import org.apache.calcite.schema.Table; //导入方法依赖的package包/类
/**
* Checks if passed table is temporary, table name is case-insensitive.
* Before looking for table checks if passed schema is temporary and returns false if not
* since temporary tables are allowed to be created in temporary workspace only.
* If passed workspace is temporary, looks for temporary table.
* First checks if table name is among temporary tables, if not returns false.
* If temporary table named was resolved, checks that temporary table exists on disk,
* to ensure that temporary table actually exists and resolved table name is not orphan
* (for example, in result of unsuccessful temporary table creation).
*
* @param drillSchema table schema
* @param config drill config
* @param tableName original table name
* @return true if temporary table exists in schema, false otherwise
*/
public boolean isTemporaryTable(AbstractSchema drillSchema, DrillConfig config, String tableName) {
if (drillSchema == null || !SchemaUtilites.isTemporaryWorkspace(drillSchema.getFullSchemaName(), config)) {
return false;
}
String temporaryTableName = resolveTemporaryTableName(tableName);
if (temporaryTableName != null) {
Table temporaryTable = SqlHandlerUtil.getTableFromSchema(drillSchema, temporaryTableName);
if (temporaryTable != null && temporaryTable.getJdbcTableType() == Schema.TableType.TABLE) {
return true;
}
}
return false;
}