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-6325] Add LOG function (enabled in Mysql and Spark library) #3732

Closed
wants to merge 7 commits into from

Conversation

caicancai
Copy link
Member

@caicancai caicancai commented Mar 13, 2024

@caicancai
Copy link
Member Author

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.

@caicancai
Copy link
Member Author

caicancai commented Mar 13, 2024

@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.
Thank you

@@ -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;
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Member Author

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.

@@ -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>. */
Copy link
Contributor

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.)

Copy link
Member Author

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

Copy link
Contributor

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.

Copy link
Member Author

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*) ?

Copy link
Contributor

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"

Copy link
Member Author

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.

@caicancai
Copy link
Member Author

I added clary as co-author, thank you for his review and suggestions

@caicancai caicancai marked this pull request as draft March 15, 2024 09:24
@caicancai caicancai marked this pull request as ready for review March 15, 2024 10:18
@caicancai
Copy link
Member Author

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,

Copy link
Contributor

@tanclary tanclary left a 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!

@caicancai
Copy link
Member Author

caicancai commented Mar 18, 2024

@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!

@tanclary Really, I submitted two commits, can you see them?
Is this a GitHub bug?
屏幕截图 2024-03-18 235633

site/_docs/reference.md 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>. */
Copy link
Contributor

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.

@caicancai caicancai changed the title [CALCITE-6325] Add LOG function (enabled in Mysql, Spark library) [CALCITE-6325] Add LOG function (enabled in Mysql library) Mar 19, 2024
@caicancai
Copy link
Member Author

@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})
Copy link
Contributor

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.

Copy link
Member Author

@caicancai caicancai Apr 1, 2024

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

Copy link
Member Author

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?

Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Member Author

@caicancai caicancai Apr 1, 2024

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)

Copy link
Contributor

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?

Copy link
Member Author

@caicancai caicancai Apr 1, 2024

Choose a reason for hiding this comment

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

LOG_MYSQL_SPARK?

Copy link
Member Author

@caicancai caicancai Apr 1, 2024

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@tanclary PTAL, thank you

@caicancai caicancai changed the title [CALCITE-6325] Add LOG function (enabled in Mysql library) [CALCITE-6325] Add LOG function (enabled in Mysql* library) Apr 1, 2024
@caicancai caicancai changed the title [CALCITE-6325] Add LOG function (enabled in Mysql* library) [CALCITE-6325] Add LOG function (enabled in Mysql Style library) Apr 1, 2024
@caicancai caicancai requested a review from tanclary April 1, 2024 08:33
@caicancai caicancai changed the title [CALCITE-6325] Add LOG function (enabled in Mysql Style library) [CALCITE-6325] Add LOG function (enabled in Mysql and Spark library) Apr 1, 2024
Copy link

sonarcloud bot commented Apr 1, 2024

@caicancai
Copy link
Member Author

caicancai commented Apr 15, 2024

@tanclary PATL, i think this pr can merge 1.37. Thank you

Copy link
Contributor

@tanclary tanclary left a 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.

@caicancai caicancai closed this Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants