hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kevinwilf...@apache.org
Subject svn commit: r1298936 - in /hive/trunk: common/src/java/org/apache/hadoop/hive/conf/ ql/src/java/org/apache/hadoop/hive/ql/parse/ ql/src/test/queries/clientnegative/ ql/src/test/results/clientnegative/
Date Fri, 09 Mar 2012 17:31:16 GMT
Author: kevinwilfong
Date: Fri Mar  9 17:31:16 2012
New Revision: 1298936

URL: http://svn.apache.org/viewvc?rev=1298936&view=rev
Log:
HIVE-2837. insert into external tables should not be allowed. (namit via kevinwilfong)

Added:
    hive/trunk/ql/src/test/queries/clientnegative/insertexternal1.q
    hive/trunk/ql/src/test/results/clientnegative/insertexternal1.q.out
Modified:
    hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java
    hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java

Modified: hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java
URL: http://svn.apache.org/viewvc/hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java?rev=1298936&r1=1298935&r2=1298936&view=diff
==============================================================================
--- hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java (original)
+++ hive/trunk/common/src/java/org/apache/hadoop/hive/conf/HiveConf.java Fri Mar  9 17:31:16
2012
@@ -572,6 +572,9 @@ public class HiveConf extends Configurat
     HIVE_DEFAULT_REGION_NAME("hive.default.region.name", ""),
     HIVE_REGION_PROPERTIES("hive.region.properties", ""),
 
+    // whether insert into external tables is allowed
+    HIVE_INSERT_INTO_EXTERNAL_TABLES("hive.insert.into.external.tables", true),
+
     ;
 
     public final String varname;

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java?rev=1298936&r1=1298935&r2=1298936&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/ErrorMsg.java Fri Mar  9 17:31:16
2012
@@ -119,6 +119,7 @@ public enum ErrorMsg {
       + "table"),
   CTAS_MULTI_LOADFILE("CREATE-TABLE-AS-SELECT results in multiple file load"),
   CTAS_EXTTBL_COEXISTENCE("CREATE-TABLE-AS-SELECT cannot create external table"),
+  INSERT_EXTERNAL_TABLE("Inserting into a external table is not allowed"),
   DATABASE_NOT_EXISTS("Database does not exist:"),
   TABLE_ALREADY_EXISTS("Table already exists:", "42S02"),
   COLUMN_ALIAS_ALREADY_EXISTS("Column alias already exists:", "42S02"),
@@ -170,10 +171,10 @@ public enum ErrorMsg {
   ARCHIVE_ON_TABLE("ARCHIVE can only be run on partitions"),
   RESERVED_PART_VAL("Partition value contains a reserved substring"),
   HOLD_DDLTIME_ON_NONEXIST_PARTITIONS("HOLD_DDLTIME hint cannot be applied to dynamic " +
-  		"partitions or non-existent partitions"),
+                                      "partitions or non-existent partitions"),
   OFFLINE_TABLE_OR_PARTITION("Query against an offline table or partition"),
   OUTERJOIN_USES_FILTERS("The query results could be wrong. " +
-  		"Turn on hive.outerjoin.supports.filters"),
+                         "Turn on hive.outerjoin.supports.filters"),
   NEED_PARTITION_SPECIFICATION("Table is partitioned and partition specification is needed"),
   INVALID_METADATA("The metadata file could not be parsed "),
   NEED_TABLE_SPECIFICATION("Table name could be determined; It should be specified "),

Modified: hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java?rev=1298936&r1=1298935&r2=1298936&view=diff
==============================================================================
--- hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java (original)
+++ hive/trunk/ql/src/java/org/apache/hadoop/hive/ql/parse/SemanticAnalyzer.java Fri Mar 
9 17:31:16 2012
@@ -172,6 +172,7 @@ import org.apache.hadoop.hive.serde2.typ
 import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoFactory;
 import org.apache.hadoop.hive.serde2.typeinfo.TypeInfoUtils;
 import org.apache.hadoop.mapred.InputFormat;
+import org.apache.hadoop.hive.metastore.TableType;
 
 /**
  * Implementation of the semantic analyzer.
@@ -3980,6 +3981,13 @@ public class SemanticAnalyzer extends Ba
 
       dest_tab = qbm.getDestTableForAlias(dest);
 
+      // Is the user trying to insert into a external tables
+      if ((!conf.getBoolVar(HiveConf.ConfVars.HIVE_INSERT_INTO_EXTERNAL_TABLES)) &&
+          (dest_tab.getTableType().equals(TableType.EXTERNAL_TABLE))) {
+          throw new SemanticException(
+            ErrorMsg.INSERT_EXTERNAL_TABLE.getMsg(dest_tab.getTableName()));
+      }
+
       Map<String, String> partSpec = qbm.getPartSpecForAlias(dest);
       dest_path = dest_tab.getPath();
 
@@ -4106,6 +4114,12 @@ public class SemanticAnalyzer extends Ba
 
       dest_part = qbm.getDestPartitionForAlias(dest);
       dest_tab = dest_part.getTable();
+      if ((!conf.getBoolVar(HiveConf.ConfVars.HIVE_INSERT_INTO_EXTERNAL_TABLES)) &&
+          dest_tab.getTableType().equals(TableType.EXTERNAL_TABLE)) {
+          throw new SemanticException(
+            ErrorMsg.INSERT_EXTERNAL_TABLE.getMsg(dest_tab.getTableName()));
+      }
+
       Path tabPath = dest_tab.getPath();
       Path partPath = dest_part.getPartitionPath();
 

Added: hive/trunk/ql/src/test/queries/clientnegative/insertexternal1.q
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/queries/clientnegative/insertexternal1.q?rev=1298936&view=auto
==============================================================================
--- hive/trunk/ql/src/test/queries/clientnegative/insertexternal1.q (added)
+++ hive/trunk/ql/src/test/queries/clientnegative/insertexternal1.q Fri Mar  9 17:31:16 2012
@@ -0,0 +1,8 @@
+set hive.insert.into.external.tables=false;
+
+
+create external table texternal(key string, val string) partitioned by (insertdate string);
+
+alter table texternal add partition (insertdate='2008-01-01') location 'pfile://${system:test.tmp.dir}/texternal/2008-01-01';
+from src insert overwrite table texternal partition (insertdate='2008-01-01') select *;
+

Added: hive/trunk/ql/src/test/results/clientnegative/insertexternal1.q.out
URL: http://svn.apache.org/viewvc/hive/trunk/ql/src/test/results/clientnegative/insertexternal1.q.out?rev=1298936&view=auto
==============================================================================
--- hive/trunk/ql/src/test/results/clientnegative/insertexternal1.q.out (added)
+++ hive/trunk/ql/src/test/results/clientnegative/insertexternal1.q.out Fri Mar  9 17:31:16
2012
@@ -0,0 +1,13 @@
+PREHOOK: query: create external table texternal(key string, val string) partitioned by (insertdate
string)
+PREHOOK: type: CREATETABLE
+POSTHOOK: query: create external table texternal(key string, val string) partitioned by (insertdate
string)
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: default@texternal
+#### A masked pattern was here ####
+PREHOOK: type: ALTERTABLE_ADDPARTS
+PREHOOK: Input: default@texternal
+#### A masked pattern was here ####
+POSTHOOK: type: ALTERTABLE_ADDPARTS
+POSTHOOK: Input: default@texternal
+POSTHOOK: Output: default@texternal@insertdate=2008-01-01
+FAILED: Error in semantic analysis: Inserting into a external table is not allowed texternal



Mime
View raw message