[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2018-04-24 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16449953#comment-16449953
 ] 

ASF GitHub Bot commented on NIFI-4561:
--

Github user asfgit closed the pull request at:

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


> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>Priority: Major
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind of statement, including multi-statement 
> requests.
> This allowed users to submit multiple SQL statements in one JDBC Statement 
> and get back multiple result sets. This was part of the reason I wrote 
> [NIFI-3432].
> After having NIFI-3432 merged, I found that some request types no longer 
> cause a FlowFile to be generated because there is no ResultSet. Also, if 
> request types are mixed, such as an insert followed by a Select, then no 
> ResultSet is returned because the first result is not a result set but an 
> Update Count.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2018-04-24 Thread ASF subversion and git services (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16449951#comment-16449951
 ] 

ASF subversion and git services commented on NIFI-4561:
---

Commit 0390c0f1967d1a57a333d15e1ec41b06ceb88590 in nifi's branch 
refs/heads/master from [~patricker]
[ https://git-wip-us.apache.org/repos/asf?p=nifi.git;h=0390c0f ]

NIFI-4561 ExecuteSQL returns no FlowFile for some queries

This closes #2243

Signed-off-by: Mike Thomsen 


> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>Priority: Major
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind of statement, including multi-statement 
> requests.
> This allowed users to submit multiple SQL statements in one JDBC Statement 
> and get back multiple result sets. This was part of the reason I wrote 
> [NIFI-3432].
> After having NIFI-3432 merged, I found that some request types no longer 
> cause a FlowFile to be generated because there is no ResultSet. Also, if 
> request types are mixed, such as an insert followed by a Select, then no 
> ResultSet is returned because the first result is not a result set but an 
> Update Count.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2018-04-23 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16449181#comment-16449181
 ] 

ASF GitHub Bot commented on NIFI-4561:
--

Github user patricker commented on the issue:

https://github.com/apache/nifi/pull/2243
  
@MikeThomsen Updated. I found one additional place where a 0 row count 
needed to be set (just in case). Also added a unit test to verify.


> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>Priority: Major
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind of statement, including multi-statement 
> requests.
> This allowed users to submit multiple SQL statements in one JDBC Statement 
> and get back multiple result sets. This was part of the reason I wrote 
> [NIFI-3432].
> After having NIFI-3432 merged, I found that some request types no longer 
> cause a FlowFile to be generated because there is no ResultSet. Also, if 
> request types are mixed, such as an insert followed by a Select, then no 
> ResultSet is returned because the first result is not a result set but an 
> Update Count.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2018-04-23 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16448871#comment-16448871
 ] 

ASF GitHub Bot commented on NIFI-4561:
--

Github user MikeThomsen commented on the issue:

https://github.com/apache/nifi/pull/2243
  
@patricker Any estimate on when you'll have the next commit?


> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>Priority: Major
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind of statement, including multi-statement 
> requests.
> This allowed users to submit multiple SQL statements in one JDBC Statement 
> and get back multiple result sets. This was part of the reason I wrote 
> [NIFI-3432].
> After having NIFI-3432 merged, I found that some request types no longer 
> cause a FlowFile to be generated because there is no ResultSet. Also, if 
> request types are mixed, such as an insert followed by a Select, then no 
> ResultSet is returned because the first result is not a result set but an 
> Update Count.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2018-04-23 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16448134#comment-16448134
 ] 

ASF GitHub Bot commented on NIFI-4561:
--

Github user patricker commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2243#discussion_r183391339
  
--- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteSQL.java
 ---
@@ -278,8 +289,18 @@ public void onTrigger(final ProcessContext context, 
final ProcessSession session
 } else {
 fileToProcess = session.write(fileToProcess, 
JdbcCommon::createEmptyAvroStream);
 
+fileToProcess = session.putAttribute(fileToProcess, 
CoreAttributes.MIME_TYPE.key(), JdbcCommon.MIME_TYPE_AVRO_BINARY);
 session.transfer(fileToProcess, REL_SUCCESS);
 }
