Search in sources :

Example 61 with HiveMetaException

use of org.apache.hadoop.hive.metastore.HiveMetaException in project hive by apache.

the class SchemaToolTaskCreateUser method execute.

@Override
void execute() throws HiveMetaException {
    schemaTool.testConnectionToMetastore();
    System.out.println("Starting user creation");
    String scriptDir = schemaTool.getMetaStoreSchemaInfo().getMetaStoreScriptDir();
    String protoCreateFile = schemaTool.getMetaStoreSchemaInfo().getCreateUserScript();
    try {
        File createFile = subUserAndPassword(scriptDir, protoCreateFile);
        System.out.println("Creation script " + createFile.getAbsolutePath());
        if (!schemaTool.isDryRun()) {
            if ("oracle".equals(schemaTool.getDbType()))
                oracleCreateUserHack(createFile);
            else
                schemaTool.execSql(createFile.getParent(), createFile.getName());
            System.out.println("User creation completed");
        }
    } catch (IOException e) {
        throw new HiveMetaException("User creation FAILED!" + " Metastore unusable !!", e);
    }
}
Also used : HiveMetaException(org.apache.hadoop.hive.metastore.HiveMetaException) IOException(java.io.IOException) File(java.io.File)

Example 62 with HiveMetaException

use of org.apache.hadoop.hive.metastore.HiveMetaException in project hive by apache.

the class SchemaToolTaskMoveDatabase method execute.

@Override
void execute() throws HiveMetaException {
    System.out.println(String.format("Moving database %s from catalog %s to catalog %s", dbName, fromCatName, toCatName));
    Connection conn = schemaTool.getConnectionToMetastore(true);
    boolean success = false;
    try {
        conn.setAutoCommit(false);
        try (Statement stmt = conn.createStatement()) {
            updateCatalogNameInTable(stmt, "DBS", "CTLG_NAME", "NAME", fromCatName, toCatName, dbName, false);
            updateCatalogNameInTable(stmt, "TAB_COL_STATS", "CAT_NAME", "DB_NAME", fromCatName, toCatName, dbName, true);
            updateCatalogNameInTable(stmt, "PART_COL_STATS", "CAT_NAME", "DB_NAME", fromCatName, toCatName, dbName, true);
            updateCatalogNameInTable(stmt, "PARTITION_EVENTS", "CAT_NAME", "DB_NAME", fromCatName, toCatName, dbName, true);
            updateCatalogNameInTable(stmt, "NOTIFICATION_LOG", "CAT_NAME", "DB_NAME", fromCatName, toCatName, dbName, true);
            conn.commit();
            success = true;
        }
    } catch (SQLException e) {
        throw new HiveMetaException("Failed to move database", e);
    } finally {
        try {
            if (!success) {
                conn.rollback();
            }
        } catch (SQLException e) {
            // Not really much we can do here.
            LOG.error("Failed to rollback, everything will probably go bad from here.");
        }
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) Connection(java.sql.Connection) HiveMetaException(org.apache.hadoop.hive.metastore.HiveMetaException)

Aggregations

HiveMetaException (org.apache.hadoop.hive.metastore.HiveMetaException)62 SQLException (java.sql.SQLException)39 IOException (java.io.IOException)28 ResultSet (java.sql.ResultSet)25 Statement (java.sql.Statement)24 PreparedStatement (java.sql.PreparedStatement)18 Connection (java.sql.Connection)13 File (java.io.File)12 Test (org.junit.Test)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 ParseException (org.apache.commons.cli.ParseException)5 ArrayList (java.util.ArrayList)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OutputStream (java.io.OutputStream)3 PrintStream (java.io.PrintStream)3 DatabaseMetaData (java.sql.DatabaseMetaData)3 HashSet (java.util.HashSet)3 Pair (org.apache.commons.lang3.tuple.Pair)3 MetastoreCheckinTest (org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest)3