title: How can I filter flow files upon the result of an SQL query?
body: <p>Would it be possible to route flow files according to the result of an SQL query which returns a single row result? For example, if the result is '1' the flow file will be processed; otherwise, it will be ignored.</p>
  
  <h2>Solution</h2>
  
  <p>The following approach worked best for me.</p>
  
  <ol>
  <li>Use <strong>ExecuteSQL</strong> processor in order to run filtering SQL query. The query was written to produce either a single record (match) or an empty record set (no match) in a way suggested by Shu.</li>
  <li>Connect <strong>ExecuteSQL</strong> to  <strong>RouteOnAttribute</strong> processor in order to filter out unmatched flow files using the following value of routing property value <code>${executesql.row.count:replaceNull(0):gt(0)}</code></li>
  </ol>
  
  <p><strong>Notice</strong>, that the original content of a flow file will be lost after applying <strong>ExecuteSQL</strong>. It's not an issue in my case, because I do filtering before processing flow file content and my SQL query is based entirely on the flow file attributes and not on its content. Though in a more general scenario, when the flow file content is modified by the incoming part of the flow, one should save file content somewhere (e.g. file system) and restore it after the filtering part has applied.  </p>