-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-23072][SQL][TEST] Add a Unicode schema test for file-based data sources #20266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
f9a35f1
60b8e43
144c596
5afaa28
fb708b7
8fec65b
c67809c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * 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 | ||
|
|
||
| import org.apache.spark.sql.test.SharedSQLContext | ||
|
|
||
| class FileBasedDataSourceSuite extends QueryTest with SharedSQLContext { | ||
| import testImplicits._ | ||
|
|
||
| Seq("orc", "parquet", "csv", "json", "text").foreach { format => | ||
| test(s"Writing empty datasets should not fail - $format") { | ||
| withTempPath { dir => | ||
| Seq("str").toDS().limit(0).write.format(format).save(dir.getCanonicalPath) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Seq("orc", "parquet", "csv", "json").foreach { format => | ||
| test(s"SPARK-23072 Write and read back unicode schema - $format") { | ||
| withTempPath { path => | ||
| val dir = path.getCanonicalPath | ||
|
|
||
| // scalastyle:off nonascii | ||
| val df = Seq("a").toDF("한글") | ||
| // scalastyle:on nonascii | ||
|
|
||
| df.write.format(format).option("header", "true").save(dir) | ||
| val answerDf = spark.read.format(format).option("header", "true").load(dir) | ||
|
|
||
| assert(df.schema === answerDf.schema) | ||
| checkAnswer(df, answerDf) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Seq("orc", "parquet").foreach { format => | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only these two formats support it? If so, please add the comments. This is the same comment to the other test cases. Otherwise, add all of them for each test case. You can define a global Seq to include all the built-in file formats we support.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks!
|
||
| test(s"SPARK-15474 Write and read back non-emtpy schema with empty dataframe - $format") { | ||
| withTempPath { file => | ||
| val path = file.getCanonicalPath | ||
| val emptyDf = Seq((true, 1, "str")).toDF().limit(0) | ||
| emptyDf.write.format(format).save(path) | ||
|
|
||
| val df = spark.read.format(format).load(path) | ||
| assert(df.schema.sameType(emptyDf.schema)) | ||
| checkAnswer(df, emptyDf) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Seq("orc", "parquet", "csv", "json", "text").foreach { format => | ||
| test(s"SPARK-22146 read files containing special characters using $format") { | ||
| val nameWithSpecialChars = s"sp&cial%chars" | ||
| withTempDir { dir => | ||
| val tmpFile = s"$dir/$nameWithSpecialChars" | ||
| spark.createDataset(Seq("a", "b")).write.format(format).save(tmpFile) | ||
| val fileContent = spark.read.format(format).load(tmpFile) | ||
| checkAnswer(fileContent, Seq(Row("a"), Row("b"))) | ||
| } | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unicode schema->unicode column namesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep.