use of org.apache.hadoop.hive.ql.exec.FetchTask in project hive by apache.
the class SimpleFetchOptimizer method transform.
@Override
public ParseContext transform(ParseContext pctx) throws SemanticException {
Map<String, TableScanOperator> topOps = pctx.getTopOps();
if (pctx.getQueryProperties().isQuery() && !pctx.getQueryProperties().isAnalyzeCommand() && topOps.size() == 1) {
// no join, no groupby, no distinct, no lateral view, no subq,
// no CTAS or insert, not analyze command, and single sourced.
String alias = (String) pctx.getTopOps().keySet().toArray()[0];
TableScanOperator topOp = pctx.getTopOps().values().iterator().next();
try {
FetchTask fetchTask = optimize(pctx, alias, topOp);
if (fetchTask != null) {
pctx.setFetchTask(fetchTask);
}
} catch (Exception e) {
LOG.error("Failed to transform", e);
if (e instanceof SemanticException) {
throw (SemanticException) e;
}
throw new SemanticException(e.getMessage(), e);
}
}
return pctx;
}
use of org.apache.hadoop.hive.ql.exec.FetchTask in project hive by apache.
the class TestDbTxnManagerIsolationProperties method gapOpenTxnsDirtyRead.
@Test
public void gapOpenTxnsDirtyRead() throws Exception {
driver.run(("drop table if exists gap"));
driver.run("create table gap (a int, b int) " + "stored as orc TBLPROPERTIES ('transactional'='true')");
// Create one TXN to delete later
driver.compileAndRespond("select * from gap");
long first = txnMgr.getCurrentTxnId();
driver.run();
// The second one we use for Low water mark
driver.run("select * from gap");
DbTxnManager txnMgr2 = (DbTxnManager) TxnManagerFactory.getTxnManagerFactory().getTxnManager(conf);
swapTxnManager(txnMgr2);
// Now we wait for the time window to move forward
Thread.sleep(txnHandler.getOpenTxnTimeOutMillis());
// Create a gap
deleteTransactionId(first);
CommandProcessorResponse resp = driver2.compileAndRespond("select * from gap");
long third = txnMgr2.getCurrentTxnId();
Assert.assertTrue("Sequence number goes onward", third > first);
ValidTxnList validTxns = txnMgr2.getValidTxns();
Assert.assertNull("Expect to see no gap", validTxns.getMinOpenTxn());
// Now we cheat and create a transaction with the first sequenceId again imitating a very slow openTxns call
// This should never happen
setBackSequence(first);
swapTxnManager(txnMgr);
driver.compileAndRespond("insert into gap values(1,2)");
long forth = txnMgr.getCurrentTxnId();
Assert.assertEquals(first, forth);
driver.run();
// Now we run our read query it should unfortunately see the results of the insert
swapTxnManager(txnMgr2);
driver2.run();
FetchTask fetchTask = driver2.getFetchTask();
List res = new ArrayList();
fetchTask.fetch(res);
Assert.assertEquals("Dirty read!", 1, res.size());
}
Aggregations