Search in sources :

Example 56 with CommandProcessorException

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

the class TestTxnCommands method testBadOnClause.

@Test
public void testBadOnClause() throws Exception {
    CommandProcessorException e = runStatementOnDriverNegative("merge into " + Table.ACIDTBL + " trgt\n" + "using (select *\n" + "       from " + Table.NONACIDORCTBL + " src) sub on sub.a = target.a\n" + "when not matched then insert values (sub.a,sub.b)");
    Assert.assertTrue("Error didn't match: " + e, e.getMessage().contains("No columns from target table 'trgt' found in ON clause '`sub`.`a` = `target`.`a`' of MERGE statement."));
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) Test(org.junit.Test)

Example 57 with CommandProcessorException

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

the class TestTxnCommands method testImplicitRollback.

@Test
public void testImplicitRollback() throws Exception {
    runStatementOnDriver("START TRANSACTION");
    runStatementOnDriver("insert into " + Table.ACIDTBL + "(a,b) values(1,2)");
    List<String> rs0 = runStatementOnDriver("select a,b from " + Table.ACIDTBL + " order by a,b");
    Assert.assertEquals("Can't see my own write", 1, rs0.size());
    // next command should produce an error
    CommandProcessorException e = runStatementOnDriverNegative("select * from no_such_table");
    Assert.assertEquals("Txn didn't fail?", "FAILED: SemanticException [Error 10001]: Line 1:14 Table not found 'no_such_table'", e.getMessage());
    runStatementOnDriver("start transaction");
    List<String> rs1 = runStatementOnDriver("select a,b from " + Table.ACIDTBL + " order by a,b");
    runStatementOnDriver("commit");
    Assert.assertEquals("Didn't rollback as expected", 0, rs1.size());
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) Test(org.junit.Test)

Example 58 with CommandProcessorException

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

the class TestTxnCommands method testSetClauseFakeColumn.

@Test
public void testSetClauseFakeColumn() throws Exception {
    CommandProcessorException e1 = runStatementOnDriverNegative("MERGE INTO " + Table.ACIDTBL + " target\n" + "USING " + Table.NONACIDORCTBL + "\n" + " source ON target.a = source.a\n" + "WHEN MATCHED THEN UPDATE set t = 1");
    Assert.assertEquals(ErrorMsg.INVALID_TARGET_COLUMN_IN_SET_CLAUSE, ((HiveException) e1.getCause()).getCanonicalErrorMsg());
    CommandProcessorException e2 = runStatementOnDriverNegative("update " + Table.ACIDTBL + " set t = 1");
    Assert.assertEquals(ErrorMsg.INVALID_TARGET_COLUMN_IN_SET_CLAUSE, ((HiveException) e2.getCause()).getCanonicalErrorMsg());
}
Also used : CommandProcessorException(org.apache.hadoop.hive.ql.processors.CommandProcessorException) Test(org.junit.Test)

Example 59 with CommandProcessorException

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

the class TestTxnAddPartition method addPartitionMM.

/**
 * Micro managed table test
 * 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 addPartitionMM(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', 'transactional_properties'='insert_only')");
    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 p, a, b from T order by p, a, b" : "select p, a, b, INPUT__FILE__NAME from T order by p, a, b";
    String[][] expected = new String[][] { { "0\t0\t2", "warehouse/t/p=0/delta_0000001_0000001_0000/000000_0" }, { "0\t0\t4", "warehouse/t/p=0/delta_0000001_0000001_0000/000000_0" }, { "1\t0\t2", "warehouse/t/p=1/delta_0000001_0000001_0000/000000_0" }, { "1\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
    runStatementOnDriver("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'");
    String[][] expected2 = new String[][] { { "0\t0\t2", "warehouse/t/p=0/delta_0000001_0000001_0000/000000_0" }, { "0\t0\t4", "warehouse/t/p=0/delta_0000001_0000001_0000/000000_0" }, { "1\t0\t2", "warehouse/t/p=1/delta_0000001_0000001_0000/000000_0" }, { "1\t0\t4", "warehouse/t/p=1/delta_0000001_0000001_0000/000000_0" }, { "3\t0\t2", "warehouse/t/p=3/delta_0000003_0000003_0000/000000_0" }, { "3\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 60 with CommandProcessorException

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

the class TestTxnNoBuckets method testCtasPartitioned.

/**
 * Currently CTAS doesn't support partitioned tables.  Correspondingly Acid only supports CTAS for
 * un-partitioned tables.  This test is here to make sure that if CTAS is made to support
 * un-partitioned tables, that it raises a red flag for Acid.
 */
@Test
public void testCtasPartitioned() throws Exception {
    runStatementOnDriver("insert into " + Table.NONACIDNONBUCKET + "(a,b) values(1,2),(1,3)");
    CommandProcessorException e = runStatementOnDriverNegative("create table myctas partitioned " + "by (b int) stored as " + "ORC TBLPROPERTIES ('transactional'='true') as select a, b from " + Table.NONACIDORCTBL);
    // this code doesn't propagate
    ErrorMsg.CTAS_PARCOL_COEXISTENCE.getErrorCode();
    Assert.assertTrue(e.getMessage().contains("CREATE-TABLE-AS-SELECT does not support " + "partitioning in the target table"));
}
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