Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix merge(qdigest) function #14616

Merged
merged 1 commit into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ private MergeQuantileDigestFunction() {}
@InputFunction
@TypeParameter("V")
public static void input(
@TypeParameter("V") Type type,
@TypeParameter("qdigest(V)") Type type,
@AggregationState QuantileDigestState state,
@BlockPosition @SqlType("V") Block value,
@BlockPosition @SqlType("qdigest(V)") Block value,
@BlockIndex int index)
{
merge(state, new QuantileDigest(type.getSlice(value, index)));
Expand Down Expand Up @@ -80,7 +80,7 @@ private static void merge(QuantileDigestState state, QuantileDigest input)

@OutputFunction("qdigest(V)")
public static void output(
@TypeParameter("V") Type type,
@TypeParameter("qdigest(V)") Type type,
@AggregationState QuantileDigestState state,
BlockBuilder out)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2096,6 +2096,29 @@ public void testP4ApproxSetGroupByWithNulls()
assertEqualsIgnoreOrder(actual.getMaterializedRows(), expected.getMaterializedRows());
}

@Test
public void testMergeQuantileDigest()
{
assertThat(query("""
WITH
a(field_a, field_b) AS (
VALUES (DOUBLE '10.3', 'group1'), (DOUBLE '11.3', 'group2')),
b AS (
SELECT CAST(qdigest_agg(field_a) AS varbinary) AS qdigest_binary
FROM a GROUP BY field_b)
SELECT CAST(merge(CAST(qdigest_binary AS qdigest(double))) AS varbinary)
FROM b"""))
.matches("""
VALUES X'
00 7b 14 ae 47 e1 7a 84 3f 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 9a 99 99 99 99 99 24
40 9a 99 99 99 99 99 26 40 03 00 00 00 00 00 00
00 00 00 00 f0 3f 9a 99 99 99 99 99 24 c0 00 00
00 00 00 00 00 f0 3f 9a 99 99 99 99 99 26 c0 c7
00 00 00 00 00 00 00 00 9a 99 99 99 99 99 24 c0'
""");
}

@Test
public void testValues()
{
Expand Down