feat: add comet_version() SQL function#4852
Conversation
Register a nullary SQL function via `SparkSessionExtensions.injectFunction` that returns the Comet build version string. This gives Spark users a supported way to query which Comet version is loaded from any language binding, e.g. `SELECT comet_version()`, without having to inspect JAR manifests or driver logs. The function returns the same value as the JVM `COMET_VERSION` constant (populated from `comet-git-info.properties` at build time).
8bf00ac to
fcf00db
Compare
comphead
left a comment
There was a problem hiding this comment.
Thanks @andygrove do we really need a function, we can come up with constants like sparkVerson on the sparkContext. Especially it would be more useful if we plan to expose Comet version to some sort of UI.
Currently it is possible to know Comet version by:
- checking classpath in spark UI
- asking loaded comet plugin jar filename
Today, users can evaluate |
The PySpark version is less intuitive: jvm = spark.sparkContext._jvm
pkg = getattr(jvm.org.apache.comet, "package$")
print(getattr(pkg, "MODULE$").COMET_VERSION()) |
Which issue does this PR close?
Rationale for this change
There is currently no built-in way for a Spark user to programmatically query which Comet version is loaded. The JVM
COMET_VERSIONconstant exists inorg.apache.comet.packagebut is only accessible via Scala imports; the native library also logs the version on init, but that requires driver log access. This PR exposes the version as a plain SQL function so it is reachable from PySpark, spark-sql, notebooks, and any other client that can issue SQL — no JVM/Scala imports and no log spelunking required.What changes are included in this PR?
comet_version()viaSparkSessionExtensions.injectFunctioninCometSparkSessionExtensions. The function returns theCOMET_VERSIONstring (already populated fromcomet-git-info.propertiesat build time) as a SparkStringTypeliteral.IllegalArgumentExceptionmentioning the function name.CometSparkSessionExtensionsSuite: one assertingSELECT comet_version()returns the expected build version, and one assertingcomet_version(1)fails.Compiles cleanly against
spark-3.4,spark-3.5,spark-4.0, andspark-4.1profiles.Example usage:
How are these changes tested?
CometSparkSessionExtensionsSuite(comet_version() returns the Comet build versionandcomet_version() rejects arguments).spark-3.5profile.-Pspark-3.4,-Pspark-3.5, and-Pspark-4.1 -Pscala-2.13.