Skip to content

Commit 958c1ab

Browse files
ilicmarkodbcloud-fan
authored andcommitted
[SPARK-52710][SQL] DESCRIBE SCHEMA should print collation
### What changes were proposed in this pull request? Extended `DescribeDatabaseCommand` to print collation. ### Why are the changes needed? Part of new feature. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Updated `describe.sql`. ### Was this patch authored or co-authored using generative AI tooling? No. Closes #51401 from ilicmarkodb/fix_describe_schema. Authored-by: ilicmarkodb <marko.ilic@databricks.com> Signed-off-by: Wenchen Fan <wenchen@databricks.com>
1 parent aa0a508 commit 958c1ab

File tree

5 files changed

+98
-2
lines changed

5 files changed

+98
-2
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ case class DescribeDatabaseCommand(
189189
Row("Catalog Name", SESSION_CATALOG_NAME) ::
190190
Row("Database Name", dbMetadata.name) ::
191191
Row("Comment", dbMetadata.description) ::
192-
Row("Location", CatalogUtils.URIToString(dbMetadata.locationUri))::
193-
Row("Owner", allDbProperties.getOrElse(PROP_OWNER, "")) :: Nil
192+
Row("Location", CatalogUtils.URIToString(dbMetadata.locationUri)) ::
193+
Row("Owner", allDbProperties.getOrElse(PROP_OWNER, "")) ::
194+
allDbProperties.get(PROP_COLLATION).map(Row("Collation", _)).toList
194195

195196
if (extended) {
196197
val properties = allDbProperties -- CatalogV2Util.NAMESPACE_RESERVED_PROPERTIES

sql/core/src/test/resources/sql-tests/analyzer-results/describe.sql.out

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,41 @@ org.apache.spark.sql.catalyst.parser.ParseException
213213
}
214214

215215

216+
-- !query
217+
DROP SCHEMA IF EXISTS test_schema
218+
-- !query analysis
219+
DropNamespace true, false
220+
+- ResolvedNamespace V2SessionCatalog(spark_catalog), [test_schema]
221+
222+
223+
-- !query
224+
CREATE SCHEMA test_schema DEFAULT COLLATION UNICODE
225+
-- !query analysis
226+
CreateNamespace false, [collation=UNICODE]
227+
+- ResolvedNamespace V2SessionCatalog(spark_catalog), [test_schema]
228+
229+
230+
-- !query
231+
DESCRIBE SCHEMA EXTENDED test_schema
232+
-- !query analysis
233+
DescribeNamespace true, [info_name#x, info_value#x]
234+
+- ResolvedNamespace V2SessionCatalog(spark_catalog), [test_schema]
235+
236+
237+
-- !query
238+
ALTER SCHEMA test_schema DEFAULT COLLATION UTF8_LCASE
239+
-- !query analysis
240+
SetNamespaceCollationCommand UTF8_LCASE
241+
+- ResolvedNamespace V2SessionCatalog(spark_catalog), [test_schema]
242+
243+
244+
-- !query
245+
DESCRIBE SCHEMA EXTENDED test_schema
246+
-- !query analysis
247+
DescribeNamespace true, [info_name#x, info_value#x]
248+
+- ResolvedNamespace V2SessionCatalog(spark_catalog), [test_schema]
249+
250+
216251
-- !query
217252
DESC temp_v
218253
-- !query analysis

sql/core/src/test/resources/sql-tests/inputs/describe.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,13 @@ DESC t PARTITION (c='Us');
6464
-- ParseException: PARTITION specification is incomplete
6565
DESC t PARTITION (c='Us', d);
6666

67+
-- DESC SCHEMA
68+
DROP SCHEMA IF EXISTS test_schema;
69+
CREATE SCHEMA test_schema DEFAULT COLLATION UNICODE;
70+
DESCRIBE SCHEMA EXTENDED test_schema;
71+
ALTER SCHEMA test_schema DEFAULT COLLATION UTF8_LCASE;
72+
DESCRIBE SCHEMA EXTENDED test_schema;
73+
6774
-- DESC Temp View
6875

6976
DESC temp_v;

sql/core/src/test/resources/sql-tests/results/describe.sql.out

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,58 @@ org.apache.spark.sql.catalyst.parser.ParseException
453453
}
454454

455455

456+
-- !query
457+
DROP SCHEMA IF EXISTS test_schema
458+
-- !query schema
459+
struct<>
460+
-- !query output
461+
462+
463+
464+
-- !query
465+
CREATE SCHEMA test_schema DEFAULT COLLATION UNICODE
466+
-- !query schema
467+
struct<>
468+
-- !query output
469+
470+
471+
472+
-- !query
473+
DESCRIBE SCHEMA EXTENDED test_schema
474+
-- !query schema
475+
struct<info_name:string,info_value:string>
476+
-- !query output
477+
Catalog Name spark_catalog
478+
Collation UNICODE
479+
Comment
480+
Location [not included in comparison]/{warehouse_dir}/test_schema.db
481+
Namespace Name test_schema
482+
Owner [not included in comparison]
483+
Properties
484+
485+
486+
-- !query
487+
ALTER SCHEMA test_schema DEFAULT COLLATION UTF8_LCASE
488+
-- !query schema
489+
struct<>
490+
-- !query output
491+
492+
493+
494+
-- !query
495+
DESCRIBE SCHEMA EXTENDED test_schema
496+
-- !query schema
497+
struct<info_name:string,info_value:string>
498+
-- !query output
499+
Catalog Name spark_catalog
500+
Collation UTF8_LCASE
501+
Comment
502+
Location [not included in comparison]/{warehouse_dir}/test_schema.db
503+
Namespace Name test_schema
504+
Owner [not included in comparison]
505+
Properties
506+
507+
456508
-- !query
457509
DESC temp_v
458510
-- !query schema

sql/core/src/test/scala/org/apache/spark/sql/SQLQueryTestSuite.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ class SQLQueryTestSuite extends QueryTest with SharedSparkSession with SQLHelper
156156
// SPARK-39564: don't print out serde to avoid introducing complicated and error-prone
157157
// regex magic.
158158
.set("spark.test.noSerdeInExplain", "true")
159+
.set(SQLConf.SCHEMA_LEVEL_COLLATIONS_ENABLED, true)
159160

160161
// SPARK-32106 Since we add SQL test 'transform.sql' will use `cat` command,
161162
// here we need to ignore it.

0 commit comments

Comments
 (0)