Uploaded image for project: 'Hive'
  1. Hive
  2. HIVE-27648

CREATE TABLE with CHECK constraint fails with SemanticException

    XMLWordPrintableJSON

Details

    Description

      When we run:

      create table test (
          col1 int,
          `col 2` int check (`col 2` > 10) enable novalidate rely,
          constraint check_constraint check (col1 + `col 2` > 15) enable novalidate rely
      );
      

      It fails with:

       

       org.apache.hadoop.hive.ql.parse.SemanticException: Invalid Constraint syntax Invalid CHECK constraint expression: col 2 > 10.
          at org.apache.hadoop.hive.ql.ddl.table.constraint.ConstraintsUtils.validateCheckConstraint(ConstraintsUtils.java:462)
          at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeCreateTable(SemanticAnalyzer.java:13839)
          at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.genResolvedParseTree(SemanticAnalyzer.java:12618)
          at org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeInternal(SemanticAnalyzer.java:12787)
          at org.apache.hadoop.hive.ql.parse.CalcitePlanner.analyzeInternal(CalcitePlanner.java:467)
          at org.apache.hadoop.hive.ql.parse.BaseSemanticAnalyzer.analyze(BaseSemanticAnalyzer.java:327)
          at org.apache.hadoop.hive.ql.Compiler.analyze(Compiler.java:224)
          at org.apache.hadoop.hive.ql.Compiler.compile(Compiler.java:107)
          at org.apache.hadoop.hive.ql.Driver.compile(Driver.java:519)
          at org.apache.hadoop.hive.ql.Driver.compileInternal(Driver.java:471)
          at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:436)
          at org.apache.hadoop.hive.ql.Driver.compileAndRespond(Driver.java:430)
          at org.apache.hadoop.hive.ql.reexec.ReExecDriver.compileAndRespond(ReExecDriver.java:121)
          at org.apache.hadoop.hive.ql.reexec.ReExecDriver.run(ReExecDriver.java:227)
          at org.apache.hadoop.hive.cli.CliDriver.processLocalCmd(CliDriver.java:257)
          at org.apache.hadoop.hive.cli.CliDriver.processCmd1(CliDriver.java:201)
          at org.apache.hadoop.hive.cli.CliDriver.processCmd(CliDriver.java:127)
          at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:425)
          at org.apache.hadoop.hive.cli.CliDriver.processLine(CliDriver.java:356)
          at org.apache.hadoop.hive.ql.QTestUtil.executeClientInternal(QTestUtil.java:733)
          at org.apache.hadoop.hive.ql.QTestUtil.executeClient(QTestUtil.java:703)
          at org.apache.hadoop.hive.cli.control.CoreCliDriver.runTest(CoreCliDriver.java:115)
          at org.apache.hadoop.hive.cli.control.CliAdapter.runTest(CliAdapter.java:157)
          at org.apache.hadoop.hive.cli.TestMiniLlapLocalCliDriver.testCliDriver(TestMiniLlapLocalCliDriver.java:62) 

       

      I noticed while debugging that the check constraint expression in cc.getCheck_expression() doesn't include the backticks (`), and this results in wrong token generation.

      Attachments

        Issue Links

          Activity

            People

              kkasa Krisztian Kasa
              soumyakanti.das Soumyakanti Das
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: