Skip to content
Closed
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
Next Next commit
fix
  • Loading branch information
LuciferYang committed Oct 31, 2022
commit 82cd8d8f98d5c36fb1f416377f61b735e4062984
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.apache.spark.sql.catalyst.expressions.Cast.{toSQLExpr, toSQLType}
import org.apache.spark.sql.catalyst.expressions.aggregate.{AggregateFunction, DeclarativeAggregate, NoOp}
import org.apache.spark.sql.catalyst.trees.{BinaryLike, LeafLike, TernaryLike, UnaryLike}
import org.apache.spark.sql.catalyst.trees.TreePattern.{TreePattern, UNRESOLVED_WINDOW_EXPRESSION, WINDOW_EXPRESSION}
import org.apache.spark.sql.errors.QueryExecutionErrors
import org.apache.spark.sql.errors.{QueryErrorsBase, QueryExecutionErrors}
import org.apache.spark.sql.types._

/**
Expand Down Expand Up @@ -709,7 +709,7 @@ case class CumeDist() extends RowNumberLike with SizeBasedWindowFunction with Le
// scalastyle:on line.size.limit line.contains.tab
case class NthValue(input: Expression, offset: Expression, ignoreNulls: Boolean)
extends AggregateWindowFunction with OffsetWindowFunction with ImplicitCastInputTypes
with BinaryLike[Expression] {
with BinaryLike[Expression] with QueryErrorsBase {

def this(child: Expression, offset: Expression) = this(child, offset, false)

Expand All @@ -729,10 +729,23 @@ case class NthValue(input: Expression, offset: Expression, ignoreNulls: Boolean)
if (check.isFailure) {
check
} else if (!offset.foldable) {
TypeCheckFailure(s"Offset expression '$offset' must be a literal.")
DataTypeMismatch(
errorSubClass = "NON_FOLDABLE_INPUT",
messageParameters = Map(
"inputName" -> "offset",
"inputType" -> toSQLType(offset.dataType),
"inputExpr" -> toSQLExpr(offset)
)
)
} else if (offsetVal <= 0) {
TypeCheckFailure(
s"The 'offset' argument of nth_value must be greater than zero but it is $offsetVal.")
DataTypeMismatch(
errorSubClass = "VALUE_OUT_OF_RANGE",
messageParameters = Map(
"exprName" -> "offset",
"valueRange" -> s"(0, ${Long.MaxValue}]",
"currentValue" -> toSQLValue(offsetVal, LongType)
)
)
} else {
TypeCheckSuccess
}
Expand Down Expand Up @@ -815,7 +828,7 @@ case class NthValue(input: Expression, offset: Expression, ignoreNulls: Boolean)
group = "window_funcs")
// scalastyle:on line.size.limit line.contains.tab
case class NTile(buckets: Expression) extends RowNumberLike with SizeBasedWindowFunction
with UnaryLike[Expression] {
with UnaryLike[Expression] with QueryErrorsBase {

def this() = this(Literal(1))

Expand All @@ -825,18 +838,39 @@ case class NTile(buckets: Expression) extends RowNumberLike with SizeBasedWindow
// for each partition.
override def checkInputDataTypes(): TypeCheckResult = {
if (!buckets.foldable) {
return TypeCheckFailure(s"Buckets expression must be foldable, but got $buckets")
DataTypeMismatch(
errorSubClass = "NON_FOLDABLE_INPUT",
messageParameters = Map(
"inputName" -> "buckets",
"inputType" -> toSQLType(buckets.dataType),
"inputExpr" -> toSQLExpr(buckets)
)
)
}

if (buckets.dataType != IntegerType) {
return TypeCheckFailure(s"Buckets expression must be integer type, but got $buckets")
DataTypeMismatch(
errorSubClass = "UNEXPECTED_INPUT_TYPE",
messageParameters = Map(
"paramIndex" -> "1",
"requiredType" -> toSQLType(IntegerType),
"inputSql" -> toSQLExpr(buckets),
"inputType" -> toSQLType(buckets.dataType))
)
}

val i = buckets.eval().asInstanceOf[Int]
if (i > 0) {
TypeCheckSuccess
} else {
TypeCheckFailure(s"Buckets expression must be positive, but got: $i")
DataTypeMismatch(
errorSubClass = "VALUE_OUT_OF_RANGE",
messageParameters = Map(
"exprName" -> "buckets",
"valueRange" -> s"(0, ${Int.MaxValue}]",
"currentValue" -> toSQLValue(i, IntegerType)
)
)
}
}

Expand Down