io.prestosql.spi.connector.SchemaTableName Java Examples

The following examples show how to use io.prestosql.spi.connector.SchemaTableName. 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: MockConnectorFactory.java    From presto with Apache License 2.0 6 votes vote down vote up
private MockConnector(
        ConnectorContext context,
        Function<ConnectorSession, List<String>> listSchemaNames,
        BiFunction<ConnectorSession, String, List<SchemaTableName>> listTables,
        BiFunction<ConnectorSession, SchemaTablePrefix, Map<SchemaTableName, ConnectorViewDefinition>> getViews,
        BiFunction<ConnectorSession, SchemaTableName, ConnectorTableHandle> getTableHandle,
        Function<SchemaTableName, List<ColumnMetadata>> getColumns,
        ApplyProjection applyProjection,
        BiFunction<ConnectorSession, SchemaTableName, Optional<ConnectorNewTableLayout>> getInsertLayout,
        BiFunction<ConnectorSession, ConnectorTableMetadata, Optional<ConnectorNewTableLayout>> getNewTableLayout,
        Supplier<Iterable<EventListener>> eventListeners,
        ListRoleGrants roleGrants)
{
    this.context = requireNonNull(context, "context is null");
    this.listSchemaNames = requireNonNull(listSchemaNames, "listSchemaNames is null");
    this.listTables = requireNonNull(listTables, "listTables is null");
    this.getViews = requireNonNull(getViews, "getViews is null");
    this.getTableHandle = requireNonNull(getTableHandle, "getTableHandle is null");
    this.getColumns = requireNonNull(getColumns, "getColumns is null");
    this.applyProjection = requireNonNull(applyProjection, "applyProjection is null");
    this.getInsertLayout = requireNonNull(getInsertLayout, "getInsertLayout is null");
    this.getNewTableLayout = requireNonNull(getNewTableLayout, "getNewTableLayout is null");
    this.eventListeners = requireNonNull(eventListeners, "eventListeners is null");
    this.roleGrants = requireNonNull(roleGrants, "roleGrants is null");
}
 
Example #2
Source File: BaseJdbcClient.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public List<SchemaTableName> getTableNames(JdbcIdentity identity, Optional<String> schema)
{
    try (Connection connection = connectionFactory.openConnection(identity)) {
        Optional<String> remoteSchema = schema.map(schemaName -> toRemoteSchemaName(identity, connection, schemaName));
        try (ResultSet resultSet = getTables(connection, remoteSchema, Optional.empty())) {
            ImmutableList.Builder<SchemaTableName> list = ImmutableList.builder();
            while (resultSet.next()) {
                String tableSchema = getTableSchemaName(resultSet);
                String tableName = resultSet.getString("TABLE_NAME");
                list.add(new SchemaTableName(tableSchema, tableName));
            }
            return list.build();
        }
    }
    catch (SQLException e) {
        throw new PrestoException(JDBC_ERROR, e);
    }
}
 
Example #3
Source File: ColumnRangesSystemTable.java    From presto with Apache License 2.0 6 votes vote down vote up
public ColumnRangesSystemTable(RaptorTableHandle sourceTable, IDBI dbi)
{
    this.sourceTable = requireNonNull(sourceTable, "sourceTable is null");
    this.dbi = requireNonNull(dbi, "dbi is null");

    this.indexedRaptorColumns = dbi.onDemand(MetadataDao.class)
            .listTableColumns(sourceTable.getTableId()).stream()
            .filter(column -> isIndexedType(column.getDataType()))
            .collect(toImmutableList());
    List<ColumnMetadata> systemTableColumns = indexedRaptorColumns.stream()
            .flatMap(column -> Stream.of(
                    new ColumnMetadata(column.getColumnName() + MIN_COLUMN_SUFFIX, column.getDataType()),
                    new ColumnMetadata(column.getColumnName() + MAX_COLUMN_SUFFIX, column.getDataType())))
            .collect(toImmutableList());
    SchemaTableName tableName = new SchemaTableName(sourceTable.getSchemaName(), sourceTable.getTableName() + COLUMN_RANGES_TABLE_SUFFIX);
    this.tableMetadata = new ConnectorTableMetadata(tableName, systemTableColumns);
}
 
