-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Support integral cast projection pushdown in redshift #22951
Support integral cast projection pushdown in redshift #22951
Conversation
case Types.TINYINT: | ||
// TODO what will be the impact here after enabling this | ||
// -- Redshift doesn't support tinyint | ||
return Optional.of(tinyintColumnMapping()); |
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.
IIUC this will be just a dead code.
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.
If Redshift doesn't support tinyint - how would the cast would look like ?
if (isDecimalType(sourceType) && isIntegralType(targetType)) { | ||
return "CAST(ROUND(%s) AS %s)".formatted(expression, castType); | ||
} |
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.
I have some doubts if the trino behaviour is a correct one.
Do you know the internals of the trino behaviour?
Maybe at least add a comment here to match trino behaviour
? Not sure if it's helpful (kind of obvious if comment exists, and not that obvious if not)
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.
In Trino cast from double
to any other type we use DoubleOperators
and here is one example where casting from double to long roundup the value.
return DoubleMath.roundToLong(value, HALF_UP); |
Anyway, we will not support Float/Double value cast to other types, since for NaN
and Infinity
values we are getting behavior deference between with and without pushdown.
55d618d
to
1761934
Compare
Hi @ebyhr | @Praveen2112 Could you please run this PR with secrets? |
@krvikash Sure, but did you miss adding |
1761934
to
4c2701c
Compare
Thanks @ebyhr for reminding me. Added test in |
/test-with-secrets sha=4c2701c4942bf52adc08044fef48887489eb020b |
The CI workflow run with tests that require additional secrets finished as failure: https://github.com/trinodb/trino/actions/runs/10370817481 |
This pull request has gone a while without any activity. Tagging the Trino developer relations team: @bitsondatadev @colebow @mosabua |
Once #22728 is merged, I will continue working on this PR. |
4c2701c
to
ef7405b
Compare
(rebased with master) |
ef7405b
to
1d0542e
Compare
(fix error prone check) |
plugin/trino-redshift/src/test/java/io/trino/plugin/redshift/TestRedshiftConnectorTest.java
Outdated
Show resolved
Hide resolved
1d0542e
to
92d9563
Compare
Hi @ebyhr Could you please run this PR against secrets? |
/test-with-secrets sha=92d956338dfa3d357483d8297fe06a4b2e6d94b5 |
9aebd47
to
f6cb700
Compare
(uncommented the test) |
The PR is ready for another round of review. |
plugin/trino-redshift/src/test/java/io/trino/plugin/redshift/TestRedshiftCastPushdown.java
Outdated
Show resolved
Hide resolved
plugin/trino-redshift/src/test/java/io/trino/plugin/redshift/TestRedshiftCastPushdown.java
Outdated
Show resolved
Hide resolved
f6cb700
to
186e231
Compare
Thanks @mayankvadariya for the review. Refactored the test cases. |
186e231
to
a80b450
Compare
(rebased with master) |
plugin/trino-redshift/src/main/java/io/trino/plugin/redshift/RewriteCast.java
Outdated
Show resolved
Hide resolved
return "CAST(%s AS %s)".formatted(expression, castType); | ||
} | ||
|
||
private boolean isIntegralType(Type type) |
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.
Isn't this check redundant ?
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 redundant as of now since with this PR we are only supporting integral type cast. This is to ensure that in future if we are supporting other types (like varchar
) then we should not fall under CAST(ROUND(%s) AS %s)
.
plugin/trino-redshift/src/test/java/io/trino/plugin/redshift/TestRedshiftCastPushdown.java
Outdated
Show resolved
Hide resolved
plugin/trino-redshift/src/test/java/io/trino/plugin/redshift/TestRedshiftCastPushdown.java
Outdated
Show resolved
Hide resolved
case Types.TINYINT: | ||
// -- Redshift doesn't support tinyint, but requires | ||
// tinyint data type mapping for CAST pushdown | ||
return Optional.of(tinyintColumnMapping()); |
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.
We map that column as smallint
and read them as tinyint
so things would fail at the time of reading ? What if the expression is hidden within the query like some sort of a filter and this column doesn't need to be read by the underlying system.
public void setupTable() | ||
{ | ||
left = closeAfterClass(CastDataTypeTestTable.create(3) | ||
.addColumn("id", "int", asList(11, 12, 13)) |
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.
As a follow-up I think it would be nice if we could capture the cast equivalent data so it would be easy to know on how cast would end up
a80b450
to
d93fc2d
Compare
Thanks @Praveen2112 for the review. ACs. |
new InvalidCastTestCase("c_decimal_16", "bigint", "Cannot cast '9223372036854775808.49' to BIGINT", "(?s).*Value out of range for 8 bytes(?s).*"), | ||
|
||
// No pushdown for double datatype to integral types | ||
new InvalidCastTestCase("c_infinity_1", "tinyint", "Out of range for tinyint: Infinity"), |
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.
How does Trino handles it out without this pushdown enabled ?
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 uses DoubleOperators#castToTinyint
for casting
trino/core/trino-main/src/main/java/io/trino/type/DoubleOperators.java
Lines 147 to 158 in 3c20a5c
public static long castToTinyint(@SqlType(StandardTypes.DOUBLE) double value) | |
{ | |
if (Double.isNaN(value)) { | |
throw new TrinoException(INVALID_CAST_ARGUMENT, "Cannot cast double NaN to tinyint"); | |
} | |
try { | |
return SignedBytes.checkedCast((long) MathFunctions.round(value)); | |
} | |
catch (IllegalArgumentException e) { | |
throw new TrinoException(NUMERIC_VALUE_OUT_OF_RANGE, "Out of range for tinyint: " + value, e); | |
} | |
} |
plugin/trino-redshift/src/test/java/io/trino/plugin/redshift/TestRedshiftCastPushdown.java
Outdated
Show resolved
Hide resolved
plugin/trino-redshift/src/test/java/io/trino/plugin/redshift/TestRedshiftCastPushdown.java
Outdated
Show resolved
Hide resolved
protected List<InvalidCastTestCase> invalidCast() | ||
{ | ||
return ImmutableList.of( | ||
new InvalidCastTestCase("c_varchar_decimal", "integer"), |
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.
Can we capture the error message on Trino and redshift side ?
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.
These data types in invalidCast
does not get pushdown, So can't capture the error message here. Trino Error message (.*)Cannot cast (.*) to (.*)
is already mentioned inside InvalidCastTestCase
. Should be explicitly mention error message here?
@krvikash Lets update the PR description as well |
d93fc2d
to
f37d54c
Compare
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.
% comment
plugin/trino-redshift/src/test/java/io/trino/plugin/redshift/TestRedshiftCastPushdown.java
Outdated
Show resolved
Hide resolved
f37d54c
to
b5c69fa
Compare
@Praveen2112 can you please run this PR against secrets? |
/test-with-secrets sha=b5c69fafda2e99316c2a501e786d08978b6bad9b |
The CI workflow run with tests that require additional secrets has been started: https://github.com/trinodb/trino/actions/runs/11348864763 |
Passed |
Description
This PR adds support for cast projection pushdown for the Oracle connector. This uses the framework introduced in #22203 for cast projection pushdown.
Currently, this PR only adds support for the
SMALLINT
,INT
,BIGINT
type cast pushdown.The below Source type can be cast pushdown to
SMALLINT
,INT
,BIGINT
typeOther source types not listed above are not supported for cast pushdown.
Release notes
(X) Release notes are required, with the following suggested text: