/** * Given an error code, returns the ErrorMsg object associated with it. * @param errorCode An error code * @return ErrorMsg */ public static ErrorMsg getErrorMsg(int errorCode) { for (ErrorMsg errorMsg : values()) { if (errorMsg.getErrorCode() == errorCode) { return errorMsg; } } return null; }
/** * Given an error code, returns the ErrorMsg object associated with it. * @param errorCode An error code * @return ErrorMsg */ public static ErrorMsg getErrorMsg(int errorCode) { for (ErrorMsg errorMsg : values()) { if (errorMsg.getErrorCode() == errorCode) { return errorMsg; } } return null; }
public CommandProcessorResponse(int responseCode, ErrorMsg canonicalErrMsg, Throwable t, String ... msgArgs) { this(responseCode, canonicalErrMsg.format(msgArgs), canonicalErrMsg.getSQLState(), null, t, canonicalErrMsg.getErrorCode(), null); }
public CommandProcessorResponse(int responseCode, ErrorMsg canonicalErrMsg, Throwable t, String ... msgArgs) { this(responseCode, canonicalErrMsg.format(msgArgs), canonicalErrMsg.getSQLState(), null, t, canonicalErrMsg.getErrorCode(), null); }
private void testReverseMatch(ErrorMsg errorMsg, String... args) { String parametrizedMsg = errorMsg.format(args); ErrorMsg canonicalMsg = ErrorMsg.getErrorMsg(parametrizedMsg); Assert.assertEquals("Didn't find expected msg", errorMsg.getErrorCode(), canonicalMsg.getErrorCode()); } }
private void verifyThatTimedOutCompileOpsCountIsNotZero(List<CommandProcessorResponse> responseList) { verifyErrorCount(ErrorMsg.COMPILE_LOCK_TIMED_OUT.getErrorCode(), is(not(equalTo(0))), responseList); }
private void verifyThatTimedOutCompileOpsCountIsZero(List<CommandProcessorResponse> responseList) { verifyErrorCount(ErrorMsg.COMPILE_LOCK_TIMED_OUT.getErrorCode(), is(equalTo(0)), responseList); }
private void verifyThatTimedOutCompileOpsCount(List<CommandProcessorResponse> responseList, int count) { verifyErrorCount(ErrorMsg.COMPILE_LOCK_TIMED_OUT.getErrorCode(), is(equalTo(count)), responseList); }
@Test public void testUniqueErrorCode() { Set<Integer> numbers = new HashSet<Integer>(); for (ErrorMsg err : ErrorMsg.values()) { int code = err.getErrorCode(); Assert.assertTrue("duplicated error number " + code, numbers.add(code)); } } @Test
@Override protected int execute(DriverContext driverContext) { try { Hive hiveDb = getHive(); Path dumpRoot = new Path(conf.getVar(HiveConf.ConfVars.REPLDIR), getNextDumpDir()); DumpMetaData dmd = new DumpMetaData(dumpRoot, conf); Path cmRoot = new Path(conf.getVar(HiveConf.ConfVars.REPLCMDIR)); Long lastReplId; if (work.isBootStrapDump()) { lastReplId = bootStrapDump(dumpRoot, dmd, cmRoot, hiveDb); } else { lastReplId = incrementalDump(dumpRoot, dmd, cmRoot, hiveDb); } prepareReturnValues(Arrays.asList(dumpRoot.toUri().toString(), String.valueOf(lastReplId))); } catch (Exception e) { LOG.error("failed", e); setException(e); return ErrorMsg.getErrorMsg(e.getMessage()).getErrorCode(); } return 0; }
private String singleTable(String json, String table) throws IOException { Map obj = JsonBuilder.jsonToMap(json); if (JsonBuilder.isError(obj)) return json; List tables = (List) obj.get("tables"); if (TempletonUtils.isset(tables)) return JsonBuilder.mapToJson(tables.get(0)); else { return JsonBuilder .createError(ErrorMsg.INVALID_TABLE.format(table), ErrorMsg.INVALID_TABLE.getErrorCode()). buildJson(); } }
private CommandProcessorResponse createProcessorResponse(int ret) { SessionState.getPerfLogger().cleanupPerfLogMetrics(); queryDisplay.setErrorMessage(errorMessage); if(downstreamError != null && downstreamError instanceof HiveException) { ErrorMsg em = ((HiveException)downstreamError).getCanonicalErrorMsg(); if(em != null) { return new CommandProcessorResponse(ret, errorMessage, SQLState, schema, downstreamError, em.getErrorCode(), null); } } return new CommandProcessorResponse(ret, errorMessage, SQLState, downstreamError); }
@Test public void testUsNonExistentDB() throws Exception { CommandProcessorResponse resp = hcatDriver.run("use no_such_db"); assertEquals(ErrorMsg.DATABASE_NOT_EXISTS.getErrorCode(), resp.getResponseCode()); }
put("error", "Partition already exists") .put("errorCode", ErrorMsg.PARTITION_EXISTS.getErrorCode()) .put("database", db) .put("table", table)
/** * 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)"); CommandProcessorResponse cpr = runStatementOnDriverNegative("create table myctas " + "clustered by (a) into 2 buckets stored as ORC TBLPROPERTIES ('transactional'='true') as " + "select a, b from " + Table.NONACIDORCTBL); int j = ErrorMsg.CTAS_PARCOL_COEXISTENCE.getErrorCode(); //this code doesn't propagate // Assert.assertEquals("Wrong msg", ErrorMsg.CTAS_PARCOL_COEXISTENCE.getErrorCode(), cpr.getErrorCode()); Assert.assertTrue(cpr.getErrorMessage().contains("CREATE-TABLE-AS-SELECT does not support")); } /**
/** * 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)"); CommandProcessorResponse cpr = runStatementOnDriverNegative("create table myctas partitioned " + "by (b int) stored as " + "ORC TBLPROPERTIES ('transactional'='true') as select a, b from " + Table.NONACIDORCTBL); int j = ErrorMsg.CTAS_PARCOL_COEXISTENCE.getErrorCode();//this code doesn't propagate Assert.assertTrue(cpr.getErrorMessage().contains("CREATE-TABLE-AS-SELECT does not support " + "partitioning in the target table")); } /**
@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")); //T2 is an acid table so this should fail CommandProcessorResponse cpr = runStatementOnDriverNegative( "load data local inpath '" + rs.get(0) + "' into table T2"); Assert.assertEquals("Unexpected error code", ErrorMsg.LOAD_DATA_ACID_FILE.getErrorCode(), cpr.getErrorCode()); } }
runStatementOnDriver("start transaction"); CommandProcessorResponse cpr2 = runStatementOnDriverNegative("create table foo(x int, y int)"); Assert.assertEquals("Expected DDL to fail in an open txn", ErrorMsg.OP_NOT_ALLOWED_IN_TXN.getErrorCode(), cpr2.getErrorCode()); CommandProcessorResponse cpr3 = runStatementOnDriverNegative("update " + Table.ACIDTBL + " set a = 1 where b != 1"); Assert.assertEquals("Expected update of bucket column to fail", cpr3.getErrorMessage()); Assert.assertEquals("Expected update of bucket column to fail", ErrorMsg.UPDATE_CANNOT_UPDATE_BUCKET_VALUE.getErrorCode(), cpr3.getErrorCode()); cpr3 = runStatementOnDriverNegative("commit");//not allowed in w/o tx Assert.assertEquals("Error didn't match: " + cpr3, ErrorMsg.OP_NOT_ALLOWED_WITHOUT_TXN.getErrorCode(), cpr3.getErrorCode()); cpr3 = runStatementOnDriverNegative("rollback");//not allowed in w/o tx Assert.assertEquals("Error didn't match: " + cpr3, ErrorMsg.OP_NOT_ALLOWED_WITHOUT_TXN.getErrorCode(), cpr3.getErrorCode()); runStatementOnDriver("start transaction"); cpr3 = runStatementOnDriverNegative("start transaction");//not allowed in a tx Assert.assertEquals("Expected start transaction to fail", ErrorMsg.OP_NOT_ALLOWED_IN_TXN.getErrorCode(), cpr3.getErrorCode()); runStatementOnDriver("start transaction");//ok since previously opened txn was killed runStatementOnDriver("insert into " + Table.ACIDTBL + "(a,b) values(1,2)");
@Test public void testDummyTxnManagerOnAcidTable() throws Exception { dropTable(new String[] {"T10", "T11"}); // Create an ACID table with DbTxnManager CommandProcessorResponse cpr = driver.run("create table T10 (a int, b int) clustered by(b) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true')"); checkCmdOnDriver(cpr); cpr = driver.run("create table T11 (a int, b int) clustered by(b) into 2 buckets stored as orc"); checkCmdOnDriver(cpr); // All DML should fail with DummyTxnManager on ACID table useDummyTxnManagerTemporarily(conf); cpr = driver.compileAndRespond("select * from T10", true); Assert.assertEquals(ErrorMsg.TXNMGR_NOT_ACID.getErrorCode(), cpr.getResponseCode()); Assert.assertTrue(cpr.getErrorMessage().contains("This command is not allowed on an ACID table")); useDummyTxnManagerTemporarily(conf); cpr = driver.compileAndRespond("insert into table T10 values (1, 2)", true); Assert.assertEquals(ErrorMsg.TXNMGR_NOT_ACID.getErrorCode(), cpr.getResponseCode()); Assert.assertTrue(cpr.getErrorMessage().contains("This command is not allowed on an ACID table")); useDummyTxnManagerTemporarily(conf); cpr = driver.compileAndRespond("update T10 set a=0 where b=1", true); Assert.assertEquals(ErrorMsg.ACID_OP_ON_NONACID_TXNMGR.getErrorCode(), cpr.getResponseCode()); Assert.assertTrue(cpr.getErrorMessage().contains("Attempt to do update or delete using transaction manager that does not support these operations.")); useDummyTxnManagerTemporarily(conf); cpr = driver.compileAndRespond("delete from T10", true); Assert.assertEquals(ErrorMsg.ACID_OP_ON_NONACID_TXNMGR.getErrorCode(), cpr.getResponseCode()); Assert.assertTrue(cpr.getErrorMessage().contains("Attempt to do update or delete using transaction manager that does not support these operations.")); conf.setVar(HiveConf.ConfVars.HIVE_TXN_MANAGER, "org.apache.hadoop.hive.ql.lockmgr.DbTxnManager"); }
@Test public void testSimpleAcidInsert() throws Exception { int[][] rows1 = {{1,2},{3,4}}; runStatementOnDriver("insert into " + Table.ACIDTBL + "(a,b) " + makeValuesClause(rows1)); //List<String> rs = runStatementOnDriver("select a,b from " + Table.ACIDTBL + " order by a,b"); //Assert.assertEquals("Data didn't match in autocommit=true (rs)", stringifyValues(rows1), rs); runStatementOnDriver("START TRANSACTION"); int[][] rows2 = {{5,6},{7,8}}; runStatementOnDriver("insert into " + Table.ACIDTBL + "(a,b) " + makeValuesClause(rows2)); List<String> allData = stringifyValues(rows1); allData.addAll(stringifyValues(rows2)); List<String> rs0 = runStatementOnDriver("select a,b from " + Table.ACIDTBL + " order by a,b"); Assert.assertEquals("Data didn't match inside tx (rs0)", allData, rs0); runStatementOnDriver("COMMIT WORK"); dumpTableData(Table.ACIDTBL, 1, 0); dumpTableData(Table.ACIDTBL, 2, 0); runStatementOnDriver("select a,b from " + Table.ACIDTBL + " order by a,b"); CommandProcessorResponse cpr = runStatementOnDriverNegative("COMMIT");//txn started implicitly by previous statement Assert.assertEquals("Error didn't match: " + cpr, ErrorMsg.OP_NOT_ALLOWED_WITHOUT_TXN.getErrorCode(), cpr.getErrorCode()); List<String> rs1 = runStatementOnDriver("select a,b from " + Table.ACIDTBL + " order by a,b"); Assert.assertEquals("Data didn't match inside tx (rs0)", allData, rs1); }