Example #4
Source File: IcebergMetadata.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public IcebergTableHandle getTableHandle(ConnectorSession session, SchemaTableName tableName)
{
    IcebergTableHandle handle = IcebergTableHandle.from(tableName);
    Optional<Table> table = metastore.getTable(new HiveIdentity(session), handle.getSchemaName(), handle.getTableName());
    if (table.isEmpty()) {
        return null;
    }
    if (handle.getTableType() != DATA) {
        throw new PrestoException(NOT_SUPPORTED, "Table type not yet supported: " + handle.getSchemaTableNameWithType());
    }
    if (!isIcebergTable(table.get())) {
        throw new UnknownTableTypeException(tableName);
    }
    return handle;
}
 
Example #5
Source File: TestRaptorMetadata.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void testRenameTable()
{
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    metadata.createTable(SESSION, getOrdersTable(), false);
    ConnectorTableHandle tableHandle = metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS);
    assertInstanceOf(tableHandle, RaptorTableHandle.class);

    RaptorTableHandle raptorTableHandle = (RaptorTableHandle) tableHandle;
    SchemaTableName renamedTable = new SchemaTableName(raptorTableHandle.getSchemaName(), "orders_renamed");

    metadata.renameTable(SESSION, raptorTableHandle, renamedTable);
    assertNull(metadata.getTableHandle(SESSION, DEFAULT_TEST_ORDERS));
    ConnectorTableHandle renamedTableHandle = metadata.getTableHandle(SESSION, renamedTable);
    assertNotNull(renamedTableHandle);
    assertEquals(((RaptorTableHandle) renamedTableHandle).getTableName(), renamedTable.getTableName());
}
 
Example #6
Source File: ZooKeeperMetadataManager.java    From presto with Apache License 2.0 6 votes vote down vote up
public AccumuloView getView(SchemaTableName stName)
{
    try {
        String tablePath = getTablePath(stName);
        if (curator.checkExists().forPath(tablePath) != null) {
            byte[] data = curator.getData().forPath(tablePath);
            if (isAccumuloView(data)) {
                return toAccumuloView(data);
            }
        }

        return null;
    }
    catch (Exception e) {
        // Capture race condition between checkExists and getData
        if (e instanceof KeeperException && ((KeeperException) e).code() == NONODE) {
            return null;
        }

        throw new PrestoException(ZOOKEEPER_ERROR, "Error fetching view", e);
    }
}
 
Example #7
Source File: ZooKeeperMetadataManager.java    From presto with Apache License 2.0 6 votes vote down vote up
public AccumuloTable getTable(SchemaTableName stName)
{
    try {
        if (curator.checkExists().forPath(getTablePath(stName)) != null) {
            return toAccumuloTable(curator.getData().forPath(getTablePath(stName)));
        }

        return null;
    }
    catch (Exception e) {
        // Capture race condition between checkExists and getData
        if (e instanceof KeeperException && ((KeeperException) e).code() == NONODE) {
            return null;
        }

        throw new PrestoException(ZOOKEEPER_ERROR, "Error fetching table", e);
    }
}
 
Example #8
Source File: RedisMetadata.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix)
{
    requireNonNull(prefix, "prefix is null");

    ImmutableMap.Builder<SchemaTableName, List<ColumnMetadata>> columns = ImmutableMap.builder();

    List<SchemaTableName> tableNames;
    if (prefix.getTable().isEmpty()) {
        tableNames = listTables(session, prefix.getSchema());
    }
    else {
        tableNames = ImmutableList.of(prefix.toSchemaTableName());
    }

    for (SchemaTableName tableName : tableNames) {
        ConnectorTableMetadata tableMetadata = getTableMetadata(tableName);
        // table can disappear during listing operation
        if (tableMetadata != null) {
            columns.put(tableName, tableMetadata.getColumns());
        }
    }
    return columns.build();
}
 
