|
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; |
|
52 | 53 | import static com.facebook.presto.SystemSessionProperties.REMOVE_MAP_CAST; |
53 | 54 | import static com.facebook.presto.common.Utils.checkArgument; |
54 | 55 | import static com.facebook.presto.common.type.BigintType.BIGINT; |
| 56 | +import static com.facebook.presto.common.type.DoubleType.DOUBLE; |
| 57 | +import static com.facebook.presto.common.type.VarcharType.VARCHAR; |
55 | 58 | import static com.facebook.presto.nativeworker.NativeQueryRunnerUtils.createCustomer; |
56 | 59 | import static com.facebook.presto.nativeworker.NativeQueryRunnerUtils.createLineitem; |
57 | 60 | import static com.facebook.presto.nativeworker.NativeQueryRunnerUtils.createNation; |
58 | 61 | import static com.facebook.presto.nativeworker.NativeQueryRunnerUtils.createOrders; |
59 | 62 | import static com.facebook.presto.nativeworker.NativeQueryRunnerUtils.createOrdersEx; |
60 | 63 | import static com.facebook.presto.nativeworker.NativeQueryRunnerUtils.createRegion; |
| 64 | +import static com.facebook.presto.testing.MaterializedResult.resultBuilder; |
61 | 65 | import static java.lang.String.format; |
62 | 66 | import static org.testng.Assert.assertEquals; |
63 | 67 | import static org.testng.Assert.assertFalse; |
@@ -622,6 +626,20 @@ public void testNonOverriddenInlinedSqlInvokedFunctionsWhenConfigDisabled() |
622 | 626 | ".*Scalar function name not registered: native.default.key_sampling_percent.*"); |
623 | 627 | } |
624 | 628 |
|
| 629 | + @Test |
| 630 | + public void testP4HyperLogLogWithApproxSet() |
| 631 | + { |
| 632 | + ImmutableList<Type> types = ImmutableList.of(BIGINT, VARCHAR, DOUBLE); |
| 633 | + ImmutableList<Long> expected = ImmutableList.of(1002L, 1024L, 1014L); |
| 634 | + for (Type type : types) { |
| 635 | + MaterializedResult actual = computeActual(String.format("SELECT cardinality(cast(approx_set(cast(custkey AS %s)) AS P4HYPERLOGLOG)) FROM orders", type.getTypeSignature().toString())); |
| 636 | + MaterializedResult expectedResult = resultBuilder(getSession(), BIGINT) |
| 637 | + .row(expected.get(types.indexOf(type))) |
| 638 | + .build(); |
| 639 | + assertEquals(actual.getMaterializedRows(), expectedResult.getMaterializedRows()); |
| 640 | + } |
| 641 | + } |
| 642 | + |
625 | 643 | private String generateRandomTableName() |
626 | 644 | { |
627 | 645 | String tableName = "tmp_presto_" + UUID.randomUUID().toString().replace("-", ""); |
|
0 commit comments