Search in sources :

Example 36 with CommandProcessorException

use of org.apache.hadoop.hive.ql.processors.CommandProcessorException in project hive by apache.

the class TestTxnAddPartition method addPartition.

/**
 * Tests adding multiple partitions
 * adding partition w/o location
 * adding partition when it already exists
 * adding partition when it already exists with "if not exists"
 */
private void addPartition(boolean isVectorized) throws Exception {
    runStatementOnDriver("drop table if exists T");
    runStatementOnDriver("drop table if exists Tstage");
    runStatementOnDriver("create table T (a int, b int) partitioned by (p int) stored as orc" + " tblproperties('transactional'='true')");
    runStatementOnDriver("create table Tstage (a int, b int) stored as orc" + " tblproperties('transactional'='false')");
    runStatementOnDriver("insert into Tstage values(0,2),(0,4)");
    runStatementOnDriver("export table Tstage to '" + getWarehouseDir() + "/1'");
    runStatementOnDriver("export table Tstage to '" + getWarehouseDir() + "/2'");
    runStatementOnDriver("ALTER TABLE T ADD" + " PARTITION (p=0) location '" + getWarehouseDir() + "/1/data'" + " PARTITION (p=1) location '" + getWarehouseDir() + "/2/data'" + " PARTITION (p=2)");
    String testQuery = isVectorized ? "select ROW__ID, p, a, b from T order by p, ROW__ID" : "select ROW__ID, p, a, b, INPUT__FILE__NAME from T order by p, ROW__ID";
    String[][] expected = new String[][] { { "{\"writeid\":1,\"bucketid\":536870912,\"rowid\":0}\t0\t0\t2", "warehouse/t/p=0/delta_0000001_0000001_0000/000000_0" }, { "{\"writeid\":1,\"bucketid\":536870912,\"rowid\":1}\t0\t0\t4", "warehouse/t/p=0/delta_0000001_0000001_0000/000000_0" }, { "{\"writeid\":1,\"bucketid\":536870912,\"rowid\":0}\t1\t0\t2", "warehouse/t/p=1/delta_0000001_0000001_0000/000000_0" }, { "{\"writeid\":1,\"bucketid\":536870912,\"rowid\":1}\t1\t0\t4", "warehouse/t/p=1/delta_0000001_0000001_0000/000000_0" } };
    checkResult(expected, testQuery, isVectorized, "add 2 parts w/data and 1 empty", LOG);
    runStatementOnDriver("export table Tstage to '" + getWarehouseDir() + "/3'");
    // should be an error since p=3 exists
    CommandProcessorException e = runStatementOnDriverNegative("ALTER TABLE T ADD PARTITION (p=0) location '" + getWarehouseDir() + "/3/data'");
    Assert.assertTrue("add existing partition", e.getMessage() != null && e.getMessage().contains("Partition already exists"));
    // should be no-op since p=3 exists
    String stmt = "ALTER TABLE T ADD IF NOT EXISTS " + "PARTITION (p=0) location '" + getWarehouseDir() + // p=0 exists and is not empty
    "/3/data' " + "PARTITION (p=2) location '" + getWarehouseDir() + // p=2 exists and is empty
    "/3/data'" + "PARTITION (p=3) location '" + getWarehouseDir() + // p=3 doesn't exist
    "/3/data'";
    runStatementOnDriver(stmt);
    String[][] expected2 = new String[][] { { "{\"writeid\":1,\"bucketid\":536870912,\"rowid\":0}\t0\t0\t2", "warehouse/t/p=0/delta_0000001_0000001_0000/000000_0" }, { "{\"writeid\":1,\"bucketid\":536870912,\"rowid\":1}\t0\t0\t4", "warehouse/t/p=0/delta_0000001_0000001_0000/000000_0" }, { "{\"writeid\":1,\"bucketid\":536870912,\"rowid\":0}\t1\t0\t2", "warehouse/t/p=1/delta_0000001_0000001_0000/000000_0" }, { "{\"writeid\":1,\"bucketid\":536870912,\"rowid\":1}\t1\t0\t4", "warehouse/t/p=1/delta_0000001_0000001_0000/000000_0" }, { "{\"writeid\":3,\"bucketid\":536870912,\"rowid\":0}\t3\t0\t2", "warehouse/t/p=3/delta_0000003_0000003_0000/000000_0" }, { "{\"writeid\":3,\"bucketid\":536870912,\"rowid\":1}\t3\t0\t4", "warehouse/t/p=3/delta_0000003_0000003_0000/000000_0" } };
    checkResult(expected2, testQuery, isVectorized, "add 2 existing parts and 1 empty", LOG);
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException)

Example 37 with CommandProcessorException

use of org.apache.hadoop.hive.ql.processors.CommandProcessorException in project hive by apache.

the class TestTxnCommands method testMergeNegative2.

@Test
public void testMergeNegative2() throws Exception {
    CommandProcessorException e = runStatementOnDriverNegative("MERGE INTO " + Table.ACIDTBL + " target USING " + Table.NONACIDORCTBL + "\n source ON target.pk = source.pk " + "\nWHEN MATCHED THEN UPDATE set b = 1 " + "\nWHEN MATCHED THEN UPDATE set b=a");
    Assert.assertEquals(ErrorMsg.MERGE_TOO_MANY_UPDATE, ((HiveException) e.getCause()).getCanonicalErrorMsg());
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) Test(org.junit.Test)