+} else if(resultCount == 0){
+//If we had no inbound FlowFile, no exceptions, and the 
SQL generated no result sets (Insert/Update/Delete statements only)
+// Then generate an empty Output FlowFile
+FlowFile resultSetFF = session.create();
+
+resultSetFF = session.write(resultSetFF, out -> 
JdbcCommon.createEmptyAvroStream(out));
+
+resultSetFF = session.putAttribute(resultSetFF, 
CoreAttributes.MIME_TYPE.key(), JdbcCommon.MIME_TYPE_AVRO_BINARY);
--- End diff --

This is a good suggestion. I'll update the `else` to cover this scenario 
with a `0` `RESULT_ROW_COUNT`.


> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>Priority: Major
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind of statement, including multi-statement 
> requests.
> This allowed users to submit multiple SQL statements in one JDBC Statement 
> and get back multiple result sets. This was part of the reason I wrote 
> [NIFI-3432].
> After having NIFI-3432 merged, I found that some request types no longer 
> cause a FlowFile to be generated because there is no ResultSet. Also, if 
> request types are mixed, such as an insert followed by a Select, then no 
> ResultSet is returned because the first result is not a result set but an 
> Update Count.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2018-04-23 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16448127#comment-16448127
 ] 

ASF GitHub Bot commented on NIFI-4561:
--

Github user patricker commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2243#discussion_r183389726
  
--- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteSQL.java
 ---
@@ -220,17 +224,19 @@ public void onTrigger(final ProcessContext context, 
final ProcessSession session
 JdbcCommon.setParameters(st, 
fileToProcess.getAttributes());
 }
 logger.debug("Executing query {}", new Object[]{selectQuery});
-boolean results = st.execute();
+boolean hasResults = st.execute();
+boolean hasUpdateCount = st.getUpdateCount() != -1;
 
