Add an optional JDBC connector type mapping to varchar#186
Add an optional JDBC connector type mapping to varchar#186guyco33 wants to merge 1 commit intotrinodb:masterfrom
Conversation
|
BTW if we treat an unsupported type as a varchar
|
6e99107 to
b1a19a6
Compare
|
AFAIK most of the use-cases with such non-standard types in Presto are for reading and extracting needed values for analytic processing to gain valuable insights. |
b1a19a6 to
62405ff
Compare
|
I suggest to change the parameter name to
|
|
@guyco33 i don't fully understand. |
|
@findepi nonstandard_types are all the types that are not implemented in |
|
Maybe it will be better to define it with 2 parameters like this:
When |
I don't think this is a sufficient definition.
This is intersting idea. Actually, this could be simplified (we don't need to have two parameters): some concerns:
|
|
@findepi
For example: |
a105792 to
503a36b
Compare
73b057e to
2562c56
Compare
2562c56 to
ce0829e
Compare
e1bede8 to
da4019d
Compare
findepi
left a comment
There was a problem hiding this comment.
As discussed offline:
I would strongly prefer this mapping to be done based on JdbcTypeHandle#jdbcTypeName only, so that we have one, easy to understand configuration toggle.
da4019d to
edee55b
Compare
Using jdbcTypeName only might not be sufficient for RDBMS connectors with types without names. |
@guyco33 i am aware of this. |
|
@guyco33 thanks for checking. So the plan would be:
|
edee55b to
dfcc52c
Compare
d218031 to
774c50c
Compare
774c50c to
22f973c
Compare
22f973c to
68140a1
Compare
163903f to
e26d20f
Compare
f49eb88 to
2867771
Compare
There was a problem hiding this comment.
- You should reset
jdbcTypesMappedToVarcharwhen setter is called. - avoid
String#splitfor all its weirdnesses
this.jdbcTypesMappedToVarchar = ImmutableSet.copyOf(Splitter.on(",").omitEmptyStrings().split(nullToEmpty(jdbcTypesMappedToVarchar)));
There was a problem hiding this comment.
Whops.. add .trimResults() too.
There was a problem hiding this comment.
| this.jdbcTypesMappedToVarchar = jdbcTypesMappedToVarchar; | |
| this.jdbcTypesMappedToVarchar = ImmutableSet.copyOf(requireNonNull(jdbcTypesMappedToVarchar, "jdbcTypesMappedToVarchar is null")); |
There was a problem hiding this comment.
move the new arg right after identifierQuote and connectionFactory (same in assignments below)
(i'm aware the identifierQuote and connectionFactory are misordered)
There was a problem hiding this comment.
Add getter/setter in same order you added the field (ie field is last, so move getter/setter to the end of the class)
There was a problem hiding this comment.
don't fail when type.getJdbcTypeName() is empty
There was a problem hiding this comment.
it won't fail since jdbcTypesMappedToVarchar doesn't contain empty strings
There was a problem hiding this comment.
| assertEquals(expected.getJdbcTypesMappedToVarchar().contains("supported_type"), false); | |
| assertEquals(expected.getJdbcTypesMappedToVarchar(), ImmutableSet.of("mytype", "struct_type1")); |
There was a problem hiding this comment.
This should be handled before calling jdbcTypeToPrestoType, so let's keep it inside JdbcClient and don't change that method.
Since the mapping is not that trivial (eg disabling predicate pushdown), I think a helper method could be useful.
It could be used like that:
Optional<ColumnMapping> mapping = getForcedMappingToVarchar(typeHandle);
if (mapping.isPresent()) {
return mapping;
}
where getForcedMappingToVarchar is defined in BaseJdbcClient:
protected Optional<...> getForcedMappingToVarchar(...) { ... }
There was a problem hiding this comment.
| private Set<String> jdbcTypesMappedToVarchar = new HashSet<>(); | |
| private Set<String> jdbcTypesMappedToVarchar = ImmutableSet.of(); |
There was a problem hiding this comment.
| new HashSet<>()); | |
| ImmutableSet.of()); |
There was a problem hiding this comment.
This needs to be added to MySqlClient and SqlServerClient as well, since they too override toPrestoType()
| this.includeTypeNamesMappingToVarchar = new HashSet<String>(); | ||
| if (typesMappedToVarcharInclude != null) { | ||
| for (String type : typesMappedToVarcharInclude.split(",")) { | ||
| if (typesMap.containsKey(type.toUpperCase())) { |
There was a problem hiding this comment.
toUpperCase(ENGLISH) here and below
| this.typesMappedToVarcharInclude = typesMappedToVarcharInclude; | ||
| this.includeTypesMappingToVarchar = new HashSet<Integer>(); | ||
| this.includeTypeNamesMappingToVarchar = new HashSet<String>(); | ||
| if (typesMappedToVarcharInclude != null) { |
There was a problem hiding this comment.
invert the condition, that way you will avoid long nested blocks
| private Set<Integer> includeTypesMappingToVarchar; | ||
| private Set<String> includeTypeNamesMappingToVarchar; | ||
| private Set<Integer> excludeTypesMappingToVarchar; | ||
| private Set<String> excludeTypeNamesMappingToVarchar; |
There was a problem hiding this comment.
I would extract these collection of the config classes to some new entity like MappingToVarchar. IMO config should not have any logic.
| @@ -115,6 +115,7 @@ public class BaseJdbcClient | |||
|
|
|||
There was a problem hiding this comment.
Please add "end-to-end" test where you SELECT unsupported type as varchar. Maybe to io.prestosql.plugin.jdbc.TestJdbcIntegrationSmokeTest or somewhere close.
There was a problem hiding this comment.
A test in TestPostgreSqlTypeMapping would be nice too.
There was a problem hiding this comment.
please squash the commits. Changes in single PR should not go back and forth.
There was a problem hiding this comment.
:) sorry @kokosing i didn't warn you this has significantly altered since the beginning
There was a problem hiding this comment.
Please move this up, after this.connectionFactory =
There was a problem hiding this comment.
Sorry, missed that one ...
There was a problem hiding this comment.
if (typeHandle.getJdbcTypeName().isPresent() && jdbcTypesMappedToVarchar.contains(typeHandle.getJdbcTypeName().get()))
presto-base-jdbc/src/test/java/io/prestosql/plugin/jdbc/TestBaseJdbcConfig.java
Outdated
Show resolved
Hide resolved
35644d3 to
21bae0e
Compare
21bae0e to
50276f2
Compare
|
Merged as 52c7c39, thanks! I fixed an unused import and introduced |
Add optional catalog parameters that map Jdbc types to varchar:
jdbc-types-mapped-to-varchar = jdbcTypeName[,jdbcTypeName[,...]]Now catalogs can control whether or not to fetch unsupported Presto types and to stay compatible when future support will be implemented.
For example:
PostgreSQL catalog with the following configuration will map
tsrangeandinetto Presto VARCHAR:jdbc-types-mapped-to-varchar = tsrange,inetRef prestodb/presto#11833