Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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._
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,14 @@ case class Uuid(randomSeed: Option[Long] = None) extends LeafExpression with Sta

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

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

override def dataType: DataType = StringType

override def eval(input: InternalRow): Any = {
UTF8String.fromString(SPARK_VERSION + " " + SPARK_REVISION)
}

}
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._
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))
}
}

object ReflectClass {
Expand Down