-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Push CAST into PostgreSQL #11522
Push CAST into PostgreSQL #11522
Conversation
78076b2
to
4df9597
Compare
Adding this to connector expressions seems like right thing to do. |
@findepi that's why I've left it up to connector to decide how this should be mapped so proper type semantic can be guaranteed |
@wendigo would you be OK separating |
@findepi sure |
core/trino-main/src/main/java/io/trino/sql/planner/ConnectorExpressionTranslator.java
Outdated
Show resolved
Hide resolved
4df9597
to
7ca6319
Compare
This will be rebased or reworked when #11551 is merged |
Marked as draft, as it depends on #11551 |
7ca6319
to
6f07eee
Compare
@findepi ptal |
plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/expression/RewriteCast.java
Outdated
Show resolved
Hide resolved
plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/expression/RewriteCast.java
Outdated
Show resolved
Hide resolved
plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/expression/RewriteCast.java
Outdated
Show resolved
Hide resolved
plugin/trino-postgresql/src/main/java/io/trino/plugin/postgresql/PostgreSqlClient.java
Outdated
Show resolved
Hide resolved
plugin/trino-base-jdbc/src/main/java/io/trino/plugin/jdbc/expression/RewriteCast.java
Outdated
Show resolved
Hide resolved
plugin/trino-postgresql/src/main/java/io/trino/plugin/postgresql/PostgreSqlClient.java
Outdated
Show resolved
Hide resolved
plugin/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlClient.java
Show resolved
Hide resolved
plugin/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlClient.java
Outdated
Show resolved
Hide resolved
...n/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlConnectorTest.java
Outdated
Show resolved
Hide resolved
plugin/trino-postgresql/src/test/java/io/trino/plugin/postgresql/TestPostgreSqlClient.java
Outdated
Show resolved
Hide resolved
6f07eee
to
2c15e41
Compare
} | ||
|
||
try { | ||
return Optional.ofNullable(this.toWriteMapping(connectorSession, type).getDataType()); |
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.
Delegating to toWriteMapping
isn't generally safe correct, hence the exclusions above.
The code may be producing correct results today (i haven't checked), but is error prone: any new addition or change in toWriteMapping
may the code to work incorrectly, without any test failing. Thus, the delegation here is error-prone.
For example, let's say i add support for TIMESTAMP_PICOS in toWriteMapping
... (actually, it's already there...).
Instead,
- let's call this method
mapTypeForCast
- let's explicitly define which types we support for CAST pushdown; for these, we don't need to delegate to
toWriteMapping
, since we know the mapping - let's have a test coverage for every supported type.
- Maybe
io.trino.testing.BaseConnectorTest#testDataMappingSmokeTest
could exercise query correctness (obvious when pushdown doesn't happen, but important to test when it does)
{BIGINT, "bigint"}, | ||
{TIMESTAMP_TZ_SECONDS, "timestamptz(0)"}, | ||
{TIMESTAMP_TZ_MICROS, "timestamptz(6)"}, | ||
{JsonType.JSON, "jsonb"}, |
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 this be imported statically?
@Test | ||
public void testCastPushdown() | ||
{ | ||
assertThat(query("SELECT name FROM nation WHERE CAST(nationkey + regionkey AS varchar) = '3'")) |
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.
nice test case!
👋 @wendigo - this PR is inactive and doesn't seem to be under development. If you'd like to continue work on this at any point in the future, feel free to re-open. |
Let's discuss if it is safe approach to let decide connector if it can cast on its side.