Skip to content

Commit

Permalink
[CALCITE-6876] Druid Adapter support more functions
Browse files Browse the repository at this point in the history
  • Loading branch information
xuzifu666 committed Mar 7, 2025
1 parent 0ff9fcf commit 54f3fc6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class DruidQuery extends AbstractRelNode implements BindableRel {
/**
* Provides a standard list of supported Calcite operators that can be converted to
* Druid Expressions. This can be used as is or re-adapted based on underline
* engine operator syntax.
* engine operator syntax.Methods can refer to https://druid.apache.org/docs/latest/querying/
*/
public static final List<DruidSqlOperatorConverter> DEFAULT_OPERATORS_LIST =
ImmutableList.<DruidSqlOperatorConverter>builder()
Expand All @@ -120,6 +120,12 @@ public class DruidQuery extends AbstractRelNode implements BindableRel {
.add(new DirectOperatorConversion(SqlStdOperatorTable.SIN, "sin"))
.add(new DirectOperatorConversion(SqlStdOperatorTable.COS, "cos"))
.add(new DirectOperatorConversion(SqlStdOperatorTable.TAN, "tan"))
.add(new DirectOperatorConversion(SqlStdOperatorTable.COT, "cot"))
.add(new DirectOperatorConversion(SqlStdOperatorTable.ASIN, "asin"))
.add(new DirectOperatorConversion(SqlStdOperatorTable.ACOS, "acos"))
.add(new DirectOperatorConversion(SqlStdOperatorTable.ATAN, "atan"))
.add(new DirectOperatorConversion(SqlStdOperatorTable.ATAN2, "atan2"))
.add(new DirectOperatorConversion(SqlStdOperatorTable.DEGREES, "degrees"))
.add(new DirectOperatorConversion(SqlStdOperatorTable.CASE, "case_searched"))
.add(new DirectOperatorConversion(SqlStdOperatorTable.CHAR_LENGTH, "strlen"))
.add(new DirectOperatorConversion(SqlStdOperatorTable.CHARACTER_LENGTH, "strlen"))
Expand Down
24 changes: 24 additions & 0 deletions druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -3969,6 +3969,30 @@ private void testCountWithApproxDistinct(boolean approx, String sql, String expe
+ "filter=[AND(>(SIN($91), 0.9129452507276277E0), >(COS($90), 0.40808206181339196E0), =(FLOOR(TAN($91)), 2.0E0), "
+ "<(ABS(-(TAN($91), /(SIN($91), COS($91)))), 1.0E-6))], "
+ "groups=[{}], aggs=[[COUNT()]])");

final String sql1 = "SELECT COUNT(*) FROM " + FOODMART_TABLE + " WHERE "
+ "COT(\"store_cost\") > COT(20) AND ASIN(\"store_sales\") > ASIN(1) "
+ "AND FLOOR(ACOS(\"store_cost\")) = 2 "
+ "AND ABS(ATAN(\"store_cost\") - ATAN(\"store_cost\") / ATAN(\"store_cost\")) < 10e-7";
sql(sql1, FOODMART)
.returnsOrdered("EXPR$0=0")
.explainContains("PLAN=EnumerableInterpreter\n"
+ " DruidQuery(table=[[foodmart, foodmart]], "
+ "intervals=[[1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z]], "
+ "filter=[AND(>(COT($91), 0.4469951089489167E0), >(ASIN($90), 1.5707963267948966E0), =(FLOOR(ACOS($91)), 2.0E0), "
+ "<(ABS(-(ATAN($91), /(ATAN($91), ATAN($91)))), 1.0E-6))], "
+ "groups=[{}], aggs=[[COUNT()]])");

final String sql2 = "SELECT COUNT(*) FROM " + FOODMART_TABLE + " WHERE "
+ "FLOOR(ATAN2(\"store_cost\", \"store_cost\")) = 2 ";
sql(sql2, FOODMART)
.returnsOrdered("EXPR$0=0")
.explainContains("PLAN=EnumerableInterpreter\n"
+ " DruidQuery(table=[[foodmart, foodmart]], "
+ "intervals=[[1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z]], "
+ "filter=[=(FLOOR(ATAN2($91, $91)), 2.0E0)], "
+ "groups=[{}], aggs=[[COUNT()]])");

}

@Test void testCastLiteralToTimestamp() {
Expand Down

0 comments on commit 54f3fc6

Please sign in to comment.