Repository navigation
Conversation
Add a `query` argument to `spark.SparkJDBCDataset` so that the result of a SQL query can be loaded through Spark's JDBC `query` option, instead of only whole tables. `table` and `query` are mutually exclusive, a query-based dataset is read-only, and only `properties` (including the credentials) are accepted in `load_args` together with `query`, since Spark does not allow partitioning options with `query`. Closes kedro-org#639 Signed-off-by: Dhruv Gupta <todhruvg@gmail.com>
|
Thanks @DG47 for this PR! The issue associated with this PR has not been marked for external contribution yet. As a policy, we only accept contributions for issues marked as "Ready" on this board: OS contribution tasks |
|
Thanks @DG47 for this PR! The issue associated with this PR has not been marked for external contribution yet. As a policy, we only accept contributions for issues marked as "Ready" on this board: OS contribution tasks |
Description
Closes #639.
spark.SparkJDBCDatasetcan currently only load whole tables. Spark's JDBC source also supports aqueryoption, which lets the database run the filtering, joins or aggregation and return only the result. This PR adds aqueryargument to the dataset, as discussed in the issue:Development notes
tableis now optional andqueryis new; exactly one of them must be provided (DatasetErrorif both or neither are given).query,load()usesspark.read.format("jdbc")with thepropertiesfromload_args(credentials included, as before) plus theurlandqueryoptions. Unlike the sketch in the issue thread, the connection properties and credentials are passed through, so authenticated databases work.save()raises aDatasetErrorasking fortableinstead.query,load_argsmay only containproperties. Spark does not allowpartitionColumnwithquery, andpredicatesrelies ondbtable, socolumn/lowerBound/upperBound/numPartitions/predicatesare rejected at construction with a clear message rather than failing later inside Spark._describe()now includesquery.spark.SparkJDBCDatasetentry instatic/jsonschema/kedro-catalog-1.0.0.json(queryproperty,tableno longer required,oneOftable/query like other datasets in the schema),RELEASE.md, and the line number in.secrets.baselinethat moved with the docstring.Testing:
pytest tests/spark/test_spark_jdbc_dataset.py --cov-config pyproject.toml --cov=kedro_datasets: 22 passed,spark_jdbc_dataset.pyat 100% coverage. The 7 new tests fail onmain.pre-commit run --hook-stage manual --files <changed files>(ruff, black, detect-secrets, bandit, blacken-docs and the file checks) passes, andmypy kedro_datasets/spark/spark_jdbc_dataset.py --ignore-missing-importsreports no issues.table=..., loaded a filtered query withquery=...usingcredentials.urland extraproperties, and confirmed thatsave()on the query dataset raises the new error.Developer Certificate of Origin
We need all contributions to comply with the Developer Certificate of Origin (DCO). All commits must be signed off by including a
Signed-off-byline in the commit message. See our wiki for guidance.If your PR is blocked due to unsigned commits, then you must follow the instructions under "Rebase the branch" on the GitHub Checks page for your PR. This will retroactively add the sign-off to all unsigned commits and allow the DCO check to pass.
Checklist
jsonschema/kedro-catalog-X.XX.jsonif necessaryRELEASE.mdfile