[jira] [Created] (FLINK-17045) If multiple views are based on tables not defined in the yaml config file, dropping one of the views will throw exception

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (FLINK-17045) If multiple views are based on tables not defined in the yaml config file, dropping one of the views will throw exception

Shang Yuanchun (Jira)
Caizhi Weng created FLINK-17045:
-----------------------------------

             Summary: If multiple views are based on tables not defined in the yaml config file, dropping one of the views will throw exception
                 Key: FLINK-17045
                 URL: https://issues.apache.org/jira/browse/FLINK-17045
             Project: Flink
          Issue Type: Bug
          Components: Table SQL / Client
    Affects Versions: 1.11.0
            Reporter: Caizhi Weng


Add the following test in {{LocalExecutorITCase}} and run it
{code:java}
@Test
public void testBuggyViews() throws Exception {
    final Executor executor = createDefaultExecutor(clusterClient);
    final SessionContext session = new SessionContext("test-session", new Environment());
    String sessionId = executor.openSession(session);

    final String ddlTemplate = "create table %s(\n" +
        "  a int,\n" +
        "  b bigint,\n" +
        "  c varchar\n" +
        ") with (\n" +
        "  'connector.type'='filesystem',\n" +
        "  'format.type'='csv',\n" +
        "  'connector.path'='xxx'\n" +
        ")\n";

    executor.useCatalog(sessionId, "catalog1");
    executor.createTable(sessionId, String.format(ddlTemplate, "MyTable1"));
    executor.createTable(sessionId, String.format(ddlTemplate, "MyTable2"));

    executor.addView(sessionId, "AdditionalView1", "SELECT * FROM MyTable1");
    executor.addView(sessionId, "AdditionalView2", "SELECT * FROM MyTable2");

    // exception thrown here
    executor.removeView(sessionId, "AdditionalView1");

    executor.closeSession(sessionId);
}
{code}
The following exception is thrown
{code:java}
org.apache.flink.table.client.gateway.SqlExecutionException: Could not create execution context.

        at org.apache.flink.table.client.gateway.local.ExecutionContext$Builder.build(ExecutionContext.java:767)
        at org.apache.flink.table.client.gateway.local.LocalExecutor.removeView(LocalExecutor.java:320)
        at org.apache.flink.table.client.gateway.local.LocalExecutorITCase.testBuggyViews(LocalExecutorITCase.java:163)
        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.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at org.junit.rules.ExpectedException$ExpectedExceptionStatement.evaluate(ExpectedException.java:239)
        at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:55)
        at org.junit.rules.RunRules.evaluate(RunRules.java:20)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.junit.runners.Suite.runChild(Suite.java:128)
        at org.junit.runners.Suite.runChild(Suite.java:27)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
        at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
        at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
        at org.junit.rules.RunRules.evaluate(RunRules.java:20)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
        at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
        at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
        at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
        at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: org.apache.flink.table.client.gateway.SqlExecutionException: Invalid view 'AdditionalView2' with query:
SELECT * FROM MyTable2
Cause: SQL validation failed. From line 1, column 15 to line 1, column 22: Object 'MyTable2' not found
        at org.apache.flink.table.client.gateway.local.ExecutionContext.registerView(ExecutionContext.java:682)
        at org.apache.flink.table.client.gateway.local.ExecutionContext.lambda$initializeCatalogs$9(ExecutionContext.java:602)
        at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
        at org.apache.flink.table.client.gateway.local.ExecutionContext.initializeCatalogs(ExecutionContext.java:597)
        at org.apache.flink.table.client.gateway.local.ExecutionContext.initializeTableEnvironment(ExecutionContext.java:508)
        at org.apache.flink.table.client.gateway.local.ExecutionContext.<init>(ExecutionContext.java:164)
        at org.apache.flink.table.client.gateway.local.ExecutionContext.<init>(ExecutionContext.java:121)
        at org.apache.flink.table.client.gateway.local.ExecutionContext$Builder.build(ExecutionContext.java:756)
        ... 39 more
{code}
This is caused by not adding the {{SessionState}} in {{LocalExecutor#removeView}} when creating the new builder.
{code:java}
if (newEnv.getTables().remove(name) != null) {
   // Renew the ExecutionContext.
   this.contextMap.put(
         sessionId,
         createExecutionContextBuilder(context.getOriginalSessionContext())
               // should be: .env(newEnv).sessionState(getExecutionContext(sessionId).getSessionState()).build());
               .env(newEnv).build());
}{code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)