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 aeb00ab [FLINK-15256][hive] HiveModuleFactory should take hive-version as required supported property aeb00ab is described below commit aeb00ab478d5d518bec6722378ae05e966c0ff8a Author: bowen.li <bowenl...@gmail.com> AuthorDate: Fri Dec 13 14:15:48 2019 -0800 [FLINK-15256][hive] HiveModuleFactory should take hive-version as required supported property HiveModuleFactory should have hive-version as property. Currently it cannot pick up hive-version from service discovery this closes #10577. --- .../apache/flink/table/module/hive/HiveModule.java | 11 +++++ .../table/module/hive/HiveModuleDescriptor.java | 5 +- .../flink/table/module/hive/HiveModuleFactory.java | 4 +- .../module/hive/HiveModuleDescriptorTest.java | 5 +- .../table/module/hive/HiveModuleFactoryTest.java | 55 ++++++++++++++++++++++ .../client/gateway/local/ExecutionContextTest.java | 6 ++- .../test/resources/test-sql-client-modules.yaml | 5 ++ 7 files changed, 82 insertions(+), 9 deletions(-) diff --git a/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/module/hive/HiveModule.java b/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/module/hive/HiveModule.java index 048e416..588eec6 100644 --- a/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/module/hive/HiveModule.java +++ b/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/module/hive/HiveModule.java @@ -23,21 +23,28 @@ import org.apache.flink.table.catalog.hive.client.HiveShimLoader; import org.apache.flink.table.catalog.hive.factories.HiveFunctionDefinitionFactory; import org.apache.flink.table.functions.FunctionDefinition; import org.apache.flink.table.module.Module; +import org.apache.flink.util.StringUtils; import org.apache.hadoop.hive.ql.exec.FunctionInfo; import java.util.Optional; import java.util.Set; +import static org.apache.flink.util.Preconditions.checkArgument; + /** * Module to provide Hive built-in metadata. */ public class HiveModule implements Module { private final HiveFunctionDefinitionFactory factory; + private final String hiveVersion; private final HiveShim hiveShim; public HiveModule(String hiveVersion) { + checkArgument(!StringUtils.isNullOrWhitespaceOnly(hiveVersion), "hiveVersion cannot be null"); + + this.hiveVersion = hiveVersion; this.hiveShim = HiveShimLoader.loadHiveShim(hiveVersion); this.factory = new HiveFunctionDefinitionFactory(hiveShim); } @@ -55,4 +62,8 @@ public class HiveModule implements Module { Optional.of(factory.createFunctionDefinitionFromHiveFunction(name, info.get().getFunctionClass().getName())) : Optional.empty(); } + + public String getHiveVersion() { + return hiveVersion; + } } diff --git a/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/module/hive/HiveModuleDescriptor.java b/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/module/hive/HiveModuleDescriptor.java index 5391e70..0acd653 100644 --- a/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/module/hive/HiveModuleDescriptor.java +++ b/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/module/hive/HiveModuleDescriptor.java @@ -34,14 +34,11 @@ import static org.apache.flink.util.Preconditions.checkArgument; public class HiveModuleDescriptor extends ModuleDescriptor { private String hiveVersion; - public HiveModuleDescriptor() { + public HiveModuleDescriptor(String hiveVersion) { super(MODULE_TYPE_HIVE); - } - public HiveModuleDescriptor hiveVersion(String hiveVersion) { checkArgument(!StringUtils.isNullOrWhitespaceOnly(hiveVersion)); this.hiveVersion = hiveVersion; - return this; } @Override diff --git a/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/module/hive/HiveModuleFactory.java b/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/module/hive/HiveModuleFactory.java index 48dcd9f..aabdf54 100644 --- a/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/module/hive/HiveModuleFactory.java +++ b/flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/module/hive/HiveModuleFactory.java @@ -23,7 +23,7 @@ import org.apache.flink.table.descriptors.DescriptorProperties; import org.apache.flink.table.factories.ModuleFactory; import org.apache.flink.table.module.Module; -import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -66,6 +66,6 @@ public class HiveModuleFactory implements ModuleFactory { @Override public List<String> supportedProperties() { - return new ArrayList<>(); + return Arrays.asList(MODULE_HIVE_VERSION); } } diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleDescriptorTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleDescriptorTest.java index 0f5ac3e..b6a0e27 100644 --- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleDescriptorTest.java +++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleDescriptorTest.java @@ -32,9 +32,11 @@ import java.util.Map; */ public class HiveModuleDescriptorTest extends DescriptorTestBase { + private final String hiveVersion = "2.3.4"; + @Override protected List<Descriptor> descriptors() { - final Descriptor descriptor = new HiveModuleDescriptor(); + final Descriptor descriptor = new HiveModuleDescriptor(hiveVersion); return Arrays.asList(descriptor); } @@ -43,6 +45,7 @@ public class HiveModuleDescriptorTest extends DescriptorTestBase { protected List<Map<String, String>> properties() { final Map<String, String> props1 = new HashMap<>(); props1.put("type", "hive"); + props1.put("hive-version", hiveVersion); return Arrays.asList(props1); } diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleFactoryTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleFactoryTest.java new file mode 100644 index 0000000..22e3adb --- /dev/null +++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleFactoryTest.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.flink.table.module.hive; + +import org.apache.flink.table.descriptors.ModuleDescriptor; +import org.apache.flink.table.factories.ModuleFactory; +import org.apache.flink.table.factories.TableFactoryService; +import org.apache.flink.table.module.Module; + +import org.junit.Test; + +import java.util.Map; + +import static org.junit.Assert.assertEquals; + + +/** + * Test for {@link HiveModuleFactory}. + */ +public class HiveModuleFactoryTest { + @Test + public void test() { + final String hiveVersion = "2.3.4"; + + final HiveModule expected = new HiveModule(hiveVersion); + + final ModuleDescriptor moduleDescriptor = new HiveModuleDescriptor(hiveVersion); + + final Map<String, String> properties = moduleDescriptor.toProperties(); + + final Module actualModule = TableFactoryService.find(ModuleFactory.class, properties) + .createModule(properties); + + checkEquals(expected, (HiveModule) actualModule); + } + + private static void checkEquals(HiveModule m1, HiveModule m2) { + assertEquals(m1.getHiveVersion(), m2.getHiveVersion()); + } +} diff --git a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/ExecutionContextTest.java b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/ExecutionContextTest.java index 3aacc5c..167fdf9 100644 --- a/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/ExecutionContextTest.java +++ b/flink-table/flink-sql-client/src/test/java/org/apache/flink/table/client/gateway/local/ExecutionContextTest.java @@ -90,12 +90,14 @@ public class ExecutionContextTest { final TableEnvironment tableEnv = context.getTableEnvironment(); Set<String> allModules = new HashSet<>(Arrays.asList(tableEnv.listModules())); - assertEquals(2, allModules.size()); + assertEquals(4, allModules.size()); assertEquals( new HashSet<>( Arrays.asList( "core", - "mymodule") + "mymodule", + "myhive", + "myhive2") ), allModules ); diff --git a/flink-table/flink-sql-client/src/test/resources/test-sql-client-modules.yaml b/flink-table/flink-sql-client/src/test/resources/test-sql-client-modules.yaml index 0e19028..12f7011 100644 --- a/flink-table/flink-sql-client/src/test/resources/test-sql-client-modules.yaml +++ b/flink-table/flink-sql-client/src/test/resources/test-sql-client-modules.yaml @@ -49,4 +49,9 @@ modules: - name: mymodule type: ModuleDependencyTest test: test + - name: myhive + type: hive + - name: myhive2 + type: hive + hive-version: 2.3.4