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

ASF GitHub Bot commented on NIFI-1409:
--------------------------------------

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

    https://github.com/apache/nifi/pull/178#discussion_r50174170
  
    --- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ExecuteSQL.java
 ---
    @@ -164,17 +166,22 @@ public void process(final OutputStream out) throws 
IOException {
                 });
     
                 // set attribute how many rows were selected
    -            outgoing = session.putAttribute(outgoing, RESULT_ROW_COUNT, 
nrOfRows.get().toString());
    +            fileToProcess = session.putAttribute(fileToProcess, 
RESULT_ROW_COUNT, nrOfRows.get().toString());
     
    -            logger.info("{} contains {} Avro records; transferring to 
'success'", new Object[] {outgoing, nrOfRows.get()});
    -            session.getProvenanceReporter().modifyContent(outgoing, 
"Retrieved " + nrOfRows.get() + " rows", 
stopWatch.getElapsed(TimeUnit.MILLISECONDS));
    -            session.transfer(outgoing, REL_SUCCESS);
    +            logger.info("{} contains {} Avro records; transferring to 
'success'",
    +                    new Object[] {fileToProcess, nrOfRows.get()});
    +            session.getProvenanceReporter().modifyContent(fileToProcess, 
"Retrieved " + nrOfRows.get() + " rows",
    +                    stopWatch.getElapsed(TimeUnit.MILLISECONDS));
    +            session.transfer(fileToProcess, REL_SUCCESS);
             } catch (final ProcessException | SQLException e) {
    -            if (incoming == null) {
    +            if (fileToProcess == null) {
    +                // This can happen if any exceptions occur while setting 
up the connection, statement, etc.
                     logger.error("Unable to execute SQL select query {} due to 
{}. No incoming flow file to route to failure", new Object[] {selectQuery, e});
    +                context.yield();
                 } else {
    -                logger.error("Unable to execute SQL select query {} for {} 
due to {}; routing to failure", new Object[] {selectQuery, incoming, e});
    -                session.transfer(incoming, REL_FAILURE);
    +                logger.error("Unable to execute SQL select query {} due to 
{}; routing to failure", new Object[] {selectQuery, e});
    --- End diff --
    
    Almost there, need to check if there is an incoming connection 
(context.hasIncomingConnection) to see if the flowfile was used to created 
query. If so it should be logged (the way the incoming flowfile was).


> ExecuteSQL gives transfer error when SQLException occurs with no input 
> flowfile
> -------------------------------------------------------------------------------
>
>                 Key: NIFI-1409
>                 URL: https://issues.apache.org/jira/browse/NIFI-1409
>             Project: Apache NiFi
>          Issue Type: Bug
>            Reporter: Matt Burgess
>
> When the result set from ExecuteSQL has no columns, a bulletin is issued 
> saying a flowfile was not transferred:
> 13:35:12 ESTERROR05845c66-73a4-49ff-a973-ad986fb651bf
> ExecuteSQL[id=05845c66-73a4-49ff-a973-ad986fb651bf] Unable to execute SQL 
> select query SELECT * FROM test due to 
> org.apache.nifi.processor.exception.ProcessException: 
> org.postgresql.util.PSQLException: The column index is out of range: 1, 
> number of columns: 0.. No incoming flow file to route to failure: 
> org.apache.nifi.processor.exception.ProcessException: 
> org.postgresql.util.PSQLException: The column index is out of range: 1, 
> number of columns: 0.
> 13:35:12 ESTERROR05845c66-73a4-49ff-a973-ad986fb651bf
> ExecuteSQL[id=05845c66-73a4-49ff-a973-ad986fb651bf] 
> ExecuteSQL[id=05845c66-73a4-49ff-a973-ad986fb651bf] failed to process due to 
> org.apache.nifi.processor.exception.FlowFileHandlingException: 
> StandardFlowFileRecord[uuid=c9077d5c-d873-4bf2-a8c0-4cc92a6f3309,claim=,offset=0,name=258316166470532,size=0]
>  transfer relationship not specified; rolling back session: 
> org.apache.nifi.processor.exception.FlowFileHandlingException: 
> StandardFlowFileRecord[uuid=c9077d5c-d873-4bf2-a8c0-4cc92a6f3309,claim=,offset=0,name=258316166470532,size=0]
>  transfer relationship not specified
> If there is any problem with the query (such as selecting a column that 
> doesn't exist, or SELECT * from a table with no columns), a SQLException is 
> thrown, which becomes a ProcessException in the ExecuteSQL processor. In 
> addition, the exception handling tries to route the flowfile to failure, but 
> for the newly created flowfile (to contain the result set), the reference has 
> since been lost, and thus the flowfile is never transferred.
> At present, if it desired that an empty result set causes a route to failure, 
> then a workaround is to add a GenerateFlowFile processor (with a 0-byte size) 
> in front of the ExecuteSQL processor. This bypasses the logic error because 
> the incoming flowfile is reused and eventually transferred to failure because 
> of the exception thrown.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to