Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-29554][SQL] Add version SQL function #26209

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ object FunctionRegistry {
expression[CurrentDatabase]("current_database"),
expression[CallMethodViaReflection]("reflect"),
expression[CallMethodViaReflection]("java_method"),
expression[Version]("version"),

// grouping sets
expression[Cube]("cube"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@

package org.apache.spark.sql.catalyst.expressions

import java.util.UUID

import org.apache.spark._
dongjoon-hyun marked this conversation as resolved.
Show resolved Hide resolved
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.expressions.codegen._
import org.apache.spark.sql.catalyst.expressions.codegen.Block._
Expand Down Expand Up @@ -164,3 +163,17 @@ case class Uuid(randomSeed: Option[Long] = None) extends LeafExpression with Sta

override def freshCopy(): Uuid = Uuid(randomSeed)
}

// scalastyle:off line.size.limit
@ExpressionDescription(
usage =
"""_FUNC_() - Returns the Spark version. The string contains 2 fields, the first being a release or snapshot version and the second being a git revision.""",
yaooqinn marked this conversation as resolved.
Show resolved Hide resolved
since = """3.0.0""")
dongjoon-hyun marked this conversation as resolved.
Show resolved Hide resolved
dongjoon-hyun marked this conversation as resolved.
Show resolved Hide resolved
// scalastyle:on line.size.limit
case class Version() extends LeafExpression with CodegenFallback {
Copy link
Member

Choose a reason for hiding this comment

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

Could we change the class name to SparkVersion()? Version() is too general as a class name.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

+1

Copy link
Member Author

Choose a reason for hiding this comment

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

+1

Copy link
Member

Choose a reason for hiding this comment

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

+1.

Copy link
Member

Choose a reason for hiding this comment

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

+1

override def nullable: Boolean = false
dongjoon-hyun marked this conversation as resolved.
Show resolved Hide resolved
override def dataType: DataType = StringType
override def eval(input: InternalRow): Any = {
UTF8String.fromString(SPARK_VERSION + " " + SPARK_REVISION)
dongjoon-hyun marked this conversation as resolved.
Show resolved Hide resolved
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package org.apache.spark.sql

import org.apache.spark._
dongjoon-hyun marked this conversation as resolved.
Show resolved Hide resolved
import org.apache.spark.sql.test.SharedSparkSession

class MiscFunctionsSuite extends QueryTest with SharedSparkSession {
Expand All @@ -31,6 +32,12 @@ class MiscFunctionsSuite extends QueryTest with SharedSparkSession {
s"java_method('$className', 'method1', a, b)"),
Row("m1one", "m1one"))
}

test("version") {
checkAnswer(
Seq("").toDF("a").selectExpr("version()"),
Row(SPARK_VERSION + " " + SPARK_REVISION))
dongjoon-hyun marked this conversation as resolved.
Show resolved Hide resolved
}
}

object ReflectClass {
Expand Down