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
Prev Previous commit
Next Next commit
fix scala style.
  • Loading branch information
jovanpavl-db committed Sep 25, 2024
commit 5328ab7141d5d61ee5802700676879287c87f94f
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,11 @@ private[sql] object QueryCompilationErrors extends QueryErrorsBase with Compilat
)
}

def trimCollationNotEnabledError() : Throwable = {
def trimCollationNotEnabledError(): Throwable = {
new AnalysisException(
errorClass = "UNSUPPORTED_FEATURE.TRIM_COLLATION",
messageParameters = Map.empty)
messageParameters = Map.empty
)
}

def unresolvedUsingColForJoinError(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -761,9 +761,11 @@ object SQLConf {

lazy val TRIM_COLLATION_ENABLED =
buildConf("spark.sql.collation.trim.enabled")
.doc("Trim collation feature is under development and its use should be done under this" +
.doc(
"Trim collation feature is under development and its use should be done under this" +
"feature flag. Trim collation trims leading, trailing or both spaces depending of" +
"specifier (LTRIM, RTRIM, TRIM).")
"specifier (LTRIM, RTRIM, TRIM)."
)
.version("4.0.0")
.booleanConf
.createWithDefault(Utils.isTesting)
Expand Down
47 changes: 27 additions & 20 deletions sql/core/src/test/scala/org/apache/spark/sql/CollationSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ class CollationSuite extends DatasourceV2SQLBase with AdaptiveSparkPlanHelper {
"unicode_ltrim_ci",
"utf8_lcase_trim",
"utf8_binary_rtrim"
).foreach {
collationName =>
checkAnswer(sql(s"select 'aaa' collate $collationName"), Row("aaa"))
val collationId = CollationFactory.collationNameToId(collationName)
assert(sql(s"select 'aaa' collate $collationName").schema(0).dataType
== StringType(collationId))
).foreach { collationName =>
checkAnswer(sql(s"select 'aaa' collate $collationName"), Row("aaa"))
val collationId = CollationFactory.collationNameToId(collationName)
assert(
sql(s"select 'aaa' collate $collationName").schema(0).dataType
== StringType(collationId)
)
}
}

Expand All @@ -70,12 +71,13 @@ class CollationSuite extends DatasourceV2SQLBase with AdaptiveSparkPlanHelper {
"uNiCoDE_ltRIm_cI",
"UtF8_lCaSE_tRIM",
"utf8_biNAry_RtRiM"
).foreach {
collationName =>
checkAnswer(sql(s"select 'aaa' collate $collationName"), Row("aaa"))
val collationId = CollationFactory.collationNameToId(collationName)
assert(sql(s"select 'aaa' collate $collationName").schema(0).dataType
== StringType(collationId))
).foreach { collationName =>
checkAnswer(sql(s"select 'aaa' collate $collationName"), Row("aaa"))
val collationId = CollationFactory.collationNameToId(collationName)
assert(
sql(s"select 'aaa' collate $collationName").schema(0).dataType
== StringType(collationId)
)
}
}

Expand All @@ -88,10 +90,11 @@ class CollationSuite extends DatasourceV2SQLBase with AdaptiveSparkPlanHelper {
"unicode_ci_ltrim",
"utf8_lcase_trim",
"utf8_binary_rtrim"
).foreach {
collationName =>
checkAnswer(
sql(s"select collation('aaa' collate $collationName)"), Row(collationName.toUpperCase()))
).foreach { collationName =>
checkAnswer(
sql(s"select collation('aaa' collate $collationName)"),
Row(collationName.toUpperCase())
)
}
}

Expand All @@ -104,11 +107,15 @@ class CollationSuite extends DatasourceV2SQLBase with AdaptiveSparkPlanHelper {

test("collate function syntax with default collation set") {
withSQLConf(SqlApiConf.DEFAULT_COLLATION -> "UTF8_LCASE") {
assert(sql(s"select collate('aaa', 'utf8_lcase')").schema(0).dataType ==
StringType("UTF8_LCASE"))
assert(
sql(s"select collate('aaa', 'utf8_lcase')").schema(0).dataType ==
StringType("UTF8_LCASE")
)
assert(sql(s"select collate('aaa', 'UNICODE')").schema(0).dataType == StringType("UNICODE"))
assert(sql(s"select collate('aaa', 'UNICODE_TRIM')").schema(0).dataType ==
StringType("UNICODE_TRIM"))
assert(
sql(s"select collate('aaa', 'UNICODE_TRIM')").schema(0).dataType ==
StringType("UNICODE_TRIM")
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -873,11 +873,12 @@ class QueryCompilationErrorsSuite
Seq(
"CREATE TABLE t(col STRING COLLATE EN_TRIM_CI) USING parquet",
"CREATE TABLE t(col STRING COLLATE UTF8_LCASE_TRIM) USING parquet",
"SELECT 'aaa' COLLATE UNICODE_LTRIM_CI",
"SELECT 'aaa' COLLATE UNICODE_LTRIM_CI"
).foreach { sqlText =>
checkError(
exception = intercept[AnalysisException](sql(sqlText)),
condition = "UNSUPPORTED_FEATURE.TRIM_COLLATION")
condition = "UNSUPPORTED_FEATURE.TRIM_COLLATION"
)
}
}
}
Expand All @@ -887,14 +888,15 @@ class QueryCompilationErrorsSuite
Seq(
"SELECT collate('aaa', 'UNICODE_TRIM')",
"SELECT collate('aaa', 'UTF8_BINARY_TRIM')",
"SELECT collate('aaa', 'EN_AI_RTRIM')",
"SELECT collate('aaa', 'EN_AI_RTRIM')"
).foreach { sqlText =>
checkError(
exception = intercept[AnalysisException](sql(sqlText)),
condition = "UNSUPPORTED_FEATURE.TRIM_COLLATION",
parameters = Map.empty,
context = ExpectedContext(
fragment = sqlText.substring(7), start = 7, stop = sqlText.length - 1))
context =
ExpectedContext(fragment = sqlText.substring(7), start = 7, stop = sqlText.length - 1)
)
}
}
}
Expand Down