pan3793 commented on code in PR #54411:
URL: https://github.com/apache/spark/pull/54411#discussion_r2836091851


##########
sql/core/src/test/scala/org/apache/spark/sql/connector/DataSourceV2SQLSessionCatalogSuite.scala:
##########
@@ -86,4 +86,34 @@ class DataSourceV2SQLSessionCatalogSuite
       sql("SELECT char_length('Hello') as v1, ns.strlen('Spark') as v2"),
       Row(5, 5))
   }
+
+  test("SPARK-55024: data source tables with multi-part identifiers") {
+    // This test querying data source tables with multi part identifiers,
+    // with the example of Iceberg's metadata table, eg db.table.snapshots
+    val t1 = "metadata_test_tbl"
+
+    def verify(snapshots: DataFrame, queryDesc: String): Unit = {
+      assert(snapshots.count() == 3,
+        s"$queryDesc: expected 3 snapshots")
+      assert(snapshots.schema.fieldNames.toSeq == Seq("committed_at", 
"snapshot_id"),
+        s"$queryDesc: expected schema [committed_at, snapshot_id], " +
+          s"got: ${snapshots.schema.fieldNames.toSeq}")
+      val snapshotIds = 
snapshots.select("snapshot_id").collect().map(_.getLong(0))
+      assert(snapshotIds.forall(_ > 0),
+        s"$queryDesc: all snapshot IDs should be positive, got: 
${snapshotIds.toSeq}")
+    }
+
+    withTable(t1) {
+      sql(s"CREATE TABLE $t1 (id bigint, data string) USING $v2Format")
+      sql(s"INSERT INTO $t1 VALUES (1, 'first')")
+      sql(s"INSERT INTO $t1 VALUES (2, 'second')")
+      sql(s"INSERT INTO $t1 VALUES (3, 'third')")
+
+      verify(sql(s"SELECT * FROM $t1.snapshots"), "table.snapshots")
+      verify(sql(s"SELECT * FROM default.$t1.snapshots"), 
"default.table.snapshots")
+      verify(
+        sql(s"SELECT * FROM spark_catalog.default.$t1.snapshots"),
+        "spark_catalog.default.table.snapshots")
+    }

Review Comment:
   
   ```
   Seq("$t1.snapshots", "default.$t1.snapshots", 
"spark_catalog.default.$t1.snapshots").foreach { tblName =>
     verify ...
   }
   ```



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