@Override public void dropTable(JdbcTableHandle handle) { StringBuilder sql = new StringBuilder() .append("DROP TABLE ") .append(quoted(handle.getCatalogName(), handle.getSchemaName(), handle.getTableName())); try (Connection connection = connectionFactory.openConnection()) { execute(connection, sql.toString()); } catch (SQLException e) { throw new PrestoException(JDBC_ERROR, e); } }
private static ResultSet getColumns(JdbcTableHandle tableHandle, DatabaseMetaData metadata) throws SQLException { String escape = metadata.getSearchStringEscape(); return metadata.getColumns( tableHandle.getCatalogName(), escapeNamePattern(tableHandle.getSchemaName(), escape), escapeNamePattern(tableHandle.getTableName(), escape), null); } }
@Override public ConnectorSplitSource getSplits(JdbcTableLayoutHandle layoutHandle) { JdbcTableHandle tableHandle = layoutHandle.getTable(); JdbcSplit jdbcSplit = new JdbcSplit( connectorId, tableHandle.getCatalogName(), tableHandle.getSchemaName(), tableHandle.getTableName(), layoutHandle.getTupleDomain(), Optional.empty()); return new FixedSplitSource(ImmutableList.of(jdbcSplit)); }
@Test public void testMetadata() { assertTrue(jdbcClient.getSchemaNames().containsAll(ImmutableSet.of("example", "tpch"))); assertEquals(jdbcClient.getTableNames("example"), ImmutableList.of( new SchemaTableName("example", "numbers"), new SchemaTableName("example", "view_source"), new SchemaTableName("example", "view"))); assertEquals(jdbcClient.getTableNames("tpch"), ImmutableList.of( new SchemaTableName("tpch", "lineitem"), new SchemaTableName("tpch", "orders"))); SchemaTableName schemaTableName = new SchemaTableName("example", "numbers"); JdbcTableHandle table = jdbcClient.getTableHandle(schemaTableName); assertNotNull(table, "table is null"); assertEquals(table.getCatalogName(), catalogName.toUpperCase(ENGLISH)); assertEquals(table.getSchemaName(), "EXAMPLE"); assertEquals(table.getTableName(), "NUMBERS"); assertEquals(table.getSchemaTableName(), schemaTableName); assertEquals(jdbcClient.getColumns(session, table), ImmutableList.of( new JdbcColumnHandle(CONNECTOR_ID, "TEXT", JDBC_VARCHAR, VARCHAR), new JdbcColumnHandle(CONNECTOR_ID, "TEXT_SHORT", JDBC_VARCHAR, createVarcharType(32)), new JdbcColumnHandle(CONNECTOR_ID, "VALUE", JDBC_BIGINT, BIGINT))); }
@Override public void dropTable(JdbcTableHandle handle) { StringBuilder sql = new StringBuilder() .append("DROP TABLE ") .append(quoted(handle.getCatalogName(), handle.getSchemaName(), handle.getTableName())); try (Connection connection = driver.connect(connectionUrl, connectionProperties)) { execute(connection, sql.toString()); } catch (SQLException e) { throw new PrestoException(JDBC_ERROR, e); } }
try (Connection connection = driver.connect(connectionUrl, connectionProperties)) { final DatabaseMetaData metadata = connection.getMetaData(); try (ResultSet resultSet = metadata.getColumns(tableHandle.getCatalogName(), tableHandle.getSchemaName(), tableHandle.getTableName(), null); ResultSet indexSet = metadata.getIndexInfo(tableHandle.getCatalogName(), tableHandle.getSchemaName(), tableHandle.getTableName(), false, true)) { final List<ColumnDetailHandle> columns = new ArrayList<>();
private static ResultSet getColumns(JdbcTableHandle tableHandle, DatabaseMetaData metadata) throws SQLException { String escape = metadata.getSearchStringEscape(); return metadata.getColumns( tableHandle.getCatalogName(), escapeNamePattern(tableHandle.getSchemaName(), escape), escapeNamePattern(tableHandle.getTableName(), escape), null); }
try (Connection connection = driver.connect(connectionUrl, connectionProperties)) { final DatabaseMetaData metadata = connection.getMetaData(); try (ResultSet resultSet = metadata.getColumns(tableHandle.getCatalogName(), tableHandle.getSchemaName(), tableHandle.getTableName(), null)) { final List<ColumnDetailHandle> columns = new ArrayList<>();
@Override public ConnectorSplitSource getSplits(JdbcTableLayoutHandle layoutHandle) { JdbcTableHandle tableHandle = layoutHandle.getTable(); JdbcSplit jdbcSplit = new JdbcSplit( connectorId, tableHandle.getCatalogName(), tableHandle.getSchemaName(), tableHandle.getTableName(), connectionUrl, fromProperties(connectionProperties), layoutHandle.getTupleDomain()); return new FixedSplitSource(connectorId, ImmutableList.of(jdbcSplit)); }
@Test public void testMetadata() { assertTrue(jdbcClient.getSchemaNames().containsAll(ImmutableSet.of("example", "tpch"))); assertEquals(jdbcClient.getTableNames("example"), ImmutableList.of( new SchemaTableName("example", "numbers"), new SchemaTableName("example", "view_source"), new SchemaTableName("example", "view"))); assertEquals(jdbcClient.getTableNames("tpch"), ImmutableList.of( new SchemaTableName("tpch", "lineitem"), new SchemaTableName("tpch", "orders"))); SchemaTableName schemaTableName = new SchemaTableName("example", "numbers"); JdbcTableHandle table = jdbcClient.getTableHandle(schemaTableName); assertNotNull(table, "table is null"); assertEquals(table.getCatalogName(), catalogName.toUpperCase(ENGLISH)); assertEquals(table.getSchemaName(), "EXAMPLE"); assertEquals(table.getTableName(), "NUMBERS"); assertEquals(table.getSchemaTableName(), schemaTableName); assertEquals(jdbcClient.getColumns(session, table), ImmutableList.of( new JdbcColumnHandle(CONNECTOR_ID, "TEXT", JDBC_VARCHAR, VARCHAR), new JdbcColumnHandle(CONNECTOR_ID, "TEXT_SHORT", JDBC_VARCHAR, createVarcharType(32)), new JdbcColumnHandle(CONNECTOR_ID, "VALUE", JDBC_BIGINT, BIGINT))); }