|
15 | 15 |
|
16 | 16 | import com.facebook.airlift.units.DataSize; |
17 | 17 | import com.facebook.presto.Session; |
| 18 | +import com.facebook.presto.common.type.Type; |
18 | 19 | import com.facebook.presto.nativeworker.PrestoNativeQueryRunnerUtils; |
19 | 20 | import com.facebook.presto.scalar.sql.NativeSqlInvokedFunctionsPlugin; |
20 | 21 | import com.facebook.presto.scalar.sql.SqlInvokedFunctionsPlugin; |
|
42 | 43 | import org.testng.annotations.Test; |
43 | 44 |
|
44 | 45 | import java.util.List; |
| 46 | +import java.util.Map; |
45 | 47 | import java.util.UUID; |
46 | 48 | import java.util.regex.Pattern; |
47 | 49 | import java.util.stream.Collectors; |
|
52 | 54 | import static com.facebook.presto.SystemSessionProperties.REMOVE_MAP_CAST; |
53 | 55 | import static com.facebook.presto.common.Utils.checkArgument; |
54 | 56 | 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; |
55 | 59 | import static com.facebook.presto.nativeworker.NativeQueryRunnerUtils.createCustomer; |
56 | 60 | import static com.facebook.presto.nativeworker.NativeQueryRunnerUtils.createLineitem; |
57 | 61 | import static com.facebook.presto.nativeworker.NativeQueryRunnerUtils.createNation; |
58 | 62 | import static com.facebook.presto.nativeworker.NativeQueryRunnerUtils.createOrders; |
59 | 63 | import static com.facebook.presto.nativeworker.NativeQueryRunnerUtils.createOrdersEx; |
60 | 64 | import static com.facebook.presto.nativeworker.NativeQueryRunnerUtils.createRegion; |
| 65 | +import static com.facebook.presto.testing.MaterializedResult.resultBuilder; |
61 | 66 | import static java.lang.String.format; |
62 | 67 | import static org.testng.Assert.assertEquals; |
63 | 68 | import static org.testng.Assert.assertFalse; |
@@ -622,6 +627,25 @@ public void testNonOverriddenInlinedSqlInvokedFunctionsWhenConfigDisabled() |
622 | 627 | ".*Scalar function name not registered: native.default.key_sampling_percent.*"); |
623 | 628 | } |
624 | 629 |
|
| 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 | + |
625 | 649 | private String generateRandomTableName() |
626 | 650 | { |
627 | 651 | String tableName = "tmp_presto_" + UUID.randomUUID().toString().replace("-", ""); |
|
0 commit comments