From 759d954960cbec28437955e5f482788902342035 Mon Sep 17 00:00:00 2001 From: huangxingbo Date: Mon, 31 Oct 2022 16:17:27 +0800 Subject: [PATCH] [FLINK-29733][hive] Fix the version error in HiveVersionTestUtil --- .../HiveTableSourceStatisticsReportTest.java | 78 +++++++++---------- .../table/module/hive/HiveModuleTest.java | 18 ++--- 2 files changed, 44 insertions(+), 52 deletions(-) diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSourceStatisticsReportTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSourceStatisticsReportTest.java index 20347114d6d00..662b196e144bc 100644 --- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSourceStatisticsReportTest.java +++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/connectors/hive/HiveTableSourceStatisticsReportTest.java @@ -18,6 +18,7 @@ package org.apache.flink.connectors.hive; +import org.apache.flink.table.HiveVersionTestUtil; import org.apache.flink.table.api.SqlDialect; import org.apache.flink.table.catalog.hive.HiveCatalog; import org.apache.flink.table.catalog.hive.HiveTestUtils; @@ -41,8 +42,6 @@ import java.util.List; import java.util.Map; -import static org.apache.flink.table.catalog.hive.client.HiveShimLoader.HIVE_VERSION_V2_3_9; -import static org.apache.flink.table.catalog.hive.client.HiveShimLoader.HIVE_VERSION_V3_1_1; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; @@ -299,45 +298,42 @@ private static void assertHiveTableOrcFormatTableStatsEquals( expectedColumnStatsMap.put( "f_string", new ColumnStats.Builder().setMax("def").setMin("abcd").setNullCount(0L).build()); - switch (HiveShimLoader.getHiveVersion()) { - case HIVE_VERSION_V2_3_9: - expectedColumnStatsMap.put( - "f_decimal5", - new ColumnStats.Builder() - .setMax(new BigDecimal("223.45")) - .setMin(new BigDecimal("123.45")) - .setNullCount(0L) - .build()); - expectedColumnStatsMap.put( - "f_decimal14", - new ColumnStats.Builder() - .setMax(new BigDecimal("123333333355.33")) - .setMin(new BigDecimal("123333333333.33")) - .setNullCount(0L) - .build()); - break; - case HIVE_VERSION_V3_1_1: - // TODO For hive 3.x version, Orc format encounter decimal type columns (like - // decimal(5, 2), decimal(14, 2)) will write a wrong column stat 'min' or 'max' in - // orc metadata footer. This branch will remove after this error is fixed, following - // issue HIVE-26492 - expectedColumnStatsMap.put( - "f_decimal5", - new ColumnStats.Builder() - .setMax(new BigDecimal("223.45")) - .setMin(new BigDecimal("0")) - .setNullCount(0L) - .build()); - expectedColumnStatsMap.put( - "f_decimal14", - new ColumnStats.Builder() - .setMax(new BigDecimal("123333333355.33")) - .setMin(new BigDecimal("0")) - .setNullCount(0L) - .build()); - break; - default: - fail("Unknown test version " + HiveShimLoader.getHiveVersion()); + if (HiveVersionTestUtil.HIVE_310_OR_LATER) { + // TODO For hive 3.x version, Orc format encounter decimal type columns (like + // decimal(5, 2), decimal(14, 2)) will write a wrong column stat 'min' or 'max' in + // orc metadata footer. This branch will remove after this error is fixed, following + // issue HIVE-26492 + expectedColumnStatsMap.put( + "f_decimal5", + new ColumnStats.Builder() + .setMax(new BigDecimal("223.45")) + .setMin(new BigDecimal("0")) + .setNullCount(0L) + .build()); + expectedColumnStatsMap.put( + "f_decimal14", + new ColumnStats.Builder() + .setMax(new BigDecimal("123333333355.33")) + .setMin(new BigDecimal("0")) + .setNullCount(0L) + .build()); + } else if (HiveVersionTestUtil.HIVE_230_OR_LATER) { + expectedColumnStatsMap.put( + "f_decimal5", + new ColumnStats.Builder() + .setMax(new BigDecimal("223.45")) + .setMin(new BigDecimal("123.45")) + .setNullCount(0L) + .build()); + expectedColumnStatsMap.put( + "f_decimal14", + new ColumnStats.Builder() + .setMax(new BigDecimal("123333333355.33")) + .setMin(new BigDecimal("123333333333.33")) + .setNullCount(0L) + .build()); + } else { + fail("Unknown test version " + HiveShimLoader.getHiveVersion()); } expectedColumnStatsMap.put( "f_decimal38", diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleTest.java index 9b42d9f8d007a..6108acf8219ef 100644 --- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleTest.java +++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleTest.java @@ -17,6 +17,7 @@ package org.apache.flink.table.module.hive; +import org.apache.flink.table.HiveVersionTestUtil; import org.apache.flink.table.api.DataTypes; import org.apache.flink.table.api.TableEnvironment; import org.apache.flink.table.catalog.hive.HiveTestUtils; @@ -37,8 +38,6 @@ import java.util.Collections; import java.util.List; -import static org.apache.flink.table.catalog.hive.client.HiveShimLoader.HIVE_VERSION_V2_3_9; -import static org.apache.flink.table.catalog.hive.client.HiveShimLoader.HIVE_VERSION_V3_1_1; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; @@ -72,15 +71,12 @@ public void testNumberOfBuiltinFunctions() { } private void verifyNumBuiltInFunctions(String hiveVersion, HiveModule hiveModule) { - switch (hiveVersion) { - case HIVE_VERSION_V2_3_9: - assertThat(hiveModule.listFunctions()).hasSize(277); - break; - case HIVE_VERSION_V3_1_1: - assertThat(hiveModule.listFunctions()).hasSize(296); - break; - default: - fail("Unknown test version " + hiveVersion); + if (HiveVersionTestUtil.HIVE_310_OR_LATER) { + assertThat(hiveModule.listFunctions()).hasSize(296); + } else if (HiveVersionTestUtil.HIVE_230_OR_LATER) { + assertThat(hiveModule.listFunctions()).hasSize(277); + } else { + fail("Unknown test version " + hiveVersion); } }