diff --git a/presto-hive/src/main/java/com/facebook/presto/hive/HiveUtil.java b/presto-hive/src/main/java/com/facebook/presto/hive/HiveUtil.java index 5d90ebb575b1b..88d27cfd5a3d7 100644 --- a/presto-hive/src/main/java/com/facebook/presto/hive/HiveUtil.java +++ b/presto-hive/src/main/java/com/facebook/presto/hive/HiveUtil.java @@ -524,8 +524,7 @@ private static boolean isValidPartitionType(Type type) public static NullableValue parsePartitionValue(String partitionName, String value, Type type, DateTimeZone timeZone) { verifyPartitionTypeSupported(partitionName, type); - - boolean isNull = HIVE_DEFAULT_DYNAMIC_PARTITION.equals(value); + boolean isNull = HIVE_DEFAULT_DYNAMIC_PARTITION.equals(value) || isHiveNull(value.getBytes(UTF_8)); if (type instanceof DecimalType) { DecimalType decimalType = (DecimalType) type; diff --git a/presto-hive/src/test/java/com/facebook/presto/hive/TestHiveDistributedJoinQueriesWithDynamicFiltering.java b/presto-hive/src/test/java/com/facebook/presto/hive/TestHiveDistributedJoinQueriesWithDynamicFiltering.java index 493e81b3cd18f..edd0df89f4a34 100644 --- a/presto-hive/src/test/java/com/facebook/presto/hive/TestHiveDistributedJoinQueriesWithDynamicFiltering.java +++ b/presto-hive/src/test/java/com/facebook/presto/hive/TestHiveDistributedJoinQueriesWithDynamicFiltering.java @@ -110,6 +110,23 @@ public void testJoinDynamicFilteringMultiJoin() assertQuery(session, query, "SELECT 1, 1, 1"); } + @Test + public void testJoinOnNullPartitioning() + { + assertUpdate("CREATE TABLE t3(c2 bigint, c1 bigint)"); + assertUpdate("INSERT INTO t3 VALUES(null, 2)", 1); + assertUpdate("CREATE TABLE t4(c2 bigint, c1 bigint) with(partitioned_by=array['c1'])"); + assertUpdate("INSERT INTO t4 VALUES(null, null), (2,2)", 2); + + String query = "select * from t3, t4 where t3.c1=t4.c2"; + Session session = Session.builder(getSession()) + .setSystemProperty(ENABLE_DYNAMIC_FILTERING, "true") + .setSystemProperty(JOIN_DISTRIBUTION_TYPE, FeaturesConfig.JoinDistributionType.AUTOMATIC.name()) + .setSystemProperty(JOIN_REORDERING_STRATEGY, FeaturesConfig.JoinReorderingStrategy.AUTOMATIC.name()) + .build(); + assertQuery(session, query, "SELECT null, 2, 2, 2"); + } + private OperatorStats searchScanFilterAndProjectOperatorStats(QueryId queryId, String tableName) { DistributedQueryRunner runner = (DistributedQueryRunner) getQueryRunner(); diff --git a/presto-hive/src/test/java/com/facebook/presto/hive/statistics/TestMetastoreHiveStatisticsProvider.java b/presto-hive/src/test/java/com/facebook/presto/hive/statistics/TestMetastoreHiveStatisticsProvider.java index a34dcc04a70db..28e3ff10c8160 100644 --- a/presto-hive/src/test/java/com/facebook/presto/hive/statistics/TestMetastoreHiveStatisticsProvider.java +++ b/presto-hive/src/test/java/com/facebook/presto/hive/statistics/TestMetastoreHiveStatisticsProvider.java @@ -13,6 +13,7 @@ */ package com.facebook.presto.hive.statistics; +import com.facebook.presto.common.predicate.NullableValue; import com.facebook.presto.common.type.DecimalType; import com.facebook.presto.common.type.Type; import com.facebook.presto.hive.HiveBasicStatistics; @@ -87,6 +88,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; public class TestMetastoreHiveStatisticsProvider { @@ -116,6 +118,14 @@ public void testGetPartitionsSample() assertEquals(getPartitionsSample(ImmutableList.of(p1, p2, p3, p4, p5), 3), ImmutableList.of(p1, p5, p4)); } + @Test + public void testNullablePartitionValue() + { + HivePartition part = partition("p1=name/p2=\\N"); + NullableValue verify = new NullableValue(BIGINT, null); + assertTrue(part.getKeys().containsValue(verify)); + } + @Test public void testValidatePartitionStatistics() {