Github user ijokarumawak commented on a diff in the pull request:
https://github.com/apache/nifi/pull/1376#discussion_r100969417
--- Diff:
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/GenerateTableFetch.java
---
@@ -223,19 +237,34 @@ public void onTrigger(final ProcessContext context,
final ProcessSessionFactory
}
final int numberOfFetches = (partitionSize == 0) ? rowCount :
(rowCount / partitionSize) + (rowCount % partitionSize == 0 ? 0 : 1);
+ if("null".equals(indexValue)) {
+ // Generate SQL statements to read "pages" of data
+ for (int i = 0; i < numberOfFetches; i++) {
+ FlowFile sqlFlowFile;
- // Generate SQL statements to read "pages" of data
- for (int i = 0; i < numberOfFetches; i++) {
- FlowFile sqlFlowFile;
+ Integer limit = partitionSize == 0 ? null :
partitionSize;
+ Integer offset = partitionSize == 0 ? null : i *
partitionSize;
+ final String query =
dbAdapter.getSelectStatement(tableName, columnNames, whereClause,
StringUtils.join(maxValueColumnNameList, ", "), limit, offset);
+ sqlFlowFile = session.create();
+ sqlFlowFile = session.write(sqlFlowFile, out -> {
+ out.write(query.getBytes());
+ });
+ session.transfer(sqlFlowFile, REL_SUCCESS);
+ }
+ }else {
+ for (int i = 0; i < numberOfFetches; i++) {
+ FlowFile sqlFlowFile;
- Integer limit = partitionSize == 0 ? null : partitionSize;
- Integer offset = partitionSize == 0 ? null : i *
partitionSize;
- final String query =
dbAdapter.getSelectStatement(tableName, columnNames, whereClause,
StringUtils.join(maxValueColumnNameList, ", "), limit, offset);
- sqlFlowFile = session.create();
- sqlFlowFile = session.write(sqlFlowFile, out -> {
- out.write(query.getBytes());
- });
- session.transfer(sqlFlowFile, REL_SUCCESS);
+ Integer limit = partitionSize;
+ whereClause = indexValue + " >= " + limit * i;
--- End diff --
GenerateTableFetch stores max value columns in managed state, so that when
it runs again, it fetches only records those have grater max column values.
If we rewrite the `whereClause` here based on only partitionSize, it breaks
this behavior when it runs the 2nd time or later.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---