Skip to content

Commit

Permalink
[FLINK-29733][hive] Fix the version error in HiveVersionTestUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
HuangXingBo committed Oct 31, 2022
1 parent f73189d commit 759d954
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 759d954

Please sign in to comment.