Fix pushdown filter for PostgreSQL enum type#408
Conversation
presto-postgresql/src/test/java/io/prestosql/plugin/postgresql/TestPostgreSqlTypeMapping.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/test/java/io/prestosql/plugin/postgresql/TestPostgreSqlTypeMapping.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
You can retrieve JdbcColumnHandle from 4th argument JdbcColumnHandle column. Why don't you reuse the exising argument?
There was a problem hiding this comment.
Here it's just the function's signature. I am using the actual 4th argument in the apply in the return clause
There was a problem hiding this comment.
Sorry, my comment was not enough. I meant we can change the type to Optional<String> bindingPlaceholder or boolean and then change like below. This is just my idea, therefore let's wait for other member's review. I understand your implementation is opened for future changes.
bindingPlaceholder.map(bind -> bind + column.getJdbcTypeHandle().getJdbcTypeName()).orElse("?")There was a problem hiding this comment.
Function<JdbcColumnHandle, String> is much generic and the connector can also pass function that results with something like this: "cast(? as typeName)"
There was a problem hiding this comment.
I agree with the generics. I wanted to avoid optional-functional argument. Let's follow kokosing's suggestion.
presto-postgresql/src/main/java/io/prestosql/plugin/postgresql/PostgreSqlClient.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
- No point to pass
Optionalhere. You can always pass function that always return"?" - Can you make it a field of
QueryBuilder, this function should not changed between queries, right?
presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/QueryBuilder.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
please extract (columnHandle) -> "?::" + columnHandle.getJdbcTypeHandle().getJdbcTypeName() as method, then replace it with this::yourNewMethodName
There was a problem hiding this comment.
Please format this like:
assertQuery(
"SELECT column_name, data_type FROM information_schema.columns WHERE table_schema = 'tpch' AND table_name = 'test_enum'",
"VALUES ('id','integer'),('col_s','varchar'),('col_e','varchar')");
099d29b to
73c5d04
Compare
|
@guyco33 I think we should investigate alternatives within existing framework before committing to this approach. |
|
Thanks @findepi for your feedback! How are we going to filter enum types in I've pushed a fixup to illustrate it |
findepi
left a comment
There was a problem hiding this comment.
Thanks @guyco33!
Looks better to me and lower risk of side effects.
Some comments. Then we need to look into how to pull "is enum" information more directly.
Can you please check what are the other types that show up as Types.VARCHAR in Postgres?
There was a problem hiding this comment.
Call it typedVarcharWriteFunction. Name is not perfect, but at least it signals some varchar-like Slice and UTF-8 decoding takes place.
There was a problem hiding this comment.
just typedStringWriteFunction("json"), there is no need to use jdbcTypeName here
There was a problem hiding this comment.
This was writing JSON as "json", not "jsonb".
Please use "json". If your change is intentional, please extract to a separate commit
There was a problem hiding this comment.
Can you revert changes related to "bindingPlaceholder"?
There was a problem hiding this comment.
For now add explanatory comment here:
// This can be e.g. an ENUM
There was a problem hiding this comment.
Once you cleanup, I will see whether we can pull "is enum" information in some better way.
presto-postgresql/src/test/java/io/prestosql/plugin/postgresql/TestPostgreSqlTypeMapping.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
call it typedVarcharColumnMapping
findepi
left a comment
There was a problem hiding this comment.
@guyco33 good job!
I looked into how to improve/replace if (typeHandle.getJdbcType() == Types.VARCHAR && !typeHandle.getJdbcTypeName().equals("varchar")), but neither information_schema.columns nor pg_attribute didn't seem to explicitly say "this is enum".
Let's leave it as it is.
Several minor comments in the test code. Otherwise LGTM.
Please squash everything into single commit.
There was a problem hiding this comment.
nit: upper case "AS ENUM" as in Postgres docs https://www.postgresql.org/docs/11/datatype-enum.html
3d07187 to
e545fba
Compare
select * from pg_type where typcategory = 'E' and typname='enum_t' |
|
Merged, thanks! |
Filters on PostgreSQL enum type are failing since they are pushdown to connector (enum type is considered as a Jdbc VARCHAR type:
JdbcTypeHandle.jdbcType=java.sql.Types.VARCHAR ,JdbcTypeHandle.jdbcTypeName=<name of user-defined enum type>)In order to fix it and keep the pushdown, a cast to the proper typeName is implemented by passing a proper bindingPlaceholder