@Override public String buildInsertSql(JdbcOutputTableHandle handle) { String vars = Joiner.on(',').join(nCopies(handle.getColumnNames().size(), "?")); return new StringBuilder() .append("INSERT INTO ") .append(quoted(handle.getCatalogName(), handle.getSchemaName(), handle.getTemporaryTableName())) .append(" VALUES (").append(vars).append(")") .toString(); }
@Override public void commitCreateTable(JdbcOutputTableHandle handle) { // PostgreSQL does not allow qualifying the target of a rename StringBuilder sql = new StringBuilder() .append("ALTER TABLE ") .append(quoted(handle.getCatalogName(), handle.getSchemaName(), handle.getTemporaryTableName())) .append(" RENAME TO ") .append(quoted(handle.getTableName())); try (Connection connection = getConnection(handle)) { execute(connection, sql.toString()); } catch (SQLException e) { throw new RuntimeException(e); } }
@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 commitCreateTable(JdbcOutputTableHandle handle) { StringBuilder sql = new StringBuilder() .append("sp_rename ") .append(singleQuote(handle.getCatalogName(), handle.getSchemaName(), handle.getTemporaryTableName())) .append(", ") .append(singleQuote(handle.getTableName())); try (Connection connection = getConnection(handle)) { execute(connection, sql.toString()); } catch (SQLException e) { throw new PrestoException(JDBC_ERROR, e); } }
@Override public void commitCreateTable(JdbcOutputTableHandle handle) { // Redshift does not allow qualifying the target of a rename StringBuilder sql = new StringBuilder() .append("ALTER TABLE ") .append(quoted(handle.getCatalogName(), handle.getSchemaName(), handle.getTemporaryTableName())) .append(" RENAME TO ") .append(quoted(handle.getTableName())); try (Connection connection = getConnection(handle)) { execute(connection, sql.toString()); } catch (SQLException e) { throw new PrestoException(JDBC_ERROR, e); } }
@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 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 String buildInsertSql(JdbcOutputTableHandle handle) { String vars = Joiner.on(',').join(nCopies(handle.getColumnNames().size(), "?")); return new StringBuilder() .append("INSERT INTO ") .append(quoted(handle.getCatalogName(), handle.getSchemaName(), handle.getTemporaryTableName())) .append(" VALUES (").append(vars).append(")") .toString(); }
@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 void commitCreateTable(JdbcOutputTableHandle handle) { // PostgreSQL does not allow qualifying the target of a rename StringBuilder sql = new StringBuilder() .append("ALTER TABLE ") .append(quoted(handle.getCatalogName(), handle.getSchemaName(), handle.getTemporaryTableName())) .append(" RENAME TO ") .append(quoted(handle.getTableName())); try (Connection connection = getConnection(handle)) { execute(connection, sql.toString()); } catch (SQLException e) { throw new RuntimeException(e); } }
@Override public void commitCreateTable(final JdbcOutputTableHandle handle, final Collection<Slice> fragments) { // PostgreSQL does not allow qualifying the target of a rename final StringBuilder sql = new StringBuilder() .append("ALTER TABLE ") .append(quoted(handle.getCatalogName(), handle.getSchemaName(), handle.getTemporaryTableName())) .append(" RENAME TO ") .append(quoted(handle.getTableName())); try (Connection connection = getConnection(handle)) { execute(connection, sql.toString()); } catch (SQLException e) { throw Throwables.propagate(e); } } }