Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -218,7 +218,7 @@ object FunctionRegistry {
expression[PosExplode]("posexplode"),
expressionGeneratorOuter[PosExplode]("posexplode_outer"),
expression[Rand]("rand"),
expression[Rand]("random"),
expression[Rand]("random", true),
expression[Randn]("randn"),
expression[Stack]("stack"),
expression[CaseWhen]("when"),
Expand All @@ -235,7 +235,7 @@ object FunctionRegistry {
expression[BRound]("bround"),
expression[Cbrt]("cbrt"),
expression[Ceil]("ceil"),
expression[Ceil]("ceiling"),
expression[Ceil]("ceiling", true),
expression[Cos]("cos"),
expression[Cosh]("cosh"),
expression[Conv]("conv"),
Expand All @@ -252,20 +252,20 @@ object FunctionRegistry {
expression[Log1p]("log1p"),
expression[Log2]("log2"),
expression[Log]("ln"),
expression[Remainder]("mod"),
expression[Remainder]("mod", true),
expression[UnaryMinus]("negative"),
expression[Pi]("pi"),
expression[Pmod]("pmod"),
expression[UnaryPositive]("positive"),
expression[Pow]("pow"),
expression[Pow]("pow", true),
expression[Pow]("power"),
expression[ToRadians]("radians"),
expression[Rint]("rint"),
expression[Round]("round"),
expression[ShiftLeft]("shiftleft"),
expression[ShiftRight]("shiftright"),
expression[ShiftRightUnsigned]("shiftrightunsigned"),
expression[Signum]("sign"),
expression[Signum]("sign", true),
expression[Signum]("signum"),
expression[Sin]("sin"),
expression[Sinh]("sinh"),
Expand Down Expand Up @@ -323,12 +323,12 @@ object FunctionRegistry {

// string functions
expression[Ascii]("ascii"),
expression[Chr]("char"),
expression[Chr]("char", true),
expression[Chr]("chr"),
expression[Base64]("base64"),
expression[BitLength]("bit_length"),
expression[Length]("char_length"),
expression[Length]("character_length"),
expression[Length]("char_length", true),
expression[Length]("character_length", true),
expression[ConcatWs]("concat_ws"),
expression[Decode]("decode"),
expression[Elt]("elt"),
Expand All @@ -351,7 +351,7 @@ object FunctionRegistry {
expression[JsonTuple]("json_tuple"),
expression[ParseUrl]("parse_url"),
expression[StringLocate]("position"),
expression[FormatString]("printf"),
expression[FormatString]("printf", true),
expression[RegExpExtract]("regexp_extract"),
expression[RegExpReplace]("regexp_replace"),
expression[StringRepeat]("repeat"),
Expand All @@ -364,21 +364,21 @@ object FunctionRegistry {
expression[SoundEx]("soundex"),
expression[StringSpace]("space"),
expression[StringSplit]("split"),
expression[Substring]("substr"),
expression[Substring]("substr", true),
expression[Substring]("substring"),
expression[Left]("left"),
expression[Right]("right"),
expression[SubstringIndex]("substring_index"),
expression[StringTranslate]("translate"),
expression[StringTrim]("trim"),
expression[Upper]("ucase"),
expression[Upper]("ucase", true),
expression[UnBase64]("unbase64"),
expression[Unhex]("unhex"),
expression[Upper]("upper"),
expression[XPathList]("xpath"),
expression[XPathBoolean]("xpath_boolean"),
expression[XPathDouble]("xpath_double"),
expression[XPathDouble]("xpath_number"),
expression[XPathDouble]("xpath_number", true),
expression[XPathFloat]("xpath_float"),
expression[XPathInt]("xpath_int"),
expression[XPathLong]("xpath_long"),
Expand All @@ -393,7 +393,7 @@ object FunctionRegistry {
expression[DateAdd]("date_add"),
expression[DateFormatClass]("date_format"),
expression[DateSub]("date_sub"),
expression[DayOfMonth]("day"),
expression[DayOfMonth]("day", true),
expression[DayOfYear]("dayofyear"),
expression[DayOfMonth]("dayofmonth"),
expression[FromUnixTime]("from_unixtime"),
Expand All @@ -404,7 +404,7 @@ object FunctionRegistry {
expression[Month]("month"),
expression[MonthsBetween]("months_between"),
expression[NextDay]("next_day"),
expression[CurrentTimestamp]("now"),
expression[CurrentTimestamp]("now", true),
expression[Quarter]("quarter"),
expression[Second]("second"),
expression[ParseToTimestamp]("to_timestamp"),
Expand Down Expand Up @@ -445,7 +445,7 @@ object FunctionRegistry {
expression[MapConcat]("map_concat"),
expression[Size]("size"),
expression[Slice]("slice"),
expression[Size]("cardinality"),
expression[Size]("cardinality", true),
expression[ArraysZip]("arrays_zip"),
expression[SortArray]("sort_array"),
expression[Shuffle]("shuffle"),
Expand Down Expand Up @@ -478,7 +478,7 @@ object FunctionRegistry {
expression[Uuid]("uuid"),
expression[Murmur3Hash]("hash"),
expression[XxHash64]("xxhash64"),
expression[Sha1]("sha"),
expression[Sha1]("sha", true),
expression[Sha1]("sha1"),
expression[Sha2]("sha2"),
expression[SparkPartitionID]("spark_partition_id"),
Expand All @@ -488,7 +488,7 @@ object FunctionRegistry {
expression[MonotonicallyIncreasingID]("monotonically_increasing_id"),
expression[CurrentDatabase]("current_database"),
expression[CallMethodViaReflection]("reflect"),
expression[CallMethodViaReflection]("java_method"),
expression[CallMethodViaReflection]("java_method", true),
expression[SparkVersion]("version"),
expression[TypeOf]("typeof"),

Expand Down Expand Up @@ -590,7 +590,9 @@ object FunctionRegistry {
if (varargCtor.isDefined) {
// If there is an apply method that accepts Seq[Expression], use that one.
try {
varargCtor.get.newInstance(expressions).asInstanceOf[Expression]
val exp = varargCtor.get.newInstance(expressions).asInstanceOf[Expression]
if (setAlias) exp.setTagValue(FUNC_ALIAS, name)
exp
} catch {
// the exception is an invocation exception. To get a meaningful message, we need the
// cause.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package org.apache.spark.sql.catalyst.expressions
import java.lang.reflect.{Method, Modifier}

import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult
import org.apache.spark.sql.catalyst.analysis.{FunctionRegistry, TypeCheckResult}
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult.{TypeCheckFailure, TypeCheckSuccess}
import org.apache.spark.sql.catalyst.expressions.codegen.CodegenFallback
import org.apache.spark.sql.types._
Expand Down Expand Up @@ -55,7 +55,7 @@ import org.apache.spark.util.Utils
case class CallMethodViaReflection(children: Seq[Expression])
extends Expression with CodegenFallback {

override def prettyName: String = "reflect"
override def prettyName: String = getTagValue(FunctionRegistry.FUNC_ALIAS).getOrElse("reflect")

override def checkInputDataTypes(): TypeCheckResult = {
if (children.size < 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ package org.apache.spark.sql.catalyst.expressions
import java.util.Locale

import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.analysis.{TypeCheckResult, TypeCoercion}
import org.apache.spark.sql.catalyst.analysis.{FunctionRegistry, TypeCheckResult, TypeCoercion}
import org.apache.spark.sql.catalyst.expressions.aggregate.DeclarativeAggregate
import org.apache.spark.sql.catalyst.expressions.codegen._
import org.apache.spark.sql.catalyst.expressions.codegen.Block._
Expand Down Expand Up @@ -258,7 +258,8 @@ abstract class Expression extends TreeNode[Expression] {
* Returns a user-facing string representation of this expression's name.
* This should usually match the name of the function in SQL.
*/
def prettyName: String = nodeName.toLowerCase(Locale.ROOT)
def prettyName: String =
getTagValue(FunctionRegistry.FUNC_ALIAS).getOrElse(nodeName.toLowerCase(Locale.ROOT))

protected def flatArguments: Iterator[Any] = stringArgs.flatMap {
case t: Iterable[_] => t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,5 @@ case class First(child: Expression, ignoreNullsExpr: Expression)

override lazy val evaluateExpression: AttributeReference = first

override def prettyName: String = getTagValue(FunctionRegistry.FUNC_ALIAS).getOrElse("first")

override def toString: String = s"$prettyName($child)${if (ignoreNulls) " ignore nulls"}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,5 @@ case class Last(child: Expression, ignoreNullsExpr: Expression)

override lazy val evaluateExpression: AttributeReference = last

override def prettyName: String = getTagValue(FunctionRegistry.FUNC_ALIAS).getOrElse("last")

override def toString: String = s"$prettyName($child)${if (ignoreNulls) " ignore nulls"}"
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.spark.sql.catalyst.expressions

import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.analysis.{TypeCheckResult, TypeCoercion}
import org.apache.spark.sql.catalyst.analysis.{FunctionRegistry, TypeCheckResult, TypeCoercion}
import org.apache.spark.sql.catalyst.expressions.codegen._
import org.apache.spark.sql.catalyst.expressions.codegen.Block._
import org.apache.spark.sql.catalyst.util.{IntervalUtils, TypeUtils}
Expand Down Expand Up @@ -457,6 +457,18 @@ case class Remainder(left: Expression, right: Expression) extends DivModLike {

override def symbol: String = "%"
override def decimalMethod: String = "remainder"
override def toString: String = {
getTagValue(FunctionRegistry.FUNC_ALIAS).getOrElse(sqlOperator) match {
case operator if operator == sqlOperator => s"($left $sqlOperator $right)"
case funcName => s"$funcName($left, $right)"
}
}
override def sql: String = {
getTagValue(FunctionRegistry.FUNC_ALIAS).getOrElse(sqlOperator) match {
case operator if operator == sqlOperator => s"(${left.sql} $sqlOperator ${right.sql})"
case funcName => s"$funcName(${left.sql}, ${right.sql})"
}
}

private lazy val mod: (Any, Any) => Any = dataType match {
// special cases to make float/double primitive types faster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import org.apache.commons.text.StringEscapeUtils
import org.apache.spark.SparkUpgradeException
import org.apache.spark.sql.AnalysisException
import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.analysis.FunctionRegistry
import org.apache.spark.sql.catalyst.expressions.codegen._
import org.apache.spark.sql.catalyst.expressions.codegen.Block._
import org.apache.spark.sql.catalyst.util.{DateTimeUtils, LegacyDateFormats, TimestampFormatter}
Expand Down Expand Up @@ -99,7 +100,8 @@ case class CurrentTimestamp() extends LeafExpression with CodegenFallback {

override def eval(input: InternalRow): Any = currentTimestamp()

override def prettyName: String = "current_timestamp"
override def prettyName: String =
getTagValue(FunctionRegistry.FUNC_ALIAS).getOrElse("current_timestamp")
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import java.{lang => jl}
import java.util.Locale

import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult
import org.apache.spark.sql.catalyst.analysis.{FunctionRegistry, TypeCheckResult}
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult.{TypeCheckFailure, TypeCheckSuccess}
import org.apache.spark.sql.catalyst.expressions.codegen._
import org.apache.spark.sql.catalyst.expressions.codegen.Block._
Expand Down Expand Up @@ -62,8 +62,8 @@ abstract class UnaryMathExpression(val f: Double => Double, name: String)
override def inputTypes: Seq[AbstractDataType] = Seq(DoubleType)
override def dataType: DataType = DoubleType
override def nullable: Boolean = true
override def toString: String = s"$name($child)"
override def prettyName: String = name
override def toString: String = s"$prettyName($child)"
override def prettyName: String = getTagValue(FunctionRegistry.FUNC_ALIAS).getOrElse(name)

protected override def nullSafeEval(input: Any): Any = {
f(input.asInstanceOf[Double])
Expand Down Expand Up @@ -115,9 +115,9 @@ abstract class BinaryMathExpression(f: (Double, Double) => Double, name: String)

override def inputTypes: Seq[DataType] = Seq(DoubleType, DoubleType)

override def toString: String = s"$name($left, $right)"
override def toString: String = s"$prettyName($left, $right)"

override def prettyName: String = name
override def prettyName: String = getTagValue(FunctionRegistry.FUNC_ALIAS).getOrElse(name)

override def dataType: DataType = DoubleType

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import scala.collection.mutable.ArrayBuffer
import org.apache.commons.codec.binary.{Base64 => CommonsBase64}

import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult
import org.apache.spark.sql.catalyst.analysis.{FunctionRegistry, TypeCheckResult}
import org.apache.spark.sql.catalyst.expressions.codegen._
import org.apache.spark.sql.catalyst.expressions.codegen.Block._
import org.apache.spark.sql.catalyst.util.{ArrayData, GenericArrayData, TypeUtils}
Expand Down Expand Up @@ -1450,7 +1450,7 @@ case class ParseUrl(children: Seq[Expression])
// scalastyle:on line.size.limit
case class FormatString(children: Expression*) extends Expression with ImplicitCastInputTypes {

require(children.nonEmpty, "format_string() should take at least 1 argument")
require(children.nonEmpty, s"$prettyName() should take at least 1 argument")

override def foldable: Boolean = children.forall(_.foldable)
override def nullable: Boolean = children(0).nullable
Expand Down Expand Up @@ -1517,7 +1517,8 @@ case class FormatString(children: Expression*) extends Expression with ImplicitC
}""")
}

override def prettyName: String = "format_string"
override def prettyName: String = getTagValue(
FunctionRegistry.FUNC_ALIAS).getOrElse("format_string")
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

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

import org.apache.spark.sql.catalyst.analysis.TypeCheckResult
import org.apache.spark.sql.catalyst.analysis.{FunctionRegistry, TypeCheckResult}
import org.apache.spark.sql.catalyst.analysis.TypeCheckResult.TypeCheckFailure
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.expressions.codegen.CodegenFallback
Expand Down Expand Up @@ -160,7 +160,8 @@ case class XPathFloat(xml: Expression, path: Expression) extends XPathExtract {
""")
// scalastyle:on line.size.limit
case class XPathDouble(xml: Expression, path: Expression) extends XPathExtract {
override def prettyName: String = "xpath_double"
override def prettyName: String =
getTagValue(FunctionRegistry.FUNC_ALIAS).getOrElse("xpath_double")
override def dataType: DataType = DoubleType

override def nullSafeEval(xml: Any, path: Any): Any = {
Expand Down
14 changes: 7 additions & 7 deletions sql/core/src/test/resources/sql-tests/results/operators.sql.out
Original file line number Diff line number Diff line change
Expand Up @@ -293,15 +293,15 @@ struct<COT(CAST(-1 AS DOUBLE)):double>
-- !query
select ceiling(0)
-- !query schema
struct<CEIL(CAST(0 AS DOUBLE)):bigint>
struct<ceiling(CAST(0 AS DOUBLE)):bigint>
-- !query output
0


-- !query
select ceiling(1)
-- !query schema
struct<CEIL(CAST(1 AS DOUBLE)):bigint>
struct<ceiling(CAST(1 AS DOUBLE)):bigint>
-- !query output
1

Expand All @@ -317,7 +317,7 @@ struct<CEIL(1234567890123456):bigint>
-- !query
select ceiling(1234567890123456)
-- !query schema
struct<CEIL(1234567890123456):bigint>
struct<ceiling(1234567890123456):bigint>
-- !query output
1234567890123456

Expand All @@ -333,7 +333,7 @@ struct<CEIL(0.01):decimal(1,0)>
-- !query
select ceiling(-0.10)
-- !query schema
struct<CEIL(-0.10):decimal(1,0)>
struct<ceiling(-0.10):decimal(1,0)>
-- !query output
0

Expand Down Expand Up @@ -389,7 +389,7 @@ true
-- !query
select mod(7, 2), mod(7, 0), mod(0, 2), mod(7, null), mod(null, 2), mod(null, null)
-- !query schema
struct<(7 % 2):int,(7 % 0):int,(0 % 2):int,(7 % CAST(NULL AS INT)):int,(CAST(NULL AS INT) % 2):int,(CAST(NULL AS DOUBLE) % CAST(NULL AS DOUBLE)):double>
struct<mod(7, 2):int,mod(7, 0):int,mod(0, 2):int,mod(7, CAST(NULL AS INT)):int,mod(CAST(NULL AS INT), 2):int,mod(CAST(NULL AS DOUBLE), CAST(NULL AS DOUBLE)):double>
-- !query output
1 NULL 0 NULL NULL NULL

Expand All @@ -405,15 +405,15 @@ struct<bit_length(abc):int>
-- !query
select CHAR_LENGTH('abc')
-- !query schema
struct<length(abc):int>
struct<char_length(abc):int>
-- !query output
3


-- !query
select CHARACTER_LENGTH('abc')
-- !query schema
struct<length(abc):int>
struct<character_length(abc):int>
-- !query output
3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ struct<>
-- !query
select col1, col2, char_length(col3) from inserttest
-- !query schema
struct<col1:int,col2:int,length(col3):int>
struct<col1:int,col2:int,char_length(col3):int>
-- !query output
30 50 10000
NULL 3 7
Expand Down
Loading