Uploaded image for project: 'Tajo'
  1. Tajo
  2. TAJO-1467

Parenthesis at the start of SQL query is ignored

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.11.0
    • Component/s: None
    • Labels:
      None

      Description

      According to Tajo parser grammar,

      non_join_query_primary
        : simple_table
        | LEFT_PAREN non_join_query_expression RIGHT_PAREN
        ;
      

      it should support following query with parentheses:

      (select n_nationkey, n_name from nation where n_nationkey = 1);
      

      However, isStatementStart() of SimpleParser only accepts digit or letter as a start of SQL query, so that it only takes:

      select n_nationkey, n_name from nation where n_nationkey = 1);
      

      , which results in parser error at SQLParser().

      2015-03-30 11:25:43,765 INFO: org.apache.tajo.master.GlobalEngine (executeQuery(150)) - Query: select n_nationkey, n_name from nation where n_nationkey = 1)
      org.apache.tajo.engine.parser.SQLParseError: ERROR: syntax error at or near '1'
      LINE 1:59 select n_nationkey, n_name from nation where n_nationkey = 1)
                                                                           ^
      	at org.apache.tajo.engine.parser.SQLErrorListener.syntaxError(SQLErrorListener.java:36)
      	at org.antlr.v4.runtime.ProxyErrorListener.syntaxError(ProxyErrorListener.java:65)
      	at org.antlr.v4.runtime.Parser.notifyErrorListeners(Parser.java:473)
      	at org.apache.tajo.engine.parser.SQLErrorStrategy.reportNoViableAltException(SQLErrorStrategy.java:57)
      	at org.apache.tajo.engine.parser.SQLErrorStrategy.reportError(SQLErrorStrategy.java:35)
      	at org.apache.tajo.engine.parser.SQLParser.row_value_predicand(SQLParser.java:9676)
      	at org.apache.tajo.engine.parser.SQLParser.comparison_predicate(SQLParser.java:14355)
      	at org.apache.tajo.engine.parser.SQLParser.predicate(SQLParser.java:14264)
      	at org.apache.tajo.engine.parser.SQLParser.boolean_primary(SQLParser.java:9202)
      	at org.apache.tajo.engine.parser.SQLParser.boolean_test(SQLParser.java:9040)
      	at org.apache.tajo.engine.parser.SQLParser.boolean_factor(SQLParser.java:8983)
      	at org.apache.tajo.engine.parser.SQLParser.and_predicate(SQLParser.java:8920)
      	at org.apache.tajo.engine.parser.SQLParser.or_predicate(SQLParser.java:8850)
      	at org.apache.tajo.engine.parser.SQLParser.boolean_value_expression(SQLParser.java:8796)
      	at org.apache.tajo.engine.parser.SQLParser.value_expression(SQLParser.java:6960)
      	at org.apache.tajo.engine.parser.SQLParser.search_condition(SQLParser.java:11175)
      	at org.apache.tajo.engine.parser.SQLParser.where_clause(SQLParser.java:11132)
      	at org.apache.tajo.engine.parser.SQLParser.table_expression(SQLParser.java:9796)
      	at org.apache.tajo.engine.parser.SQLParser.query_specification(SQLParser.java:13551)
      	at org.apache.tajo.engine.parser.SQLParser.simple_table(SQLParser.java:13261)
      	at org.apache.tajo.engine.parser.SQLParser.non_join_query_primary(SQLParser.java:13200)
      	at org.apache.tajo.engine.parser.SQLParser.non_join_query_term(SQLParser.java:13039)
      	at org.apache.tajo.engine.parser.SQLParser.non_join_query_expression(SQLParser.java:12851)
      	at org.apache.tajo.engine.parser.SQLParser.query_expression_body(SQLParser.java:12769)
      	at org.apache.tajo.engine.parser.SQLParser.query_expression(SQLParser.java:12720)
      	at org.apache.tajo.engine.parser.SQLParser.data_statement(SQLParser.java:679)
      	at org.apache.tajo.engine.parser.SQLParser.statement(SQLParser.java:432)
      	at org.apache.tajo.engine.parser.SQLParser.sql(SQLParser.java:307)
      	at org.apache.tajo.engine.parser.SQLAnalyzer.parse(SQLAnalyzer.java:65)
      	at org.apache.tajo.master.GlobalEngine.buildExpressionFromSql(GlobalEngine.java:190)
      	at org.apache.tajo.master.GlobalEngine.executeQuery(GlobalEngine.java:158)
      	at org.apache.tajo.master.TajoMasterClientService$TajoMasterClientProtocolServiceHandler.submitQuery(TajoMasterClientService.java:287)
      	at org.apache.tajo.ipc.TajoMasterClientProtocol$TajoMasterClientProtocolService$2.callBlockingMethod(TajoMasterClientProtocol.java:543)
      	at org.apache.tajo.rpc.BlockingRpcServer$ServerHandler.channelRead(BlockingRpcServer.java:113)
      	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
      	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
      	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
      	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
      	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
      	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:182)
      	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:308)
      	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:294)
      	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
      	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:130)
      	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
      	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
      	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
      	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
      	at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:116)
      	at java.lang.Thread.run(Thread.java:695)
      

      As most DBMSs support above type of queries with parentheses and Tajo grammar does also,
      I think SimpleParser should be changed to accept parenthesis as a start character of a query.

      1. TAJO-1467.patch
        4 kB
        Keuntae Park

        Activity

        Hide
        sirpkt Keuntae Park added a comment -

        During making the patch for this issue,
        I found that SQLAnalyzer also has problem on handling subquery with parentheses.
        It is because it does not handle non_join_query_primary properly based on the type of children.
        I'll add patch for the code.

        Show
        sirpkt Keuntae Park added a comment - During making the patch for this issue, I found that SQLAnalyzer also has problem on handling subquery with parentheses. It is because it does not handle non_join_query_primary properly based on the type of children. I'll add patch for the code.
        Hide
        githubbot ASF GitHub Bot added a comment -

        GitHub user sirpkt opened a pull request:

        https://github.com/apache/tajo/pull/479

        TAJO-1467: Parenthesis at the start of SQL query is ignored

        Fix SimpleParser to accept a SQL query starts with '(' character.
        Also fix SQLAnalyzer to handle non_join_query_primary properly as defined in Tajo grammar.

        You can merge this pull request into a Git repository by running:

        $ git pull https://github.com/sirpkt/tajo TAJO-1467

        Alternatively you can review and apply these changes as the patch at:

        https://github.com/apache/tajo/pull/479.patch

        To close this pull request, make a commit to your master/trunk branch
        with (at least) the following in the commit message:

        This closes #479


        commit 9531e49c43c71bb6fb514af58ffccd3456dc37fd
        Author: Keuntae Park <sirpkt@apache.org>
        Date: 2015-03-30T03:58:37Z

        Fix SimpleParser to accept the SQL query starts with '('

        Also fix SQLAnalyzer to handle non_join_query_primary properly as defined in Parser


        Show
        githubbot ASF GitHub Bot added a comment - GitHub user sirpkt opened a pull request: https://github.com/apache/tajo/pull/479 TAJO-1467 : Parenthesis at the start of SQL query is ignored Fix SimpleParser to accept a SQL query starts with '(' character. Also fix SQLAnalyzer to handle non_join_query_primary properly as defined in Tajo grammar. You can merge this pull request into a Git repository by running: $ git pull https://github.com/sirpkt/tajo TAJO-1467 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/tajo/pull/479.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #479 commit 9531e49c43c71bb6fb514af58ffccd3456dc37fd Author: Keuntae Park <sirpkt@apache.org> Date: 2015-03-30T03:58:37Z Fix SimpleParser to accept the SQL query starts with '(' Also fix SQLAnalyzer to handle non_join_query_primary properly as defined in Parser
        Hide
        tajoqa Tajo QA added a comment -

        +1 overall. Here are the results of testing the latest attachment
        http://issues.apache.org/jira/secure/attachment/12708081/TAJO-1467.patch
        against master revision release-0.9.0-rc0-225-g7f77593.

        +1 @author. The patch does not contain any @author tags.

        +1 tests included. The patch appears to include 5 new or modified test files.

        +1 javac. The applied patch does not increase the total number of javac compiler warnings.

        +1 javadoc. The applied patch does not increase the total number of javadoc warnings.

        +1 checkstyle. The patch generated 0 code style errors.

        +1 findbugs. The patch does not introduce any new Findbugs (version 2.0.3) warnings.

        +1 release audit. The applied patch does not increase the total number of release audit warnings.

        +1 core tests. The patch passed unit tests in tajo-cli tajo-core.

        Test results: https://builds.apache.org/job/PreCommit-TAJO-Build/675//testReport/
        Console output: https://builds.apache.org/job/PreCommit-TAJO-Build/675//console

        This message is automatically generated.

        Show
        tajoqa Tajo QA added a comment - +1 overall. Here are the results of testing the latest attachment http://issues.apache.org/jira/secure/attachment/12708081/TAJO-1467.patch against master revision release-0.9.0-rc0-225-g7f77593. +1 @author. The patch does not contain any @author tags. +1 tests included. The patch appears to include 5 new or modified test files. +1 javac. The applied patch does not increase the total number of javac compiler warnings. +1 javadoc. The applied patch does not increase the total number of javadoc warnings. +1 checkstyle. The patch generated 0 code style errors. +1 findbugs. The patch does not introduce any new Findbugs (version 2.0.3) warnings. +1 release audit. The applied patch does not increase the total number of release audit warnings. +1 core tests. The patch passed unit tests in tajo-cli tajo-core. Test results: https://builds.apache.org/job/PreCommit-TAJO-Build/675//testReport/ Console output: https://builds.apache.org/job/PreCommit-TAJO-Build/675//console This message is automatically generated.
        Hide
        githubbot ASF GitHub Bot added a comment -

        Github user babokim commented on the pull request:

        https://github.com/apache/tajo/pull/479#issuecomment-93213761

        This patch looks good to me. I had same problem to run TPC-DS query66. After applying this patch that query runs well and all test cases passed.
        Here is my +1. I'll commit this patch soon.

        Show
        githubbot ASF GitHub Bot added a comment - Github user babokim commented on the pull request: https://github.com/apache/tajo/pull/479#issuecomment-93213761 This patch looks good to me. I had same problem to run TPC-DS query66. After applying this patch that query runs well and all test cases passed. Here is my +1. I'll commit this patch soon.
        Hide
        githubbot ASF GitHub Bot added a comment -

        Github user babokim commented on the pull request:

        https://github.com/apache/tajo/pull/479#issuecomment-93216468

        @sirpkt, I misunderstood a contributor worked this patch. I am sorry about that.

        Show
        githubbot ASF GitHub Bot added a comment - Github user babokim commented on the pull request: https://github.com/apache/tajo/pull/479#issuecomment-93216468 @sirpkt, I misunderstood a contributor worked this patch. I am sorry about that.
        Hide
        githubbot ASF GitHub Bot added a comment -

        Github user sirpkt commented on the pull request:

        https://github.com/apache/tajo/pull/479#issuecomment-93638899

        It's ok, @babokim.
        Thank you for the review!
        I'll commit the patch soon.

        Show
        githubbot ASF GitHub Bot added a comment - Github user sirpkt commented on the pull request: https://github.com/apache/tajo/pull/479#issuecomment-93638899 It's ok, @babokim. Thank you for the review! I'll commit the patch soon.
        Hide
        githubbot ASF GitHub Bot added a comment -

        Github user asfgit closed the pull request at:

        https://github.com/apache/tajo/pull/479

        Show
        githubbot ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/tajo/pull/479
        Hide
        githubbot ASF GitHub Bot added a comment -

        Github user sirpkt commented on the pull request:

        https://github.com/apache/tajo/pull/479#issuecomment-93640006

        I just committed the patch.

        Show
        githubbot ASF GitHub Bot added a comment - Github user sirpkt commented on the pull request: https://github.com/apache/tajo/pull/479#issuecomment-93640006 I just committed the patch.
        Hide
        hudson Hudson added a comment -

        FAILURE: Integrated in Tajo-master-CODEGEN-build #306 (See https://builds.apache.org/job/Tajo-master-CODEGEN-build/306/)
        TAJO-1467: Parenthesis at the start of SQL query is ignored. (Keuntae Park) (sirpkt: rev 338a2b777854de0ed8344d3d1fcbc5276f3e3cba)

        • tajo-core/src/test/resources/queries/TestSelectQuery/testSelectWithParentheses2.sql
        • tajo-core/src/test/resources/results/TestSelectQuery/testSelectWithParentheses1.result
        • tajo-core/src/test/resources/queries/TestSelectQuery/testSelectWithParentheses1.sql
        • CHANGES
        • tajo-core/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java
        • tajo-cli/src/main/java/org/apache/tajo/cli/tsql/SimpleParser.java
        • tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
        • tajo-core/src/test/resources/results/TestSelectQuery/testSelectWithParentheses2.result
        Show
        hudson Hudson added a comment - FAILURE: Integrated in Tajo-master-CODEGEN-build #306 (See https://builds.apache.org/job/Tajo-master-CODEGEN-build/306/ ) TAJO-1467 : Parenthesis at the start of SQL query is ignored. (Keuntae Park) (sirpkt: rev 338a2b777854de0ed8344d3d1fcbc5276f3e3cba) tajo-core/src/test/resources/queries/TestSelectQuery/testSelectWithParentheses2.sql tajo-core/src/test/resources/results/TestSelectQuery/testSelectWithParentheses1.result tajo-core/src/test/resources/queries/TestSelectQuery/testSelectWithParentheses1.sql CHANGES tajo-core/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java tajo-cli/src/main/java/org/apache/tajo/cli/tsql/SimpleParser.java tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java tajo-core/src/test/resources/results/TestSelectQuery/testSelectWithParentheses2.result
        Hide
        hudson Hudson added a comment -

        SUCCESS: Integrated in Tajo-master-build #668 (See https://builds.apache.org/job/Tajo-master-build/668/)
        TAJO-1467: Parenthesis at the start of SQL query is ignored. (Keuntae Park) (sirpkt: rev 338a2b777854de0ed8344d3d1fcbc5276f3e3cba)

        • tajo-cli/src/main/java/org/apache/tajo/cli/tsql/SimpleParser.java
        • CHANGES
        • tajo-core/src/test/resources/results/TestSelectQuery/testSelectWithParentheses1.result
        • tajo-core/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java
        • tajo-core/src/test/resources/queries/TestSelectQuery/testSelectWithParentheses2.sql
        • tajo-core/src/test/resources/results/TestSelectQuery/testSelectWithParentheses2.result
        • tajo-core/src/test/resources/queries/TestSelectQuery/testSelectWithParentheses1.sql
        • tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java
        Show
        hudson Hudson added a comment - SUCCESS: Integrated in Tajo-master-build #668 (See https://builds.apache.org/job/Tajo-master-build/668/ ) TAJO-1467 : Parenthesis at the start of SQL query is ignored. (Keuntae Park) (sirpkt: rev 338a2b777854de0ed8344d3d1fcbc5276f3e3cba) tajo-cli/src/main/java/org/apache/tajo/cli/tsql/SimpleParser.java CHANGES tajo-core/src/test/resources/results/TestSelectQuery/testSelectWithParentheses1.result tajo-core/src/test/java/org/apache/tajo/engine/query/TestSelectQuery.java tajo-core/src/test/resources/queries/TestSelectQuery/testSelectWithParentheses2.sql tajo-core/src/test/resources/results/TestSelectQuery/testSelectWithParentheses2.result tajo-core/src/test/resources/queries/TestSelectQuery/testSelectWithParentheses1.sql tajo-core/src/main/java/org/apache/tajo/engine/parser/SQLAnalyzer.java

          People

          • Assignee:
            sirpkt Keuntae Park
            Reporter:
            sirpkt Keuntae Park
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development