Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-5252

JDBC adapter sometimes miss parentheses around SELECT in WITH_ITEM body

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 1.33.0
    • None

    Description

       

      //testkit/src/main/java/org/apache/calcite/sql/parser/SqlParserTest.java
      @Test void testWithUnion1() {
      finalStringsql="with emp2 as (select * from emp union select * from emp)\n"
      +"select * from emp2\n";
      finalStringexpected="WITH `EMP2` AS (SELECT *\n"
      +"FROM `EMP`\n"
      +"UNION\n"
      +"SELECT *\n"
      +"FROM `EMP`) (SELECT *\n"
      +"FROM `EMP2`)";
      sql(sql).ok(expected);
      }

      This test fails with SqlUnParserTest (
      core/src/test/java/org/apache/calcite/sql/parser/SqlUnParserTest.java) because the parentheses after AS are missing.

      Error while parsing SQL: WITH "EMP2" AS SELECT *FROM "EMP"UNIONSELECT *FROM "EMP" (SELECT *FROM "EMP2")java.lang.RuntimeException: Error while parsing SQL: WITH "EMP2" AS SELECT *FROM "EMP"UNIONSELECT *FROM "EMP" (SELECT *FROM "EMP2")    at org.apache.calcite.sql.parser.SqlParserTest$TesterImpl.parseStmtAndHandleEx(SqlParserTest.java:10400)    at org.apache.calcite.sql.parser.SqlParserTest$UnparsingTesterImpl.check(SqlParserTest.java:10620)    at org.apache.calcite.sql.parser.SqlParserFixture.ok(SqlParserFixture.java:83)    at org.apache.calcite.sql.parser.SqlParserTest.testWithUnion1(SqlParserTest.java:2282)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)    at org.junit.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:725)    at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)    at org.junit.jupiter.engine.extension.TimeoutInvocation.proceed(TimeoutInvocation.java:46)    at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:149)    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:140)    at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:84)    at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115)    at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105)    at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)    at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104)    at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98)    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:214)    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:210)    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135)    at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:66)    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)    at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)    at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)    at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)    at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)    at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)    at org.junit.platform.engine.support.hierarchical.ForkJoinPoolHierarchicalTestExecutorService$ExclusiveTask.compute(ForkJoinPoolHierarchicalTestExecutorService.java:185)    at java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:189)    at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)    at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)    at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)    at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:175)Caused by: java.lang.RuntimeException: org.apache.calcite.sql.parser.SqlParseException: Encountered "SELECT" at line 1, column 16.Was expecting:    "(" ...        at org.apache.calcite.sql.parser.SqlParseException.writeReplace(SqlParseException.java:171)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)    at java.io.ObjectStreamClass.invokeWriteReplace(ObjectStreamClass.java:1244)    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1136)    at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1548)    at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:441)    at java.lang.Throwable.writeObject(Throwable.java:1014)    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)    at java.lang.reflect.Method.invoke(Method.java:498)    at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:1154)    at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1496)    at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1432)    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1178)    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)    at org.gradle.internal.serialize.ExceptionPlaceholder.<init>(ExceptionPlaceholder.java:133)    at org.gradle.internal.serialize.TopLevelExceptionPlaceholder.<init>(TopLevelExceptionPlaceholder.java:28)    at org.gradle.internal.serialize.ExceptionReplacingObjectOutputStream.doReplaceObject(ExceptionReplacingObjectOutputStream.java:67)    at org.gradle.internal.serialize.ExceptionReplacingObjectOutputStream$1.transform(ExceptionReplacingObjectOutputStream.java:31)    at org.gradle.internal.serialize.ExceptionReplacingObjectOutputStream.replaceObject(ExceptionReplacingObjectOutputStream.java:62)    at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1144)    at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)    at org.gradle.internal.serialize.Message.send(Message.java:36)    at org.gradle.internal.serialize.BaseSerializerFactory$ThrowableSerializer.write(BaseSerializerFactory.java:321)    at org.gradle.internal.serialize.BaseSerializerFactory$ThrowableSerializer.write(BaseSerializerFactory.java:313)    at org.gradle.internal.remote.internal.hub.DefaultMethodArgsSerializer$ArraySerializer.write(DefaultMethodArgsSerializer.java:80)    at org.gradle.internal.remote.internal.hub.DefaultMethodArgsSerializer$ArraySerializer.write(DefaultMethodArgsSerializer.java:61)    at org.gradle.internal.remote.internal.hub.MethodInvocationSerializer$MethodInvocationWriter.writeArgs(MethodInvocationSerializer.java:78)    at org.gradle.internal.remote.internal.hub.MethodInvocationSerializer$MethodInvocationWriter.write(MethodInvocationSerializer.java:74)    at org.gradle.internal.remote.internal.hub.MethodInvocationSerializer$MethodInvocationWriter.write(MethodInvocationSerializer.java:58)    at org.gradle.internal.serialize.kryo.TypeSafeSerializer$2.write(TypeSafeSerializer.java:47)    at org.gradle.internal.remote.internal.hub.InterHubMessageSerializer$MessageWriter.write(InterHubMessageSerializer.java:104)    at org.gradle.internal.remote.internal.hub.InterHubMessageSerializer$MessageWriter.write(InterHubMessageSerializer.java:88)    at org.gradle.internal.remote.internal.inet.SocketConnection.dispatch(SocketConnection.java:122)    at org.gradle.internal.remote.internal.hub.MessageHub$ConnectionDispatch.run(MessageHub.java:328)    at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)    at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)    at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:61)    at java.lang.Thread.run(Thread.java:750) 

      Attachments

        Issue Links

          Activity

            People

              4wei Mou Wu
              yingyu Yingyu Wang
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 2h
                  2h