Skip to content

Commit 54f3fc6

Browse files
committed
[CALCITE-6876] Druid Adapter support more functions
1 parent 0ff9fcf commit 54f3fc6

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

druid/src/main/java/org/apache/calcite/adapter/druid/DruidQuery.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public class DruidQuery extends AbstractRelNode implements BindableRel {
101101
/**
102102
* Provides a standard list of supported Calcite operators that can be converted to
103103
* Druid Expressions. This can be used as is or re-adapted based on underline
104-
* engine operator syntax.
104+
* engine operator syntax.Methods can refer to https://druid.apache.org/docs/latest/querying/
105105
*/
106106
public static final List<DruidSqlOperatorConverter> DEFAULT_OPERATORS_LIST =
107107
ImmutableList.<DruidSqlOperatorConverter>builder()
@@ -120,6 +120,12 @@ public class DruidQuery extends AbstractRelNode implements BindableRel {
120120
.add(new DirectOperatorConversion(SqlStdOperatorTable.SIN, "sin"))
121121
.add(new DirectOperatorConversion(SqlStdOperatorTable.COS, "cos"))
122122
.add(new DirectOperatorConversion(SqlStdOperatorTable.TAN, "tan"))
123+
.add(new DirectOperatorConversion(SqlStdOperatorTable.COT, "cot"))
124+
.add(new DirectOperatorConversion(SqlStdOperatorTable.ASIN, "asin"))
125+
.add(new DirectOperatorConversion(SqlStdOperatorTable.ACOS, "acos"))
126+
.add(new DirectOperatorConversion(SqlStdOperatorTable.ATAN, "atan"))
127+
.add(new DirectOperatorConversion(SqlStdOperatorTable.ATAN2, "atan2"))
128+
.add(new DirectOperatorConversion(SqlStdOperatorTable.DEGREES, "degrees"))
123129
.add(new DirectOperatorConversion(SqlStdOperatorTable.CASE, "case_searched"))
124130
.add(new DirectOperatorConversion(SqlStdOperatorTable.CHAR_LENGTH, "strlen"))
125131
.add(new DirectOperatorConversion(SqlStdOperatorTable.CHARACTER_LENGTH, "strlen"))

druid/src/test/java/org/apache/calcite/test/DruidAdapterIT.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3969,6 +3969,30 @@ private void testCountWithApproxDistinct(boolean approx, String sql, String expe
39693969
+ "filter=[AND(>(SIN($91), 0.9129452507276277E0), >(COS($90), 0.40808206181339196E0), =(FLOOR(TAN($91)), 2.0E0), "
39703970
+ "<(ABS(-(TAN($91), /(SIN($91), COS($91)))), 1.0E-6))], "
39713971
+ "groups=[{}], aggs=[[COUNT()]])");
3972+
3973+
final String sql1 = "SELECT COUNT(*) FROM " + FOODMART_TABLE + " WHERE "
3974+
+ "COT(\"store_cost\") > COT(20) AND ASIN(\"store_sales\") > ASIN(1) "
3975+
+ "AND FLOOR(ACOS(\"store_cost\")) = 2 "
3976+
+ "AND ABS(ATAN(\"store_cost\") - ATAN(\"store_cost\") / ATAN(\"store_cost\")) < 10e-7";
3977+
sql(sql1, FOODMART)
3978+
.returnsOrdered("EXPR$0=0")
3979+
.explainContains("PLAN=EnumerableInterpreter\n"
3980+
+ " DruidQuery(table=[[foodmart, foodmart]], "
3981+
+ "intervals=[[1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z]], "
3982+
+ "filter=[AND(>(COT($91), 0.4469951089489167E0), >(ASIN($90), 1.5707963267948966E0), =(FLOOR(ACOS($91)), 2.0E0), "
3983+
+ "<(ABS(-(ATAN($91), /(ATAN($91), ATAN($91)))), 1.0E-6))], "
3984+
+ "groups=[{}], aggs=[[COUNT()]])");
3985+
3986+
final String sql2 = "SELECT COUNT(*) FROM " + FOODMART_TABLE + " WHERE "
3987+
+ "FLOOR(ATAN2(\"store_cost\", \"store_cost\")) = 2 ";
3988+
sql(sql2, FOODMART)
3989+
.returnsOrdered("EXPR$0=0")
3990+
.explainContains("PLAN=EnumerableInterpreter\n"
3991+
+ " DruidQuery(table=[[foodmart, foodmart]], "
3992+
+ "intervals=[[1900-01-09T00:00:00.000Z/2992-01-10T00:00:00.000Z]], "
3993+
+ "filter=[=(FLOOR(ATAN2($91, $91)), 2.0E0)], "
3994+
+ "groups=[{}], aggs=[[COUNT()]])");
3995+
39723996
}
39733997

39743998
@Test void testCastLiteralToTimestamp() {

0 commit comments

Comments
 (0)