nacz0 opened a new pull request, #41840: URL: https://github.com/apache/beam/pull/41840
addresses #26661 MySQL Connector/J ignores positive fetch sizes by default and buffers the entire result set inside `executeQuery()`. Streaming requires either `Integer.MIN_VALUE` or `useCursorFetch=true` in the JDBC URL or connection properties. `ReadRows`, `Read`, and `ReadAll.withFetchSize()` have accepted `Integer.MIN_VALUE` since #23441, leaving three gaps: - `JdbcReadSchemaTransformProvider` (backing YAML `ReadFromJdbc`/`ReadFromMySql` and Managed MySQL) skipped any non-positive `fetchSize`, silently dropping `fetch_size: -2147483648` and falling back to the default 50,000. - `ReadFromMySqlSchemaTransformProvider.from()` rejected positive `fetchSize` values unless `useCursorFetch=true` appeared in `jdbcUrl`, rejecting configurations that set it in `connectionProperties`. - `ReadWithPartitions.withFetchSize()` rejected `Integer.MIN_VALUE` (`"fetchSize can not be less than 1"`), even though it delegates to `Read` and `ReadAll`, which accept it. ### Changes - `JdbcReadSchemaTransformProvider`: passes `Integer.MIN_VALUE` through on both the partitioned and unpartitioned read paths. `0` is still skipped as before; other negative values now fail fast in `validate()` instead of silently falling back to 50,000. - `ReadFromMySqlSchemaTransformProvider.from()`: calls `configuration.validate(jdbcType())` up front (matching `JdbcReadSchemaTransformProvider.from()`), accepts `useCursorFetch=true` in either `jdbcUrl` or `connectionProperties` when `fetchSize > 0`, and updates the error message to mention both options and `Integer.MIN_VALUE` (`-2147483648`). - `JdbcIO.ReadWithPartitions.withFetchSize()`: accepts `Integer.MIN_VALUE` while continuing to reject `0` and other negative values, with an updated error message. - Documentation: updates the `withFetchSize` Javadoc on `ReadRows`, `Read`, `ReadAll`, and `ReadWithPartitions`, the `fetchSize` `@SchemaFieldDescription`, and Python `ReadFromJdbc`'s `fetch_size` docstring to note MySQL's buffering behavior and streaming/cursor-fetch options. Python's docstring points to `connection_properties='useCursorFetch=true'` because `JdbcSchemaIOProvider` declares `fetchSize` as `int16` and cannot carry `Integer.MIN_VALUE` (widening the cross-language config schema is left for a separate change). No behavior change for other databases: `Integer.MIN_VALUE` only reaches the driver when explicitly configured, and drivers that reject it still fail in `Statement.setFetchSize` as with `ReadRows`. ### Tests - `JdbcReadSchemaTransformProviderTest`: verifies `Integer.MIN_VALUE` reaches both `JdbcIO.ReadRows` and `JdbcIO.ReadWithPartitions` (previously 50,000), `0` still keeps the default fetch size, and other negative values fail `validate()`. - `MysqlSchemaTransformTranslationTest`: verifies `ReadFromMySqlSchemaTransformProvider` accepts `Integer.MIN_VALUE` without `useCursorFetch=true`, accepts positive `fetchSize` with `useCursorFetch=true` in either `jdbc_url` or `connection_properties`, rejects positive `fetchSize` without `useCursorFetch=true`, and rejects other negative values. - `JdbcIOTest`: verifies `ReadWithPartitions.withFetchSize()` accepts `Integer.MIN_VALUE` and rejects `0` and `-1`. - Verified with `./gradlew :sdks:java:io:jdbc:check :sdks:java:managed:test :validateChanges` and E2E against MySQL 8.0 + Connector/J 8.0.22 (`DirectRunner`) on both partitioned and unpartitioned reads. With a 256 MB heap and 400k × ~1 KB rows, fetch size 50,000 OOMs while `Integer.MIN_VALUE` reads all rows at 152 MB peak heap (details in #26661). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
