Skip to content

Commit 42f83d7

Browse files
committed
[SPARK-17920][FOLLOWUP] simplify the schema file creation in test
## What changes were proposed in this pull request? a followup of #19779 , to simplify the file creation. ## How was this patch tested? test only change Author: Wenchen Fan <[email protected]> Closes #19799 from cloud-fan/minor.
1 parent b4edafa commit 42f83d7

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

sql/hive/src/test/scala/org/apache/spark/sql/hive/client/VersionsSuite.scala

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -843,15 +843,12 @@ class VersionsSuite extends SparkFunSuite with Logging {
843843

844844
test(s"$version: SPARK-17920: Insert into/overwrite avro table") {
845845
withTempDir { dir =>
846-
val path = dir.getAbsolutePath
847-
val schemaPath = s"""$path${File.separator}avroschemadir"""
848-
849-
new File(schemaPath).mkdir()
850846
val avroSchema =
851-
"""{
847+
"""
848+
|{
852849
| "name": "test_record",
853850
| "type": "record",
854-
| "fields": [ {
851+
| "fields": [{
855852
| "name": "f0",
856853
| "type": [
857854
| "null",
@@ -862,17 +859,17 @@ class VersionsSuite extends SparkFunSuite with Logging {
862859
| "logicalType": "decimal"
863860
| }
864861
| ]
865-
| } ]
862+
| }]
866863
|}
867864
""".stripMargin
868-
val schemaUrl = s"""$schemaPath${File.separator}avroDecimal.avsc"""
869-
val schemaFile = new File(schemaPath, "avroDecimal.avsc")
865+
val schemaFile = new File(dir, "avroDecimal.avsc")
870866
val writer = new PrintWriter(schemaFile)
871867
writer.write(avroSchema)
872868
writer.close()
869+
val schemaPath = schemaFile.getCanonicalPath
873870

874871
val url = Thread.currentThread().getContextClassLoader.getResource("avroDecimal")
875-
val srcLocation = new File(url.getFile)
872+
val srcLocation = new File(url.getFile).getCanonicalPath
876873
val destTableName = "tab1"
877874
val srcTableName = "tab2"
878875

@@ -886,7 +883,7 @@ class VersionsSuite extends SparkFunSuite with Logging {
886883
| INPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat'
887884
| OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat'
888885
|LOCATION '$srcLocation'
889-
|TBLPROPERTIES ('avro.schema.url' = '$schemaUrl')
886+
|TBLPROPERTIES ('avro.schema.url' = '$schemaPath')
890887
""".stripMargin
891888
)
892889

@@ -898,7 +895,7 @@ class VersionsSuite extends SparkFunSuite with Logging {
898895
|STORED AS
899896
| INPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat'
900897
| OUTPUTFORMAT 'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat'
901-
|TBLPROPERTIES ('avro.schema.url' = '$schemaUrl')
898+
|TBLPROPERTIES ('avro.schema.url' = '$schemaPath')
902899
""".stripMargin
903900
)
904901
versionSpark.sql(

0 commit comments

Comments
 (0)