We recommend switching to the latest versions of Edge, Firefox, Chrome or Safari. Using Internet Explorer will result in a loss of website functionality.

Check for Zero records (Record Count)

Comments

5 comments

  • Avatar
    Adrian Williams

    Here is an example of how this could be achieved using the Meta Check node and the Switch node:

    Case 1 - Zero Records

    In case 1 there are no records output by the Create Data node (i.e. there is only metadata at its output). The Meta Check node is configured to check the minimum number of records available on its input:

    If the check fails (i.e. record count = 0) the TerminusAction is taken - which is configured so that only nodes attached to the Meta Check's Clock are executed. 

    A Generate Data node 'CLEAR' has a clock (run dependency) configured so that it waits for the completion of the Meta Check node. When it is clocked it outputs the Suffix field with a single record containing a value of "_CLEAR".

    As the Meta Check node's check(s) failed, nodes clocked to its output are not executed. This means no data (including metadata) is available at the output of the 'NONZERO' Transform node.

    The output of the Generate Data node is connected to the Sleep node which is configured to introduce a known delay in the propogation of this data stream downstream. The delay is to reduce the likelyhood of a 'race condition' occuring at the Switch node.

    The ouptut of the Sleep node and the output of the Transform node are connected to the Switch node's first (mandatory data) input pin and its second (optional data) input pin, respectively. The Switch node runs when it is enabled due to data being present at its first (mandatory) input pin. As no data is available at the second (optional data) input, the data at the Switch node's first (mandatory data) input pin is passed through to the node's output.

     

    Case 2 - Non-Zero Records

    In this case there is (one) record available at the Meta Check node's input pin. This means the minimum record count check is successful so the SuccessAction is taken by the node. On success, nodes attached to the Meta Check node's Clock AND nodes attached to its output pin are executed.

    So, the 'CLEAR' Generate Data node and Sleep node are run as for the first case. But now the 'First Record' Head node also runs, passing only the first record to it's output. The 'NONZERO' Transform node is connected to the Head node so it also runs. The Transform node is configured to output a single record containing the Suffiix field with a value of "NONZERO". The purpose of the upstream Head node is to reduce the processing time of the Transform node (since it now only needs to process a single record regardless of how many input records were available at the Meta Check node's input).

    The Sleep node delays the execution of the Switch node, allowing sufficient time for the Head and Transform node to complete their execution (if they are to be run) before the Switch node tests for data at it's input. In this case there is data available at the Switch node's first (mandatory data) input pin and at it's second (optional data) pin so the node passes the optional data through to its output pin.

     

     

     

    Attached files

    Check_for_Zero_Records - 31 Mar 2020.lna

     

    0
    Comment actions Permalink
  • Avatar
    Geoff

    wow.. thats a whole lot just to check for zero records.... seems like there should be a function like execCount to do it.

    Thanks Adrian.

    0
    Comment actions Permalink
  • Avatar
    Gerry Mullin

    Maybe this data flow would be a little easier? We can just add one dummy record to ensure you always get 1 into the final Transform node and when we count up how many records we had we will do (node.execCount - 1).

     

    Attached files

    Zero Records - v3.4.3.lna

     

    1
    Comment actions Permalink
  • Avatar
    Adrian Williams

    Thanks Gerry, I prefer your solution. It just shows that there is always multiple ways to acieve the aim.  :)

     

    0
    Comment actions Permalink
  • Avatar
    Geoff

    Gerry, thats perfect! thank you!

    0
    Comment actions Permalink

Please sign in to leave a comment.