Skip to content

[CALCITE-6182] Add LENGTH/LEN functions (enabled in Snowflake library)#3604

Merged
tanclary merged 1 commit intoapache:mainfrom
tanclary:snowflake-length
Jan 3, 2024
Merged

[CALCITE-6182] Add LENGTH/LEN functions (enabled in Snowflake library)#3604
tanclary merged 1 commit intoapache:mainfrom
tanclary:snowflake-length

Conversation

@tanclary
Copy link
Contributor

Enabling LENGTH for Snowflake and adding the LEN alias

@mihaibudiu
Copy link
Contributor

Should this wait for #3590?

@tanclary
Copy link
Contributor Author

tanclary commented Dec 27, 2023

Should this wait for #3590?

@mihaibudiu Yes going to rebase once thats merged.

@tanclary tanclary force-pushed the snowflake-length branch 2 times, most recently from 33fa420 to b5e23f8 Compare December 28, 2023 16:40
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.

I suggested a few clarifying comments.

Also I would like clarity whether this will go in before or after the fix for CALCITE-6172. Before is probably better. But if before, then 6172 should add tests for LEN and LENGTH as aliases of CHAR_LENGTH.

f.checkNull("CHARACTER_LENGTH(cast(null as varchar(1)))");
}

@Test void testLenFunc() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could use a comment - that LEN is a snowflake-specific alias for CHAR_LENGTH, and that snowflake also supports LENGTH

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

f.checkScalar("length('')", "0", "INTEGER NOT NULL");
f.checkScalar("length(CAST('x' as CHAR(3)))", "3", "INTEGER NOT NULL");
f.checkScalar("length(CAST('x' as VARCHAR(4)))", "1", "INTEGER NOT NULL");
f.checkNull("length(CAST(NULL as CHAR(5)))");
Copy link
Contributor

Choose a reason for hiding this comment

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

None of these tests has a call to 'len(...)'. Maybe LEN is getting tested via some aliasing mechanism. It's difficult to tell.

So, let's have at least one test for LEN. So we can still trust the test even if the clever stuff fails.

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 just forgot to change them, fixed now

final String expectedSnowflake = "SELECT LENGTH(\"brand_name\")\n"
+ "FROM \"foodmart\".\"product\"";
sql(query).withLibrary(SqlLibrary.BIG_QUERY).withBigQuery().ok(expectedBigQuery);
sql(query).withLibrary(SqlLibrary.BIG_QUERY).withSnowflake().ok(expectedSnowflake);
Copy link
Contributor

Choose a reason for hiding this comment

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

can you combine those lines? you only need to parse the query once. then you generate SQL for two dialects.

the structure of the test should make it clear that people can other target dialects too.

I don't see any mention of LEN in the test. Not that there should be. It's ok to generate LENGTH for Snowflake. But it needs explanation, given that the jira case mentions LEN.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment and combined lines

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 3, 2024

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

1 New issue
0 Security Hotspots
100.0% Coverage on New Code
0.0% Duplication on New Code

See analysis details on SonarCloud

@tanclary tanclary merged commit 88a4150 into apache:main Jan 3, 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.

3 participants