yihua commented on code in PR #10167:
URL: https://github.com/apache/hudi/pull/10167#discussion_r1418053082


##########
hudi-spark-datasource/hudi-spark-common/src/test/scala/org/apache/spark/execution/datasources/parquet/TestHoodieFileGroupReaderBasedParquetFileFormat.scala:
##########
@@ -0,0 +1,96 @@
+/*
+ * 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.execution.datasources.parquet
+
+import org.apache.hudi.HoodieSparkUtils
+import org.apache.hudi.testutils.SparkClientFunctionalTestHarness
+import 
org.apache.spark.sql.execution.datasources.parquet.HoodieFileGroupReaderBasedParquetFileFormat
+import org.apache.spark.sql.sources.{EqualTo, GreaterThan, IsNotNull}
+import org.apache.spark.sql.types.{LongType, StringType, StructField, 
StructType}
+import org.junit.jupiter.api.Assertions.assertEquals
+import org.junit.jupiter.api.Test
+
+class TestHoodieFileGroupReaderBasedParquetFileFormat extends 
SparkClientFunctionalTestHarness {

Review Comment:
   For the validation in all the tests here, could you do exact match of 
objects/values instead of checking the length only?



##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/common/table/read/TestIfRecordPositionColumnWorkForSpark3_5.scala:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.hudi.common.table.read
+
+import org.apache.hadoop.conf.Configuration
+import org.apache.hudi.SparkAdapterSupport.sparkAdapter
+import org.apache.hudi.common.config.HoodieStorageConfig
+import org.apache.hudi.common.testutils.HoodieTestTable
+import org.apache.hudi.config.HoodieWriteConfig
+import org.apache.hudi.testutils.SparkClientFunctionalTestHarness
+import org.apache.hudi.util.CloseableInternalRowIterator
+import org.apache.hudi.{DataSourceWriteOptions, HoodieSparkUtils}
+import org.apache.spark.sql.catalyst.InternalRow
+import 
org.apache.spark.sql.execution.datasources.parquet.{HoodieFileGroupReaderBasedParquetFileFormat,
 ParquetFileFormat}
+import org.apache.spark.sql.types.{IntegerType, StringType, StructField, 
StructType}
+import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue}
+import org.junit.jupiter.api.Test
+
+class TestIfRecordPositionColumnWorkForSpark3_5 extends 
SparkClientFunctionalTestHarness {
+  private val HOOD_FORMAT = "org.apache.hudi"
+  private val MOR_TABLE_TYPE = "MERGE_ON_READ"
+  private val PARQUET_FORMAT = "parquet"
+  private val ROW_INDEX_COLUMN = "_tmp_metadata_row_index"
+  private val SPARK_MERGER = "org.apache.hudi.HoodieSparkRecordMerger"

Review Comment:
   Some of these are already defined in Hudi code, could you reuse the instead 
of defining the variables here?



##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/common/table/read/TestIfRecordPositionColumnWorkForSpark3_5.scala:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.hudi.common.table.read
+
+import org.apache.hadoop.conf.Configuration
+import org.apache.hudi.SparkAdapterSupport.sparkAdapter
+import org.apache.hudi.common.config.HoodieStorageConfig
+import org.apache.hudi.common.testutils.HoodieTestTable
+import org.apache.hudi.config.HoodieWriteConfig
+import org.apache.hudi.testutils.SparkClientFunctionalTestHarness
+import org.apache.hudi.util.CloseableInternalRowIterator
+import org.apache.hudi.{DataSourceWriteOptions, HoodieSparkUtils}
+import org.apache.spark.sql.catalyst.InternalRow
+import 
org.apache.spark.sql.execution.datasources.parquet.{HoodieFileGroupReaderBasedParquetFileFormat,
 ParquetFileFormat}
+import org.apache.spark.sql.types.{IntegerType, StringType, StructField, 
StructType}
+import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue}
+import org.junit.jupiter.api.Test
+
+class TestIfRecordPositionColumnWorkForSpark3_5 extends 
SparkClientFunctionalTestHarness {
+  private val HOOD_FORMAT = "org.apache.hudi"
+  private val MOR_TABLE_TYPE = "MERGE_ON_READ"
+  private val PARQUET_FORMAT = "parquet"
+  private val ROW_INDEX_COLUMN = "_tmp_metadata_row_index"
+  private val SPARK_MERGER = "org.apache.hudi.HoodieSparkRecordMerger"
+
+  @Test
+  def testConfirmIfRowIndexColumnWorks(): Unit = {

Review Comment:
   rename to sth like `testWithRecordPositionsFromSparkReader`



##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/common/table/read/TestIfRecordPositionColumnWorkForSpark3_5.scala:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.hudi.common.table.read
+
+import org.apache.hadoop.conf.Configuration
+import org.apache.hudi.SparkAdapterSupport.sparkAdapter
+import org.apache.hudi.common.config.HoodieStorageConfig
+import org.apache.hudi.common.testutils.HoodieTestTable
+import org.apache.hudi.config.HoodieWriteConfig
+import org.apache.hudi.testutils.SparkClientFunctionalTestHarness
+import org.apache.hudi.util.CloseableInternalRowIterator
+import org.apache.hudi.{DataSourceWriteOptions, HoodieSparkUtils}
+import org.apache.spark.sql.catalyst.InternalRow
+import 
org.apache.spark.sql.execution.datasources.parquet.{HoodieFileGroupReaderBasedParquetFileFormat,
 ParquetFileFormat}
+import org.apache.spark.sql.types.{IntegerType, StringType, StructField, 
StructType}
+import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue}
+import org.junit.jupiter.api.Test
+
+class TestIfRecordPositionColumnWorkForSpark3_5 extends 
SparkClientFunctionalTestHarness {
+  private val HOOD_FORMAT = "org.apache.hudi"
+  private val MOR_TABLE_TYPE = "MERGE_ON_READ"
+  private val PARQUET_FORMAT = "parquet"
+  private val ROW_INDEX_COLUMN = "_tmp_metadata_row_index"
+  private val SPARK_MERGER = "org.apache.hudi.HoodieSparkRecordMerger"
+
+  @Test
+  def testConfirmIfRowIndexColumnWorks(): Unit = {
+    val _spark = spark
+    import _spark.implicits._
+
+    val userToCountryDF = Seq(
+      (1, "US", "1000"),
+      (2, "US", "1000"),
+      (3, "China", "1000"),
+      (4, "Singapore", "1000")
+    ).toDF("userid", "country", "ts")
+    val userToCountryTblPath = s"$basePath/user_to_country_table"
+
+    userToCountryDF.write.format(HOOD_FORMAT)
+      .option(DataSourceWriteOptions.RECORDKEY_FIELD.key, "userid")
+      .option(DataSourceWriteOptions.PRECOMBINE_FIELD.key, "ts")
+      .option(HoodieWriteConfig.TBL_NAME.key, "user_to_country")
+      .option(HoodieWriteConfig.RECORD_MERGER_IMPLS.key, SPARK_MERGER)
+      .option(HoodieWriteConfig.WRITE_RECORD_POSITIONS.key, "true")
+      .option(HoodieStorageConfig.LOGFILE_DATA_BLOCK_FORMAT.key, 
PARQUET_FORMAT)
+      .option(DataSourceWriteOptions.TABLE_TYPE.key(), MOR_TABLE_TYPE)
+      .save(userToCountryTblPath)
+
+    val dataSchema = new StructType(
+      Array(
+        StructField("userid", IntegerType, nullable = false),
+        StructField("country", StringType, nullable = false),
+        StructField("ts", StringType, nullable = false)
+      )
+    )
+    val requiredSchema = 
HoodieFileGroupReaderBasedParquetFileFormat.getAppliedRequiredSchema(
+      dataSchema, shouldUseRecordPosition = true, ROW_INDEX_COLUMN)
+    if (HoodieSparkUtils.gteqSpark3_5) {
+      assertEquals(4, requiredSchema.fields.length)
+    }
+
+    _spark.conf.set("spark.sql.parquet.enableVectorizedReader", "false")
+    val metaClient = getHoodieMetaClient(
+      spark().sparkContext.hadoopConfiguration, userToCountryTblPath)
+    val fileReader = new ParquetFileFormat().buildReaderWithPartitionValues(

Review Comment:
   Could you directly test `preMergeBaseFileReader` returned from 
`HoodieFileGroupReaderBasedParquetFileFormat#buildFileReaders` and validate the 
row positions returned from the Spark parquet reader?



##########
hudi-spark-datasource/hudi-spark3-common/src/main/scala/org/apache/spark/sql/adapter/BaseSpark3Adapter.scala:
##########
@@ -18,22 +18,24 @@
 package org.apache.spark.sql.adapter
 
 import org.apache.avro.Schema
-import org.apache.hadoop.fs.Path
+import org.apache.hadoop.fs.{FileStatus, Path}

Review Comment:
   Revert the cosmetic changes in the Spark adapter classes.



##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/common/table/read/TestIfRecordPositionColumnWorkForSpark3_5.scala:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.hudi.common.table.read
+
+import org.apache.hadoop.conf.Configuration
+import org.apache.hudi.SparkAdapterSupport.sparkAdapter
+import org.apache.hudi.common.config.HoodieStorageConfig
+import org.apache.hudi.common.testutils.HoodieTestTable
+import org.apache.hudi.config.HoodieWriteConfig
+import org.apache.hudi.testutils.SparkClientFunctionalTestHarness
+import org.apache.hudi.util.CloseableInternalRowIterator
+import org.apache.hudi.{DataSourceWriteOptions, HoodieSparkUtils}
+import org.apache.spark.sql.catalyst.InternalRow
+import 
org.apache.spark.sql.execution.datasources.parquet.{HoodieFileGroupReaderBasedParquetFileFormat,
 ParquetFileFormat}
+import org.apache.spark.sql.types.{IntegerType, StringType, StructField, 
StructType}
+import org.junit.jupiter.api.Assertions.{assertEquals, assertTrue}
+import org.junit.jupiter.api.Test
+
+class TestIfRecordPositionColumnWorkForSpark3_5 extends 
SparkClientFunctionalTestHarness {
+  private val HOOD_FORMAT = "org.apache.hudi"
+  private val MOR_TABLE_TYPE = "MERGE_ON_READ"
+  private val PARQUET_FORMAT = "parquet"
+  private val ROW_INDEX_COLUMN = "_tmp_metadata_row_index"
+  private val SPARK_MERGER = "org.apache.hudi.HoodieSparkRecordMerger"
+
+  @Test
+  def testConfirmIfRowIndexColumnWorks(): Unit = {
+    val _spark = spark
+    import _spark.implicits._
+
+    val userToCountryDF = Seq(
+      (1, "US", "1000"),
+      (2, "US", "1000"),
+      (3, "China", "1000"),
+      (4, "Singapore", "1000")
+    ).toDF("userid", "country", "ts")
+    val userToCountryTblPath = s"$basePath/user_to_country_table"
+
+    userToCountryDF.write.format(HOOD_FORMAT)
+      .option(DataSourceWriteOptions.RECORDKEY_FIELD.key, "userid")
+      .option(DataSourceWriteOptions.PRECOMBINE_FIELD.key, "ts")
+      .option(HoodieWriteConfig.TBL_NAME.key, "user_to_country")
+      .option(HoodieWriteConfig.RECORD_MERGER_IMPLS.key, SPARK_MERGER)
+      .option(HoodieWriteConfig.WRITE_RECORD_POSITIONS.key, "true")
+      .option(HoodieStorageConfig.LOGFILE_DATA_BLOCK_FORMAT.key, 
PARQUET_FORMAT)
+      .option(DataSourceWriteOptions.TABLE_TYPE.key(), MOR_TABLE_TYPE)
+      .save(userToCountryTblPath)
+
+    val dataSchema = new StructType(
+      Array(
+        StructField("userid", IntegerType, nullable = false),
+        StructField("country", StringType, nullable = false),
+        StructField("ts", StringType, nullable = false)
+      )
+    )
+    val requiredSchema = 
HoodieFileGroupReaderBasedParquetFileFormat.getAppliedRequiredSchema(
+      dataSchema, shouldUseRecordPosition = true, ROW_INDEX_COLUMN)
+    if (HoodieSparkUtils.gteqSpark3_5) {
+      assertEquals(4, requiredSchema.fields.length)
+    }
+
+    _spark.conf.set("spark.sql.parquet.enableVectorizedReader", "false")

Review Comment:
   Is this needed?



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