use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.
the class TestDbTxnManager2 method testWriteSetTracking8.
/**
* Concurrent updates with partition pruning predicate and w/o one
*/
@Test
public void testWriteSetTracking8() throws Exception {
dropTable(new String[] { "tab1", "TAB1" });
CommandProcessorResponse cpr = driver.run("create table if not exists tab1 (a int, b int) partitioned by (p string) " + "clustered by (a) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true')");
checkCmdOnDriver(cpr);
checkCmdOnDriver(driver.run("insert into tab1 partition(p)(a,b,p) values(1,1,'one'),(2,2,'two')"));
HiveTxnManager txnMgr2 = TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
swapTxnManager(txnMgr2);
checkCmdOnDriver(driver.compileAndRespond("update tab1 set b = 7 where b=1"));
long idTxnUpdate1 = txnMgr2.getCurrentTxnId();
txnMgr2.acquireLocks(driver.getPlan(), ctx, "T2");
List<ShowLocksResponseElement> locks = getLocks(txnMgr2);
Assert.assertEquals("Unexpected lock count", 2, locks.size());
checkLock(LockType.SHARED_WRITE, LockState.ACQUIRED, "default", "TAB1", "p=two", locks);
checkLock(LockType.SHARED_WRITE, LockState.ACQUIRED, "default", "TAB1", "p=one", locks);
// now start concurrent txn
swapTxnManager(txnMgr);
checkCmdOnDriver(driver.compileAndRespond("update tab1 set b = 7 where p='two'"));
long idTxnUpdate2 = txnMgr.getCurrentTxnId();
((DbTxnManager) txnMgr).acquireLocks(driver.getPlan(), ctx, "T3", false);
locks = getLocks(txnMgr);
Assert.assertEquals("Unexpected lock count", 3, locks.size());
checkLock(LockType.SHARED_WRITE, LockState.ACQUIRED, "default", "TAB1", "p=two", locks);
checkLock(LockType.SHARED_WRITE, LockState.ACQUIRED, "default", "TAB1", "p=one", locks);
checkLock(LockType.SHARED_WRITE, LockState.WAITING, "default", "TAB1", "p=two", locks);
// this simulates the completion of txnid:idTxnUpdate1
long writeId = txnMgr2.getTableWriteId("default", "tab1");
AddDynamicPartitions adp = new AddDynamicPartitions(txnMgr2.getCurrentTxnId(), writeId, "default", "tab1", Collections.singletonList("p=one"));
adp.setOperationType(DataOperationType.UPDATE);
txnHandler.addDynamicPartitions(adp);
// txnid:idTxnUpdate1
txnMgr2.commitTxn();
// retest WAITING locks (both have same ext id)
((DbLockManager) txnMgr.getLockManager()).checkLock(locks.get(2).getLockid());
locks = getLocks(txnMgr);
Assert.assertEquals("Unexpected lock count", 1, locks.size());
checkLock(LockType.SHARED_WRITE, LockState.ACQUIRED, "default", "TAB1", "p=two", locks);
// completion of txnid:idTxnUpdate2
writeId = txnMgr.getTableWriteId("default", "tab1");
adp = new AddDynamicPartitions(txnMgr.getCurrentTxnId(), writeId, "default", "tab1", Collections.singletonList("p=two"));
adp.setOperationType(DataOperationType.UPDATE);
txnHandler.addDynamicPartitions(adp);
// txnid:idTxnUpdate2
txnMgr.commitTxn();
Assert.assertEquals("WRITE_SET mismatch: " + TxnDbUtil.queryToString(conf, "select * from WRITE_SET"), 1, TxnDbUtil.countQueryAgent(conf, "select count(*) from WRITE_SET where ws_partition='p=one' and ws_operation_type='u' and ws_table='tab1'"));
Assert.assertEquals("WRITE_SET mismatch: " + TxnDbUtil.queryToString(conf, "select * from WRITE_SET"), 1, TxnDbUtil.countQueryAgent(conf, "select count(*) from WRITE_SET where ws_partition='p=two' and ws_operation_type='u' and ws_table='tab1'"));
Assert.assertEquals("COMPLETED_TXN_COMPONENTS mismatch: " + TxnDbUtil.queryToString(conf, "select * from COMPLETED_TXN_COMPONENTS"), 4, TxnDbUtil.countQueryAgent(conf, "select count(*) from COMPLETED_TXN_COMPONENTS where ctc_table='tab1' and ctc_partition is not null"));
}
use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.
the class TestDbTxnManager2 method testWriteSetTracking1.
/**
* txns update same resource but do not overlap in time - no conflict
*/
@Test
public void testWriteSetTracking1() throws Exception {
dropTable(new String[] { "TAB_PART" });
CommandProcessorResponse cpr = driver.run("create table if not exists TAB_PART (a int, b int) " + "partitioned by (p string) clustered by (a) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true')");
checkCmdOnDriver(cpr);
checkCmdOnDriver(driver.compileAndRespond("select * from TAB_PART"));
txnMgr.acquireLocks(driver.getPlan(), ctx, "Nicholas");
txnMgr.commitTxn();
HiveTxnManager txnMgr2 = TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
swapTxnManager(txnMgr2);
checkCmdOnDriver(driver.compileAndRespond("update TAB_PART set b = 7 where p = 'blah'"));
checkCmdOnDriver(driver.compileAndRespond("update TAB_PART set b = 7 where p = 'blah'"));
txnMgr2.acquireLocks(driver.getPlan(), ctx, "Alexandra");
txnMgr2.commitTxn();
}
use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.
the class TestDbTxnManager2 method testShowLocksFilterOptions.
@Test
public void testShowLocksFilterOptions() throws Exception {
CommandProcessorResponse cpr = driver.run("drop table if exists db1.t14");
checkCmdOnDriver(cpr);
// Note that db1 and db2 have a table with common name
cpr = driver.run("drop table if exists db2.t14");
checkCmdOnDriver(cpr);
cpr = driver.run("drop table if exists db2.t15");
checkCmdOnDriver(cpr);
cpr = driver.run("drop table if exists db2.t16");
checkCmdOnDriver(cpr);
cpr = driver.run("drop database if exists db1");
checkCmdOnDriver(cpr);
cpr = driver.run("drop database if exists db2");
checkCmdOnDriver(cpr);
cpr = driver.run("create database if not exists db1");
checkCmdOnDriver(cpr);
cpr = driver.run("create database if not exists db2");
checkCmdOnDriver(cpr);
cpr = driver.run("create table if not exists db1.t14 (a int, b int) partitioned by (ds string) clustered by (b) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true')");
checkCmdOnDriver(cpr);
cpr = driver.run("create table if not exists db2.t14 (a int, b int) clustered by (b) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true')");
checkCmdOnDriver(cpr);
cpr = driver.run("create table if not exists db2.t15 (a int, b int) clustered by (b) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true')");
checkCmdOnDriver(cpr);
cpr = driver.run("create table if not exists db2.t16 (a int, b int) clustered by (b) into 2 buckets stored as orc TBLPROPERTIES ('transactional'='true')");
checkCmdOnDriver(cpr);
// Acquire different locks at different levels
HiveTxnManager txnMgr1 = TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
swapTxnManager(txnMgr1);
cpr = driver.compileAndRespond("insert into table db1.t14 partition (ds='today') values (1, 2)");
checkCmdOnDriver(cpr);
txnMgr1.acquireLocks(driver.getPlan(), ctx, "Tom");
HiveTxnManager txnMgr2 = TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
swapTxnManager(txnMgr2);
cpr = driver.compileAndRespond("insert into table db1.t14 partition (ds='tomorrow') values (3, 4)");
checkCmdOnDriver(cpr);
txnMgr2.acquireLocks(driver.getPlan(), ctx, "Jerry");
HiveTxnManager txnMgr3 = TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
swapTxnManager(txnMgr3);
cpr = driver.compileAndRespond("select * from db2.t15");
checkCmdOnDriver(cpr);
txnMgr3.acquireLocks(driver.getPlan(), ctx, "Donald");
HiveTxnManager txnMgr4 = TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
swapTxnManager(txnMgr4);
cpr = driver.compileAndRespond("select * from db2.t16");
checkCmdOnDriver(cpr);
txnMgr4.acquireLocks(driver.getPlan(), ctx, "Hillary");
HiveTxnManager txnMgr5 = TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
swapTxnManager(txnMgr5);
cpr = driver.compileAndRespond("select * from db2.t14");
checkCmdOnDriver(cpr);
txnMgr5.acquireLocks(driver.getPlan(), ctx, "Obama");
// Simulate SHOW LOCKS with different filter options
// SHOW LOCKS (no filter)
List<ShowLocksResponseElement> locks = getLocks();
Assert.assertEquals("Unexpected lock count", 7, locks.size());
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db1", "t14", "ds=today", locks);
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db1", "t14", "ds=tomorrow", locks);
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db2", "t15", null, locks);
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db2", "t16", null, locks);
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db2", "t14", null, locks);
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "_dummy_database", "_dummy_table", null, locks);
// SHOW LOCKS db2
locks = getLocksWithFilterOptions(txnMgr3, "db2", null, null);
Assert.assertEquals("Unexpected lock count", 3, locks.size());
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db2", "t15", null, locks);
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db2", "t16", null, locks);
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db2", "t14", null, locks);
// SHOW LOCKS t14
swapTxnManager(txnMgr);
cpr = driver.run("use db1");
checkCmdOnDriver(cpr);
locks = getLocksWithFilterOptions(txnMgr, null, "t14", null);
Assert.assertEquals("Unexpected lock count", 2, locks.size());
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db1", "t14", "ds=today", locks);
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db1", "t14", "ds=tomorrow", locks);
// Note that it shouldn't show t14 from db2
// SHOW LOCKS t14 PARTITION ds='today'
Map<String, String> partSpec = new HashMap<String, String>();
partSpec.put("ds", "today");
locks = getLocksWithFilterOptions(txnMgr, null, "t14", partSpec);
Assert.assertEquals("Unexpected lock count", 1, locks.size());
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db1", "t14", "ds=today", locks);
// SHOW LOCKS t15
cpr = driver.run("use db2");
checkCmdOnDriver(cpr);
locks = getLocksWithFilterOptions(txnMgr3, null, "t15", null);
Assert.assertEquals("Unexpected lock count", 1, locks.size());
checkLock(LockType.SHARED_READ, LockState.ACQUIRED, "db2", "t15", null, locks);
}
use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.
the class TestReOptimization method getMapperForQuery.
private PlanMapper getMapperForQuery(IDriver driver, String query) throws CommandProcessorResponse {
CommandProcessorResponse res = driver.run(query);
if (res.getResponseCode() != 0) {
throw res;
}
PlanMapper pm0 = driver.getContext().getPlanMapper();
return pm0;
}
use of org.apache.hadoop.hive.ql.processors.CommandProcessorResponse in project hive by apache.
the class GenericUDTFGetSplits method createPlanFragment.
public PlanFragment createPlanFragment(String query, int num) throws HiveException {
HiveConf conf = new HiveConf(SessionState.get().getConf());
HiveConf.setVar(conf, ConfVars.HIVEFETCHTASKCONVERSION, "none");
HiveConf.setVar(conf, ConfVars.HIVEQUERYRESULTFILEFORMAT, PlanUtils.LLAP_OUTPUT_FORMAT_KEY);
String originalMode = HiveConf.getVar(conf, ConfVars.HIVE_EXECUTION_MODE);
HiveConf.setVar(conf, ConfVars.HIVE_EXECUTION_MODE, "llap");
HiveConf.setBoolVar(conf, ConfVars.HIVE_TEZ_GENERATE_CONSISTENT_SPLITS, true);
HiveConf.setBoolVar(conf, ConfVars.LLAP_CLIENT_CONSISTENT_SPLITS, true);
conf.setBoolean(TezSplitGrouper.TEZ_GROUPING_NODE_LOCAL_ONLY, true);
// Tez/LLAP requires RPC query plan
HiveConf.setBoolVar(conf, ConfVars.HIVE_RPC_QUERY_PLAN, true);
try {
jc = DagUtils.getInstance().createConfiguration(conf);
} catch (IOException e) {
throw new HiveException(e);
}
Driver driver = new Driver(conf);
try {
CommandProcessorResponse cpr = driver.compileAndRespond(query);
if (cpr.getResponseCode() != 0) {
throw new HiveException("Failed to compile query: " + cpr.getException());
}
QueryPlan plan = driver.getPlan();
List<Task<?>> roots = plan.getRootTasks();
Schema schema = convertSchema(plan.getResultSchema());
if (roots == null || roots.size() != 1 || !(roots.get(0) instanceof TezTask)) {
throw new HiveException("Was expecting a single TezTask.");
}
TezWork tezWork = ((TezTask) roots.get(0)).getWork();
if (tezWork.getAllWork().size() != 1) {
String tableName = "table_" + UUID.randomUUID().toString().replaceAll("[^A-Za-z0-9 ]", "");
String ctas = "create temporary table " + tableName + " as " + query;
LOG.info("Materializing the query for LLAPIF; CTAS: " + ctas);
try {
driver.resetQueryState();
HiveConf.setVar(conf, ConfVars.HIVE_EXECUTION_MODE, originalMode);
cpr = driver.run(ctas, false);
} catch (CommandNeedRetryException e) {
throw new HiveException(e);
}
if (cpr.getResponseCode() != 0) {
throw new HiveException("Failed to create temp table: " + cpr.getException());
}
HiveConf.setVar(conf, ConfVars.HIVE_EXECUTION_MODE, "llap");
query = "select * from " + tableName;
cpr = driver.compileAndRespond(query);
if (cpr.getResponseCode() != 0) {
throw new HiveException("Failed to create temp table: " + cpr.getException());
}
plan = driver.getPlan();
roots = plan.getRootTasks();
schema = convertSchema(plan.getResultSchema());
if (roots == null || roots.size() != 1 || !(roots.get(0) instanceof TezTask)) {
throw new HiveException("Was expecting a single TezTask.");
}
tezWork = ((TezTask) roots.get(0)).getWork();
}
return new PlanFragment(tezWork, schema, jc);
} finally {
driver.close();
driver.destroy();
}
}
Aggregations