-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Add support to NUMBER to Python UDFs #28901
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ | |
| import static io.trino.testing.TestingHandles.TEST_CATALOG_NAME; | ||
| import static io.trino.testing.TestingSession.testSessionBuilder; | ||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
| import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS; | ||
| import static org.junit.jupiter.api.parallel.ExecutionMode.CONCURRENT; | ||
|
|
||
|
|
@@ -751,6 +752,38 @@ SELECT bad_bigint_return() | |
| "TypeError: 'str' object cannot be interpreted as an integer"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTypeNumber() | ||
| { | ||
| String query = | ||
| """ | ||
| WITH FUNCTION multiply(x number, y number) | ||
| RETURNS number | ||
| LANGUAGE PYTHON | ||
| WITH (handler = 'multiply') | ||
| AS $$ | ||
| from decimal import Decimal | ||
| def multiply(x, y): | ||
| return x * y * Decimal("100000000000000000000.000000000000000000000000000000000000001") | ||
| $$ | ||
| """; | ||
|
|
||
| assertThat(assertions.query( | ||
| query + "SELECT multiply(NUMBER '1.12345', NUMBER '2.54321')")) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please add a test with NULL, NaN and ±Infinity?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NaN and +/- Infinity are not supported by wasm python yet so nothing to test.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the behavior should still be tested, regardless of current behavior |
||
| .matches("VALUES NUMBER '2.8571692745E+20'"); | ||
|
|
||
| // TODO: https://github.com/trinodb/trino-wasm-python/pull/11 | ||
| assertThatThrownBy(() -> assertThat(assertions.query( | ||
| query + "SELECT multiply(NUMBER 'NaN', NUMBER '2.54321')")) | ||
| .matches("VALUES NUMBER 'NaN'")) | ||
| .hasMessageContaining("ValueError: Decimal is not finite: NaN"); | ||
|
|
||
| assertThatThrownBy(() -> assertThat(assertions.query( | ||
| query + "SELECT multiply(NUMBER '-Infinity', NUMBER '2.54321')")) | ||
| .matches("VALUES NUMBER 'NaN'")) | ||
| .hasMessageContaining("ValueError: Decimal is not finite: -Infinity"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTypeInteger() | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the semantics of TrinoType enum?
I don't see javadoc nor usages on it... Why is it safe to present NUMBER as a decimal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a translation between the host and the wasm environment. Types are covered here: https://github.com/trinodb/trino-wasm-python/blob/master/pyhost.h#L10
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to me this looks like we need to expand that enum when a new trino type is added