-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NIFI-3093 HIVE Support for QueryDatabaseTable #1281
Conversation
@@ -186,8 +186,10 @@ public void onTrigger(final ProcessContext context, final ProcessSessionFactory | |||
try (final Connection con = dbcpService.getConnection(); | |||
final Statement st = con.createStatement()) { | |||
|
|||
final Integer queryTimeout = context.getProperty(QUERY_TIMEOUT).asTimePeriod(TimeUnit.SECONDS).intValue(); | |||
st.setQueryTimeout(queryTimeout); // timeout in seconds | |||
if(dbAdapter.getSupportsStatementTimeout()) { |
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.
This makes sense to me, but when we were talking about supporting Hive in ExecuteSQL, there were concerns about those drivers that don't support statement timeouts, which is one reason why there's a separate Hive NAR (and Select/PutHiveQL processors). This was before DatabaseAdapter came along, so perhaps now this can be alleviated as you've done here. Does this work when using a HiveConnectionPool? Or are you using a DBCPConnectionPool that points to Hive JARs? It seems like if this works with a HiveConnectionPool (with your changes to JdbcCommon below), then the Select/PutHiveQL processors could be deprecated.
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.
I used a HiveConnectionPool. Still easiest way to handle Kerberos, custom Hive-Site.xml, etc...
@@ -284,7 +291,7 @@ public static Schema createSchema(final ResultSet rs, String recordName, boolean | |||
break; | |||
|
|||
case INTEGER: | |||
if (meta.isSigned(i)) { | |||
if (!dbAdapter.getSupportsMetaDataColumnIsSigned() || meta.isSigned(i)) { |
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.
If the DB doesn't support isSigned(), should we treat them all as Longs? I assume it's done this way if Hive returns INTEGER as the type and Integer objects for values. I wonder if there's another DB that doesn't support isSigned() and could return Long objects. In that case we might want another check for getSupportsMetaDataColumnIsSigned() (and for the type of object) when storing the values into the record.
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.
Your spot on. Originally I had this without the !
, but in my table I had an INT and when I tried to put it into an Avro Long field it threw an exception.
@@ -300,7 +307,7 @@ public static Schema createSchema(final ResultSet rs, String recordName, boolean | |||
// Check the precision of the BIGINT. Some databases allow arbitrary precision (> 19), but Avro won't handle that. | |||
// If the precision > 19 (or is negative), use a string for the type, otherwise use a long. The object(s) will be converted | |||
// to strings as necessary | |||
int precision = meta.getPrecision(i); | |||
int precision = dbAdapter.getSupportsMetaDataColumnGetPrecision()?meta.getPrecision(i):0; |
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.
Should we assume a default of zero here or < 0?
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.
Probably -1
would be a safer choice if we can't retrieve precision. HIVE appears to supports up to DECIMAL(38,18), but who knows what might happen with other databases down the road; we don't want to accidentally lose data or start throwing exceptions for overflows.
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.
Looks like we don't need this. I got tired of fighting exceptions one after another and started reading the HIVE JDBC driver code to find unsupported methods. It looks like I misread the code and getPrecision is a supported HIVE JDBC method call.
query.append(limit); | ||
} | ||
if (offset != null && offset > 0) { | ||
query.append(" OFFSET "); |
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.
@mattyb149 I copy/pasted this from the Generic adapter, but from what I can find HIVE has no support for OFFSET
. Do you think this should throw an exception at this stage?
@@ -161,7 +161,7 @@ | |||
.description("The type/flavor of database, used for generating database-specific code. In many cases the Generic type " | |||
+ "should suffice, but some databases (such as Oracle) require custom SQL clauses. ") | |||
.allowableValues(dbAdapters.keySet()) | |||
.defaultValue(dbAdapters.values().stream().findFirst().get().getName()) | |||
.defaultValue("Generic") |
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.
@mattyb149 In case your curious, I found that Generic
may or may not be selected as the default after you start adding new DBAdapters. I ran into this exact issue when I added a new Hive
DBAdapter, so I just hard coded it rather then having the default value possibly change.
Do you mind rebasing this against the latest master? Please and thanks! |
@mattyb149 I am still planning to update this PR. Any chance you could take a look at #1510 first and see if we can get it pulled in? It is simpler and has some direct conflicts/overlap with this PR, I'd rather get it into master before I rebase and cleanup my Hive work. |
#1510 is now merged, do you mind rebasing this one? Please and thanks! |
@mattyb149 I'm working through this. I found a couple of issues that I'm figuring out. |
@mattyb149 I've completed the changes. I added support for GenerateTableFetch, though Hive being hive it's not all that fast... There is one quirk, and I feel it should be documented but I'm not sure where. When using QueryDatabaseTable with Hive you need to qualify your max value column with the table name. This is because Hive always qualifies the column names in the ResultSet. Also, as a result of this, you'll need to Normalize the column names. With GenerateTableFetch, since it pulls back the max value through a query and aliases the column name, I don't think the above issue is a problem. ExecuteSQL should work without any special changes, just remember to select a Database Adapter when testing HIVE, this didn't used to be an available option. |
@patricker This PR has now conflicts since #1798 (NIFI-2624: Avro logical types) and others are merged. Would you mind rebasing this? I'd like to review once the merge conflicts get addressed, and test to see if logical types can be used with Hive tables. |
@ijokarumawak I'll work on it. |
@patricker Are you working on this one? If not, perhaps @ijokarumawak or I can take over. |
@mattyb149 @ijokarumawak Thanks for checking in on me. I had planned to work on this, but due to recent shifts at work I don't even use HIVE anymore... If someone wants to put a bow on this I'd appreciate it. |
This update adds HIVE support to
QueryDatabaseTable
.I included a few changes to
GenerateTableFetch
, but these were only for compatability with the new properties added to the DB Adapter interface. This does NOT add support toGenerateTableFetch
for HIVE (as I don't think paging HIVE is possible).I'm expecting this will need a few tweaks, just let me know.
For all changes:
Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
Has your PR been rebased against the latest commit within the target branch (typically master)?
Is your initial contribution a single, squashed commit?
For code changes:
For documentation related changes: