Skip to content

SAFE_CAST (enabled for BigQuery) #3093

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

Closed
wants to merge 27 commits into from
Closed

Conversation

olivrlee
Copy link
Contributor

@olivrlee olivrlee commented Mar 2, 2023

@olivrlee olivrlee changed the title SAFE_CAST WIP SAFE_CAST (enabled for BigQuery) Mar 9, 2023
@olivrlee
Copy link
Contributor Author

Hey @julianhyde if you could take a look at what I've done here: https://github.com/apache/calcite/pull/3093/files#diff-9e0f6e9c4d4f86444e48290b1e613ba700c0854cd614bee4a1912ccb75aed272R1203

@tjbanghart helped me take a look at your suggestion too with using some Supplier

public static final Object safe(Supplier r) {
	try {
	 return r.get();
	} catch (RuntimeException e) {
	return null;
	}
}

but the typing isn't so compatible with Expressions.lambda, which expects a subclass of Function.class and we haven't figured it out

@julianhyde
Copy link
Contributor

In future, please use the jira case number in the first commit message and in the title of the PR. (Yes, that requires that you log a jira case before starting work on the bug. That is a good thing.)

(Too late to change the first commit message now. That would destroy history.)

@julianhyde
Copy link
Contributor

I think Expressions.lambda(BlockStatement, Iterable) will work. If there are zero parameters deduceType will return Function0.class, which is equivalent to java.lang.Supplier. (This code was written before Supplier was added in JDK 8.)

BlockStatement will probably contain a single statement, a GotoStatement with your expression, which you will create using Expressions.return_.

@olivrlee
Copy link
Contributor Author

I'm still in the middle of cleaning up the PR, thanks for reviewing @zoudan

Do you have any thoughts on SqlSyntax.SPECIAL?
It should be SPECIAL, but the operator table lookup currently doesn't look for SPECIAL syntax functions, so that was just a temporary workaround.

@olivrlee olivrlee marked this pull request as ready for review March 17, 2023 22:00
@olivrlee olivrlee requested a review from julianhyde March 17, 2023 22:00
@olivrlee olivrlee requested review from zoudan and removed request for julianhyde March 17, 2023 22:10
@olivrlee olivrlee requested review from julianhyde and removed request for zoudan March 17, 2023 22:13
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

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

83.6% 83.6% Coverage
14.9% 14.9% Duplication

@julianhyde
Copy link
Contributor

@olivrlee Can you review my additional commits? I was able to solve the SPECIAL issue

@asfgit asfgit closed this in 093fa7b Mar 22, 2023
@olivrlee
Copy link
Contributor Author

I did take a look but communicated to Julian offline*

julianhyde added a commit that referenced this pull request Mar 22, 2023
SAFE_CAST is similar to CAST, except that it returns NULL
rather than throwing an error if conversion fails.

The Java code generation generates the same code as for CAST,
wraps it as a lambda, and converts the exception to Java null.

Add a wrapper around SqlOperatorFixture so that existing
tests for CAST can also test SAFE_CAST (Julian Hyde).

Close #3093

Co-authored-by: Oliver Lee <[email protected]>
Co-authored-by: Julian Hyde <[email protected]>
julianhyde added a commit to julianhyde/calcite that referenced this pull request May 16, 2024
SAFE_CAST is similar to CAST, except that it returns NULL
rather than throwing an error if conversion fails.

The Java code generation generates the same code as for CAST,
wraps it as a lambda, and converts the exception to Java null.

Add a wrapper around SqlOperatorFixture so that existing
tests for CAST can also test SAFE_CAST (Julian Hyde).

Close apache#3093

Co-authored-by: Oliver Lee <[email protected]>
Co-authored-by: Julian Hyde <[email protected]>
julianhyde added a commit to julianhyde/calcite that referenced this pull request May 19, 2024
SAFE_CAST is similar to CAST, except that it returns NULL
rather than throwing an error if conversion fails.

The Java code generation generates the same code as for CAST,
wraps it as a lambda, and converts the exception to Java null.

Add a wrapper around SqlOperatorFixture so that existing
tests for CAST can also test SAFE_CAST (Julian Hyde).

Close apache#3093

Co-authored-by: Oliver Lee <[email protected]>
Co-authored-by: Julian Hyde <[email protected]>
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