Skip to content

[CALCITE-6149] Unparse for CAST Nullable with ClickHouseSqlDialect#3556

Merged
mihaibudiu merged 1 commit intoapache:mainfrom
Chen768959:ck-dialect-add-nullable-type
Dec 28, 2023
Merged

[CALCITE-6149] Unparse for CAST Nullable with ClickHouseSqlDialect#3556
mihaibudiu merged 1 commit intoapache:mainfrom
Chen768959:ck-dialect-add-nullable-type

Conversation

@Chen768959
Copy link
Copy Markdown
Contributor

@Chen768959 Chen768959 commented Dec 1, 2023

In ClickHouse, there is an issue with RelDataType of Nullable type when casting to a non-Nullable type. For example, SELECT CAST(NULL, 'Int32') will throw an error. In such cases, we should use SELECT CAST(NULL, 'Nullable(Int32)') instead.

CREATE TABLE default.test
(
    `id` Int64,
    `a` Nullable(Int64)
)
ENGINE = MergeTree
ORDER BY id

insert into test(id,a) values(1,1);
insert into test(id,a) values(2,null);
SELECT CAST(a, 'String') FROM test;

DB::Exception: Cannot convert NULL value to non-Nullable type
image

@Chen768959 Chen768959 changed the title [CALCITE-6149] unparse for CAST Nullable with ClickHouseSqlDialect [CALCITE-6149] Unparse for CAST Nullable with ClickHouseSqlDialect Dec 1, 2023
@Test void testClickhouseNullableFieldCast() {
final String query = "SELECT CASE WHEN \"product_name\" IS NULL THEN \"product_name\"+ 1 END\n"
+ "FROM \"foodmart\".\"product\"";
final String expectedSql = "SELECT CAST(NULL AS `Nullable(Int32)`)\n"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you have not-null case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Okay, let me add these case.

@Chen768959 Chen768959 force-pushed the ck-dialect-add-nullable-type branch from d1f9cd9 to c061249 Compare December 8, 2023 09:09
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Dec 8, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

53.3% 53.3% Coverage
0.0% 0.0% Duplication

@mihaibudiu
Copy link
Copy Markdown
Contributor

If this is ready for merging can you please rebase and resolve the conflicts?
Thank you.

@Chen768959
Copy link
Copy Markdown
Contributor Author

If this is ready for merging can you please rebase and resolve the conflicts?
Thank you.

Sure

@Chen768959 Chen768959 force-pushed the ck-dialect-add-nullable-type branch from c061249 to 89d623f Compare December 28, 2023 12:34
@mihaibudiu mihaibudiu merged commit 7b97c4e into apache:main Dec 28, 2023
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