Example 38 with CommandProcessorException

use of org.apache.hadoop.hive.ql.processors.CommandProcessorException in project hive by apache.

the class TestTxnNoBuckets method testCtasBucketed.

/**
 * Currently CTAS doesn't support bucketed tables.  Correspondingly Acid only supports CTAS for
 * unbucketed tables.  This test is here to make sure that if CTAS is made to support unbucketed
 * tables, that it raises a red flag for Acid.
 */
@Test
public void testCtasBucketed() throws Exception {
    runStatementOnDriver("insert into " + Table.NONACIDNONBUCKET + "(a,b) values(1,2),(1,3)");
    CommandProcessorException e = runStatementOnDriverNegative("create table myctas " + "clustered by (a) into 2 buckets stored as ORC TBLPROPERTIES ('transactional'='true') as " + "select a, b from " + Table.NONACIDORCTBL);
    // this code doesn't propagate
    ErrorMsg.CTAS_PARCOL_COEXISTENCE.getErrorCode();
    // Assert.assertEquals("Wrong msg", ErrorMsg.CTAS_PARCOL_COEXISTENCE.getErrorCode(), cpr.getErrorCode());
    Assert.assertTrue(e.getMessage().contains("CREATE-TABLE-AS-SELECT does not support"));
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) Test(org.junit.Test)

Example 39 with CommandProcessorException

use of org.apache.hadoop.hive.ql.processors.CommandProcessorException in project hive by apache.

the class TestTxnNoBuckets method testInsertOverwriteToAcidWithUnionRemove.

@Test
public void testInsertOverwriteToAcidWithUnionRemove() throws Exception {
    hiveConf.setBoolVar(HiveConf.ConfVars.HIVE_OPTIMIZE_UNION_REMOVE, true);
    hiveConf.setVar(HiveConf.ConfVars.HIVEFETCHTASKCONVERSION, "none");
    d.close();
    d = new Driver(hiveConf);
    int[][] values = { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 }, { 9, 10 } };
    runStatementOnDriver("drop table if exists T");
    runStatementOnDriver("create table T (a int, b int) stored as ORC  TBLPROPERTIES ('transactional'='true')");
    CommandProcessorException e = runStatementOnDriverNegative("insert overwrite table T select a, b from " + TxnCommandsBaseForTests.Table.ACIDTBL + " where a between 1 and 3 group by a, b union all select a, b from " + TxnCommandsBaseForTests.Table.ACIDTBL + " where a between 5 and 7 union all select a, b from " + TxnCommandsBaseForTests.Table.ACIDTBL + " where a >= 9");
    Assert.assertTrue("", e.getMessage().contains("not supported due to OVERWRITE and UNION ALL"));
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) Test(org.junit.Test)

Example 40 with CommandProcessorException

use of org.apache.hadoop.hive.ql.processors.CommandProcessorException in project hive by apache.

the class TestTxnLoadData method testLoadAcidFile.

@Test
public void testLoadAcidFile() throws Exception {
    MetastoreConf.setBoolVar(hiveConf, MetastoreConf.ConfVars.CREATE_TABLES_AS_ACID, true);
    runStatementOnDriver("drop table if exists T");
    runStatementOnDriver("drop table if exists T2");
    runStatementOnDriver("create table T (a int, b int) stored as orc");
    // This is just a simple way to generate test data
    runStatementOnDriver("create table T2(a int, b int) stored as orc");
    runStatementOnDriver("insert into T values(1,2)");
    List<String> rs = runStatementOnDriver("select INPUT__FILE__NAME from T");
    Assert.assertEquals(1, rs.size());
    Assert.assertTrue("Unexpcted file name", rs.get(0).endsWith("t/delta_0000001_0000001_0000/bucket_00000_0"));
    // T2 is an acid table so this should fail
    CommandProcessorException e = runStatementOnDriverNegative("load data local inpath '" + rs.get(0) + "' into table T2");
    Assert.assertEquals("Unexpected error code", ErrorMsg.LOAD_DATA_ACID_FILE.getErrorCode(), e.getErrorCode());
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) Test(org.junit.Test)

Aggregations

CommandProcessorException (org.apache.hadoop.hive.ql.processors.CommandProcessorException)85 Test (org.junit.Test)42 IOException (java.io.IOException)14 CommandProcessorResponse (org.apache.hadoop.hive.ql.processors.CommandProcessorResponse)14 Driver (org.apache.hadoop.hive.ql.Driver)12 ArrayList (java.util.ArrayList)10 HiveConf (org.apache.hadoop.hive.conf.HiveConf)10 QTestProcessExecResult (org.apache.hadoop.hive.ql.QTestProcessExecResult)9 Path (org.apache.hadoop.fs.Path)8 FileSystem (org.apache.hadoop.fs.FileSystem)7 CliSessionState (org.apache.hadoop.hive.cli.CliSessionState)6 File (java.io.File)5 IDriver (org.apache.hadoop.hive.ql.IDriver)5 FileNotFoundException (java.io.FileNotFoundException)4 LockException (org.apache.hadoop.hive.ql.lockmgr.LockException)4 HiveException (org.apache.hadoop.hive.ql.metadata.HiveException)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Map (java.util.Map)3 Nullable (javax.annotation.Nullable)3 Database (org.apache.hadoop.hive.metastore.api.Database)3