Map PostgreSQL JSON, JSONB to Presto JSON#81
Conversation
d80ab2c to
2e0f193
Compare
|
Whereas I could SELECT json from postgresql using this commit, CTAS failed with below message. |
|
@ebyhr I already encountered this issue when I first used it to CTAS in postgres catalog and solved it by appending |
|
Sorry, my update's notication might have not been sent you. I tried same thing as @guyco33 commented, it works in my environment too. |
5085008 to
a9bad83
Compare
|
@findepi Now after merging #109 the pushdown predicate in QueryBuilder (https://github.com/prestosql/presto/pull/109/files#diff-88e8a0a25b51f372e2a50ab027085b33) picks also JSON types (previously it was prevented by |
findepi
left a comment
There was a problem hiding this comment.
Some initial comments.
We will need @electrum review for in/out conversions around JsonType, but please apply my feedback first. Please do all new changes as fixups, so i can re-review (i'll let you know when you can squash them).
presto-base-jdbc/src/main/java/io/prestosql/plugin/jdbc/JdbcTypeHandle.java
Outdated
Show resolved
Hide resolved
presto-postgresql/src/test/java/io/prestosql/plugin/postgresql/PostgreSqlQueryRunner.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
I recall @electrum's comment saying the JsonType should not be moved to SPI
prestodb/presto#11913 (comment)
(i didn't review this class, i think there were some changes that would require review)
There was a problem hiding this comment.
@findepi Should I create a new JsonType in SPI and use the signature to correlate them ?
There was a problem hiding this comment.
I assume we don't want to push down JSON predicates. Otherwise this requires extensive testing that this does not change query semantics, while this is likely not very needed feature.
To disable pushdown, use ColumnMapping.sliceMapping overload which takes UnaryOperator<Domain> pushdownConverter and pass domain -> Domain.all(domain.getType()) as the converter. Or better, rebase on #225 and use DISABLE_PUSHDOWN constant.
There was a problem hiding this comment.
I disabled pushdown and SELECT * FROM test_json where json_column = json'{"x":123}' still fails on Domain type must be orderable
There was a problem hiding this comment.
@findepi It works while skipping
builder.add(toPredicate(column.getColumnName(), domain, column, accumulator))inio.prestosql.plugin.jdbc.QueryBuilderwhen domain type is not orderable:
private List<String> toConjuncts(JdbcClient client, ConnectorSession session, List<JdbcColumnHandle> columns, TupleDomain<ColumnHandle> tupleDomain, List<TypeAndValue> accumulator)
{
ImmutableList.Builder<String> builder = ImmutableList.builder();
for (JdbcColumnHandle column : columns) {
Domain domain = tupleDomain.getDomains().get().get(column);
if (domain != null) {
domain = pushDownDomain(client, session, column, domain);
if (domain.getType().isOrderable()) {
builder.add(toPredicate(column.getColumnName(), domain, column, accumulator));
}
}
}
return builder.build();
}
There was a problem hiding this comment.
| value -> format("JSON'%s'", value), | |
| value -> format("JSON '%s'", value), |
There was a problem hiding this comment.
This actually applies to in a few places in your test queries. Also, by a convention, we always uppercase type name in type constructors like JSON '....' rather than json '...' (or json'...'.)
presto-tests/src/main/java/io/prestosql/tests/H2QueryRunner.java
Outdated
Show resolved
Hide resolved
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
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
findepi
left a comment
There was a problem hiding this comment.
PIng me when you address all my comments (or when you feel blocked).
presto-postgresql/src/test/java/io/prestosql/plugin/postgresql/TestPostgreSqlTypeMapping.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
replace jsonPushdown() method with io.prestosql.plugin.jdbc.ColumnMapping#DISABLE_PUSHDOWN (static-import it)
here you're changing domain's type. Why so?
There was a problem hiding this comment.
I see the reason now. Can you check if #238 is sufficient? I didn't test that change with your code.
There was a problem hiding this comment.
Your fix works for me. Thanks!
There was a problem hiding this comment.
nit: format with each arg on separate line, for readability
ColumnMapping.sliceMapping(
JSON,
(resultSet, columnIndex) -> jsonParse(utf8Slice(resultSet.getString(columnIndex))),
jsonWriteFunction(),
jsonPushdown());
|
Thanks for the fixups, that was helpful. You can squash what you have so far. |
findepi
left a comment
There was a problem hiding this comment.
Please squash the fixups you have so far.
There was a problem hiding this comment.
| domain -> Domain.all(domain.getType())); | |
| DISABLE_PUSHDOWN); |
00c2319 to
6748f0b
Compare
|
Sorry for the confusion and delay on this PR. We'd like to get this in, but there are two main things to resolve:
Please update the commit title to "Map PostgreSQL JSON to Presto JSON" |
|
For the JSON type constructor, it will likely be several weeks before the function and constructor PRs will land, so we can move forward on this PR using the duplicated code (and clean it up later). We do still need to revert the part about moving To get access to
Then in the |
|
@guyco33 Thanks for your work on this so far. Please let me know when you've updated the PR so that we can do a final review and merge. Feel free to ping me on Slack if you have any questions. |
There was a problem hiding this comment.
The comparison below needs to be against JsonType.JSON
electrum
left a comment
There was a problem hiding this comment.
A few minor comments, otherwise this looks good. Please address the comments and squash into a single commit.
There was a problem hiding this comment.
Make this protected final (no static) since it is initialized in the constructor
There was a problem hiding this comment.
I need it to be static since it used in private static ColumnMapping jsonColumnMapping()
There was a problem hiding this comment.
Make that method non-static. Initializing a static field from a constructor is problematic.
There was a problem hiding this comment.
Why the 2 at the end? I don't see any other usages of this name
There was a problem hiding this comment.
tpch.postgresql_test_json used to be there before :) Fixed
There was a problem hiding this comment.
Nit: add space after , and lowercase column and table names (but keep SQL keywords in uppercase)
There was a problem hiding this comment.
Nit: static import dataType and identity
There was a problem hiding this comment.
This doesn't work if the value has single quotes, but that's probably fine for this test
There was a problem hiding this comment.
value -> {
checkArgument(!value.contains("'"));
return format("JSON '%s'", value);
}
There was a problem hiding this comment.
Make this private since it's not used elsewhere
There was a problem hiding this comment.
You can use JsonType.JSON here since it is available to test code
There was a problem hiding this comment.
Same, this can use JsonType.JSON
a58aed2 to
8b27ae4
Compare
electrum
left a comment
There was a problem hiding this comment.
This is ready to merge. GitHub is showing a merge conflict, please rebase and then I'll merge it.
There was a problem hiding this comment.
I don't think we need to check the JDBC type here. The switch on the type name should be sufficient.
8b27ae4 to
653ee44
Compare
|
@guyco33 congrats! |
No description provided.