Skip to content

Allow user to control how unsupported JDBC type should be handled#1182

Merged
kokosing merged 2 commits intotrinodb:masterfrom
kokosing:origin/master/145_display_unknown_types
Dec 10, 2019
Merged

Allow user to control how unsupported JDBC type should be handled#1182
kokosing merged 2 commits intotrinodb:masterfrom
kokosing:origin/master/145_display_unknown_types

Conversation

@kokosing
Copy link
Copy Markdown
Member

@kokosing kokosing commented Jul 25, 2019

No description provided.

@cla-bot cla-bot bot added the cla-signed label Jul 25, 2019
@kokosing
Copy link
Copy Markdown
Member Author

Better version of #1105

@kokosing kokosing requested review from electrum and findepi and removed request for electrum July 25, 2019 12:44
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be extracted to a helper method:

checkNull(block, position);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a session toggle here. Otherwise SELECT * .. LIMIT 1 isn't going to work.
Add tests for the session toggle.

Also, no INSERT statements are going to work (even ones specifying column names), due to #1185.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will address that in separate commit.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can assume table creation is always in the form of CREATE TABLE table_name ....
See how @kokosing did this in io.prestosql.plugin.sqlserver.TestSqlServerIntegrationSmokeTest#withTable

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to use TestTable because it generates unique name. Here, it is not a problem, however recently I got several issues with tests that are using non unique name so I try to push the new convention.
Once you have an unique name you need something more than AutoCloseable.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's orthogonal. You can return TestTable that a) is autocloseable and b) has generated name, all without having people ever touch {TABLE_NAME} constant

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. {TABLE_NAME} got removed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can try do this without nested try-catch, i.e. try with try:

catch (Exception e) {
   try (AutoCloseable self = this) {
      throw e;
   }
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied the first part.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define ctor where data is String without Optional

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use some more esoteric data type? We should support PostgreSQL's GEOMETRY.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I am using testing H2. Other types would need to add some plugins to h2. Do you think that presto-base-jdbc is going to support GEOMETRY some day?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should succeed. #1185
Add a TODO

@kokosing kokosing force-pushed the origin/master/145_display_unknown_types branch from c43bde5 to d6d9dc9 Compare July 26, 2019 11:07
Copy link
Copy Markdown
Member Author

@kokosing kokosing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed comments. Also add session properties to ignore and convert unsupported types to varchar.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I am using testing H2. Other types would need to add some plugins to h2. Do you think that presto-base-jdbc is going to support GEOMETRY some day?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied the first part.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will address that in separate commit.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to use TestTable because it generates unique name. Here, it is not a problem, however recently I got several issues with tests that are using non unique name so I try to push the new convention.
Once you have an unique name you need something more than AutoCloseable.

@kokosing kokosing force-pushed the origin/master/145_display_unknown_types branch 4 times, most recently from 04e972c to f91965c Compare July 29, 2019 10:45
@kokosing
Copy link
Copy Markdown
Member Author

@findepi ping

@electrum
Copy link
Copy Markdown
Member

The unknown type part needs @martint to review it. My memory is that this is an internal detail which shouldn’t be exposed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think IGNORE should be the default.

@findepi
Copy link
Copy Markdown
Member

findepi commented Jul 31, 2019

Regarding the default behavior (https://github.com/prestosql/presto/pull/1182/files#r309276154), let me quote my comment from previous PR (#1105 (comment)):

I propose a different new behavior:

  • expose all columns, including those unsupported (perhaps as unknown type)
  • fail query only when it accesses unsupported columns (either explicitly, or SELECT *)

Regarding default behavior, there are different use-cases for SELECT *:

  1. copying/migrating data (usually CREAT TABLE .. AS SELECT * FROM ..)

    • in this case, the new behavior is more appropriate
  2. poking around (usually SELECT * FROM .. LIMIT 1)

    • in this case, the current behavior is more appropriate

Since current behavior is more appropriate in certain use-cases, I would not change current default behavior.

@kokosing
Copy link
Copy Markdown
Member Author

kokosing commented Aug 1, 2019

The unknown type part needs @martint to review it. My memory is that this is an internal detail which shouldn’t be exposed.

Notice that:

presto:tiny> select typeof(null);
  _col0
---------
 unknown
(1 row)

To me it is like regular type, which may have only single value null.

@kokosing kokosing force-pushed the origin/master/145_display_unknown_types branch from f91965c to 4ec0c00 Compare August 1, 2019 09:01
@kokosing
Copy link
Copy Markdown
Member Author

kokosing commented Aug 1, 2019

I think IGNORE should be the default.

@findepi done.

@kokosing kokosing changed the title Display unknown JDBC type as UnknownType Allow to display unknown JDBC type as UnknownType Aug 5, 2019
@kokosing kokosing force-pushed the origin/master/145_display_unknown_types branch from 4ec0c00 to 222640d Compare August 6, 2019 11:35
@findepi
Copy link
Copy Markdown
Member

findepi commented Aug 6, 2019

cc @guyco33 . In particular the CONVERT_TO_VARCHAR option. This is related to yours #186

Copy link
Copy Markdown
Member

@findepi findepi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kokosing Regarding CONVERT_TO_VARCHAR option, please see previous discussion at #186 > "future-compatibility".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline sessionProperties

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not handle the conversion in jdbcClient.toPrestoType?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

columnMapping.orElseGet ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add

assertQuery("SELECT * FROM " + table.getName(), "VALUES 1");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from... from where?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use more descriptive column names, eg regular_column, unsupported_column.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a test
SELECT * FROM .. WHERE x = 'wrong value'

make sure PPD is disbaled then

@kokosing kokosing force-pushed the origin/master/145_display_unknown_types branch from 222640d to 4199d27 Compare November 26, 2019 13:10
@kokosing kokosing changed the title Allow to display unknown JDBC type as UnknownType Allow user to control how unsupported JDBC type should be handled Nov 26, 2019
@kokosing
Copy link
Copy Markdown
Member Author

@findepi Please notice that even if we have jdbc-types-mapped-to-varchar then unsupported-type-handling=CONVERT_TO_VARCHAR is still useful for cases where underlying type does not fit Presto type. Like DECIMAL(180,40), where user would like to keep regular DECIMAL mapping but handle this particular type as VARCHAR.

@guyco33
Copy link
Copy Markdown
Member

guyco33 commented Nov 26, 2019

Would be helpful for #2088
Users will be able to query DECIMAL column values of precision larger than 38

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is handled in toPrestoType. Here we should validate:

default:
checkState(unsupportedTypeHandling != CONVERT_TO_VARCHAR);

Copy link
Copy Markdown
Member

@findepi findepi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@electrum do you want to check the piece around unknown type and SPI?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be sufficient to add a const to StandardTypes instead of moving the class

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

incl whole typeHandle

also you can pull column name from io.prestosql.plugin.jdbc.JdbcOutputTableHandle#columnNames

you can inline columnMapping now

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Unsupported data type for column: "

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MAP_TO_UNKNOWN ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null -> NULL

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: tt

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rebase

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

old version; rebase

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as a test in postgres, with decimal(129567) or sth

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i am not convinced this is a needed functionality. let's discuss

@kokosing kokosing force-pushed the origin/master/145_display_unknown_types branch 2 times, most recently from 7234415 to ccc636c Compare December 4, 2019 13:26
@kokosing
Copy link
Copy Markdown
Member Author

kokosing commented Dec 4, 2019

Applied comments. I removed options to map to unknown type and failing the query. Let's us revisit that later if needed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this needs to move too

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Unsupported type handling is set to %s, but toPrestoType() returned empty"

also

verify(columnMapping.isPresent() || getUnsupportedTypeHandling(session) == IGNORE, .. so that you can place it above, without else

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"is force mapped to" is not applicable wording when type is unsupported

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"unsupported type" -> "an unsupported type"

or, rather, just "Unsupported type handling strategy", as in sess prop desc

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert? i think this should be "unreachable" now

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the code here is so different than in super.?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private; this class is not expected to be extended

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could what?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

withUnsupportedType ?

@kokosing kokosing force-pushed the origin/master/145_display_unknown_types branch from ccc636c to 98af532 Compare December 5, 2019 15:09
@kokosing
Copy link
Copy Markdown
Member Author

kokosing commented Dec 5, 2019

Addressed comments. Thank you!

@kokosing kokosing force-pushed the origin/master/145_display_unknown_types branch from 98af532 to 51860ff Compare December 6, 2019 08:40
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use import static com.google.common.base.Verify.verify

@kokosing kokosing force-pushed the origin/master/145_display_unknown_types branch from 51860ff to 213d81e Compare December 9, 2019 19:46
@kokosing kokosing force-pushed the origin/master/145_display_unknown_types branch from 213d81e to 9e59703 Compare December 10, 2019 08:28
@kokosing kokosing merged commit c32fed1 into trinodb:master Dec 10, 2019
@kokosing kokosing deleted the origin/master/145_display_unknown_types branch December 10, 2019 11:26
@kokosing kokosing mentioned this pull request Dec 10, 2019
7 tasks
@kokosing kokosing added this to the 327 milestone Dec 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants