forked from apache/spark
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-48906][SQL] Introduce
SHOW COLLATIONS LIKE ...
syntax to sho…
…w all collations ### What changes were proposed in this pull request? The pr aims to introduce `SHOW COLLATIONS LIKE ...` syntax to `show all collations`. ### Why are the changes needed? End-users will be able to obtain `collations` currently supported by the spark through SQL. Other databases, such as `MySQL`, also have similar syntax, ref: https://dev.mysql.com/doc/refman/9.0/en/show-collation.html <img width="958" alt="image" src="https://github.com/user-attachments/assets/1d5106b3-f8b8-42c5-b3ad-0f35c61ad5e2"> postgresql: https://database.guide/how-to-return-a-list-of-available-collations-in-postgresql/ ### Does this PR introduce _any_ user-facing change? Yes, end-users will be able to obtain `collation` currently supported by the spark through commands similar to the following |name|provider|version|binaryEquality|binaryOrdering|lowercaseEquality| | --------- | ----------- | ----------- | ----------- | ----------- | ----------- | ``` spark-sql (default)> SHOW COLLATIONS; UTF8_BINARY spark 1.0 true true false UTF8_LCASE spark 1.0 false false true ff_Adlm icu 153.120.0.0 false false false ff_Adlm_CI icu 153.120.0.0 false false false ff_Adlm_AI icu 153.120.0.0 false false false ff_Adlm_CI_AI icu 153.120.0.0 false false false ... spark-sql (default)> SHOW COLLATIONS LIKE '*UTF8_BINARY*'; UTF8_BINARY spark 1.0 true true false Time taken: 0.043 seconds, Fetched 1 row(s) ``` <img width="513" alt="image" src="https://github.com/user-attachments/assets/d5765e32-718d-4236-857d-d508f5473329"> ### How was this patch tested? Add new UT. ### Was this patch authored or co-authored using generative AI tooling? No. Closes apache#47364 from panbingkun/show_collation_syntax. Authored-by: panbingkun <panbingkun@baidu.com> Signed-off-by: Max Gekk <max.gekk@gmail.com>
- Loading branch information
1 parent
b466f32
commit 0f4d289
Showing
12 changed files
with
278 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ CLOSE | |
COALESCE | ||
COLLATE | ||
COLLATION | ||
COLLATIONS | ||
COLLECT | ||
COLUMN | ||
COMMIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
sql/core/src/main/scala/org/apache/spark/sql/execution/command/ShowCollationsCommand.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql.execution.command | ||
|
||
import org.apache.spark.sql.{Row, SparkSession} | ||
import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeReference} | ||
import org.apache.spark.sql.catalyst.util.CollationFactory.CollationMeta | ||
import org.apache.spark.sql.types.StringType | ||
|
||
/** | ||
* A command for `SHOW COLLATIONS`. | ||
* | ||
* The syntax of this command is: | ||
* {{{ | ||
* SHOW COLLATIONS (LIKE? pattern=stringLit)?; | ||
* }}} | ||
*/ | ||
case class ShowCollationsCommand(pattern: Option[String]) extends LeafRunnableCommand { | ||
|
||
override val output: Seq[Attribute] = Seq( | ||
AttributeReference("COLLATION_CATALOG", StringType, nullable = false)(), | ||
AttributeReference("COLLATION_SCHEMA", StringType, nullable = false)(), | ||
AttributeReference("COLLATION_NAME", StringType, nullable = false)(), | ||
AttributeReference("LANGUAGE", StringType)(), | ||
AttributeReference("COUNTRY", StringType)(), | ||
AttributeReference("ACCENT_SENSITIVITY", StringType, nullable = false)(), | ||
AttributeReference("CASE_SENSITIVITY", StringType, nullable = false)(), | ||
AttributeReference("PAD_ATTRIBUTE", StringType, nullable = false)(), | ||
AttributeReference("ICU_VERSION", StringType)()) | ||
|
||
override def run(sparkSession: SparkSession): Seq[Row] = { | ||
val systemCollations: Seq[CollationMeta] = | ||
sparkSession.sessionState.catalog.listCollations(pattern) | ||
|
||
systemCollations.map(m => Row( | ||
m.catalog, | ||
m.schema, | ||
m.collationName, | ||
m.language, | ||
m.country, | ||
if (m.accentSensitivity) "ACCENT_SENSITIVE" else "ACCENT_INSENSITIVE", | ||
if (m.caseSensitivity) "CASE_SENSITIVE" else "CASE_INSENSITIVE", | ||
m.padAttribute, | ||
m.icuVersion | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.