mirror of https://github.com/apache/nifi.git
NIFI-5855: Remove unnecessary ORDER BY clause in GenerateTableFetch when Partition Size is zero
Signed-off-by: Pierre Villard <pierre.villard.fr@gmail.com> This closes #3191.
This commit is contained in:
parent
72662f0b2c
commit
8a12307d1a
|
@ -315,8 +315,8 @@ public class GenerateTableFetch extends AbstractDatabaseFetchProcessor {
|
|||
String columnsClause = null;
|
||||
List<String> maxValueSelectColumns = new ArrayList<>(numMaxValueColumns + 1);
|
||||
|
||||
// replace unnecessary row count with -1 stub value when paging is used
|
||||
if (useColumnValsForPaging) {
|
||||
// replace unnecessary row count with -1 stub value when column values for paging is used, or when partition size is zero.
|
||||
if (useColumnValsForPaging || partitionSize == 0) {
|
||||
maxValueSelectColumns.add("-1");
|
||||
} else {
|
||||
maxValueSelectColumns.add("COUNT(*)");
|
||||
|
@ -496,8 +496,10 @@ public class GenerateTableFetch extends AbstractDatabaseFetchProcessor {
|
|||
//Update WHERE list to include new right hand boundaries
|
||||
whereClause = maxValueClauses.isEmpty() ? "1=1" : StringUtils.join(maxValueClauses, " AND ");
|
||||
Long offset = partitionSize == 0 ? null : i * partitionSize + (useColumnValsForPaging ? minValueForPartitioning : 0);
|
||||
// Don't use an ORDER BY clause if there's only one partition
|
||||
final String orderByClause = partitionSize == 0 ? null : maxColumnNames;
|
||||
|
||||
final String query = dbAdapter.getSelectStatement(tableName, columnNames, whereClause, maxColumnNames, limit, offset, columnForPartitioning);
|
||||
final String query = dbAdapter.getSelectStatement(tableName, columnNames, whereClause, orderByClause, limit, offset, columnForPartitioning);
|
||||
FlowFile sqlFlowFile = (fileToProcess == null) ? session.create() : session.create(fileToProcess);
|
||||
sqlFlowFile = session.write(sqlFlowFile, out -> out.write(query.getBytes()));
|
||||
Map<String,String> attributesToAdd = new HashMap<>();
|
||||
|
|
|
@ -541,7 +541,7 @@ public class TestGenerateTableFetch {
|
|||
runner.run();
|
||||
runner.assertAllFlowFilesTransferred(GenerateTableFetch.REL_SUCCESS, 1);
|
||||
MockFlowFile flowFile = runner.getFlowFilesForRelationship(GenerateTableFetch.REL_SUCCESS).get(0);
|
||||
flowFile.assertContentEquals("SELECT * FROM TEST_QUERY_DB_TABLE WHERE ID <= 2 ORDER BY ID");
|
||||
flowFile.assertContentEquals("SELECT * FROM TEST_QUERY_DB_TABLE WHERE ID <= 2");
|
||||
flowFile.assertAttributeExists("generatetablefetch.limit");
|
||||
flowFile.assertAttributeEquals("generatetablefetch.limit", null);
|
||||
runner.clearTransferState();
|
||||
|
|
Loading…
Reference in New Issue