Java Code Examples for io.prestosql.spi.connector.SchemaTableName#getTableName()
The following examples show how to use
io.prestosql.spi.connector.SchemaTableName#getTableName() .
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: RaptorMetadata.java From presto with Apache License 2.0 | 6 votes |
private RaptorTableHandle getTableHandle(SchemaTableName tableName) { requireNonNull(tableName, "tableName is null"); Table table = dao.getTableInformation(tableName.getSchemaName(), tableName.getTableName()); if (table == null) { return null; } List<TableColumn> tableColumns = dao.listTableColumns(table.getTableId()); checkArgument(!tableColumns.isEmpty(), "Table '%s' does not have any columns", tableName); return new RaptorTableHandle( tableName.getSchemaName(), tableName.getTableName(), table.getTableId(), table.getDistributionId(), table.getDistributionName(), table.getBucketCount(), table.isOrganized(), OptionalLong.empty(), TupleDomain.all(), table.getDistributionId().map(shardManager::getBucketAssignments), false); }
Example 2
Source File: BaseJdbcClient.java From presto with Apache License 2.0 | 6 votes |
protected void renameTable(JdbcIdentity identity, String catalogName, String schemaName, String tableName, SchemaTableName newTable) { try (Connection connection = connectionFactory.openConnection(identity)) { String newSchemaName = newTable.getSchemaName(); String newTableName = newTable.getTableName(); if (connection.getMetaData().storesUpperCaseIdentifiers()) { newSchemaName = newSchemaName.toUpperCase(ENGLISH); newTableName = newTableName.toUpperCase(ENGLISH); } String sql = format( "ALTER TABLE %s RENAME TO %s", quoted(catalogName, schemaName, tableName), quoted(catalogName, newSchemaName, newTableName)); execute(connection, sql); } catch (SQLException e) { throw new PrestoException(JDBC_ERROR, e); } }
Example 3
Source File: AccumuloMetadata.java From presto with Apache License 2.0 | 6 votes |
@Override public ConnectorOutputTableHandle beginCreateTable(ConnectorSession session, ConnectorTableMetadata tableMetadata, Optional<ConnectorNewTableLayout> layout) { checkNoRollback(); SchemaTableName tableName = tableMetadata.getTable(); AccumuloTable table = client.createTable(tableMetadata); AccumuloTableHandle handle = new AccumuloTableHandle( tableName.getSchemaName(), tableName.getTableName(), table.getRowId(), table.isExternal(), table.getSerializerClassName(), table.getScanAuthorizations()); setRollback(() -> rollbackCreateTable(table)); return handle; }
Example 4
Source File: HiveMetadata.java From presto with Apache License 2.0 | 5 votes |
@Override public HiveTableHandle getTableHandle(ConnectorSession session, SchemaTableName tableName) { requireNonNull(tableName, "tableName is null"); if (!filterSchema(tableName.getSchemaName())) { return null; } Optional<Table> table = metastore.getTable(new HiveIdentity(session), tableName.getSchemaName(), tableName.getTableName()); if (table.isEmpty()) { return null; } if (isDeltaLakeTable(table.get())) { throw new PrestoException(HIVE_UNSUPPORTED_FORMAT, "Cannot query Delta Lake table"); } // we must not allow system tables due to how permissions are checked in SystemTableAwareAccessControl if (getSourceTableNameFromSystemTable(tableName).isPresent()) { throw new PrestoException(HIVE_INVALID_METADATA, "Unexpected table present in Hive metastore: " + tableName); } verifyOnline(tableName, Optional.empty(), getProtectMode(table.get()), table.get().getParameters()); return new HiveTableHandle( tableName.getSchemaName(), tableName.getTableName(), table.get().getParameters(), getPartitionKeyColumnHandles(table.get(), typeManager), getHiveBucketHandle(table.get(), typeManager)); }
Example 5
Source File: SchemaEmulationByTableNameConvention.java From presto with Apache License 2.0 | 5 votes |
@Override public String toRawName(SchemaTableName schemaTableName) { if (DEFAULT_SCHEMA.equals(schemaTableName.getSchemaName())) { if (commonPrefix.isEmpty()) { if (schemaTableName.getTableName().indexOf('.') != -1) { // in default schema table name must not contain dots if common prefix is empty throw new PrestoException(GENERIC_USER_ERROR, "Table name conflicts with schema emulation settings. No '.' allowed for tables in schema 'default'."); } } else { if (schemaTableName.getTableName().startsWith(commonPrefix)) { // in default schema table name must not start with common prefix throw new PrestoException(GENERIC_USER_ERROR, "Table name conflicts with schema emulation settings. Table name must not start with '" + commonPrefix + "'."); } } } else if (schemaTableName.getSchemaName().indexOf('.') != -1) { // schema names with dots are not possible throw new SchemaNotFoundException(schemaTableName.getSchemaName()); } if (DEFAULT_SCHEMA.equals(schemaTableName.getSchemaName())) { return schemaTableName.getTableName(); } else { return commonPrefix + schemaTableName.getSchemaName() + "." + schemaTableName.getTableName(); } }
Example 6
Source File: RaptorMetadata.java From presto with Apache License 2.0 | 5 votes |
@Override public void createView(ConnectorSession session, SchemaTableName viewName, ConnectorViewDefinition definition, boolean replace) { String schemaName = viewName.getSchemaName(); String tableName = viewName.getTableName(); String viewData = VIEW_CODEC.toJson(definition); if (getTableHandle(viewName) != null) { throw new PrestoException(ALREADY_EXISTS, "Table already exists: " + viewName); } if (replace) { daoTransaction(dbi, MetadataDao.class, dao -> { dao.dropView(schemaName, tableName); dao.insertView(schemaName, tableName, viewData); }); return; } try { dao.insertView(schemaName, tableName, viewData); } catch (PrestoException e) { if (viewExists(session, viewName)) { throw new PrestoException(ALREADY_EXISTS, "View already exists: " + viewName); } throw e; } }
Example 7
Source File: SqlStandardAccessControlMetadata.java From presto with Apache License 2.0 | 5 votes |
@Override public void grantTablePrivileges(ConnectorSession session, SchemaTableName schemaTableName, Set<Privilege> privileges, HivePrincipal grantee, boolean grantOption) { String schemaName = schemaTableName.getSchemaName(); String tableName = schemaTableName.getTableName(); Set<HivePrivilegeInfo> hivePrivilegeInfos = privileges.stream() .map(privilege -> new HivePrivilegeInfo(toHivePrivilege(privilege), grantOption, new HivePrincipal(USER, session.getUser()), new HivePrincipal(USER, session.getUser()))) .collect(toSet()); metastore.grantTablePrivileges(new HiveIdentity(session), schemaName, tableName, grantee, hivePrivilegeInfos); }
Example 8
Source File: AccumuloClient.java From presto with Apache License 2.0 | 5 votes |
public void renameTable(SchemaTableName oldName, SchemaTableName newName) { if (!oldName.getSchemaName().equals(newName.getSchemaName())) { throw new PrestoException(NOT_SUPPORTED, "Accumulo does not support renaming tables to different namespaces (schemas)"); } AccumuloTable oldTable = getTable(oldName); if (oldTable == null) { throw new TableNotFoundException(oldName); } AccumuloTable newTable = new AccumuloTable( oldTable.getSchema(), newName.getTableName(), oldTable.getColumns(), oldTable.getRowId(), oldTable.isExternal(), oldTable.getSerializerClassName(), oldTable.getScanAuthorizations()); // Validate table existence if (!tableManager.exists(oldTable.getFullTableName())) { throw new PrestoException(ACCUMULO_TABLE_DNE, format("Table '%s' does not exist", oldTable.getFullTableName())); } if (tableManager.exists(newTable.getFullTableName())) { throw new PrestoException(ACCUMULO_TABLE_EXISTS, format("Table '%s' already exists", newTable.getFullTableName())); } // Rename index tables (which will also validate table existence) renameIndexTables(oldTable, newTable); // Rename the Accumulo table tableManager.renameAccumuloTable(oldTable.getFullTableName(), newTable.getFullTableName()); // We'll then create the metadata metaManager.deleteTableMetadata(oldTable.getSchemaTableName()); metaManager.createTableMetadata(newTable); }
Example 9
Source File: DruidJdbcClient.java From presto with Apache License 2.0 | 5 votes |
@Override public Optional<JdbcTableHandle> getTableHandle(JdbcIdentity identity, SchemaTableName schemaTableName) { try (Connection connection = connectionFactory.openConnection(identity)) { String jdbcSchemaName = schemaTableName.getSchemaName(); String jdbcTableName = schemaTableName.getTableName(); try (ResultSet resultSet = getTables(connection, Optional.of(jdbcSchemaName), Optional.of(jdbcTableName))) { List<JdbcTableHandle> tableHandles = new ArrayList<>(); while (resultSet.next()) { tableHandles.add(new JdbcTableHandle( schemaTableName, DRUID_CATALOG, resultSet.getString("TABLE_SCHEM"), resultSet.getString("TABLE_NAME"))); } if (tableHandles.isEmpty()) { return Optional.empty(); } return Optional.of( getOnlyElement( tableHandles .stream() .filter( jdbcTableHandle -> Objects.equals(jdbcTableHandle.getSchemaName(), schemaTableName.getSchemaName()) && Objects.equals(jdbcTableHandle.getTableName(), schemaTableName.getTableName())) .collect(Collectors.toList()))); } } catch (SQLException e) { throw new PrestoException(JDBC_ERROR, e); } }
Example 10
Source File: PulsarMetadata.java From pulsar with Apache License 2.0 | 5 votes |
@Override public ConnectorTableHandle getTableHandle(ConnectorSession session, SchemaTableName tableName) { return new PulsarTableHandle( this.connectorId, tableName.getSchemaName(), tableName.getTableName(), tableName.getTableName()); }
Example 11
Source File: RedisTestUtils.java From presto with Apache License 2.0 | 5 votes |
public static Map.Entry<SchemaTableName, RedisTableDescription> createEmptyTableDescription(SchemaTableName schemaTableName) { RedisTableDescription tableDescription = new RedisTableDescription( schemaTableName.getTableName(), schemaTableName.getSchemaName(), null, null); return new AbstractMap.SimpleImmutableEntry<>(schemaTableName, tableDescription); }
Example 12
Source File: SheetsMetadata.java From presto with Apache License 2.0 | 5 votes |
@Override public SheetsTableHandle getTableHandle(ConnectorSession session, SchemaTableName tableName) { requireNonNull(tableName, "tableName is null"); if (!listSchemaNames(session).contains(tableName.getSchemaName())) { return null; } Optional<SheetsTable> table = sheetsClient.getTable(tableName.getTableName()); if (table.isEmpty()) { return null; } return new SheetsTableHandle(tableName.getSchemaName(), tableName.getTableName()); }
Example 13
Source File: ExampleMetadata.java From presto with Apache License 2.0 | 5 votes |
@Override public ExampleTableHandle getTableHandle(ConnectorSession session, SchemaTableName tableName) { if (!listSchemaNames(session).contains(tableName.getSchemaName())) { return null; } ExampleTable table = exampleClient.getTable(tableName.getSchemaName(), tableName.getTableName()); if (table == null) { return null; } return new ExampleTableHandle(tableName.getSchemaName(), tableName.getTableName()); }
Example 14
Source File: PrometheusMetadata.java From presto with Apache License 2.0 | 5 votes |
@Override public PrometheusTableHandle getTableHandle(ConnectorSession session, SchemaTableName tableName) { if (!listSchemaNames(session).contains(tableName.getSchemaName())) { return null; } if (prometheusClient.getTable(tableName.getSchemaName(), tableName.getTableName()) == null) { return null; } return new PrometheusTableHandle(tableName.getSchemaName(), tableName.getTableName()); }
Example 15
Source File: SqlStandardAccessControlMetadata.java From presto with Apache License 2.0 | 5 votes |
@Override public void revokeTablePrivileges(ConnectorSession session, SchemaTableName schemaTableName, Set<Privilege> privileges, HivePrincipal grantee, boolean grantOption) { String schemaName = schemaTableName.getSchemaName(); String tableName = schemaTableName.getTableName(); Set<HivePrivilegeInfo> hivePrivilegeInfos = privileges.stream() .map(privilege -> new HivePrivilegeInfo(toHivePrivilege(privilege), grantOption, new HivePrincipal(USER, session.getUser()), new HivePrincipal(USER, session.getUser()))) .collect(toSet()); metastore.revokeTablePrivileges(new HiveIdentity(session), schemaName, tableName, grantee, hivePrivilegeInfos); }
Example 16
Source File: HiveMetadata.java From presto with Apache License 2.0 | 4 votes |
@Override public HiveInsertTableHandle beginInsert(ConnectorSession session, ConnectorTableHandle tableHandle) { verifyJvmTimeZone(); HiveIdentity identity = new HiveIdentity(session); SchemaTableName tableName = ((HiveTableHandle) tableHandle).getSchemaTableName(); Table table = metastore.getTable(identity, tableName.getSchemaName(), tableName.getTableName()) .orElseThrow(() -> new TableNotFoundException(tableName)); checkTableIsWritable(table, writesToNonManagedTablesEnabled); for (Column column : table.getDataColumns()) { if (!isWritableType(column.getType())) { throw new PrestoException(NOT_SUPPORTED, format("Inserting into Hive table %s with column type %s not supported", tableName, column.getType())); } } List<HiveColumnHandle> handles = hiveColumnHandles(table, typeManager).stream() .filter(columnHandle -> !columnHandle.isHidden()) .collect(toList()); HiveStorageFormat tableStorageFormat = extractHiveStorageFormat(table); if (table.getParameters().containsKey(SKIP_HEADER_COUNT_KEY)) { throw new PrestoException(NOT_SUPPORTED, format("Inserting into Hive table with %s property not supported", SKIP_HEADER_COUNT_KEY)); } if (table.getParameters().containsKey(SKIP_FOOTER_COUNT_KEY)) { throw new PrestoException(NOT_SUPPORTED, format("Inserting into Hive table with %s property not supported", SKIP_FOOTER_COUNT_KEY)); } LocationHandle locationHandle = locationService.forExistingTable(metastore, session, table); HiveInsertTableHandle result = new HiveInsertTableHandle( tableName.getSchemaName(), tableName.getTableName(), handles, metastore.generatePageSinkMetadata(identity, tableName), locationHandle, table.getStorage().getBucketProperty(), tableStorageFormat, isRespectTableFormat(session) ? tableStorageFormat : getHiveStorageFormat(session)); WriteInfo writeInfo = locationService.getQueryWriteInfo(locationHandle); metastore.declareIntentionToWrite(session, writeInfo.getWriteMode(), writeInfo.getWritePath(), tableName); return result; }
Example 17
Source File: PhoenixMetadata.java From presto with Apache License 2.0 | 4 votes |
private JdbcOutputTableHandle createTable(ConnectorSession session, ConnectorTableMetadata tableMetadata) { SchemaTableName schemaTableName = tableMetadata.getTable(); Optional<String> schema = Optional.of(schemaTableName.getSchemaName()); String table = schemaTableName.getTableName(); if (!phoenixClient.getSchemaNames(JdbcIdentity.from(session)).contains(schema.orElse(null))) { throw new SchemaNotFoundException(schema.orElse(null)); } try (Connection connection = phoenixClient.getConnection(JdbcIdentity.from(session))) { boolean uppercase = connection.getMetaData().storesUpperCaseIdentifiers(); if (uppercase) { schema = schema.map(schemaName -> schemaName.toUpperCase(ENGLISH)); table = table.toUpperCase(ENGLISH); } schema = toPhoenixSchemaName(schema); LinkedList<ColumnMetadata> tableColumns = new LinkedList<>(tableMetadata.getColumns()); Map<String, Object> tableProperties = tableMetadata.getProperties(); Optional<Boolean> immutableRows = PhoenixTableProperties.getImmutableRows(tableProperties); String immutable = immutableRows.isPresent() && immutableRows.get() ? "IMMUTABLE" : ""; ImmutableList.Builder<String> columnNames = ImmutableList.builder(); ImmutableList.Builder<Type> columnTypes = ImmutableList.builder(); ImmutableList.Builder<String> columnList = ImmutableList.builder(); Set<ColumnMetadata> rowkeyColumns = tableColumns.stream().filter(col -> isPrimaryKey(col, tableProperties)).collect(toSet()); ImmutableList.Builder<String> pkNames = ImmutableList.builder(); boolean hasUUIDRowkey = false; if (rowkeyColumns.isEmpty()) { // Add a rowkey when not specified in DDL columnList.add(ROWKEY + " bigint not null"); pkNames.add(ROWKEY); phoenixClient.execute(session, format("CREATE SEQUENCE %s", getEscapedTableName(schema, table + "_sequence"))); hasUUIDRowkey = true; } for (ColumnMetadata column : tableColumns) { String columnName = column.getName(); if (uppercase) { columnName = columnName.toUpperCase(ENGLISH); } columnNames.add(columnName); columnTypes.add(column.getType()); String typeStatement = phoenixClient.toWriteMapping(session, column.getType()).getDataType(); if (rowkeyColumns.contains(column)) { typeStatement += " not null"; pkNames.add(columnName); } columnList.add(format("%s %s", columnName, typeStatement)); } ImmutableList.Builder<String> tableOptions = ImmutableList.builder(); PhoenixTableProperties.getSaltBuckets(tableProperties).ifPresent(value -> tableOptions.add(TableProperty.SALT_BUCKETS + "=" + value)); PhoenixTableProperties.getSplitOn(tableProperties).ifPresent(value -> tableOptions.add("SPLIT ON (" + value.replace('"', '\'') + ")")); PhoenixTableProperties.getDisableWal(tableProperties).ifPresent(value -> tableOptions.add(TableProperty.DISABLE_WAL + "=" + value)); PhoenixTableProperties.getDefaultColumnFamily(tableProperties).ifPresent(value -> tableOptions.add(TableProperty.DEFAULT_COLUMN_FAMILY + "=" + value)); PhoenixTableProperties.getBloomfilter(tableProperties).ifPresent(value -> tableOptions.add(HColumnDescriptor.BLOOMFILTER + "='" + value + "'")); PhoenixTableProperties.getVersions(tableProperties).ifPresent(value -> tableOptions.add(HConstants.VERSIONS + "=" + value)); PhoenixTableProperties.getMinVersions(tableProperties).ifPresent(value -> tableOptions.add(HColumnDescriptor.MIN_VERSIONS + "=" + value)); PhoenixTableProperties.getCompression(tableProperties).ifPresent(value -> tableOptions.add(HColumnDescriptor.COMPRESSION + "='" + value + "'")); PhoenixTableProperties.getTimeToLive(tableProperties).ifPresent(value -> tableOptions.add(HColumnDescriptor.TTL + "=" + value)); String sql = format( "CREATE %s TABLE %s (%s , CONSTRAINT PK PRIMARY KEY (%s)) %s", immutable, getEscapedTableName(schema, table), join(", ", columnList.build()), join(", ", pkNames.build()), join(", ", tableOptions.build())); phoenixClient.execute(session, sql); return new PhoenixOutputTableHandle( schema, table, columnNames.build(), columnTypes.build(), Optional.empty(), hasUUIDRowkey); } catch (SQLException e) { if (e.getErrorCode() == SQLExceptionCode.TABLE_ALREADY_EXIST.getErrorCode()) { throw new PrestoException(ALREADY_EXISTS, "Phoenix table already exists", e); } throw new PrestoException(PHOENIX_METADATA_ERROR, "Error creating Phoenix table", e); } }
Example 18
Source File: SystemTableHandle.java From presto with Apache License 2.0 | 4 votes |
public static SystemTableHandle fromSchemaTableName(SchemaTableName tableName) { requireNonNull(tableName, "tableName is null"); return new SystemTableHandle(tableName.getSchemaName(), tableName.getTableName(), TupleDomain.all()); }
Example 19
Source File: TableJdbcTable.java From presto with Apache License 2.0 | 4 votes |
private static Object[] tableRow(String catalog, SchemaTableName name, String type) { return new Object[] {catalog, name.getSchemaName(), name.getTableName(), type, null, null, null, null, null, null}; }
Example 20
Source File: TestPushProjectionIntoTableScan.java From presto with Apache License 2.0 | 4 votes |
private Optional<ProjectionApplicationResult<ConnectorTableHandle>> mockApplyProjection( ConnectorSession session, ConnectorTableHandle tableHandle, List<ConnectorExpression> projections, Map<String, ColumnHandle> assignments) { // Prepare new table handle SchemaTableName inputSchemaTableName = ((MockConnectorTableHandle) tableHandle).getTableName(); SchemaTableName projectedTableName = new SchemaTableName( inputSchemaTableName.getSchemaName(), "projected_" + inputSchemaTableName.getTableName()); MockConnectorTableHandle newTableHandle = new MockConnectorTableHandle(projectedTableName); // Prepare new column handles ImmutableList.Builder<ConnectorExpression> outputExpressions = ImmutableList.builder(); ImmutableList.Builder<Assignment> outputAssignments = ImmutableList.builder(); for (ConnectorExpression projection : projections) { String variablePrefix; if (projection instanceof Variable) { variablePrefix = "projected_variable_"; } else if (projection instanceof FieldDereference) { variablePrefix = "projected_dereference_"; } else if (projection instanceof Constant) { variablePrefix = "projected_constant_"; } else { throw new UnsupportedOperationException(); } String newVariableName = variablePrefix + projection.toString(); Variable newVariable = new Variable(newVariableName, projection.getType()); ColumnHandle newColumnHandle = new TpchColumnHandle(newVariableName, projection.getType()); outputExpressions.add(newVariable); outputAssignments.add(new Assignment(newVariableName, newColumnHandle, projection.getType())); } return Optional.of(new ProjectionApplicationResult<>(newTableHandle, outputExpressions.build(), outputAssignments.build())); }