Example #9
Source File: JmxMetadata.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public List<SchemaTableName> listTables(ConnectorSession session, Optional<String> schemaName)
{
    Set<String> schemaNames = schemaName.map(ImmutableSet::of)
            .orElseGet(() -> ImmutableSet.copyOf(listSchemaNames(session)));
    ImmutableList.Builder<SchemaTableName> schemaTableNames = ImmutableList.builder();
    for (String schema : schemaNames) {
        if (JMX_SCHEMA_NAME.equals(schema)) {
            return listJmxTables();
        }
        else if (HISTORY_SCHEMA_NAME.equals(schema)) {
            return jmxHistoricalData.getTables().stream()
                    .map(tableName -> new SchemaTableName(JmxMetadata.HISTORY_SCHEMA_NAME, tableName))
                    .collect(toList());
        }
    }
    return schemaTableNames.build();
}
 
Example #10
Source File: HBaseInsertTableHandle.java    From presto-hbase-connector with Apache License 2.0 6 votes vote down vote up
@JsonCreator
public HBaseInsertTableHandle(
        @JsonProperty("connectorId") String connectorId,
        @JsonProperty("schemaTableName") SchemaTableName schemaTableName,
        @JsonProperty("columnNames") List<String> columnNames,
        @JsonProperty("columnTypes") List<Type> columnTypes,
        @JsonProperty("rowKeyColumnChannel") int rowKeyColumnChannel,
        @JsonProperty("colNameAndFamilyNameMap") Map<String, String> colNameAndFamilyNameMap) {
    // super(connectorId, schemaTableName, columnNames, columnTypes);
    this.schemaTableName = requireNonNull(schemaTableName, "schemaTableName is null");
    requireNonNull(columnNames, "columnNames is null");
    requireNonNull(columnTypes, "columnTypes is null");
    checkArgument(columnNames.size() == columnTypes.size(), "columnNames and columnTypes sizes don't match");
    this.columnNames = ImmutableList.copyOf(columnNames);
    this.columnTypes = ImmutableList.copyOf(columnTypes);
    this.connectorId = requireNonNull(connectorId, "connectorId is null");
    this.rowKeyColumnChannel = rowKeyColumnChannel;
    this.colNameAndFamilyNameMap = colNameAndFamilyNameMap;
}
 
Example #11
Source File: ThriftHiveMetastore.java    From presto with Apache License 2.0 6 votes vote down vote up
private static LockComponent createLockComponentForRead(SchemaTableName table, Optional<String> partitionName)
{
    requireNonNull(table, "table is null");
    requireNonNull(partitionName, "partitionName is null");

    LockComponentBuilder builder = new LockComponentBuilder();
    builder.setShared();
    builder.setOperationType(DataOperationType.SELECT);

    builder.setDbName(table.getSchemaName());
    builder.setTableName(table.getTableName());
    requireNonNull(partitionName, "partitionName is null").ifPresent(builder::setPartitionName);

    // acquire locks is called only for TransactionalTable
    builder.setIsTransactional(true);
    return builder.build();
}
 
Example #12
Source File: ManifestsTable.java    From presto with Apache License 2.0 6 votes vote down vote up
public ManifestsTable(SchemaTableName tableName, Table icebergTable, Optional<Long> snapshotId)
{
    this.icebergTable = requireNonNull(icebergTable, "icebergTable is null");

    tableMetadata = new ConnectorTableMetadata(
            tableName,
            ImmutableList.<ColumnMetadata>builder()
                    .add(new ColumnMetadata("path", VARCHAR))
                    .add(new ColumnMetadata("length", BIGINT))
                    .add(new ColumnMetadata("partition_spec_id", INTEGER))
                    .add(new ColumnMetadata("added_snapshot_id", BIGINT))
                    .add(new ColumnMetadata("added_data_files_count", INTEGER))
                    .add(new ColumnMetadata("existing_data_files_count", INTEGER))
                    .add(new ColumnMetadata("deleted_data_files_count", INTEGER))
                    .add(new ColumnMetadata("partitions", RowType.rowType(
                            RowType.field("contains_null", BOOLEAN),
                            RowType.field("lower_bound", VARCHAR),
                            RowType.field("upper_bound", VARCHAR))))
                    .build());
    this.snapshotId = requireNonNull(snapshotId, "snapshotId is null");
}
 
Example #13
Source File: BlackHoleMetadata.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix)
{
    return tables.values().stream()
            .filter(table -> prefix.matches(table.toSchemaTableName()))
            .collect(toMap(BlackHoleTableHandle::toSchemaTableName, handle -> handle.toTableMetadata().getColumns()));
}
 
Example #14
Source File: KuduClientSession.java    From presto with Apache License 2.0 5 votes vote down vote up
public void renameColumn(SchemaTableName schemaTableName, String oldName, String newName)
{
    try {
        String rawName = schemaEmulation.toRawName(schemaTableName);
        AlterTableOptions alterOptions = new AlterTableOptions();
        alterOptions.renameColumn(oldName, newName);
        client.alterTable(rawName, alterOptions);
    }
    catch (KuduException e) {
        throw new PrestoException(GENERIC_INTERNAL_ERROR, e);
    }
}
 
Example #15
Source File: TestingMetadata.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, ConnectorTableHandle tableHandle)
{
    requireNonNull(tableHandle, "tableHandle is null");
    SchemaTableName tableName = getTableName(tableHandle);
    ConnectorTableMetadata tableMetadata = tables.get(tableName);
    checkArgument(tableMetadata != null, "Table '%s' does not exist", tableName);
    return tableMetadata;
}
 
Example #16
Source File: RaptorMetadata.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void renameTable(ConnectorSession session, ConnectorTableHandle tableHandle, SchemaTableName newTableName)
{
    RaptorTableHandle table = (RaptorTableHandle) tableHandle;
    runTransaction(dbi, (handle, status) -> {
        MetadataDao dao = handle.attach(MetadataDao.class);
        dao.renameTable(table.getTableId(), newTableName.getSchemaName(), newTableName.getTableName());
        return null;
    });
}
 
Example #17
Source File: KuduTableHandle.java    From presto with Apache License 2.0 5 votes vote down vote up
public KuduTableHandle(
        SchemaTableName schemaTableName,
        KuduTable table,
        TupleDomain<ColumnHandle> constraint,
        Optional<List<ColumnHandle>> desiredColumns,
        boolean isDeleteHandle)
{
    this.schemaTableName = requireNonNull(schemaTableName, "schemaTableName is null");
    this.table = table;
    this.constraint = requireNonNull(constraint, "constraint is null");
    this.desiredColumns = requireNonNull(desiredColumns, "desiredColumns is null");
    this.isDeleteHandle = isDeleteHandle;
}
 
Example #18
Source File: HiveSplitManager.java    From presto with Apache License 2.0 5 votes vote down vote up
private PrestoException tablePartitionColumnMismatchException(SchemaTableName tableName, String partName, String tableColumnName, HiveType tableType, String partitionColumnName, HiveType partitionType)
{
    return new PrestoException(HIVE_PARTITION_SCHEMA_MISMATCH, format("" +
                    "There is a mismatch between the table and partition schemas. " +
                    "The types are incompatible and cannot be coerced. " +
                    "The column '%s' in table '%s' is declared as type '%s', " +
                    "but partition '%s' declared column '%s' as type '%s'.",
            tableColumnName,
            tableName,
            tableType,
            partName,
            partitionColumnName,
            partitionType));
}
 
Example #19
Source File: TestInformationSchemaMetadata.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testInformationSchemaPredicatePushdownForEmptyNames()
{
    TransactionId transactionId = transactionManager.beginTransaction(false);
    ConnectorSession session = createNewSession(transactionId);
    ConnectorMetadata metadata = new InformationSchemaMetadata("test_catalog", this.metadata);
    InformationSchemaColumnHandle tableSchemaColumn = new InformationSchemaColumnHandle("table_schema");
    InformationSchemaColumnHandle tableNameColumn = new InformationSchemaColumnHandle("table_name");
    ConnectorTableHandle tableHandle = metadata.getTableHandle(session, new SchemaTableName("information_schema", "tables"));

    // Empty schema name
    InformationSchemaTableHandle filtered = metadata.applyFilter(session, tableHandle, new Constraint(TupleDomain.withColumnDomains(
            ImmutableMap.of(tableSchemaColumn, Domain.singleValue(VARCHAR, Slices.utf8Slice(""))))))
            .map(ConstraintApplicationResult::getHandle)
            .map(InformationSchemaTableHandle.class::cast)
            .orElseThrow(AssertionError::new);

    // "" schema name is valid schema name, but is (currently) valid for QualifiedTablePrefix
    assertEquals(filtered.getPrefixes(), ImmutableSet.of(new QualifiedTablePrefix("test_catalog", "")));

    // Empty table name
    filtered = metadata.applyFilter(session, tableHandle, new Constraint(TupleDomain.withColumnDomains(
            ImmutableMap.of(tableNameColumn, Domain.singleValue(VARCHAR, Slices.utf8Slice(""))))))
            .map(ConstraintApplicationResult::getHandle)
            .map(InformationSchemaTableHandle.class::cast)
            .orElseThrow(AssertionError::new);

    // "" table name is valid schema name, but is (currently) valid for QualifiedTablePrefix
    assertEquals(filtered.getPrefixes(), ImmutableSet.of(new QualifiedTablePrefix("test_catalog", "test_schema", "")));
}
 
Example #20
Source File: BigQueryMetadata.java    From presto with Apache License 2.0 5 votes vote down vote up
public ConnectorTableMetadata getTableMetadata(ConnectorSession session, SchemaTableName schemaTableName)
{
    ConnectorTableHandle table = getTableHandle(session, schemaTableName);
    if (table == null) {
        throw new TableNotFoundException(schemaTableName);
    }
    return getTableMetadata(session, table);
}
 
Example #21
Source File: TestMemoryMetadata.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateViewWithReplace()
{
    SchemaTableName test = new SchemaTableName("test", "test_view");

    metadata.createSchema(SESSION, "test", ImmutableMap.of(), new PrestoPrincipal(USER, SESSION.getUser()));
    metadata.createView(SESSION, test, testingViewDefinition("aaa"), true);
    metadata.createView(SESSION, test, testingViewDefinition("bbb"), true);

    assertThat(metadata.getView(SESSION, test))
            .map(ConnectorViewDefinition::getOriginalSql)
            .hasValue("bbb");
}
 
Example #22
Source File: NoSchemaEmulation.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public String toRawName(SchemaTableName schemaTableName)
{
    if (DEFAULT_SCHEMA.equals(schemaTableName.getSchemaName())) {
        return schemaTableName.getTableName();
    }
    else {
        throw new SchemaNotFoundException(schemaTableName.getSchemaName());
    }
}
 
Example #23
Source File: SemiTransactionalHiveMetastore.java    From presto with Apache License 2.0 5 votes vote down vote up
public DeclaredIntentionToWrite(WriteMode mode, HdfsContext hdfsContext, HiveIdentity identity, String queryId, Path stagingPathRoot, SchemaTableName schemaTableName)
{
    this.mode = requireNonNull(mode, "mode is null");
    this.hdfsContext = requireNonNull(hdfsContext, "hdfsContext is null");
    this.identity = requireNonNull(identity, "identity is null");
    this.queryId = requireNonNull(queryId, "queryId is null");
    this.rootPath = requireNonNull(stagingPathRoot, "stagingPathRoot is null");
    this.schemaTableName = requireNonNull(schemaTableName, "schemaTableName is null");
}
 
Example #24
Source File: ThriftIndexHandle.java    From presto with Apache License 2.0 5 votes vote down vote up
@JsonCreator
public ThriftIndexHandle(
        @JsonProperty("schemaTableName") SchemaTableName schemaTableName,
        @JsonProperty("tupleDomain") TupleDomain<ColumnHandle> tupleDomain)
{
    this(schemaTableName, tupleDomain, Optional.empty());
}
 
Example #25
Source File: BaseJdbcClient.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void rollbackCreateTable(JdbcIdentity identity, JdbcOutputTableHandle handle)
{
    dropTable(identity, new JdbcTableHandle(
            new SchemaTableName(handle.getSchemaName(), handle.getTemporaryTableName()),
            handle.getCatalogName(),
            handle.getSchemaName(),
            handle.getTemporaryTableName()));
}
 
Example #26
Source File: MetastoreHiveStatisticsProvider.java    From presto with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static void validatePartitionStatistics(SchemaTableName table, Map<String, PartitionStatistics> partitionStatistics)
{
    partitionStatistics.forEach((partition, statistics) -> {
        HiveBasicStatistics basicStatistics = statistics.getBasicStatistics();
        OptionalLong rowCount = basicStatistics.getRowCount();
        rowCount.ifPresent(count -> checkStatistics(count >= 0, table, partition, "rowCount must be greater than or equal to zero: %s", count));
        basicStatistics.getFileCount().ifPresent(count -> checkStatistics(count >= 0, table, partition, "fileCount must be greater than or equal to zero: %s", count));
        basicStatistics.getInMemoryDataSizeInBytes().ifPresent(size -> checkStatistics(size >= 0, table, partition, "inMemoryDataSizeInBytes must be greater than or equal to zero: %s", size));
        basicStatistics.getOnDiskDataSizeInBytes().ifPresent(size -> checkStatistics(size >= 0, table, partition, "onDiskDataSizeInBytes must be greater than or equal to zero: %s", size));
        statistics.getColumnStatistics().forEach((column, columnStatistics) -> validateColumnStatistics(table, partition, column, rowCount, columnStatistics));
    });
}
 
Example #27
Source File: SqlStandardAccessControl.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public void checkCanRevokeTablePrivilege(ConnectorSecurityContext context, Privilege privilege, SchemaTableName tableName, PrestoPrincipal revokee, boolean grantOption)
{
    if (isTableOwner(context, tableName)) {
        return;
    }

    if (!hasGrantOptionForPrivilege(context, privilege, tableName)) {
        denyRevokeTablePrivilege(privilege.name(), tableName.toString());
    }
}
 
Example #28
Source File: ClassLoaderSafeConnectorMetadata.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public List<SchemaTableName> listViews(ConnectorSession session, Optional<String> schemaName)
{
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(classLoader)) {
        return delegate.listViews(session, schemaName);
    }
}
 
Example #29
Source File: InMemoryThriftMetastore.java    From presto with Apache License 2.0 5 votes vote down vote up
private synchronized PartitionStatistics getTableStatistics(String databaseName, String tableName)
{
    SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName);
    PartitionStatistics statistics = columnStatistics.get(schemaTableName);
    if (statistics == null) {
        statistics = new PartitionStatistics(createEmptyStatistics(), ImmutableMap.of());
    }
    return statistics;
}
 
Example #30
Source File: CassandraMetadata.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public CassandraTableHandle getTableHandle(ConnectorSession session, SchemaTableName tableName)
{
    requireNonNull(tableName, "tableName is null");
    try {
        return cassandraSession.getTable(tableName).getTableHandle();
    }
    catch (TableNotFoundException | SchemaNotFoundException e) {
        // table was not found
        return null;
    }
}