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-6156] Add ENDSWITH, STARTSWITH functions (enabled in Postgres, Snowflake libraries) #3565

Merged
merged 1 commit into from
Dec 21, 2023

Conversation

tanclary
Copy link
Contributor

@tanclary tanclary commented Dec 5, 2023

No description provided.

@tanclary tanclary changed the title [CALCITE-6156] Add ENDSWITH, STARTSWITH functions (enabled in Snowflake library) [CALCITE-6156] Add ENDSWITH, STARTSWITH functions (enabled in Postgres, Snowflake libraries) Dec 5, 2023
@tanclary tanclary marked this pull request as ready for review December 5, 2023 13:57
@tanclary
Copy link
Contributor Author

tanclary commented Dec 5, 2023

Going to fix the formatting issues soon.

SPARK("s", "spark");
SPARK("s", "spark"),
/** A collection of operators that are in Snowflake but not in standard SQL. */
SNOWFLAKE("s", "snowflake");
Copy link
Contributor

Choose a reason for hiding this comment

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

I could be wrong, but do these single chars point to the symbol we use in reference.md to indicate the supported libraries?
If so should they be distinct symbols for each or its okay to use the same, I see s is used for Spark, Snowflake and Spatial but 'MSSQL' = q and 'MYSQL' = m

Copy link
Contributor

Choose a reason for hiding this comment

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

Just saw reference.md defines its own symbols for each library, just wanted to confirm what these chars are intended for.

Copy link
Contributor

Choose a reason for hiding this comment

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

List should be alphabetical.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to f and re-ordered list.

final String expected = "SELECT STARTSWITH(\"brand_name\" 'a')\n"
+ "FROM \"foodmart\".\"product\"";
sql(bigQuerySql).withLibrary(SqlLibrary.BIG_QUERY).withSnowflake().ok(expected);
sql(snowflakeSql).withLibrary(SqlLibrary.SNOWFLAKE).withSnowflake().ok(expected);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not very important to have SQL in more than one source dialect. But it's worth testing what SQL is generated in Postgres, BigQuery and Snowflake dialects.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adjusted

site/_docs/reference.md Show resolved Hide resolved
* comply with Snowflake syntax.
*/
private static void unparseEndsStartsWith(final SqlWriter writer, final SqlCall call) {
final String name = call.getKind() == SqlKind.ENDS_WITH ? "ENDSWITH" : "STARTSWITH";
Copy link
Contributor

Choose a reason for hiding this comment

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

This works, but it's a bit janky.

I would be better to map functions. If there is a call to ENDS_WITH, map it to a call to ENDSWITH. Then let the operator unparse itself.

A principled approach will allow us to scale the many functions x many dialects.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I rewrote this bit in my latest commit.

@tanclary tanclary force-pushed the 6156-startswith branch 7 times, most recently from a2ca748 to d46dc30 Compare December 21, 2023 14:46
Copy link
Contributor

@julianhyde julianhyde left a comment

Choose a reason for hiding this comment

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

Looks good.

If you have ideas about how to combine tests for alias functions please log a jira case.

f.checkBoolean("starts_with(x'1234', x'')", true);
f.checkBoolean("starts_with(x'', x'123456')", false);
f.checkBoolean("starts_with(x'', x'')", true);
final SqlOperatorFixture f0 = fixture();
Copy link
Contributor

Choose a reason for hiding this comment

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

I wish there was a way to create tests for functions that are aliases (e.g. starts_with and startswith, length and char_length) that did not use copy-paste. Any ideas?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I was thinking this too.

I filed https://issues.apache.org/jira/browse/CALCITE-6172 in the meantime while I think about it.

Copy link

sonarcloud bot commented Dec 21, 2023

@tanclary tanclary merged commit e74ff3e into apache:main Dec 21, 2023
17 checks passed
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.

4 participants