LadyForest commented on code in PR #22679: URL: https://github.com/apache/flink/pull/22679#discussion_r1217625716
########## flink-end-to-end-tests/flink-end-to-end-tests-hive/src/test/java/org/apache/flink/tests/hive/HiveITCase.java: ########## @@ -0,0 +1,295 @@ +/* + * 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.tests.hive; + +import org.apache.flink.api.common.time.Deadline; +import org.apache.flink.table.catalog.hive.HiveCatalog; +import org.apache.flink.test.resources.ResourceTestUtils; +import org.apache.flink.test.util.SQLJobSubmission; +import org.apache.flink.tests.hive.containers.HiveContainer; +import org.apache.flink.tests.util.flink.ClusterController; +import org.apache.flink.tests.util.flink.FlinkResource; +import org.apache.flink.tests.util.flink.FlinkResourceSetup; +import org.apache.flink.tests.util.flink.JarLocation; +import org.apache.flink.tests.util.flink.LocalStandaloneFlinkResourceFactory; +import org.apache.flink.util.FileUtils; +import org.apache.flink.util.TestLogger; +import org.apache.flink.util.UserClassLoaderJarTestUtils; + +import org.apache.hadoop.hive.conf.HiveConf; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.time.Duration; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** IT case for Hive including reading & writing hive and Hive dialect. */ +public class HiveITCase extends TestLogger { + + private static final Logger LOG = LoggerFactory.getLogger(HiveITCase.class); + + @ClassRule public static final TemporaryFolder TMP_FOLDER = new TemporaryFolder(); + + @ClassRule + public static final HiveContainer HIVE_CONTAINER = + new HiveContainer( + Arrays.asList("hive_sink1", "hive_sink2", "h_table_sink1", "h_table_sink2")); + + private static final String HIVE_ADD_ONE_UDF_CLASS = "HiveAddOneFunc"; + private static final String HIVE_ADD_ONE_UDF_CODE = + "public class " + + HIVE_ADD_ONE_UDF_CLASS + + " extends org.apache.hadoop.hive.ql.exec.UDF {\n" + + " public int evaluate(int content) {\n" + + " return content + 1;\n" + + " }" + + "}\n"; + + private static final Path HADOOP_CLASS_PATH = + ResourceTestUtils.getResource(".*hadoop.classpath"); + private static final Path sqlHiveJar = ResourceTestUtils.getResource(".*sql-hive-.*.jar"); + private static String hiveConfDirPath; + private static String udfDependsPath; + + @Rule public final FlinkResource flink = buildFlinkResource(); + + @BeforeClass + public static void beforeClass() throws Exception { + initUDFJar(); + initHiveConfFile(); + } + + private static void initUDFJar() throws Exception { + Path tmpPath = TMP_FOLDER.getRoot().toPath(); + LOG.info("The current temporary path: {}", tmpPath); + Map<String, String> classNameCodes = new HashMap<>(); + classNameCodes.put(HIVE_ADD_ONE_UDF_CLASS, HIVE_ADD_ONE_UDF_CODE); + File udfJar = + UserClassLoaderJarTestUtils.createJarFile( + TMP_FOLDER.newFolder("test-jar"), + "test-classloader-udf.jar", + classNameCodes); + URL udfDependency = udfJar.toURI().toURL(); + udfDependsPath = udfDependency.getPath(); Review Comment: ```suggestion udfDependsPath = udfJar.toURI().getPath(); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
