@Override public RelNode convert(RelNode rel) { final TableScan scan = (TableScan) rel; int parallelismHint = DEFAULT_PARALLELISM_HINT; final ParallelTable parallelTable = scan.getTable().unwrap(ParallelTable.class); if (parallelTable != null && parallelTable.parallelismHint() != null) { parallelismHint = parallelTable.parallelismHint(); } final Table table = scan.getTable().unwrap(Table.class); switch (table.getJdbcTableType()) { case STREAM: return new StreamsStreamScanRel(scan.getCluster(), scan.getTraitSet().replace(StreamsLogicalConvention.INSTANCE), scan.getTable(), parallelismHint); default: throw new IllegalArgumentException(String.format("Unsupported table type: %s", table.getJdbcTableType())); } } }
switch (table.getJdbcTableType()) { case STREAM: if (operation != TableModify.Operation.INSERT) { updateColumnList, sourceExpressionList, flattened, primaryKey); default: throw new IllegalArgumentException(String.format("Unsupported table type: %s", table.getJdbcTableType()));
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 = ns.getTable().unwrap(Table.class); switch (table.getJdbcTableType()) { case SEQUENCE: case TEMPORARY_SEQUENCE: return; } } throw newValidationError(id, RESOURCE.notASequence(id.toString())); }
CalciteMetaTable(Table calciteTable, String tableCat, String tableSchem, String tableName) { super(tableCat, tableSchem, tableName, calciteTable.getJdbcTableType().jdbcName); this.calciteTable = Objects.requireNonNull(calciteTable); } }
CalciteMetaTable(Table calciteTable, String tableCat, String tableSchem, String tableName) { super(tableCat, tableSchem, tableName, calciteTable.getJdbcTableType().jdbcName); this.calciteTable = Objects.requireNonNull(calciteTable); } }
QuarkMetaTable(Table calciteTable, String tableCat, String tableSchem, String tableName) { super(tableCat, tableSchem, tableName, calciteTable.getJdbcTableType().name()); this.calciteTable = Preconditions.checkNotNull(calciteTable); } }
@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; } }
@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; } }
public List<Pair<String, Schema.TableType>> getTableNamesAndTypes(boolean bulkLoad, int bulkSize) { final List<String> tableNames = Lists.newArrayList(getTableNames()); final List<Pair<String, Schema.TableType>> tableNamesAndTypes = Lists.newArrayList(); final List<Pair<String, ? extends Table>> tables; if (bulkLoad) { tables = getTablesByNamesByBulkLoad(tableNames, bulkSize); } else { tables = getTablesByNames(tableNames); } for (Pair<String, ? extends Table> table : tables) { tableNamesAndTypes.add(Pair.of(table.getKey(), table.getValue().getJdbcTableType())); } return tableNamesAndTypes; }
/** Returns the star tables defined in a schema. * * @param schema Schema */ public static List<CalciteSchema.TableEntry> getStarTables( CalciteSchema schema) { final List<CalciteSchema.LatticeEntry> list = getLatticeEntries(schema); return Lists.transform(list, entry -> { final CalciteSchema.TableEntry starTable = Objects.requireNonNull(entry).getStarTable(); assert starTable.getTable().getJdbcTableType() == Schema.TableType.STAR; return entry.getStarTable(); }); }
/** Returns the star tables defined in a schema. * * @param schema Schema */ public static List<CalciteSchema.TableEntry> getStarTables( CalciteSchema schema) { final List<CalciteSchema.LatticeEntry> list = getLatticeEntries(schema); return Lists.transform(list, entry -> { final CalciteSchema.TableEntry starTable = Objects.requireNonNull(entry).getStarTable(); assert starTable.getTable().getJdbcTableType() == Schema.TableType.STAR; return entry.getStarTable(); }); }
/** * 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; }
/** * 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(DRILL_REL_DATATYPE_SYSTEM)); for (RelDataTypeField field: tableRow.getFieldList()) { if (shouldVisitColumn(schemaPath, tableName, field.getName())) { visitField(schemaPath, tableName, field); } } } } }
@Override public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException, ForemanSetupException { SqlDropView dropView = unwrap(sqlNode, SqlDropView.class); final String viewName = FileSelection.removeLeadingSlash(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)); } }
AbstractSchema drillSchema = SchemaUtilites.resolveToMutableDrillSchema(defaultSchema, tableSchema); Table tableToDrop = SqlHandlerUtil.getTableFromSchema(drillSchema, originalTableName); if (tableToDrop == null || tableToDrop.getJdbcTableType() != Schema.TableType.TABLE) { if (dropTableNode.checkTableExistence()) { return DirectPlan.createDirectPlan(context, false, String.format("Table [%s] not found", originalTableName));
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);
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 = ns.getTable().unwrap(Table.class); switch (table.getJdbcTableType()) { case SEQUENCE: case TEMPORARY_SEQUENCE: return; } } throw newValidationError(id, RESOURCE.notASequence(id.toString())); }
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 = ns.getTable().unwrap(Table.class); switch (table.getJdbcTableType()) { case SEQUENCE: case TEMPORARY_SEQUENCE: return; } } throw newValidationError(id, RESOURCE.notASequence(id.toString())); }