Use Spark distributed JDBC DataFrame reader in SqlToRddOperator - #798
Conversation
|
@zkaoudi |
There was a problem hiding this comment.
Pull request overview
Refactors the JDBC-template Spark execution path to avoid collecting JDBC ResultSets on the Spark driver by switching SqlToRddOperator to Spark’s distributed JDBC DataFrameReader, improving scalability for large query results.
Changes:
- Replaces driver-side
ResultSetmaterialization +sc.parallelize(...)with distributedspark.read().format("jdbc")and lazyRow -> Recordconversion. - Adds configurable JDBC read options (credentials, optional partitioning, optional fetch size) and load profile estimator keys for
SqlToRddOperator. - Implements JSON serialization/deserialization for
SqlToRddOperatorand adds unit tests forrowToRecordand JSON round-trip basics.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| wayang-platforms/wayang-jdbc-template/src/main/java/org/apache/wayang/jdbc/operators/SqlToRddOperator.java | Moves JDBC reads to Spark’s distributed reader, adds query cleanup, optional read tuning, load profiling keys, and JSON (de)serialization. |
| wayang-platforms/wayang-jdbc-template/src/main/java/org/apache/wayang/jdbc/execution/DatabaseDescriptor.java | Exposes JDBC connection parameter getters needed by Spark’s JDBC reader. |
| wayang-platforms/wayang-jdbc-template/src/test/java/org/apache/wayang/jdbc/operators/SqlToRddOperatorTest.java | Adds tests for rowToRecord behavior and basic JSON serialization/deserialization. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
d942b5f to
b52cf27
Compare
|
Using Spark SQL at Tests:
Resolved Spark dependencies are mixed:
The POM needs one Please fix the dependency alignment and rerun |
b52cf27 to
df9b341
Compare
|
Updated the PR with the following:
|
|
The Spark and ANTLR mismatch is fixed, but always validate the full impact of the dependency upgrade with a full test run: => The Spark 3.5.7 upgrade introduces a Parquet runtime regression. Parquet dependencies are mixed:
Spark 3.5.7 references Test evidence: Full test run in that PR produced 3 errors:
Aligning the Parquet dependencies with Spark 3.5.7 should fix that, and rerun the Spark reactor afterwards ;) |
|
@novatechflow understood, i will just fix these deprecations. |
df9b341 to
28ef734
Compare
|
@novatechflow , I just aligned the Parquet dependencies to |
|
+1 - looks good, but also when we merge, we may introduce incompatibility issues with users relying specifically on Spark 3.4.4 or Parquet 1.15.2. "release note needed" as flag added. |
novatechflow
left a comment
There was a problem hiding this comment.
thank you @AliRana30 for this contribution.
@novatechflow whenver we will face any issue in the future regarding the incompability just mention this PR and I will continue working on it. |
Description
Closes #761
Currently,
SqlToRddOperatorexecutes JDBC queries and materializes the entireResultSetinto ajava.util.Listin the Spark driver JVM memory before callingsc.parallelize(...). On large analytical engines (such as Trino, Presto, BigQuery, and PostgreSQL), this causes out-of-memory bottlenecks on the driver and prevents Spark from leveraging distributed JDBC execution.This PR refactors
SqlToRddOperatorto use Spark's distributedDataFrameReaderJDBC interface (executor.ss.read().format("jdbc")):Dataset<Row>.Dataset<Row>toJavaRDD<Record>lazily across Spark executors using a static serializable helper method (rowToRecord).(query) as wayang_subquery.DatabaseDescriptor(getJdbcUrl(),getUser(),getPassword(),getJdbcDriverClassName()).partitionColumn,lowerBound,upperBound,numPartitions) andfetchsize.toJson()andfromJson()serialization and load profile estimator keys.Type of Change
How Has This Been Tested?
testRowToRecordandtestJsonSerializationunit tests toSqlToRddOperatorTest.