Repository: nifi Updated Branches: refs/heads/master 4edafad6e -> 1a1e01c56
NIFI-4473 - fixed NPE in parametrized queries Signed-off-by: Matthew Burgess <[email protected]> This closes #2215 Project: http://git-wip-us.apache.org/repos/asf/nifi/repo Commit: http://git-wip-us.apache.org/repos/asf/nifi/commit/1a1e01c5 Tree: http://git-wip-us.apache.org/repos/asf/nifi/tree/1a1e01c5 Diff: http://git-wip-us.apache.org/repos/asf/nifi/diff/1a1e01c5 Branch: refs/heads/master Commit: 1a1e01c5680ad8e5ba605254c4b4b12fe0e2c071 Parents: 4edafad Author: Matthew Burgess <[email protected]> Authored: Mon Oct 16 13:38:56 2017 -0400 Committer: Matthew Burgess <[email protected]> Committed: Wed Oct 18 10:13:03 2017 -0400 ---------------------------------------------------------------------- .../nifi/processors/hive/SelectHiveQL.java | 2 +- .../nifi/processors/hive/TestSelectHiveQL.java | 36 ++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/nifi/blob/1a1e01c5/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/processors/hive/SelectHiveQL.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/processors/hive/SelectHiveQL.java b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/processors/hive/SelectHiveQL.java index fb05914..d4d31cc 100644 --- a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/processors/hive/SelectHiveQL.java +++ b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/main/java/org/apache/nifi/processors/hive/SelectHiveQL.java @@ -329,7 +329,7 @@ public class SelectHiveQL extends AbstractHiveQLProcessor { int paramCount = StringUtils.countMatches(selectQuery, "?"); if (paramCount > 0) { - setParameters(1, (PreparedStatement) st, paramCount, flowfile.getAttributes()); + setParameters(1, (PreparedStatement) st, paramCount, fileToProcess.getAttributes()); } } http://git-wip-us.apache.org/repos/asf/nifi/blob/1a1e01c5/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/test/java/org/apache/nifi/processors/hive/TestSelectHiveQL.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/test/java/org/apache/nifi/processors/hive/TestSelectHiveQL.java b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/test/java/org/apache/nifi/processors/hive/TestSelectHiveQL.java index 34384ac..8313caa 100644 --- a/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/test/java/org/apache/nifi/processors/hive/TestSelectHiveQL.java +++ b/nifi-nar-bundles/nifi-hive-bundle/nifi-hive-processors/src/test/java/org/apache/nifi/processors/hive/TestSelectHiveQL.java @@ -46,6 +46,7 @@ import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; import java.sql.Statement; +import java.sql.Types; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -331,6 +332,41 @@ public class TestSelectHiveQL { } @Test + public void testParametrizedQuery() throws ClassNotFoundException, SQLException, InitializationException, IOException { + // load test data to database + final Connection con = ((DBCPService) runner.getControllerService("dbcp")).getConnection(); + Statement stmt = con.createStatement(); + + try { + stmt.execute("drop table TEST_QUERY_DB_TABLE"); + } catch (final SQLException sqle) { + // Ignore this error, probably a "table does not exist" since Derby doesn't yet support DROP IF EXISTS [DERBY-4842] + } + + stmt.execute("create table TEST_QUERY_DB_TABLE (id integer not null, name varchar(100), scale float, created_on timestamp, bignum bigint default 0)"); + int rowCount = 0; + //create larger row set + for (int batch = 0; batch < 100; batch++) { + stmt.execute("insert into TEST_QUERY_DB_TABLE (id, name, scale, created_on) VALUES (" + rowCount + ", 'Joe Smith', 1.0, '1962-09-23 03:23:34.234')"); + rowCount++; + } + + runner.setIncomingConnection(true); + runner.setProperty(SelectHiveQL.MAX_ROWS_PER_FLOW_FILE, "${" + MAX_ROWS_KEY + "}"); + runner.setProperty(SelectHiveQL.HIVEQL_OUTPUT_FORMAT, HiveJdbcCommon.AVRO); + runner.setVariable(MAX_ROWS_KEY, "9"); + + Map<String, String> attributes = new HashMap<String, String>(); + attributes.put("hiveql.args.1.value", "1"); + attributes.put("hiveql.args.1.type", String.valueOf(Types.INTEGER)); + runner.enqueue("SELECT * FROM TEST_QUERY_DB_TABLE WHERE id = ?", attributes ); + + runner.run(); + runner.assertAllFlowFilesTransferred(SelectHiveQL.REL_SUCCESS, 1); + runner.clearTransferState(); + } + + @Test public void testMaxRowsPerFlowFileCSV() throws ClassNotFoundException, SQLException, InitializationException, IOException { // load test data to database
