protected SchemaTableName getSchemaTableName(ResultSet resultSet) throws SQLException { return new SchemaTableName( resultSet.getString("TABLE_SCHEM").toLowerCase(ENGLISH), resultSet.getString("TABLE_NAME").toLowerCase(ENGLISH)); }
public void addProcedures(ConnectorId connectorId, Collection<Procedure> procedures) { requireNonNull(connectorId, "connectorId is null"); requireNonNull(procedures, "procedures is null"); procedures.forEach(this::validateProcedure); Map<SchemaTableName, Procedure> proceduresByName = Maps.uniqueIndex( procedures, procedure -> new SchemaTableName(procedure.getSchema(), procedure.getName())); checkState(connectorProcedures.putIfAbsent(connectorId, proceduresByName) == null, "Procedures already registered for connector: %s", connectorId); }
@Override public List<SchemaTableName> listTables(ConnectorSession session, Optional<String> filterSchema) { ImmutableList.Builder<SchemaTableName> builder = ImmutableList.builder(); for (String schemaName : getSchemaNames(session, filterSchema)) { for (Table tpcdsTable : Table.getBaseTables()) { builder.add(new SchemaTableName(schemaName, tpcdsTable.getName())); } } return builder.build(); }
@Override public List<SchemaTableName> listTables(ConnectorSession session, Optional<String> filterSchema) { ImmutableList.Builder<SchemaTableName> builder = ImmutableList.builder(); for (String schemaName : getSchemaNames(session, filterSchema)) { for (TpchTable<?> tpchTable : TpchTable.getTables()) { builder.add(new SchemaTableName(schemaName, tpchTable.getTableName())); } } return builder.build(); }
@Override public synchronized Optional<Table> getTable(String databaseName, String tableName) { SchemaTableName schemaTableName = new SchemaTableName(databaseName, tableName); return Optional.ofNullable(relations.get(schemaTableName)); }
protected static SchemaTableName temporaryTable(String database, String tableName) { String randomName = UUID.randomUUID().toString().toLowerCase(ENGLISH).replace("-", ""); return new SchemaTableName(database, TEMPORARY_TABLE_PREFIX + tableName + "_" + randomName); }
@Test public void testJsonRoundTrip() { assertJsonRoundTrip(TABLE_CODEC, new JdbcTableHandle("connectorId", new SchemaTableName("schema", "table"), "jdbcCatalog", "jdbcSchema", "jdbcTable")); }
@Test public void testGetTableHandle() { JdbcTableHandle tableHandle = metadata.getTableHandle(SESSION, new SchemaTableName("example", "numbers")); assertEquals(metadata.getTableHandle(SESSION, new SchemaTableName("example", "numbers")), tableHandle); assertNull(metadata.getTableHandle(SESSION, new SchemaTableName("example", "unknown"))); assertNull(metadata.getTableHandle(SESSION, new SchemaTableName("unknown", "numbers"))); assertNull(metadata.getTableHandle(SESSION, new SchemaTableName("unknown", "unknown"))); }
@Test public void testSystemDeserialize() throws Exception { String json = objectMapper.writeValueAsString(SCHEMA_AS_MAP); ConnectorTableHandle tableHandle = objectMapper.readValue(json, ConnectorTableHandle.class); assertEquals(tableHandle.getClass(), SystemTableHandle.class); SystemTableHandle systemHandle = (SystemTableHandle) tableHandle; assertEquals(systemHandle.getConnectorId(), CONNECTOR_ID); assertEquals(systemHandle.getSchemaTableName(), new SchemaTableName("system_schema", "system_table")); }
@Override public void rollbackCreateTable(JdbcOutputTableHandle handle) { dropTable(new JdbcTableHandle( handle.getConnectorId(), new SchemaTableName(handle.getSchemaName(), handle.getTemporaryTableName()), handle.getCatalogName(), handle.getSchemaName(), handle.getTemporaryTableName())); }
@Override public 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; }
@Test(expectedExceptions = PrestoException.class) public void testCreateTable() { metadata.createTable( SESSION, new ConnectorTableMetadata( new SchemaTableName("example", "foo"), ImmutableList.of(new ColumnMetadata("text", VARCHAR))), false); }
@Test public void testMetadataWithSchemaPattern() { SchemaTableName schemaTableName = new SchemaTableName("exa_ple", "num_ers"); JdbcTableHandle table = jdbcClient.getTableHandle(schemaTableName); assertNotNull(table, "table is null"); assertEquals(jdbcClient.getColumns(session, table), ImmutableList.of( new JdbcColumnHandle(CONNECTOR_ID, "TE_T", JDBC_VARCHAR, VARCHAR), new JdbcColumnHandle(CONNECTOR_ID, "VA%UE", JDBC_BIGINT, BIGINT))); }
public void updateTableLocation(String databaseName, String tableName, String location) { Optional<Table> table = getTable(databaseName, tableName); if (!table.isPresent()) { throw new TableNotFoundException(new SchemaTableName(databaseName, tableName)); } Table.Builder tableBuilder = Table.builder(table.get()); tableBuilder.getStorageBuilder().setLocation(location); // NOTE: this clears the permissions replaceTable(databaseName, tableName, tableBuilder.build(), new PrincipalPrivileges(ImmutableMultimap.of(), ImmutableMultimap.of())); }
protected AbstractPropertiesSystemTable(String tableName, TransactionManager transactionManager, Supplier<Map<ConnectorId, Map<String, PropertyMetadata<?>>>> propertySupplier) { this.tableMetadata = tableMetadataBuilder(new SchemaTableName("metadata", tableName)) .column("catalog_name", createUnboundedVarcharType()) .column("property_name", createUnboundedVarcharType()) .column("default_value", createUnboundedVarcharType()) .column("type", createUnboundedVarcharType()) .column("description", createUnboundedVarcharType()) .build(); this.transactionManager = requireNonNull(transactionManager, "transactionManager is null"); this.propertySupplier = requireNonNull(propertySupplier, "propertySupplier is null"); }
@BeforeMethod public void setUp() throws Exception { database = new TestingDatabase(); metadata = new JdbcMetadata(database.getJdbcClient(), false); tableHandle = metadata.getTableHandle(SESSION, new SchemaTableName("example", "numbers")); }
private void testNoTableStats(String schema, TpchTable<?> table) { TpchTableHandle tableHandle = tpchMetadata.getTableHandle(session, new SchemaTableName(schema, table.getTableName())); TableStatistics tableStatistics = tpchMetadata.getTableStatistics(session, tableHandle, alwaysTrue()); assertTrue(tableStatistics.getRowCount().isUnknown()); }
@Test public void test() { tester().assertThat(new RemoveEmptyDelete()) .on(p -> p.tableDelete( new SchemaTableName("sch", "tab"), p.values(), p.symbol("a", BigintType.BIGINT))) .matches( PlanMatchPattern.values(ImmutableMap.of("a", 0))); } }
public JdbcSplit getSplit(String schemaName, String tableName) { JdbcTableHandle jdbcTableHandle = jdbcClient.getTableHandle(new SchemaTableName(schemaName, tableName)); JdbcTableLayoutHandle jdbcLayoutHandle = new JdbcTableLayoutHandle(jdbcTableHandle, TupleDomain.all()); ConnectorSplitSource splits = jdbcClient.getSplits(jdbcLayoutHandle); return (JdbcSplit) getOnlyElement(getFutureValue(splits.getNextBatch(NOT_PARTITIONED, 1000)).getSplits()); }
private void testColumnStats(String schema, TpchTable<?> table, TpchColumn<?> column, Constraint<ColumnHandle> constraint, ColumnStatistics expected) { TpchTableHandle tableHandle = tpchMetadata.getTableHandle(session, new SchemaTableName(schema, table.getTableName())); TableStatistics tableStatistics = tpchMetadata.getTableStatistics(session, tableHandle, constraint); ColumnHandle columnHandle = tpchMetadata.getColumnHandles(session, tableHandle).get(column.getSimplifiedColumnName()); ColumnStatistics actual = tableStatistics.getColumnStatistics().get(columnHandle); EstimateAssertion estimateAssertion = new EstimateAssertion(TOLERANCE); estimateAssertion.assertClose(actual.getDistinctValuesCount(), expected.getDistinctValuesCount(), "distinctValuesCount"); estimateAssertion.assertClose(actual.getDataSize(), expected.getDataSize(), "dataSize"); estimateAssertion.assertClose(actual.getNullsFraction(), expected.getNullsFraction(), "nullsFraction"); estimateAssertion.assertClose(actual.getRange(), expected.getRange(), "range"); }