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
6 changes: 6 additions & 0 deletions common/utils/src/main/resources/error/error-conditions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2386,6 +2386,12 @@
],
"sqlState" : "42601"
},
"INVALID_BUCKET_COUNT" : {
"message" : [
"BucketBy must specify a bucket count > 0, received <numBuckets> instead."
],
"sqlState" : "22003"
},
"INVALID_BUCKET_FILE" : {
"message" : [
"Invalid bucket file: <path>."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,21 @@
*/
package org.apache.spark.sql.connect.common

import scala.jdk.CollectionConverters._

import org.apache.spark.{SparkThrowable, SparkThrowableHelper}

/**
* Error thrown when a connect command is not valid.
*/
final case class InvalidCommandInput(
private val message: String = "",
private val errorCondition: String,
private val messageParameters: Map[String, String] = Map.empty,
private val cause: Throwable = null)
extends Exception(message, cause)
extends Exception(SparkThrowableHelper.getMessage(errorCondition, messageParameters), cause)
with SparkThrowable {

override def getCondition: String = errorCondition

override def getMessageParameters: java.util.Map[String, String] = messageParameters.asJava
}
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ object InvalidInputErrors {
InvalidPlanInput("UnionByName `allowMissingCol` can be true only if `byName` is true.")

def invalidBucketCount(numBuckets: Int): InvalidCommandInput =
InvalidCommandInput("BucketBy must specify a bucket count > 0, received $numBuckets instead.")
InvalidCommandInput("INVALID_BUCKET_COUNT", Map("numBuckets" -> numBuckets.toString))

def invalidPythonUdtfReturnType(actualType: String): InvalidPlanInput =
InvalidPlanInput(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,9 +658,12 @@ class SparkConnectProtoSuite extends PlanTest with SparkConnectPlanTest {

test("Write with invalid bucketBy configuration") {
val cmd = localRelation.write(bucketByCols = Seq("id"), numBuckets = Some(0))
assertThrows[InvalidCommandInput] {
transform(cmd)
}
checkError(
exception = intercept[InvalidCommandInput] {
transform(cmd)
},
condition = "INVALID_BUCKET_COUNT",
parameters = Map("numBuckets" -> "0"))
}

test("Write to Path") {
Expand Down