kasakrisz commented on code in PR #6204:
URL: https://github.com/apache/hive/pull/6204#discussion_r2549417024


##########
parser/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g:
##########
@@ -2363,7 +2363,8 @@ columnConstraintType
     ;
 
 defaultVal
-    : constant
+    : (PLUS | MINUS) unsignedNumericLiterals

Review Comment:
   Please try changing this line to
   ```
   ((PLUS | MINUS)^) unsignedNumericLiterals
   ```
   So create an AST like
   ```
   -
     15
   ```
   The node representing the sign is the parent of the node representing the 
numeric literal.
   In that case, you may not need to modify `ConstraintsUtils.java` at all 
since `ExprNodeTypeCheck.genExprNode` can already parse such ASTs.
   
   Please see the result of this statement:
   ```
   explain ast
   select -15;
   ```
   ```
   TOK_QUERY
      TOK_INSERT
         TOK_DESTINATION
            TOK_DIR
               TOK_TMP_FILE
         TOK_SELECT
            TOK_SELEXPR
               -
                  15
   ```
   In this case `ExprNodeTypeCheck.genExprNode` is used for parsing the AST too.
   



##########
parser/src/java/org/apache/hadoop/hive/ql/parse/HiveParser.g:
##########
@@ -2363,7 +2363,8 @@ columnConstraintType
     ;
 
 defaultVal
-    : constant
+    : (PLUS | MINUS) unsignedNumericLiterals
+    | constant
     | function
     | castExpression

Review Comment:
   How about expressions like
   ```
   -cast(22.0 as int)
   ```
   ?



##########
ql/src/java/org/apache/hadoop/hive/ql/ddl/table/constraint/ConstraintsUtils.java:
##########
@@ -309,8 +312,8 @@ private static List<ConstraintInfo> 
generateConstraintInfos(ASTNode child, List<
    * @param node AST node corresponding to default value
    * @return retrieve the default value and return it as string
    */
-  private static Pair<TypeInfo, String> getDefaultValueAndType(ASTNode node, 
TokenRewriteStream tokenStream)
-      throws SemanticException{
+  private static Pair<TypeInfo, String> getDefaultValueAndType(ASTNode node, 
TokenRewriteStream tokenStream,
+      boolean isNegativeConstant) throws SemanticException {
     // first create expression from defaultValueAST
     TypeCheckCtx typeCheckCtx = new TypeCheckCtx(null);
     ExprNodeDesc defaultValExpr = ExprNodeTypeCheck.genExprNode(node, 
typeCheckCtx).get(node);

Review Comment:
   The function `ExprNodeTypeCheck.genExprNode` is able to parse AST trees like
   ```
   -
       15
   ```
   So The node representing the `-` sign is the parent of the node representing 
the number 15.
   The parameter `isNegativeConstant` is unnecessary.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to