-
-while(results){
-FlowFile resultSetFF;
-if(fileToProcess == null){
-resultSetFF = session.create();
-} else {
-resultSetFF = session.create(fileToProcess);
-resultSetFF = session.putAllAttributes(resultSetFF, 
fileToProcess.getAttributes());
-}
+while(hasResults || hasUpdateCount) {
+//getMoreResults() and execute() return false to indicate 
that the result of the statement is just a number and not a ResultSet
+if (hasResults) {
+FlowFile resultSetFF;
+if (fileToProcess == null) {
+resultSetFF = session.create();
+} else {
+resultSetFF = session.create(fileToProcess);
+resultSetFF = 
session.putAllAttributes(resultSetFF, fileToProcess.getAttributes());
+}
 
 final AtomicLong nrOfRows = new AtomicLong(0L);
--- End diff --

Thanks, I'll fix it.


> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>Priority: Major
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind of statement, including multi-statement 
> requests.
> This allowed users to submit multiple SQL statements in one JDBC Statement 
> and get back multiple result sets. This was part of the reason I wrote 
> [NIFI-3432].
> After having NIFI-3432 merged, I found that some request types no longer 
> cause a FlowFile to be generated because there is no ResultSet. Also, if 
> request types are mixed, such as an insert followed by a Select, then no 
> ResultSet is returned because the first result is not a result set but an 
> Update Count.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2018-04-23 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16448117#comment-16448117
 ] 

ASF GitHub Bot commented on NIFI-4561:
--

Github user MikeThomsen commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2243#discussion_r183388072
  
--- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteSQL.java
 ---
@@ -278,8 +289,18 @@ public void onTrigger(final ProcessContext context, 
final ProcessSession session
 } else {
--- End diff --

Ok. 


> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>Priority: Major
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind of statement, including multi-statement 
> requests.
> This allowed users to submit multiple SQL statements in one JDBC Statement 
> and get back multiple result sets. This was part of the reason I wrote 
> [NIFI-3432].
> After having NIFI-3432 merged, I found that some request types no longer 
> cause a FlowFile to be generated because there is no ResultSet. Also, if 
> request types are mixed, such as an insert followed by a Select, then no 
> ResultSet is returned because the first result is not a result set but an 
> Update Count.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2018-04-23 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16448113#comment-16448113
 ] 

ASF GitHub Bot commented on NIFI-4561:
--

Github user patricker commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2243#discussion_r183387242
  
--- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteSQL.java
 ---
@@ -278,8 +289,18 @@ public void onTrigger(final ProcessContext context, 
final ProcessSession session
 } else {
--- End diff --

Thanks for the review. As for adding an "original" relationship, that's 
outside the scope of this ticket. This is a bug fix ticket, with no intention 
of adding new functionality, just fixing a bug (that I introduced in a previous 
ticket...)


> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>Priority: Major
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind of statement, including multi-statement 
> requests.
> This allowed users to submit multiple SQL statements in one JDBC Statement 
> and get back multiple result sets. This was part of the reason I wrote 
> [NIFI-3432].
> After having NIFI-3432 merged, I found that some request types no longer 
> cause a FlowFile to be generated because there is no ResultSet. Also, if 
> request types are mixed, such as an insert followed by a Select, then no 
> ResultSet is returned because the first result is not a result set but an 
> Update Count.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2018-04-23 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16448103#comment-16448103
 ] 

ASF GitHub Bot commented on NIFI-4561:
--

Github user MikeThomsen commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2243#discussion_r183383744
  
--- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteSQL.java
 ---
@@ -278,8 +289,18 @@ public void onTrigger(final ProcessContext context, 
final ProcessSession session
 } else {
 fileToProcess = session.write(fileToProcess, 
JdbcCommon::createEmptyAvroStream);
 
+fileToProcess = session.putAttribute(fileToProcess, 
CoreAttributes.MIME_TYPE.key(), JdbcCommon.MIME_TYPE_AVRO_BINARY);
 session.transfer(fileToProcess, REL_SUCCESS);
 }
+} else if(resultCount == 0){
+//If we had no inbound FlowFile, no exceptions, and the 
SQL generated no result sets (Insert/Update/Delete statements only)
+// Then generate an empty Output FlowFile
+FlowFile resultSetFF = session.create();
+
+resultSetFF = session.write(resultSetFF, out -> 
JdbcCommon.createEmptyAvroStream(out));
+
+resultSetFF = session.putAttribute(resultSetFF, 
CoreAttributes.MIME_TYPE.key(), JdbcCommon.MIME_TYPE_AVRO_BINARY);
--- End diff --

Should have `RESULT_ROW_COUNT` on it to tell downstream processors that 
it's got not rows in it.


> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>Priority: Major
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind of statement, including multi-statement 
> requests.
> This allowed users to submit multiple SQL statements in one JDBC Statement 
> and get back multiple result sets. This was part of the reason I wrote 
> [NIFI-3432].
> After having NIFI-3432 merged, I found that some request types no longer 
> cause a FlowFile to be generated because there is no ResultSet. Also, if 
> request types are mixed, such as an insert followed by a Select, then no 
> ResultSet is returned because the first result is not a result set but an 
> Update Count.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2018-04-23 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16448104#comment-16448104
 ] 

ASF GitHub Bot commented on NIFI-4561:
--

Github user MikeThomsen commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2243#discussion_r183382982
  
--- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteSQL.java
 ---
@@ -220,17 +224,19 @@ public void onTrigger(final ProcessContext context, 
final ProcessSession session
 JdbcCommon.setParameters(st, 
fileToProcess.getAttributes());
 }
 logger.debug("Executing query {}", new Object[]{selectQuery});
-boolean results = st.execute();
+boolean hasResults = st.execute();
+boolean hasUpdateCount = st.getUpdateCount() != -1;
 
-
-while(results){
-FlowFile resultSetFF;
-if(fileToProcess == null){
-resultSetFF = session.create();
-} else {
-resultSetFF = session.create(fileToProcess);
-resultSetFF = session.putAllAttributes(resultSetFF, 
fileToProcess.getAttributes());
-}
+while(hasResults || hasUpdateCount) {
+//getMoreResults() and execute() return false to indicate 
that the result of the statement is just a number and not a ResultSet
+if (hasResults) {
+FlowFile resultSetFF;
+if (fileToProcess == null) {
+resultSetFF = session.create();
+} else {
+resultSetFF = session.create(fileToProcess);
+resultSetFF = 
session.putAllAttributes(resultSetFF, fileToProcess.getAttributes());
+}
 
 final AtomicLong nrOfRows = new AtomicLong(0L);
--- End diff --

Could you fix the indentation level here to harmonize it with your changes?


> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>Priority: Major
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind of statement, including multi-statement 
> requests.
> This allowed users to submit multiple SQL statements in one JDBC Statement 
> and get back multiple result sets. This was part of the reason I wrote 
> [NIFI-3432].
> After having NIFI-3432 merged, I found that some request types no longer 
> cause a FlowFile to be generated because there is no ResultSet. Also, if 
> request types are mixed, such as an insert followed by a Select, then no 
> ResultSet is returned because the first result is not a result set but an 
> Update Count.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2018-04-23 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16448102#comment-16448102
 ] 

ASF GitHub Bot commented on NIFI-4561:
--

Github user MikeThomsen commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2243#discussion_r183384397
  
--- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteSQL.java
 ---
@@ -278,8 +289,18 @@ public void onTrigger(final ProcessContext context, 
final ProcessSession session
 } else {
--- End diff --

Above this line is a call to `session.remove`. Do you see any reason to 
note add an "original" relationship to the processor so the input flowfile is 
not lost?


> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>Priority: Major
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind of statement, including multi-statement 
> requests.
> This allowed users to submit multiple SQL statements in one JDBC Statement 
> and get back multiple result sets. This was part of the reason I wrote 
> [NIFI-3432].
> After having NIFI-3432 merged, I found that some request types no longer 
> cause a FlowFile to be generated because there is no ResultSet. Also, if 
> request types are mixed, such as an insert followed by a Select, then no 
> ResultSet is returned because the first result is not a result set but an 
> Update Count.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2018-04-10 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16431796#comment-16431796
 ] 

ASF GitHub Bot commented on NIFI-4561:
--

Github user patricker commented on the issue:

https://github.com/apache/nifi/pull/2243
  
@mattyb149 Rebased against 1.6, fixed conflicts.


> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>Priority: Major
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind of statement, including multi-statement 
> requests.
> This allowed users to submit multiple SQL statements in one JDBC Statement 
> and get back multiple result sets. This was part of the reason I wrote 
> [NIFI-3432].
> After having NIFI-3432 merged, I found that some request types no longer 
> cause a FlowFile to be generated because there is no ResultSet. Also, if 
> request types are mixed, such as an insert followed by a Select, then no 
> ResultSet is returned because the first result is not a result set but an 
> Update Count.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2018-02-05 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16353322#comment-16353322
 ] 

ASF GitHub Bot commented on NIFI-4561:
--

Github user patricker commented on the issue:

https://github.com/apache/nifi/pull/2243
  
Updated


> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>Priority: Major
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind of statement, including multi-statement 
> requests.
> This allowed users to submit multiple SQL statements in one JDBC Statement 
> and get back multiple result sets. This was part of the reason I wrote 
> [NIFI-3432].
> After having NIFI-3432 merged, I found that some request types no longer 
> cause a FlowFile to be generated because there is no ResultSet. Also, if 
> request types are mixed, such as an insert followed by a Select, then no 
> ResultSet is returned because the first result is not a result set but an 
> Update Count.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2018-02-05 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16353319#comment-16353319
 ] 

ASF GitHub Bot commented on NIFI-4561:
--

Github user patricker commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2243#discussion_r166180285
  
--- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteSQL.java
 ---
@@ -202,56 +205,63 @@ public void process(InputStream in) throws 
IOException {
 st.setQueryTimeout(queryTimeout); // timeout in seconds
 
 logger.debug("Executing query {}", new Object[]{selectQuery});
-boolean results = st.execute(selectQuery);
+boolean hasResults = st.execute(selectQuery);
+boolean hasUpdateCount = st.getUpdateCount() != -1;
--- End diff --

I haven't run into any issues with calling `execute` instead of 
`executeUpdate`. I did some additional research and found the following 
concerning `execute`: https://stackoverflow.com/a/16625802/328968

> "*Executes the given SQL statement, which may return multiple results. In 
some (uncommon) situations, a single SQL statement may return multiple result 
sets and/or update counts. Normally you can ignore this unless you are (1) 
executing a stored procedure that you know may return multiple results or (2) 
you are dynamically executing an unknown SQL string.*"

Or the answer after that which provides more details on each type of call, 
`execute`, `executeUpdate`, and `executeQuery`: 
https://stackoverflow.com/a/37509744/328968.


> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>Priority: Major
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind of statement, including multi-statement 
> requests.
> This allowed users to submit multiple SQL statements in one JDBC Statement 
> and get back multiple result sets. This was part of the reason I wrote 
> [NIFI-3432].
> After having NIFI-3432 merged, I found that some request types no longer 
> cause a FlowFile to be generated because there is no ResultSet. Also, if 
> request types are mixed, such as an insert followed by a Select, then no 
> ResultSet is returned because the first result is not a result set but an 
> Update Count.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2018-02-05 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16353313#comment-16353313
 ] 

ASF GitHub Bot commented on NIFI-4561:
--

Github user patricker commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2243#discussion_r166179486
  
--- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteSQL.java
 ---
@@ -268,8 +278,23 @@ public void process(OutputStream out) throws 
IOException {
 }
 });
 
