maropu commented on a change in pull request #29045:
URL: https://github.com/apache/spark/pull/29045#discussion_r452623395



##########
File path: 
sql/core/src/test/scala/org/apache/spark/sql/execution/datasources/orc/OrcColumnarBatchReaderSuite.scala
##########
@@ -77,4 +77,43 @@ class OrcColumnarBatchReaderSuite extends QueryTest with 
SharedSparkSession {
       assert(p1.getUTF8String(0) === partitionValues.getUTF8String(0))
     }
   }
+
+  test("orc data created by the hive tables having _col fields name") {
+    var error: Throwable = null
+    val table = """CREATE TABLE `test_date_hive_orc`
+                  | (`_col1` INT,`_col2` STRING,`_col3` INT)
+                  |  USING orc""".stripMargin
+    spark.sql(table).collect
+    spark.sql("insert into test_date_hive_orc values(9, '12', 2020)").collect
+    val df = spark.sql("select _col2 from test_date_hive_orc")
+    try {
+      val data = df.collect()
+      assert(data.length == 1)
+    } catch {
+      case e: Throwable =>
+        error = e
+    }
+    assert(error == null)
+    spark.sql(s"DROP TABLE IF EXISTS test_date_hive_orc")

Review comment:
       Please check the other tests carefully then follow how to write tests 
there. How about refactoring it like this?
   ```
       withTable("test_date_hive_orc") {
         spark.sql(
           s"""
              |CREATE TABLE test_date_hive_orc
              |  (col1 INT, col2 STRING, col3 INT)
              |  USING orc
            """.stripMargin)
         spark.sql(
           s"""
              |INSERT INTO test_date_hive_orc VALUES
              |  (9, '12', 2020)
            """.stripMargin)
   
         val df = spark.sql("SELECT col2 FROM test_date_hive_orc")
         checkAnswer(df, Row(...))
       }
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to