Skip to content

Commit

Permalink
[CALCITE-6140] Add percentile test on SqlParserTest
Browse files Browse the repository at this point in the history
  • Loading branch information
caicancai committed Nov 28, 2023
1 parent 578f44e commit 855bf1f
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,13 @@ protected static SortedSet<String> keywords(@Nullable String dialect) {
.fails("(?s)Encountered \"\\*\" at .*");
}


@Test void testPercentile() {
sql("SELECT percentile(x, .5) within group (order by 3) from t")
.ok("SELECT `PERCENTILE`(`X`, 0.5) WITHIN GROUP (ORDER BY 3)\n"
+ "FROM `T`");
}

@Test void testPercentileCont() {
sql("select percentile_cont(.5) within group (order by 3) from t")
.ok("SELECT PERCENTILE_CONT(0.5) WITHIN GROUP (ORDER BY 3)\n"
Expand All @@ -796,6 +803,13 @@ protected static SortedSet<String> keywords(@Nullable String dialect) {
+ "FROM `T`");
}

@Test void testPercentileBigQuery() {
sql("select percentile(x, .5) over() from unnest(array[1,2,3,4]) as x")
.withDialect(BIG_QUERY)
.ok("SELECT (percentile(x, 0.5) OVER ())\n"
+ "FROM UNNEST((ARRAY[1, 2, 3, 4])) AS x");
}

/** Tests BigQuery's variant of PERCENTILE_CONT, which uses OVER rather than
* WITHIN GROUP, and allows RESPECT/IGNORE NULLS inside the parentheses. */
@Test void testPercentileContBigQuery() {
Expand Down

0 comments on commit 855bf1f

Please sign in to comment.