[
https://issues.apache.org/jira/browse/NIFI-5143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16504726#comment-16504726
]
ASF GitHub Bot commented on NIFI-5143:
--------------------------------------
Github user pvillard31 commented on the issue:
https://github.com/apache/nifi/pull/2728
OK, I've been doing some tests against a Postgres database and everything
is working as I'd expect. I've only one minor feedback regarding the property
description.
> This property should only be used when the default queries are not
performing well, when there is no maximum-value column or a single
maximum-value column whose type can be coerced to a long integer (i.e. not date
or timestamp), and the column values are evenly distributed and not sparse, for
best performance.
I'd just add something regarding the "and the column values are evenly
distributed and not sparse": I'd say that if this condition is not met, it
could generate a lot of flow files (and back-pressure won't apply), and a lot
of the generated queries would lead to query execution with no returned rows.
Not saying this should be added in the property description, but it could
be something nice to add/mention in an "additional details" page?
That's really minor and can be ignored. Overall I'm a +1 on this PR and can
merge whenever that's OK for you.
> Allow GenerateTableFetch to use column values for partitioning
> --------------------------------------------------------------
>
> Key: NIFI-5143
> URL: https://issues.apache.org/jira/browse/NIFI-5143
> Project: Apache NiFi
> Issue Type: Improvement
> Reporter: Matt Burgess
> Assignee: Matt Burgess
> Priority: Major
>
> 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.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)