diff --git a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java index 8aaf5467fe..8ea68c8a61 100644 --- a/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java +++ b/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java @@ -2647,6 +2647,10 @@ private static void populateLlapDaemonVarsSet(Set llapDaemonVarsSetLocal "are not hidden by the INSERT OVERWRITE."), HIVE_TXN_STATS_ENABLED("hive.txn.stats.enabled", true, "Whether Hive supports transactional stats (accurate stats for transactional tables)"), + + HIVE_TXN_READONLY_ENABLED("hive.txn.readonly.enabled", false, + "Enables read-only transaction classification and related optimizations"), + /** * @deprecated Use MetastoreConf.TXN_TIMEOUT */ diff --git a/ql/src/java/org/apache/hadoop/hive/ql/Driver.java b/ql/src/java/org/apache/hadoop/hive/ql/Driver.java index b09cf32e58..f792b86370 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/Driver.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/Driver.java @@ -473,7 +473,7 @@ public void compile(String command, boolean resetTaskIds, boolean deferClose) th && queryState.getHiveOperation().equals(HiveOperation.REPLDUMP)) { setLastReplIdForDump(queryState.getConf()); } - queryTxnType = AcidUtils.getTxnType(tree); + queryTxnType = AcidUtils.getTxnType(conf, tree); openTransaction(queryTxnType); generateValidTxnList(); diff --git a/ql/src/java/org/apache/hadoop/hive/ql/io/AcidUtils.java b/ql/src/java/org/apache/hadoop/hive/ql/io/AcidUtils.java index 67996c6db9..f164363160 100644 --- a/ql/src/java/org/apache/hadoop/hive/ql/io/AcidUtils.java +++ b/ql/src/java/org/apache/hadoop/hive/ql/io/AcidUtils.java @@ -2992,10 +2992,11 @@ public static void validateAcidPartitionLocation(String location, Configuration * Determines transaction type based on query AST. * @param tree AST */ - public static TxnType getTxnType(ASTNode tree) { + public static TxnType getTxnType(Configuration conf, ASTNode tree) { final ASTSearcher astSearcher = new ASTSearcher(); - return (tree.getToken().getType() == HiveParser.TOK_QUERY && + return (HiveConf.getBoolVar(conf, ConfVars.HIVE_TXN_READONLY_ENABLED) && + tree.getToken().getType() == HiveParser.TOK_QUERY && Stream.of( new int[]{HiveParser.TOK_INSERT_INTO}, new int[]{HiveParser.TOK_INSERT, HiveParser.TOK_TAB}) diff --git a/ql/src/test/org/apache/hadoop/hive/ql/parse/TestParseUtils.java b/ql/src/test/org/apache/hadoop/hive/ql/parse/TestParseUtils.java index bf8a0284c3..e606713b13 100644 --- a/ql/src/test/org/apache/hadoop/hive/ql/parse/TestParseUtils.java +++ b/ql/src/test/org/apache/hadoop/hive/ql/parse/TestParseUtils.java @@ -18,6 +18,8 @@ package org.apache.hadoop.hive.ql.parse; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hive.conf.HiveConf; import org.apache.hadoop.hive.metastore.api.TxnType; import org.apache.hadoop.hive.ql.io.AcidUtils; @@ -38,10 +40,12 @@ private String query; private TxnType txnType; + private Configuration conf; public TestParseUtils(String query, TxnType txnType) { this.query = query; this.txnType = txnType; + this.conf = new HiveConf(); } @Parameters @@ -89,8 +93,18 @@ public TestParseUtils(String query, TxnType txnType) { } @Test - public void testTxnType() throws ParseException { - Assert.assertEquals( - AcidUtils.getTxnType(ParseUtils.parse(query)), txnType); + public void testTxnTypeWithEnabledReadOnlyFeature() throws ParseException { + enableReadOnlyTxnFeature(true); + Assert.assertEquals(AcidUtils.getTxnType(conf, ParseUtils.parse(query)), txnType); + } + + @Test + public void testTxnTypeWithDisabledReadOnlyFeature() throws ParseException { + enableReadOnlyTxnFeature(false); + Assert.assertEquals(AcidUtils.getTxnType(conf, ParseUtils.parse(query)), TxnType.DEFAULT); + } + + private void enableReadOnlyTxnFeature(boolean featureFlag) { + conf.setBoolean(HiveConf.ConfVars.HIVE_TXN_READONLY_ENABLED.varname, featureFlag); } }