Skip to content

Commit 4781438

Browse files
authored
fix: Add P4HyperLogLog to NativeTypeManager (#26444)
## Description P4HyperLogLog type was added to Velox recently in facebookincubator/velox@75ec5ba, and this type should be supported by `NativeTypeManager`. ## Motivation and Context Support P4HLL type in `NativeTypeManager`, uncovered by `native-tests` in #23671. ## Impact Support P4HLL in Presto C++ clusters with sidecar. ## Test Plan Added tests. ``` == NO RELEASE NOTE == ```
1 parent 425499f commit 4781438

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

presto-native-sidecar-plugin/src/main/java/com/facebook/presto/sidecar/typemanager/NativeTypeManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
import static com.facebook.presto.common.type.StandardTypes.IPPREFIX;
5555
import static com.facebook.presto.common.type.StandardTypes.JSON;
5656
import static com.facebook.presto.common.type.StandardTypes.MAP;
57+
import static com.facebook.presto.common.type.StandardTypes.P4_HYPER_LOG_LOG;
5758
import static com.facebook.presto.common.type.StandardTypes.QDIGEST;
5859
import static com.facebook.presto.common.type.StandardTypes.REAL;
5960
import static com.facebook.presto.common.type.StandardTypes.ROW;
@@ -90,6 +91,7 @@ public class NativeTypeManager
9091
DOUBLE,
9192
SMALLINT,
9293
HYPER_LOG_LOG,
94+
P4_HYPER_LOG_LOG,
9395
JSON,
9496
TIMESTAMP_WITH_TIME_ZONE,
9597
UUID,

presto-native-sidecar-plugin/src/test/java/com/facebook/presto/sidecar/TestNativeSidecarPlugin.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import com.facebook.airlift.units.DataSize;
1717
import com.facebook.presto.Session;
18+
import com.facebook.presto.common.type.Type;
1819
import com.facebook.presto.nativeworker.PrestoNativeQueryRunnerUtils;
1920
import com.facebook.presto.scalar.sql.NativeSqlInvokedFunctionsPlugin;
2021
import com.facebook.presto.scalar.sql.SqlInvokedFunctionsPlugin;
@@ -42,6 +43,7 @@
4243
import org.testng.annotations.Test;
4344

4445
import java.util.List;
46+
import java.util.Map;
4547
import java.util.UUID;
4648
import java.util.regex.Pattern;
4749
import java.util.stream.Collectors;
@@ -52,12 +54,15 @@
5254
import static com.facebook.presto.SystemSessionProperties.REMOVE_MAP_CAST;
5355
import static com.facebook.presto.common.Utils.checkArgument;
5456
import static com.facebook.presto.common.type.BigintType.BIGINT;
57+
import static com.facebook.presto.common.type.DoubleType.DOUBLE;
58+
import static com.facebook.presto.common.type.VarcharType.VARCHAR;
5559
import static com.facebook.presto.nativeworker.NativeQueryRunnerUtils.createCustomer;
5660
import static com.facebook.presto.nativeworker.NativeQueryRunnerUtils.createLineitem;
5761
import static com.facebook.presto.nativeworker.NativeQueryRunnerUtils.createNation;
5862
import static com.facebook.presto.nativeworker.NativeQueryRunnerUtils.createOrders;
5963
import static com.facebook.presto.nativeworker.NativeQueryRunnerUtils.createOrdersEx;
6064
import static com.facebook.presto.nativeworker.NativeQueryRunnerUtils.createRegion;
65+
import static com.facebook.presto.testing.MaterializedResult.resultBuilder;
6166
import static java.lang.String.format;
6267
import static org.testng.Assert.assertEquals;
6368
import static org.testng.Assert.assertFalse;
@@ -622,6 +627,25 @@ public void testNonOverriddenInlinedSqlInvokedFunctionsWhenConfigDisabled()
622627
".*Scalar function name not registered: native.default.key_sampling_percent.*");
623628
}
624629

630+
@Test
631+
public void testP4HyperLogLogWithApproxSet()
632+
{
633+
// Map each SQL type to its expected NDV.
634+
Map<Type, Long> typeToNdvMap = ImmutableMap.of(
635+
BIGINT, 1002L,
636+
VARCHAR, 1024L,
637+
DOUBLE, 1014L);
638+
for (Map.Entry<Type, Long> entry : typeToNdvMap.entrySet()) {
639+
Type type = entry.getKey();
640+
Long expectedNdv = entry.getValue();
641+
MaterializedResult actual = computeActual(String.format("SELECT cardinality(cast(approx_set(cast(custkey AS %s)) AS P4HYPERLOGLOG)) FROM orders", type.getTypeSignature().toString()));
642+
MaterializedResult expectedResult = resultBuilder(getSession(), BIGINT)
643+
.row(expectedNdv)
644+
.build();
645+
assertEquals(actual.getMaterializedRows(), expectedResult.getMaterializedRows());
646+
}
647+
}
648+
625649
private String generateRandomTableName()
626650
{
627651
String tableName = "tmp_presto_" + UUID.randomUUID().toString().replace("-", "");

0 commit comments

Comments
 (0)