This is an automated email from the ASF dual-hosted git repository.
exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new fc25938740d NIFI-16433 Reject ExecuteSQL Fetch Size of 0 (#11766)
fc25938740d is described below
commit fc25938740d6a7458eeaa0031515048a430ca53f
Author: Mark Payne <[email protected]>
AuthorDate: Tue Oct 6 15:31:03 2026 -0400
NIFI-16433 Reject ExecuteSQL Fetch Size of 0 (#11766)
Signed-off-by: David Handermann <[email protected]>
---
.../processors/standard/AbstractExecuteSQL.java | 13 +++++++++---
.../nifi/processors/standard/TestExecuteSQL.java | 23 ++++++++++++++++++++--
2 files changed, 31 insertions(+), 5 deletions(-)
diff --git
a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractExecuteSQL.java
b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractExecuteSQL.java
index b13964381b6..1548f64432a 100644
---
a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractExecuteSQL.java
+++
b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/AbstractExecuteSQL.java
@@ -52,6 +52,7 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
@@ -60,6 +61,7 @@ import java.util.stream.Collectors;
public abstract class AbstractExecuteSQL extends AbstractProcessor {
+ public static final String DEFAULT_FETCH_SIZE = "1000";
public static final String RESULT_ROW_COUNT = "executesql.row.count";
public static final String RESULT_QUERY_DURATION =
"executesql.query.duration";
public static final String RESULT_QUERY_EXECUTION_TIME =
"executesql.query.executiontime";
@@ -166,10 +168,10 @@ public abstract class AbstractExecuteSQL extends
AbstractProcessor {
public static final PropertyDescriptor FETCH_SIZE = new
PropertyDescriptor.Builder()
.name("Fetch Size")
.description("The number of result rows to be fetched from the
result set at a time. This is a hint to the database driver and may not be "
- + "honored and/or exact. If the value specified is zero,
then the hint is ignored.")
- .defaultValue("0")
+ + "honored and/or exact. The value must be greater than
zero.")
+ .defaultValue(DEFAULT_FETCH_SIZE)
.required(true)
- .addValidator(StandardValidators.NON_NEGATIVE_INTEGER_VALIDATOR)
+ .addValidator(StandardValidators.POSITIVE_INTEGER_VALIDATOR)
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
.build();
@@ -220,6 +222,11 @@ public abstract class AbstractExecuteSQL extends
AbstractProcessor {
config.renameProperty("sql-post-query", SQL_POST_QUERY.getName());
config.renameProperty("esql-output-batch-size",
OUTPUT_BATCH_SIZE.getName());
config.renameProperty("esql-fetch-size", FETCH_SIZE.getName());
+ final Optional<String> configuredFetchSize =
config.getRawPropertyValue(FETCH_SIZE.getName());
+ if (configuredFetchSize.isPresent() &&
"0".equals(configuredFetchSize.get())) {
+ config.setProperty(FETCH_SIZE.getName(), DEFAULT_FETCH_SIZE);
+ }
+
config.renameProperty("esql-auto-commit", AUTO_COMMIT.getName());
OBSOLETE_MAX_ROWS_PER_FLOW_FILE.forEach(obsoleteName ->
config.renameProperty(obsoleteName, MAX_ROWS_PER_FLOW_FILE.getName()));
}
diff --git
a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQL.java
b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQL.java
index 268af9584bc..c8f5ff6e306 100644
---
a/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQL.java
+++
b/nifi-extension-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestExecuteSQL.java
@@ -21,6 +21,7 @@ import org.apache.avro.file.DataFileStream;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.io.DatumReader;
+import org.apache.nifi.components.ValidationResult;
import org.apache.nifi.dbcp.DBCPService;
import org.apache.nifi.flowfile.attributes.CoreAttributes;
import org.apache.nifi.flowfile.attributes.FragmentAttributes;
@@ -54,6 +55,7 @@ import static
org.apache.nifi.util.db.JdbcProperties.USE_AVRO_LOGICAL_TYPES;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
@@ -638,8 +640,25 @@ public class TestExecuteSQL extends
AbstractDatabaseConnectionServiceTest {
Map.entry(JdbcProperties.OLD_DEFAULT_SCALE_PROPERTY_NAME,
DEFAULT_SCALE.getName())
);
- final PropertyMigrationResult propertyMigrationResult =
runner.migrateProperties();
- assertEquals(expectedRenamed,
propertyMigrationResult.getPropertiesRenamed());
+ assertEquals(AbstractExecuteSQL.DEFAULT_FETCH_SIZE,
AbstractExecuteSQL.FETCH_SIZE.getDefaultValue());
+
+ final ValidationResult zeroFetchSize =
runner.setProperty(AbstractExecuteSQL.FETCH_SIZE, "0");
+ assertFalse(zeroFetchSize.isValid());
+
+ final PropertyMigrationResult zeroResult = runner.migrateProperties();
+ assertEquals(expectedRenamed, zeroResult.getPropertiesRenamed());
+ assertEquals(AbstractExecuteSQL.DEFAULT_FETCH_SIZE,
runner.getProcessContext().getAllProperties().get(AbstractExecuteSQL.FETCH_SIZE.getName()));
+
assertTrue(zeroResult.getPropertiesUpdated().contains(AbstractExecuteSQL.FETCH_SIZE.getName()));
+
+ runner.setProperty("esql-fetch-size", "0");
+ final PropertyMigrationResult renamedZeroResult =
runner.migrateProperties();
+ assertEquals(AbstractExecuteSQL.DEFAULT_FETCH_SIZE,
runner.getProcessContext().getAllProperties().get(AbstractExecuteSQL.FETCH_SIZE.getName()));
+
assertTrue(renamedZeroResult.getPropertiesUpdated().contains(AbstractExecuteSQL.FETCH_SIZE.getName()));
+
+ runner.setProperty(AbstractExecuteSQL.FETCH_SIZE, "${fetch.size}");
+ final PropertyMigrationResult expressionResult =
runner.migrateProperties();
+ assertEquals("${fetch.size}",
runner.getProcessContext().getAllProperties().get(AbstractExecuteSQL.FETCH_SIZE.getName()));
+
assertFalse(expressionResult.getPropertiesUpdated().contains(AbstractExecuteSQL.FETCH_SIZE.getName()));
}
private void insertRecords() throws SQLException {