bhat-vinay commented on code in PR #10491:
URL: https://github.com/apache/hudi/pull/10491#discussion_r1449904273


##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/TestHoodieTableValuedFunction.scala:
##########
@@ -558,4 +558,50 @@ class TestHoodieTableValuedFunction extends 
HoodieSparkSqlTestBase {
       }
     }
   }
+
+  test(s"Test hudi_metadata Table-Valued Function") {
+    if (HoodieSparkUtils.gteqSpark3_2) {
+      withTempDir { tmp =>
+        Seq("cow").foreach { tableType =>
+          val tableName = generateTableName
+          val identifier = tableName
+          spark.sql("set " + SPARK_SQL_INSERT_INTO_OPERATION.key + "=upsert")
+          spark.sql(
+            s"""
+               |create table $tableName (
+               |  id int,
+               |  name string,
+               |  ts long,
+               |  price int
+               |) using hudi
+               |partitioned by (price)
+               |tblproperties (
+               |  type = '$tableType',
+               |  primaryKey = 'id',
+               |  preCombineField = 'ts',
+               |  hoodie.datasource.write.recordkey.field = 'id',
+               |  hoodie.metadata.record.index.enable = 'true',
+               |  hoodie.metadata.index.column.stats.enable = 'true',
+               |  hoodie.metadata.index.column.stats.column.list = 'price'
+               |)
+               |location '${tmp.getCanonicalPath}/$tableName'
+               |""".stripMargin
+          )
+
+          spark.sql(
+            s"""
+               | insert into $tableName
+               | values (1, 'a1', 1000, 10), (2, 'a2', 2000, 20), (3, 'a3', 
3000, 30)
+               | """.stripMargin
+          )
+
+          val result1DF = spark.sql(
+            s"select * from hudi_metadata('$identifier')"
+          )
+          result1DF.show(false)

Review Comment:
   Yes, filters can be specified. For example, `select key, filesystemmetadata 
from hudi_metadata('table-name') where filesystemMetadata is not null` gives 
this
   
   ```
   
+------------------+---------------------------------------------------------------------------------------------+
   |key               |filesystemmetadata                                       
                                    |
   
+------------------+---------------------------------------------------------------------------------------------+
   |__all_partitions__|{price=30 -> {0, false}, price=20 -> {0, false}, 
price=10 -> {0, false}}                     |
   |price=30          
|{7d255a2f-185e-40c3-87a7-1ffec2513d33-0_0-34-80_20240112061638246.parquet -> 
{434873, false}}|
   |price=20          
|{d55a27a9-df00-4aed-b0fa-a491cea86039-0_1-34-81_20240112061638246.parquet -> 
{434874, false}}|
   |price=10          
|{c179d819-3d6d-4864-9099-c944f4e10265-0_2-34-82_20240112061638246.parquet -> 
{434874, false}}|
   
+------------------+---------------------------------------------------------------------------------------------+
   ``` 



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

Reply via email to