You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by patricker <gi...@git.apache.org> on 2016/11/29 22:03:37 UTC

[GitHub] nifi pull request #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

GitHub user patricker opened a pull request:

    https://github.com/apache/nifi/pull/1281

    NIFI-3093 HIVE Support for QueryDatabaseTable

    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 to `GenerateTableFetch` 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:
    - [x] Is there a JIRA ticket associated with this PR? Is it referenced 
         in the commit message?
    
    - [x] 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.
    
    - [x] Has your PR been rebased against the latest commit within the target branch (typically master)?
    
    - [x] Is your initial contribution a single, squashed commit?
    
    ### For code changes:
    - [ ] Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
    - [ ] Have you written or updated unit tests to verify your changes?
    - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? 
    - [ ] If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
    - [ ] If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?
    - [ ] If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?
    
    ### For documentation related changes:
    - [ ] Have you ensured that format looks appropriate for the output in which it is rendered?
    


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/patricker/nifi NIFI-3093

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/nifi/pull/1281.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1281
    
----
commit b11b10029caeeccdfcf7f16fed4c0ab57e15ee72
Author: patricker <pa...@gmail.com>
Date:   2016-11-23T17:48:23Z

    NIFI-3093

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1281#discussion_r90272836
  
    --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GenerateTableFetch.java ---
    @@ -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()) {
    --- End diff --
    
    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.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1281#discussion_r90273518
  
    --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/JdbcCommon.java ---
    @@ -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)) {
    --- End diff --
    
    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.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

Posted by patricker <gi...@git.apache.org>.
Github user patricker commented on the issue:

    https://github.com/apache/nifi/pull/1281
  
    @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 QueryDatabaseAdapter 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.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

Posted by patricker <gi...@git.apache.org>.
Github user patricker commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1281#discussion_r90277545
  
    --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/JdbcCommon.java ---
    @@ -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)) {
    --- End diff --
    
    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.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on the issue:

    https://github.com/apache/nifi/pull/1281
  
    Do you mind rebasing this against the latest master? Please and thanks!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

Posted by patricker <gi...@git.apache.org>.
Github user patricker commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1281#discussion_r90278242
  
    --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/db/impl/HiveDatabaseAdapter.java ---
    @@ -0,0 +1,82 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.nifi.processors.standard.db.impl;
    +
    +
    +import org.apache.commons.lang3.StringUtils;
    +import org.apache.nifi.processors.standard.db.DatabaseAdapter;
    +
    +public class HiveDatabaseAdapter implements DatabaseAdapter {
    +    @Override
    +    public String getName() {
    +        return "Hive";
    +    }
    +
    +    @Override
    +    public boolean getSupportsStatementTimeout() {
    +        return false;
    +    }
    +
    +    @Override
    +    public boolean getSupportsGetTableName() {
    +        return false;
    +    }
    +
    +    @Override
    +    public boolean getSupportsMetaDataColumnIsSigned() {
    +        return false;
    +    }
    +
    +    @Override
    +    public boolean getSupportsMetaDataColumnGetPrecision() {
    +        return false;
    +    }
    +
    +    @Override
    +    public String getSelectStatement(String tableName, String columnNames, String whereClause, String orderByClause, Integer limit, Integer offset) {
    +        if (StringUtils.isEmpty(tableName)) {
    +            throw new IllegalArgumentException("Table name cannot be null or empty");
    +        }
    +        final StringBuilder query = new StringBuilder("SELECT ");
    +        if (StringUtils.isEmpty(columnNames) || columnNames.trim().equals("*")) {
    +            query.append("*");
    +        } else {
    +            query.append(columnNames);
    +        }
    +        query.append(" FROM ");
    +        query.append(tableName);
    +
    +        if (!StringUtils.isEmpty(whereClause)) {
    +            query.append(" WHERE ");
    +            query.append(whereClause);
    +        }
    +        if (!StringUtils.isEmpty(orderByClause)) {
    +            query.append(" ORDER BY ");
    +            query.append(orderByClause);
    +        }
    +        if (limit != null) {
    +            query.append(" LIMIT ");
    +            query.append(limit);
    +        }
    +        if (offset != null && offset > 0) {
    +            query.append(" OFFSET ");
    --- End diff --
    
    @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?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

Posted by patricker <gi...@git.apache.org>.
Github user patricker commented on the issue:

    https://github.com/apache/nifi/pull/1281
  
    @mattyb149 I'm working through this. I found a couple of issues that I'm figuring out.
    Also, I might have a way to do GenerateTableFetch with HIVE, using logic similar to what you do for SQL 2008 using ROW NUMBER.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

Posted by patricker <gi...@git.apache.org>.
Github user patricker commented on the issue:

    https://github.com/apache/nifi/pull/1281
  
    @mattyb149 I am still planning to update this PR.  Any chance you could take a look at https://github.com/apache/nifi/pull/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.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

Posted by ijokarumawak <gi...@git.apache.org>.
Github user ijokarumawak commented on the issue:

    https://github.com/apache/nifi/pull/1281
  
    @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.
    Thank you for your contribution, time and effort!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1281#discussion_r90273639
  
    --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/JdbcCommon.java ---
    @@ -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;
    --- End diff --
    
    Should we assume a default of zero here or < 0?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

Posted by patricker <gi...@git.apache.org>.
Github user patricker commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1281#discussion_r90279351
  
    --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/JdbcCommon.java ---
    @@ -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;
    --- End diff --
    
    Probably `-1` would be a safer choice. If we can't retrieve precision, and especially since HIVE supports up to Decimal 38... we don't want to accidentally lose data or start throwing exceptions for overflows.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on the issue:

    https://github.com/apache/nifi/pull/1281
  
    @patricker Are you working on this one? If not, perhaps @ijokarumawak or I can take over.


---

[GitHub] nifi pull request #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

Posted by patricker <gi...@git.apache.org>.
Github user patricker commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1281#discussion_r90278625
  
    --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractDatabaseFetchProcessor.java ---
    @@ -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")
    --- End diff --
    
    @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.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

Posted by patricker <gi...@git.apache.org>.
Github user patricker commented on the issue:

    https://github.com/apache/nifi/pull/1281
  
    @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.


---

[GitHub] nifi pull request #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

Posted by patricker <gi...@git.apache.org>.
Github user patricker closed the pull request at:

    https://github.com/apache/nifi/pull/1281


---

[GitHub] nifi issue #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

Posted by patricker <gi...@git.apache.org>.
Github user patricker commented on the issue:

    https://github.com/apache/nifi/pull/1281
  
    @ijokarumawak I'll work on it.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

Posted by patricker <gi...@git.apache.org>.
Github user patricker commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1281#discussion_r90277335
  
    --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GenerateTableFetch.java ---
    @@ -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()) {
    --- End diff --
    
    I used a HiveConnectionPool.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi issue #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

Posted by mattyb149 <gi...@git.apache.org>.
Github user mattyb149 commented on the issue:

    https://github.com/apache/nifi/pull/1281
  
    #1510 is now merged, do you mind rebasing this one? Please and thanks!


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] nifi pull request #1281: NIFI-3093 HIVE Support for QueryDatabaseTable

Posted by patricker <gi...@git.apache.org>.
Github user patricker commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1281#discussion_r90281017
  
    --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/util/JdbcCommon.java ---
    @@ -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;
    --- End diff --
    
    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.
    
    https://github.com/apache/hive/blob/ff67cdda1c538dc65087878eeba3e165cf3230f4/jdbc/src/java/org/apache/hive/jdbc/HiveResultSetMetaData.java


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---