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

[CALCITE-6876] Druid Adapter support more functions #4227

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

xuzifu666
Copy link
Member

@xuzifu666 xuzifu666 commented Mar 6, 2025

As description in JIRA:https://issues.apache.org/jira/browse/CALCITE-6876
ut had test success in Druid docker test env.

final String sql2 = "SELECT COUNT(*) FROM " + FOODMART_TABLE + " WHERE "
+ "FLOOR(ATAN2(\"store_cost\", \"store_cost\")) = 2 ";
sql(sql2, FOODMART)
.returnsOrdered("EXPR$0=0")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this result has been validated in some way.

Copy link
Member Author

@xuzifu666 xuzifu666 Mar 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes,I had test the ut with Druid Adapter dataset(https://github.com/zabetak/calcite-druid-dataset) in docker env and result is passed. @mihaibudiu

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the question is about the results, not the test, something like comparing the result here with the output of a few major DBs like postgres or Oracle, could you do that and share @xuzifu666 please?

Copy link
Member Author

@xuzifu666 xuzifu666 Mar 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asolimando OK,I had test the result from Oracle,the result like follow which keep the same with Druid:
ORACLE:
select COT(10) from test_db.new_table nt ORDER BY id limit 1;
1.5423510453569202

select ASIN(0.1) from test_db.new_table nt ORDER BY id limit 1;
0.1001674211615598

select ACOS(0.1) from test_db.new_table nt ORDER BY id limit 1;
1.4706289056333368

select ATAN(10) from test_db.new_table nt ORDER BY id limit 1;
1.4711276743037347

select ATAN2(10, 20) from test_db.new_table nt ORDER BY id limit 1;
0.4636476090008061

select DEGREES(10) from test_db.new_table nt ORDER BY id limit 1;
572.9577951308232

Druid:
select COT(10)
1.5423510453569202

select ASIN(0.1)
0.1001674211615598

select ACOS(0.1)
1.4706289056333368

select ATAN(10)
1.4711276743037347

select ATAN2(10, 20)
0.4636476090008061

select DEGREES(10)
572.9577951308232

@mihaibudiu mihaibudiu added the LGTM-will-merge-soon Overall PR looks OK. Only minor things left. label Mar 7, 2025
Copy link
Member

@caicancai caicancai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall, LGTM

@@ -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"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add a link to the druid function documentation for this method, at least to let users know which version it is, thank you

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, Thanks~ @caicancai

@xuzifu666 xuzifu666 force-pushed the druid_functions_support branch from 2f0b777 to 54f3fc6 Compare March 7, 2025 02:12
.add(new DirectOperatorConversion(SqlStdOperatorTable.ACOS, "acos"))
.add(new DirectOperatorConversion(SqlStdOperatorTable.ATAN, "atan"))
.add(new DirectOperatorConversion(SqlStdOperatorTable.ATAN2, "atan2"))
.add(new DirectOperatorConversion(SqlStdOperatorTable.DEGREES, "degrees"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test cases have not covered the degrees function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your reminder,had added case for degrees @NobiGo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

degrees function had some problem for druid test, so I remove first. this pr is for COT、ASIN、ACOS、ATAN、ATAN2,and change jira description.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather leave a disabled unit test with a comment so people are aware of the problem, it's less probable that they will come check here IMO

@xuzifu666 xuzifu666 force-pushed the druid_functions_support branch 2 times, most recently from e330969 to eea1b12 Compare March 7, 2025 06:50
@asolimando
Copy link
Member

Not blocking as I have only a few minor issues with the PR but please take a look and see if you feel like including them in the final version, thanks for the contribution @xuzifu666

@xuzifu666
Copy link
Member Author

xuzifu666 commented Mar 7, 2025

Not blocking as I have only a few minor issues with the PR but please take a look and see if you feel like including them in the final version, thanks for the contribution @xuzifu666

@asolimando OK,I accept your suggestion,had included them in the final version,PTAL,thanks~

@xuzifu666 xuzifu666 force-pushed the druid_functions_support branch from 19dec2a to 80ea63b Compare March 7, 2025 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LGTM-will-merge-soon Overall PR looks OK. Only minor things left.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants