Repository: hive
Updated Branches:
  refs/heads/master 55fb0a196 -> 2e92451a6


HIVE-18857: Store default value text instead of default value expression in 
metastore(Vineet Garg, reviewed by Ashutosh Chauhan)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/2e92451a
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/2e92451a
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/2e92451a

Branch: refs/heads/master
Commit: 2e92451a61557248e47453e7917d81c428379bfa
Parents: 55fb0a1
Author: Vineet Garg <vg...@apache.org>
Authored: Mon Apr 9 19:31:14 2018 -0700
Committer: Vineet Garg <vg...@apache.org>
Committed: Mon Apr 9 19:31:14 2018 -0700

----------------------------------------------------------------------
 .../hadoop/hive/ql/parse/BaseSemanticAnalyzer.java   | 15 +++++++++------
 .../hadoop/hive/ql/parse/DDLSemanticAnalyzer.java    |  3 ++-
 2 files changed, 11 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/2e92451a/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java
----------------------------------------------------------------------
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java 
b/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java
index 5301b2a..d940cdd 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/BaseSemanticAnalyzer.java
@@ -765,10 +765,11 @@ public abstract class BaseSemanticAnalyzer {
   }
 
   protected static void processDefaultConstraints(String catName, String 
databaseName, String tableName,
-      ASTNode child, List<String> columnNames, List<SQLDefaultConstraint> 
defaultConstraints, final ASTNode typeChild)
+      ASTNode child, List<String> columnNames, List<SQLDefaultConstraint> 
defaultConstraints, final ASTNode typeChild,
+                                                  final TokenRewriteStream 
tokenRewriteStream)
       throws SemanticException {
     List<ConstraintInfo> defaultInfos = new ArrayList<ConstraintInfo>();
-    generateConstraintInfos(child, columnNames, defaultInfos, typeChild, null);
+    generateConstraintInfos(child, columnNames, defaultInfos, typeChild, 
tokenRewriteStream);
     constraintInfosToDefaultConstraints(catName, databaseName, tableName, 
defaultInfos, defaultConstraints);
   }
 
@@ -930,7 +931,8 @@ public abstract class BaseSemanticAnalyzer {
    * @return retrieve the default value and return it as string
    * @throws SemanticException
    */
-  private static String getDefaultValue(ASTNode defaultValueAST, ASTNode 
typeChild) throws SemanticException{
+  private static String getDefaultValue(ASTNode defaultValueAST, ASTNode 
typeChild,
+                                        final TokenRewriteStream tokenStream) 
throws SemanticException{
     // first create expression from defaultValueAST
     TypeCheckCtx typeCheckCtx = new TypeCheckCtx(null);
     ExprNodeDesc defaultValExpr = TypeCheckProcFactory
@@ -942,7 +944,8 @@ public abstract class BaseSemanticAnalyzer {
     }
 
     //get default value to be be stored in metastore
-    String defaultValueText  = defaultValExpr.getExprString();
+    String defaultValueText  = 
tokenStream.toOriginalString(defaultValueAST.getTokenStartIndex(),
+                                                            
defaultValueAST.getTokenStopIndex());
     final int DEFAULT_MAX_LEN = 255;
     if(defaultValueText.length() > DEFAULT_MAX_LEN) {
       throw new SemanticException(
@@ -1026,7 +1029,7 @@ public abstract class BaseSemanticAnalyzer {
         rely = false;
       } else if( child.getToken().getType() == HiveParser.TOK_DEFAULT_VALUE){
         // try to get default value only if this is DEFAULT constraint
-        checkOrDefaultValue = getDefaultValue(grandChild, typeChildForDefault);
+        checkOrDefaultValue = getDefaultValue(grandChild, typeChildForDefault, 
tokenRewriteStream);
       }
       else if(child.getToken().getType() == HiveParser.TOK_CHECK_CONSTRAINT) {
         checkOrDefaultValue = getCheckExpression(grandChild, 
tokenRewriteStream);
@@ -1259,7 +1262,7 @@ public abstract class BaseSemanticAnalyzer {
                 break;
               case HiveParser.TOK_DEFAULT_VALUE:
                 processDefaultConstraints(catName, qualifiedTabName[0], 
qualifiedTabName[1], constraintChild,
-                    ImmutableList.of(col.getName()), defaultConstraints, 
typeChild);
+                    ImmutableList.of(col.getName()), defaultConstraints, 
typeChild, tokenRewriteStream);
                 break;
                 case HiveParser.TOK_NOT_NULL:
                   processNotNullConstraints(catName, qualifiedTabName[0], 
qualifiedTabName[1], constraintChild,

http://git-wip-us.apache.org/repos/asf/hive/blob/2e92451a/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
----------------------------------------------------------------------
diff --git 
a/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java 
b/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
index e029566..f38b0bc 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/parse/DDLSemanticAnalyzer.java
@@ -3155,7 +3155,8 @@ public class DDLSemanticAnalyzer extends 
BaseSemanticAnalyzer {
       case HiveParser.TOK_DEFAULT_VALUE:
         defaultConstraints = new ArrayList<>();
         processDefaultConstraints(catName, qualified[0], qualified[1], 
constraintChild,
-                                  ImmutableList.of(newColName), 
defaultConstraints, (ASTNode)ast.getChild(2));
+                                  ImmutableList.of(newColName), 
defaultConstraints, (ASTNode)ast.getChild(2),
+                                  this.ctx.getTokenRewriteStream());
         break;
       case HiveParser.TOK_NOT_NULL:
         notNullConstraints = new ArrayList<>();

Reply via email to