gengliangwang commented on PR #59520: URL: https://github.com/apache/spark/pull/59520#issuecomment-6751943382
Thanks, @sarutak. My answers, and what I'll change in this PR: 1. Yes for offsets, since the offset log outlives any build of the library: the SDK stores exactly `serde_json::to_string(&offset)`, without an envelope, and later versions will not wrap or re-encode it, so the format of an offset is that of the connector's `Offset` type. The state, partitions and messages never outlive an application and are read by the same build (see 4), so their bytes stay an implementation detail. The serde features that they support are part of the API, though, since a format that is not self-describing would break `untagged`, `flatten` and even `skip_serializing_if` at run time. I'll document that the SDK encodes them with `serde_json`, and that they must round-trip through JSON: a NaN or an infinite float becomes `null`, which does not decode, and map keys cannot be structs or tuples. 2. Yes, and the README will say so. Stable Rust has no associated type defaults (rust-lang/rust#29661), and the alternatives either lose the typed `Factory`, `Offset` and `Message`, as trait objects would, or make an operation silently unsupported when the export macro does not list it, as one trait per operation would. New kinds of operations should be rare, and the compiler error names the missing type. Growth within an operation does not break connectors: the SDK can add `push_domains`, which SPARK-61200 (#59929) appended to version 1, as a `ScanBuilder` method with a default, and the `#[non_exhaustive]` structs can gain fields once every method takes one (see the inline thread). 3. Publishing to crates.io needs a release process, as Arrow and DataFusion have for their crates, so I'll file a follow-up JIRA and keep `publish = false`; until then, a connector uses a path dependency on a Spark source tree, as the examples do. I'd version the crate on its own, from 0.x. Spark supports [version 1 of the ABI in all the releases of Spark 4 from 4.4.0](https://github.com/apache/spark/blob/6f9123594fc7df866d28110bc9d68b2d91f592b7/sql/core/src/main/resources/org/apache/spark/sql/datasource/spark_datasource.h#L223-L226), but the Rust API may need to break in any Spark release, for a new major version of Arrow, whose types it exposes, or for a new kind of operation; with Spark's versions, both would wait for Spark 5. The README will say which ABI version and Spark releases the SDK supports. Agreed on the name: I'll rename the crate to `spark-datasource`, after `spark_datasource.h`. 4. Spark already rules this out: an executor only loads the build that the driver loaded, which it checks with [the SHA-256 checksum of the library or package](https://github.com/apache/spark/blob/6f9123594fc7df866d28110bc9d68b2d91f592b7/docs/sql-native-data-sources.md?plain=1#L360-L371), and fails the query with `NATIVE_DATA_SOURCE_LIBRARY_NOT_FOUND` on a node with another build. A fingerprint would only repeat that check, so I'll fix the misleading README sentence instead. 5. Agreed. fdf0cb1c9ddf already documents that an unplanned `ScanBuilder` may be dropped late and on another thread, and makes the SDK drop a write right after a successful `commit` or an `abort`, so the write of a micro-batch no longer lives until Spark creates the next one. I'll add that a builder must not hold exclusive resources until Drop, and that `PartitionReaderFactory::open` may run for the same partition at the same time, in several attempts of its task. As @dongjoon-hyun found ([r4515939460](https://github.com/apache/spark/pull/59520#discussion_r4515939460)), the JVM's stream writer does not close its handle after commit or abort, as its batch writer does, so I filed SPARK-61284 to fix that for the libraries without this SDK. 6. Yes, on read. Spark rejects such a value when it converts it to a row ([`Decimal.set`](https://github.com/apache/spark/blob/6f9123594fc7df866d28110bc9d68b2d91f592b7/sql/api/src/main/scala/org/apache/spark/sql/types/Decimal.scala#L119-L131) fails with `NUMERIC_VALUE_OUT_OF_RANGE`, and the `NativeColumnVector` of #59961 keeps that check), so only a native scan written to a native sink lets it through. The check goes into the traversal that already checks nullability, and one comparison per value is cheap next to producing it. The SDK will not check the batches that a sink gets: a sink can call `validate_decimal_precision` of arrow-rs itself. From your review: - CI: SPARK-61283 is the follow-up, and the description now says that the Rust and C tests do not run in CI yet. - Done in 097a532a9db0: `dev/make-distribution.sh` leaves out `examples/src/main/rust`, which only builds in a source tree. - This PR now uses SPARK-61282, a sub-task of SPARK-60488. I'll push the other changes here; the C++ SDK (#59726) will get the rename and the decimal check too. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
