Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18977#discussion_r133831063
  
    --- Diff: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/client/VersionsSuite.scala ---
    @@ -697,6 +696,71 @@ class VersionsSuite extends SparkFunSuite with Logging 
{
             assert(versionSpark.table("t1").collect() === Array(Row(2)))
           }
         }
    +
    +    test(s"$version: Decimal support of Avro Hive serde") {
    +      val tableName = "tab1"
    +      val avroSchema =
    +        """{
    +          |  "name": "test_record",
    +          |  "type": "record",
    +          |  "fields": [ {
    +          |    "name": "f0",
    +          |    "type": [
    +          |      "null",
    +          |      {
    +          |        "precision": 38,
    +          |        "scale": 2,
    +          |        "type": "bytes",
    +          |        "logicalType": "decimal"
    +          |      }
    +          |    ]
    +          |  } ]
    +          |}
    +        """.stripMargin
    +
    +      Seq(true, false).foreach { isPartitioned =>
    +        withTable(tableName) {
    +          val partitionClause = if (isPartitioned) "PARTITIONED BY (ds 
STRING)" else ""
    +          // Creates the (non-)partitioned Avro table
    +          versionSpark.sql(
    +            s"""
    +               |CREATE TABLE $tableName
    +               |$partitionClause
    +               |ROW FORMAT SERDE 
'org.apache.hadoop.hive.serde2.avro.AvroSerDe'
    +               |STORED AS
    +               |  INPUTFORMAT 
'org.apache.hadoop.hive.ql.io.avro.AvroContainerInputFormat'
    +               |  OUTPUTFORMAT 
'org.apache.hadoop.hive.ql.io.avro.AvroContainerOutputFormat'
    +               |TBLPROPERTIES ('avro.schema.literal' = '$avroSchema')
    +           """.stripMargin
    +          )
    +
    +          val errorMsg = "data type mismatch: cannot cast DecimalType(2,1) 
to BinaryType"
    +
    +          if (isPartitioned) {
    +            val insertStmt = s"INSERT OVERWRITE TABLE $tableName partition 
(ds='a') SELECT 1.3"
    +            if (version == "0.12" || version == "0.13") {
    --- End diff --
    
    Yes. Our dear Hive metastore change the schema we inferred. We got the 
warning messages for 0.12 and 0.13
    
    ```
    12:04:09.816 WARN org.apache.spark.sql.hive.test.TestHiveExternalCatalog: 
The table schema given by Hive metastore(struct<f0:binary,ds:string>) is 
different from the schema when this table was created by Spark 
SQL(struct<f0:decimal(38,2),ds:string>). We have to fall back to the table 
schema from Hive metastore which is not case preserving.
    ```


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to