Uploaded image for project: 'Apache NiFi'
  1. Apache NiFi
  2. NIFI-5143

Allow GenerateTableFetch to use column values for partitioning



    • Improvement
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 1.7.0
    • None
    • None


      GenerateTableFetch generates SQL statements for fetching "pages" of rows from a database, and the SQL it generates often leverages the concept of "row numbers" when doing things such as LIMIT and OFFSET.

      Oracle 11 is an example of a special case for GenerateTableFetch, because it doesn't make a "row number" available for doing paging ("get rows 10 through 19", e.g.). For that reason the row number is created as an extra column using a nested select with an ORDER BY clause. For large tables this can be very inefficient.

      In a general sense, the user may have a column that contains integer IDs and would like to have a more efficient query. I propose the following as a generic solution that would mostly benefit this kind of use case:

      • Add a property to GenerateTableFetch to "Use Column Values For Partitioning". This would be a boolean property defaulting to false to retain current behavior.
      • If the maximum value column type is numeric and "Use Column Values For Partitioning" is true, fetch the minimum value of the column (after the where clause is applied)
      • If "Use Column Values For Partitioning" is true, then determine the page offsets by taking the difference of the maximum value and minimum value, dividing by the Partition Size.

      These changes would use the "Max-value Columns" values rather than the result set row numbers for figuring out the paging. The documentation needs to be very clear on when this property should be used. For example, when "Use Column Values For Partitioning" is true, then the column values should be evenly distributed and not sparse, for best performance.

      As a counterexample, consider the following:

      • Use Column Values For Partitioning = true
      • Max Value Column = "id"
      • Table "myTable" has only 3 rows, one with id = 1, one with id = 50, one with id = 100
      • Partition Size = 5

      GenerateTableFetch would generate 20 flow files, of the following pattern:
      SELECT * from myTable where ID >= 1 AND ID < 5
      SELECT * from myTable where ID >= 5 AND ID < 10
      SELECT * from myTable where ID >= 10 AND ID < 15
      SELECT * from myTable where ID >= 50 AND ID < 55
      SELECT * from myTable where ID >= 100 AND ID < 105

      Note that only 3 flow files out of 20 will contain SQL statements that would retrieve any rows. The rest will return empty ResultSets. However when the columns are appropriate for use of their values, this improvement could be quite substantial.


        Issue Links



              mattyb149 Matt Burgess
              mattyb149 Matt Burgess
              0 Vote for this issue
              3 Start watching this issue