Skip to content

feat: add comet_version() SQL function#4852

Open
andygrove wants to merge 3 commits into
apache:mainfrom
andygrove:feat/comet-version-sql-function
Open

feat: add comet_version() SQL function#4852
andygrove wants to merge 3 commits into
apache:mainfrom
andygrove:feat/comet-version-sql-function

Conversation

@andygrove

Copy link
Copy Markdown
Member

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_VERSION constant exists in org.apache.comet.package but 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?

  • Register a nullary SQL function comet_version() via SparkSessionExtensions.injectFunction in CometSparkSessionExtensions. The function returns the COMET_VERSION string (already populated from comet-git-info.properties at build time) as a Spark StringType literal.
  • Reject any arguments with an IllegalArgumentException mentioning the function name.
  • Add two unit tests in CometSparkSessionExtensionsSuite: one asserting SELECT comet_version() returns the expected build version, and one asserting comet_version(1) fails.

Compiles cleanly against spark-3.4, spark-3.5, spark-4.0, and spark-4.1 profiles.

Example usage:

scala> spark.sql("SELECT comet_version()").show(false)
+----------------+
|comet_version() |
+----------------+
|1.0.0-SNAPSHOT  |
+----------------+

How are these changes tested?

  • New unit tests in CometSparkSessionExtensionsSuite (comet_version() returns the Comet build version and comet_version() rejects arguments).
  • Full suite runs green locally with the spark-3.5 profile.
  • Verified compilation with -Pspark-3.4, -Pspark-3.5, and -Pspark-4.1 -Pscala-2.13.

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).
@andygrove andygrove force-pushed the feat/comet-version-sql-function branch from 8bf00ac to fcf00db Compare July 7, 2026 21:04

@comphead comphead left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@andygrove

Copy link
Copy Markdown
Member Author

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 println(org.apache.comet.COMET_VERSION) in Scala spark-shell. I thought that having a SQL function would be more intuitive though.

@andygrove

Copy link
Copy Markdown
Member Author

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 println(org.apache.comet.COMET_VERSION) in Scala spark-shell. I thought that having a SQL function would be more intuitive though.

The PySpark version is less intuitive:

jvm = spark.sparkContext._jvm
pkg = getattr(jvm.org.apache.comet, "package$")
print(getattr(pkg, "MODULE$").COMET_VERSION())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants