gengliangwang commented on code in PR #51419:
URL: https://github.com/apache/spark/pull/51419#discussion_r2244244974


##########
sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2MetadataOnlyTableSuite.scala:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.connector
+
+import org.apache.spark.SparkConf
+import org.apache.spark.sql.{QueryTest, Row}
+import org.apache.spark.sql.catalyst.analysis.NoSuchTableException
+import org.apache.spark.sql.connector.catalog.{Identifier, MetadataOnlyTable, 
Table, TableCatalog, TableChange, TableSummary}
+import org.apache.spark.sql.connector.expressions.LogicalExpressions
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.test.SharedSparkSession
+import org.apache.spark.sql.types.StructType
+import org.apache.spark.sql.util.CaseInsensitiveStringMap
+
+class DataSourceV2MetadataOnlyTableSuite extends QueryTest with 
SharedSparkSession {
+  import testImplicits._
+
+  override def sparkConf: SparkConf = super.sparkConf
+    .set("spark.sql.catalog.general_catalog", 
classOf[TestingGeneralCatalog].getName)
+
+  test("file source table") {
+    withTempPath { path =>
+      val loc = path.getCanonicalPath
+      val tableName = s"general_catalog.`$loc`.test_json"
+
+      spark.range(10).select($"id".cast("string").as("col")).write.json(loc)
+      checkAnswer(spark.table(tableName), 0.until(10).map(i => 
Row(i.toString)))
+
+      sql(s"INSERT INTO $tableName SELECT 'abc'")
+      checkAnswer(spark.table(tableName), 0.until(10).map(i => 
Row(i.toString)) :+ Row("abc"))
+
+      sql(s"INSERT OVERWRITE $tableName SELECT 'xyz'")
+      checkAnswer(spark.table(tableName), Row("xyz"))
+    }
+  }
+
+  test("partitioned file source table") {
+    withTempPath { path =>
+      val loc = path.getCanonicalPath
+      val tableName = s"general_catalog.`$loc`.test_partitioned_json"
+
+      Seq(1 -> 1, 2 -> 1).toDF("c1", "c2").write.partitionBy("c2").json(loc)
+      checkAnswer(spark.table(tableName), Seq(Row(1, 1), Row(2, 1)))
+
+      sql(s"INSERT INTO $tableName SELECT 1, 2")
+      checkAnswer(spark.table(tableName), Seq(Row(1, 1), Row(2, 1), Row(1, 2)))
+
+      sql(s"INSERT INTO $tableName PARTITION(c2=3) SELECT 1")
+      checkAnswer(spark.table(tableName), Seq(Row(1, 1), Row(2, 1), Row(1, 2), 
Row(1, 3)))
+
+      sql(s"INSERT OVERWRITE $tableName PARTITION(c2=2) SELECT 10")
+      checkAnswer(spark.table(tableName), Seq(Row(1, 1), Row(2, 1), Row(10, 
2), Row(1, 3)))
+
+      sql(s"INSERT OVERWRITE $tableName SELECT 20, 20")
+      checkAnswer(spark.table(tableName), Row(20, 20))
+    }
+  }
+
+  // TODO: move the v2 data source table handling from V2SessionCatalog to the 
analyzer
+  ignore("v2 data source table") {

Review Comment:
   Shall we add this test case later?



-- 
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.

To unsubscribe, e-mail: [email protected]

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