@Override public void commitCreateTable(JdbcOutputTableHandle handle) { StringBuilder sql = new StringBuilder() .append("ALTER TABLE ") .append(quoted(handle.getCatalogName(), handle.getSchemaName(), handle.getTemporaryTableName())) .append(" RENAME TO ") .append(quoted(handle.getCatalogName(), handle.getSchemaName(), handle.getTableName())); try (Connection connection = getConnection(handle)) { execute(connection, sql.toString()); } catch (SQLException e) { throw new PrestoException(JDBC_ERROR, e); } }
@Override public void finishInsertTable(JdbcOutputTableHandle handle) { String temporaryTable = quoted(handle.getCatalogName(), handle.getSchemaName(), handle.getTemporaryTableName()); String targetTable = quoted(handle.getCatalogName(), handle.getSchemaName(), handle.getTableName()); String insertSql = format("INSERT INTO %s SELECT * FROM %s", targetTable, temporaryTable); String cleanupSql = "DROP TABLE " + temporaryTable; try (Connection connection = getConnection(handle)) { execute(connection, insertSql); } catch (SQLException e) { throw new PrestoException(JDBC_ERROR, e); } try (Connection connection = getConnection(handle)) { execute(connection, cleanupSql); } catch (SQLException e) { log.warn(e, "Failed to cleanup temporary table: %s", temporaryTable); } }
@Override public void commitCreateTable(JdbcOutputTableHandle handle, Collection<Slice> fragments) { StringBuilder sql = new StringBuilder() .append("ALTER TABLE ") .append(quoted(handle.getCatalogName(), handle.getSchemaName(), handle.getTemporaryTableName())) .append(" RENAME TO ") .append(quoted(handle.getCatalogName(), handle.getSchemaName(), handle.getTableName())); try (Connection connection = getConnection(handle)) { execute(connection, sql.toString()); } catch (SQLException e) { throw new PrestoException(JDBC_ERROR, e); } }
@Override public PreparedStatement buildSql(JdbcSplit split, List<JdbcColumnHandle> columnHandles) throws SQLException { return new QueryBuilder(identifierQuote).buildSql( getConnection(split), split.getCatalogName(), split.getSchemaName(), split.getTableName(), columnHandles, split.getTupleDomain()); }