Search in sources :

Example 6 with NewerTableAlreadyExistsException

use of org.apache.phoenix.schema.NewerTableAlreadyExistsException in project phoenix by apache.

the class ConnectionQueryServicesImpl method removeNotNullConstraint.

private PhoenixConnection removeNotNullConstraint(PhoenixConnection oldMetaConnection, String schemaName, String tableName, long timestamp, String columnName) throws SQLException {
    Properties props = PropertiesUtil.deepCopy(oldMetaConnection.getClientInfo());
    props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(timestamp));
    // Cannot go through DriverManager or you end up in an infinite loop because it'll call init again
    PhoenixConnection metaConnection = new PhoenixConnection(oldMetaConnection, this, props);
    SQLException sqlE = null;
    try {
        String dml = "UPSERT INTO " + SYSTEM_CATALOG_NAME + " (" + PhoenixDatabaseMetaData.TENANT_ID + "," + PhoenixDatabaseMetaData.TABLE_SCHEM + "," + PhoenixDatabaseMetaData.TABLE_NAME + "," + PhoenixDatabaseMetaData.COLUMN_NAME + "," + PhoenixDatabaseMetaData.NULLABLE + ") VALUES (null, ?, ?, ?, ?)";
        PreparedStatement stmt = metaConnection.prepareStatement(dml);
        stmt.setString(1, schemaName);
        stmt.setString(2, tableName);
        stmt.setString(3, columnName);
        stmt.setInt(4, ResultSetMetaData.columnNullable);
        stmt.executeUpdate();
        metaConnection.commit();
    } catch (NewerTableAlreadyExistsException e) {
        logger.warn("Table already modified at this timestamp, so assuming column already nullable: " + columnName);
    } catch (SQLException e) {
        logger.warn("Add column failed due to:" + e);
        sqlE = e;
    } finally {
        try {
            oldMetaConnection.close();
        } catch (SQLException e) {
            if (sqlE != null) {
                sqlE.setNextException(e);
            } else {
                sqlE = e;
            }
        }
        if (sqlE != null) {
            throw sqlE;
        }
    }
    return metaConnection;
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Properties(java.util.Properties) NewerTableAlreadyExistsException(org.apache.phoenix.schema.NewerTableAlreadyExistsException)

Example 7 with NewerTableAlreadyExistsException

use of org.apache.phoenix.schema.NewerTableAlreadyExistsException in project phoenix by apache.

the class ConnectionQueryServicesImpl method addColumn.

/**
     * This closes the passed connection.
     */
private PhoenixConnection addColumn(PhoenixConnection oldMetaConnection, String tableName, long timestamp, String columns, boolean addIfNotExists) throws SQLException {
    Properties props = PropertiesUtil.deepCopy(oldMetaConnection.getClientInfo());
    props.setProperty(PhoenixRuntime.CURRENT_SCN_ATTRIB, Long.toString(timestamp));
    // Cannot go through DriverManager or you end up in an infinite loop because it'll call init again
    PhoenixConnection metaConnection = new PhoenixConnection(oldMetaConnection, this, props);
    SQLException sqlE = null;
    try {
        metaConnection.createStatement().executeUpdate("ALTER TABLE " + tableName + " ADD " + (addIfNotExists ? " IF NOT EXISTS " : "") + columns);
    } catch (NewerTableAlreadyExistsException e) {
        logger.warn("Table already modified at this timestamp, so assuming add of these columns already done: " + columns);
    } catch (SQLException e) {
        logger.warn("Add column failed due to:" + e);
        sqlE = e;
    } finally {
        try {
            oldMetaConnection.close();
        } catch (SQLException e) {
            if (sqlE != null) {
                sqlE.setNextException(e);
            } else {
                sqlE = e;
            }
        }
        if (sqlE != null) {
            throw sqlE;
        }
    }
    return metaConnection;
}
Also used : PhoenixConnection(org.apache.phoenix.jdbc.PhoenixConnection) SQLException(java.sql.SQLException) Properties(java.util.Properties) NewerTableAlreadyExistsException(org.apache.phoenix.schema.NewerTableAlreadyExistsException)

Aggregations

Properties (java.util.Properties)7 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)7 NewerTableAlreadyExistsException (org.apache.phoenix.schema.NewerTableAlreadyExistsException)7 SQLException (java.sql.SQLException)5 TableAlreadyExistsException (org.apache.phoenix.schema.TableAlreadyExistsException)3 TableNotFoundException (org.apache.phoenix.schema.TableNotFoundException)3 IOException (java.io.IOException)2 Connection (java.sql.Connection)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 TableExistsException (org.apache.hadoop.hbase.TableExistsException)2 HBaseAdmin (org.apache.hadoop.hbase.client.HBaseAdmin)2 AccessDeniedException (org.apache.hadoop.hbase.security.AccessDeniedException)2 PhoenixIOException (org.apache.phoenix.exception.PhoenixIOException)2 RetriableUpgradeException (org.apache.phoenix.exception.RetriableUpgradeException)2 UpgradeInProgressException (org.apache.phoenix.exception.UpgradeInProgressException)2 UpgradeNotRequiredException (org.apache.phoenix.exception.UpgradeNotRequiredException)2 ColumnAlreadyExistsException (org.apache.phoenix.schema.ColumnAlreadyExistsException)2 ColumnFamilyNotFoundException (org.apache.phoenix.schema.ColumnFamilyNotFoundException)2 EmptySequenceCacheException (org.apache.phoenix.schema.EmptySequenceCacheException)2