You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by bl...@apache.org on 2019/12/16 18:46:23 UTC

[flink] branch release-1.10 updated: [FLINK-15254][sql cli][module] modules in SQL CLI yaml should preserve order

This is an automated email from the ASF dual-hosted git repository.

bli pushed a commit to branch release-1.10
in repository https://gitbox.apache.org/repos/asf/flink.git


The following commit(s) were added to refs/heads/release-1.10 by this push:
     new 6dd510e  [FLINK-15254][sql cli][module] modules in SQL CLI yaml should preserve order
6dd510e is described below

commit 6dd510e6efb372f89f4b6c7cf82064d4fa21da0d
Author: bowen.li <bo...@gmail.com>
AuthorDate: Fri Dec 13 16:04:16 2019 -0800

    [FLINK-15254][sql cli][module] modules in SQL CLI yaml should preserve order
    
    currently the module map is a hash map in sql cli, which doesn't preserve module loading order from yaml.
    fix it by always using a linked hash map
    
    this closes #10578.
---
 .../flink/table/client/config/Environment.java     |  6 ++---
 .../client/gateway/local/EnvironmentTest.java      | 28 ++++++++++++++++++++++
 2 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/config/Environment.java b/flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/config/Environment.java
index 506c23b..cb72b70 100644
--- a/flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/config/Environment.java
+++ b/flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/config/Environment.java
@@ -69,7 +69,7 @@ public class Environment {
 	private DeploymentEntry deployment;
 
 	public Environment() {
-		this.modules = Collections.emptyMap();
+		this.modules = new LinkedHashMap<>();
 		this.catalogs = Collections.emptyMap();
 		this.tables = Collections.emptyMap();
 		this.functions = Collections.emptyMap();
@@ -83,7 +83,7 @@ public class Environment {
 	}
 
 	public void setModules(List<Map<String, Object>> modules) {
-		this.modules = new HashMap<>(modules.size());
+		this.modules = new LinkedHashMap<>(modules.size());
 
 		modules.forEach(config -> {
 			final ModuleEntry entry = ModuleEntry.create(config);
@@ -235,7 +235,7 @@ public class Environment {
 		final Environment mergedEnv = new Environment();
 
 		// merge modules
-		final Map<String, ModuleEntry> modules = new HashMap<>(env1.getModules());
+		final Map<String, ModuleEntry> modules = new LinkedHashMap<>(env1.getModules());
 		modules.putAll(env2.getModules());
 		mergedEnv.modules = modules;
 
diff --git a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/EnvironmentTest.java b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/EnvironmentTest.java
index e4e2e89..49af642 100644
--- a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/EnvironmentTest.java
+++ b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/EnvironmentTest.java
@@ -26,6 +26,7 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -110,6 +111,33 @@ public class EnvironmentTest {
 			createModule("module2", "test")));
 	}
 
+	@Test
+	public void testModuleOrder() {
+		Environment env1 = new Environment();
+		Environment env2 = new Environment();
+		env1.setModules(Arrays.asList(
+			createModule("b", "test"),
+			createModule("d", "test")));
+
+		env2.setModules(Arrays.asList(
+			createModule("c", "test"),
+			createModule("a", "test")));
+
+		assertEquals(
+			Arrays.asList("b", "d"), new ArrayList<>(env1.getModules().keySet())
+		);
+
+		assertEquals(
+			Arrays.asList("c", "a"), new ArrayList<>(env2.getModules().keySet())
+		);
+
+		Environment env = Environment.merge(env1, env2);
+
+		assertEquals(
+			Arrays.asList("b", "d", "c", "a"), new ArrayList<>(env.getModules().keySet())
+		);
+	}
+
 	private static Map<String, Object> createCatalog(String name, String type) {
 		Map<String, Object> prop = new HashMap<>();