+fileToProcess = session.putAttribute(fileToProcess, 
CoreAttributes.MIME_TYPE.key(), JdbcCommon.MIME_TYPE_AVRO_BINARY);
 session.transfer(fileToProcess, REL_SUCCESS);
 }
+} else if(resultCount == 0){
+//If we had no inbound FlowFile, no exceptions, and the 
SQL generated no result sets (Insert/Update/Delete statements only)
--- End diff --

Prior to my previous change (https://github.com/apache/nifi/pull/1471) only 
a single flowfile could be returned. The way the code was written, if no 
incoming flowfile existed then `session.create()` was called. The result, 
whether it be a large resultset or no result at all, was written using a 
`session.write` call. Thus a flowfile would always be returned.


> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>Priority: Major
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind of statement, including multi-statement 
> requests.
> This allowed users to submit multiple SQL statements in one JDBC Statement 
> and get back multiple result sets. This was part of the reason I wrote 
> [NIFI-3432].
> After having NIFI-3432 merged, I found that some request types no longer 
> cause a FlowFile to be generated because there is no ResultSet. Also, if 
> request types are mixed, such as an insert followed by a Select, then no 
> ResultSet is returned because the first result is not a result set but an 
> Update Count.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)


[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2017-12-17 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16294599#comment-16294599
 ] 

ASF GitHub Bot commented on NIFI-4561:
--

Github user patricker commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2243#discussion_r157414101
  
--- Diff: 
nifi-commons/nifi-write-ahead-log/src/test/java/org/wali/TestMinimalLockingWriteAheadLog.java
 ---
@@ -538,7 +538,7 @@ public void 
testRecoverFileThatHasTrailingNULBytesAndTruncation() throws IOExcep
 @Test
 public void testRecoverFileThatHasTrailingNULBytesNoTruncation() 
throws IOException {
 final int numPartitions = 5;
-final Path path = 
Paths.get("target/testRecoverFileThatHasTrailingNULBytes");
+final Path path = 
Paths.get("target/testRecoverFileThatHasTrailingNULBytesNoTruncation");
--- End diff --

Yep, accidental inclusion.


> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind of statement, including multi-statement 
> requests.
> This allowed users to submit multiple SQL statements in one JDBC Statement 
> and get back multiple result sets. This was part of the reason I wrote 
> [NIFI-3432].
> After having NIFI-3432 merged, I found that some request types no longer 
> cause a FlowFile to be generated because there is no ResultSet. Also, if 
> request types are mixed, such as an insert followed by a Select, then no 
> ResultSet is returned because the first result is not a result set but an 
> Update Count.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2017-12-14 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16291841#comment-16291841
 ] 

ASF GitHub Bot commented on NIFI-4561:
--

Github user mattyb149 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2243#discussion_r157099185
  
--- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteSQL.java
 ---
@@ -202,56 +205,63 @@ public void process(InputStream in) throws 
IOException {
 st.setQueryTimeout(queryTimeout); // timeout in seconds
 
 logger.debug("Executing query {}", new Object[]{selectQuery});
-boolean results = st.execute(selectQuery);
+boolean hasResults = st.execute(selectQuery);
+boolean hasUpdateCount = st.getUpdateCount() != -1;
--- End diff --

I know you use MS SQL Server alot, does this call behave well? I saw 
[this](https://stackoverflow.com/questions/21757191/jdbc-getupdatecount-is-returning-0-but-1-row-is-updated-in-sql-server)
 and wondered if all is well without an executeUpdate() call.


> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind of statement, including multi-statement 
> requests.
> This allowed users to submit multiple SQL statements in one JDBC Statement 
> and get back multiple result sets. This was part of the reason I wrote 
> [NIFI-3432].
> After having NIFI-3432 merged, I found that some request types no longer 
> cause a FlowFile to be generated because there is no ResultSet. Also, if 
> request types are mixed, such as an insert followed by a Select, then no 
> ResultSet is returned because the first result is not a result set but an 
> Update Count.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2017-12-14 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16291838#comment-16291838
 ] 

ASF GitHub Bot commented on NIFI-4561:
--

Github user mattyb149 commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2243#discussion_r157098806
  
--- Diff: 
nifi-commons/nifi-write-ahead-log/src/test/java/org/wali/TestMinimalLockingWriteAheadLog.java
 ---
@@ -538,7 +538,7 @@ public void 
testRecoverFileThatHasTrailingNULBytesAndTruncation() throws IOExcep
 @Test
 public void testRecoverFileThatHasTrailingNULBytesNoTruncation() 
throws IOException {
 final int numPartitions = 5;
-final Path path = 
Paths.get("target/testRecoverFileThatHasTrailingNULBytes");
+final Path path = 
Paths.get("target/testRecoverFileThatHasTrailingNULBytesNoTruncation");
--- End diff --

This change doesn't look like it belongs?


> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind of statement, including multi-statement 
> requests.
> This allowed users to submit multiple SQL statements in one JDBC Statement 
> and get back multiple result sets. This was part of the reason I wrote 
> [NIFI-3432].
> After having NIFI-3432 merged, I found that some request types no longer 
> cause a FlowFile to be generated because there is no ResultSet. Also, if 
> request types are mixed, such as an insert followed by a Select, then no 
> ResultSet is returned because the first result is not a result set but an 
> Update Count.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2017-12-11 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16286943#comment-16286943
 ] 

ASF GitHub Bot commented on NIFI-4561:
--

Github user mattyb149 commented on the issue:

https://github.com/apache/nifi/pull/2243
  
@patricker I'll try to take a look at this soon


> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind of statement, including multi-statement 
> requests.
> This allowed users to submit multiple SQL statements in one JDBC Statement 
> and get back multiple result sets. This was part of the reason I wrote 
> [NIFI-3432].
> After having NIFI-3432 merged, I found that some request types no longer 
> cause a FlowFile to be generated because there is no ResultSet. Also, if 
> request types are mixed, such as an insert followed by a Select, then no 
> ResultSet is returned because the first result is not a result set but an 
> Update Count.



--
This message was sent by Atlassian JIRA
(v6.4.14#64029)


[jira] [Commented] (NIFI-4561) ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries

2017-10-31 Thread ASF GitHub Bot (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-4561?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=16233580#comment-16233580
 ] 

ASF GitHub Bot commented on NIFI-4561:
--

GitHub user patricker opened a pull request:

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

NIFI-4561 ExecuteSQL returns no FlowFile for some queries

In some scenarios the updated ExecuteSQL returns no FlowFile, even when the 
SQL was executed without error. This is a bug I introduced in 
https://github.com/apache/nifi/pull/1471.

If you execute a stored procedure that returns only a row count, or if the 
row count is the first result and the ResultSet follows it, then no FlowFile 
will be generated. This is because `getMoreResults()` and `execute()` return 
false to indicate that the ResultSet does not exist OR that the statement 
returned a number and not a ResultSet. So if ResultSet's and numerical 
responses are inter mixed this will also result in missed result sets.

Some JDBC drivers allow for multi-statement requests to be submitted using 
`Statement.execute`. In these cases you can have an INSERT statement followed 
by a SELECT statement. In this case no ResultSet would be returned either.

Prior to NIFI-3432, executing any number of statements would result in a 
single ReslutSet, which may or may not include data. I've seen examples of a 
DELETE followed by several INSERT statements and our JDBC driver (Teradata) 
would execute them and NiFi would return a single empty FlowFile.

This update corrects the logic. The new logic:
- For every ResultSet, output a FlowFile
- Skip non-ResultSet outputs
- If we have no more results, there were no errors, there was no original 
inbound FlowFile, and no ResultSet's were found at all (statements were 
Insert/Update/Delete only), then output a blank FlowFile.

@mattyb149 You reviewed https://github.com/apache/nifi/pull/1471 for me, 
not sure if you have the time to review this fix as well. I know in the past 
you weren't big on the idea of executing non SELECT statements from ExecuteSQL, 
but it's something I'm seeing in our environment since the JDBC driver allows 
it, and since we can do multi-statement requests.

### 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- where  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?

### Note:
Please ensure that once the PR is submitted, you check travis-ci for build 
issues and submit an update to your PR as soon as possible.


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

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

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

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


commit 59391ca9adf8ab69defa611237b3dc009cf563f9
Author: patricker 
Date:   2017-11-01T02:25:26Z

NIFI-4561 ExecuteSQL returns no FlowFile for some queries




> ExecuteSQL Stopped Returning FlowFile for non-ResultSet Queries
> ---
>
> Key: NIFI-4561
> URL: https://issues.apache.org/jira/browse/NIFI-4561
> Project: Apache NiFi
>  Issue Type: Bug
>Reporter: Peter Wicks
>Assignee: Peter Wicks
>Priority: Major
>
> While most people use ExecuteSQL for Select statements, some JDBC drivers 
> allow you to execute any kind