-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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-6325] Add LOG function (enabled in Mysql and Spark library) #3732
Conversation
I also fixed some problems with bigquery's log function. For example, one parameter of the log function defaults to ln, and the same is true for mysql and spark. |
@tanclary If you have time, can you help review the code? As you can see, I have not implemented the ln and log10 functions, I'm sorry about that. |
@@ -211,6 +211,7 @@ | |||
import static org.apache.calcite.sql.fun.SqlLibraryOperators.LOG2; | |||
import static org.apache.calcite.sql.fun.SqlLibraryOperators.LOGICAL_AND; | |||
import static org.apache.calcite.sql.fun.SqlLibraryOperators.LOGICAL_OR; | |||
import static org.apache.calcite.sql.fun.SqlLibraryOperators.LOG_MS; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We really should look into some other mechanism for operators implemented differently across different dialects. I feel that just modifying the name is confusing and not very sustainable (what if 2 dialects support 1 version and 2 support another? what do you name it then?) I know it's not in the scope of this change but just putting it out there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we could rethink how we use the @LibraryAnnotations because it seems like we have a straightforward way of referencing what dialects a given operator supports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tanclary I very much agree with your point of view, I am also thinking about this issue, maybe we should take the first step here with the log function. Do you think I should send an email to discuss it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have opened an email discussion. If there is a good way, I am willing to try it.
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
Show resolved
Hide resolved
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
Show resolved
Hide resolved
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
Outdated
Show resolved
Hide resolved
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
Outdated
Show resolved
Hide resolved
@@ -6332,6 +6346,66 @@ void checkRegexpExtract(SqlOperatorFixture f0, FunctionAlias functionAlias) { | |||
f0.forEachLibrary(list(SqlLibrary.MYSQL, SqlLibrary.SPARK), consumer); | |||
} | |||
|
|||
/** Test case for | |||
* <a href="https://issues.apache.org/jira/browse/CALCITE-6325">[CALCITE-6325] | |||
* Add LOG function (enabled in MYSQL, Spark library)</a>. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: MySQL*, and can you make that consistent across this PR (commit message, jira, etc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what it means, sorry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please write it as "MySQL", that's how they style it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add LOG function as MySql style or Add LOG function (enabled in MYSQL*) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please write it as "MySQL"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I was sick during this period and was delayed for some time.
Co-authored-by: Tanner Clary <[email protected]>
I added clary as co-author, thank you for his review and suggestions |
I tried to add LOG_Postgres(SqlFunctions.class, "log", long.class, long.class) to BuiltInMethod, trying to use method.name() to distinguish different databases, but the method of BuiltInMethod corresponds to a Sqlfunctions method, in the form of a map Save, it seems that it cannot be superimposed, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@caicancai did you forget to push your changes? All the comments are marked as resolved but it looks identical to how it was last week. Re-ping me when it's ready!
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
Show resolved
Hide resolved
@tanclary Really, I submitted two commits, can you see them? |
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
Show resolved
Hide resolved
core/src/main/java/org/apache/calcite/adapter/enumerable/RexImpTable.java
Show resolved
Hide resolved
core/src/main/java/org/apache/calcite/runtime/SqlFunctions.java
Outdated
Show resolved
Hide resolved
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
Outdated
Show resolved
Hide resolved
@@ -6332,6 +6346,66 @@ void checkRegexpExtract(SqlOperatorFixture f0, FunctionAlias functionAlias) { | |||
f0.forEachLibrary(list(SqlLibrary.MYSQL, SqlLibrary.SPARK), consumer); | |||
} | |||
|
|||
/** Test case for | |||
* <a href="https://issues.apache.org/jira/browse/CALCITE-6325">[CALCITE-6325] | |||
* Add LOG function (enabled in MYSQL, Spark library)</a>. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please write it as "MySQL", that's how they style it.
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java
Outdated
Show resolved
Hide resolved
@tanclary PTAL |
@@ -2205,6 +2205,14 @@ private static RelDataType deriveTypeMapFromEntries(SqlOperatorBinding opBinding | |||
OperandTypes.NUMERIC_OPTIONAL_NUMERIC, | |||
SqlFunctionCategory.NUMERIC); | |||
|
|||
/** The "LOG(numeric1, numeric2)" function. Returns the base numeric1 logarithm of numeric. */ | |||
@LibraryOperator(libraries = {MYSQL, SPARK}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the PR title just has MySQL.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tanclary How should I reasonably describe this PR title?
Add LOG function (enabled in MYSQL, Spark library) or Add LOG function (enabled in MYSQL* library).
Before I was Add LOG function (enabled in MYSQL, Spark library), I thought you asked me to change it to Add LOG function (enabled in MYSQL library), it seems I didn’t understand what you meant, sorry
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I use Mysql_Style to describe it. Do you think it is acceptable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. Please look at other similar function implementations to see how they handle multiple libraries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other functions do not specifically adapt their log functions to the mysql and spark dialects like the log function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tanclary I found similar cases [CALCITE-5642] Add SHA256, SHA512 functions (enabled in BigQuery and PostgreSQL libraries), so I should change back to Add LOG function (enabled in MYSQL, Spark library)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Style" doesn't add much. The issue is you can't name a functionLOG_MYSQL
if that function is also used for Spark. Does that make sense?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LOG_MYSQL_SPARK?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I wrote at the beginning was LOG_MYSQL_SPARK. It seems that I have always misunderstood what you meant. Sorry.
At present, we have some differences regarding some specifications, and the logic of the code itself is fine. If I still have problems after I modify it, I hope you can tell me how it should be modified because I really can't understand what you mean. Thank you very much. I will be very grateful. (please submit a commit and @caicancai ).
I'm sorry for my behavior of ping you multiple times, I have to admit it was not a polite way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tanclary PTAL, thank you
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Tanner Clary <[email protected]>
Co-authored-by: Tanner Clary <[email protected]>
Quality Gate passedIssues Measures |
@tanclary PATL, i think this pr can merge 1.37. Thank you |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem with this PR is I don't know what I'm reviewing. I know you're adding functions but it's not clear why you need an operator separate from BigQuery. Right now, your JIRA case is completely blank so no reviewer, viewer, or user has any context on what you're doing.
https://issues.apache.org/jira/browse/CALCITE-6325