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


##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/functional/TestPartitionStatsPruning.scala:
##########
@@ -57,6 +56,7 @@ class TestPartitionStatsPruning extends 
ColumnStatIndexTestBase {
       "hoodie.upsert.shuffle.parallelism" -> "4",
       HoodieWriteConfig.TBL_NAME.key -> "hoodie_test",
       DataSourceWriteOptions.TABLE_TYPE.key -> testCase.tableType.toString,
+      HoodieWriteConfig.WRITE_TABLE_VERSION.key() -> 
testCase.tableVersion.toString,

Review Comment:
   Could we add validation after writes to make sure the actual table version 
meets the expectation?



##########
hudi-utilities/src/test/resources/col-stats/colstats-upgrade-test-v6.zip:
##########


Review Comment:
   Add a README.md on how these test table artifacts are generated and what 
aspects are covered?



##########
hudi-utilities/src/test/java/org/apache/hudi/utilities/testutils/ColStatsUpgradeTesting.java:
##########
@@ -0,0 +1,161 @@
+/*
+ * 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.utilities.testutils;
+
+import org.apache.hudi.common.table.HoodieTableVersion;
+import org.apache.hudi.common.testutils.HoodieTestDataGenerator;
+import org.apache.hudi.common.testutils.HoodieTestUtils;
+import org.apache.hudi.storage.HoodieStorage;
+import org.apache.hudi.storage.StoragePath;
+import org.apache.hudi.utilities.deltastreamer.TestHoodieDeltaStreamer;
+
+import org.apache.avro.Schema;
+import org.junit.jupiter.api.Disabled;
+
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.List;
+
+import static 
org.apache.hudi.common.testutils.HoodieTestDataGenerator.recordsToStrings;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Used by {@link 
TestHoodieDeltaStreamer#testBackwardsCompatibility(HoodieTableVersion)}.
+ * Only run this manually
+ */
+public class ColStatsUpgradeTesting {
+
+  @Disabled
+  public void generate() throws IOException {
+    generateTestAssets("/tmp/", 6);
+    generateTestAssets("/tmp/", 8);
+  }
+
+  public void generateDsScript(StoragePath assetDirectory, StoragePath 
runScript, StoragePath tablePath, StoragePath propsFile, StoragePath 
dataDirectory, int version) throws IOException {
+    HoodieStorage storage = HoodieTestUtils.getDefaultStorage();
+    String bundleURL;
+    String bundleName;
+    String instruction;
+    if (version == 6) {
+      bundleURL = 
"https://repo1.maven.org/maven2/org/apache/hudi/hudi-utilities-bundle_2.12/0.14.1/hudi-utilities-bundle_2.12-0.14.1.jar";;
+      bundleName = "hudi-utilities-bundle_2.12-0.14.1.jar";
+      instruction = "run with spark 3.1.X";
+    } else if (version == 8) {
+      bundleURL = 
"https://repo1.maven.org/maven2/org/apache/hudi/hudi-utilities-bundle_2.12/1.0.2/hudi-utilities-bundle_2.12-1.0.2.jar";;
+      bundleName = "hudi-utilities-bundle_2.12-1.0.2.jar";
+      instruction = "run with spark 3.5.X";
+    } else {
+      throw new IllegalArgumentException("Unsupported version: " + version);
+    }
+
+    String runscript = "# " + instruction + "\n"
+        + "wget " + bundleURL + ";\n"
+        + "for i in {0..4}; do\n"
+        + "  spark-submit \\\n"
+        + "    --class org.apache.hudi.utilities.streamer.HoodieStreamer \\\n"
+        + "    " + bundleName + " \\\n"
+        + "    --table-type MERGE_ON_READ \\\n"
+        + "    --source-class org.apache.hudi.utilities.sources.JsonDFSSource 
\\\n"
+        + "    --source-ordering-field timestamp \\\n"
+        + "    --target-base-path " + tablePath + "  \\\n"
+        + "    --target-table trips_logical_types_json \\\n"
+        + "    --props " + 
propsFile.makeQualified(storage.getUri()).toUri().toString()  + "\\\n"
+        + "    --schemaprovider-class 
org.apache.hudi.utilities.schema.FilebasedSchemaProvider \\\n"
+        + "    --disable-compaction \\\n"
+        + "    --op UPSERT \\\n"
+        + "    --hoodie-conf hoodie.streamer.source.dfs.root=" + 
dataDirectory.makeQualified(storage.getUri()).toUri().toString() + "/data_$i\n"
+        + "done;\n"
+        + "cd " + assetDirectory + ";\n"
+        + "zip -r  $HUDI_HOME/hudi-utilities/src/test/resources/col-stats/" + 
assetDirectory.getName() + ".zip .;\n";
+
+    try (Writer writer = new OutputStreamWriter(storage.create(runScript))) {
+      writer.write(runscript);
+      writer.write("\n");
+    }
+  }
+
+  public void generateTestAssets(String assetDirectory, int version) throws 
IOException {
+    HoodieStorage storage = HoodieTestUtils.getDefaultStorage();
+    StoragePath directory = new StoragePath(assetDirectory, 
"colstats-upgrade-test-v" + version);
+    if (storage.exists(directory)) {
+      storage.deleteDirectory(directory);
+    }
+    assertTrue(storage.createDirectory(directory));
+    Schema schema;
+    String schemaStr;
+    //TODO: once we add the fixes to v8 to allow more types
+    if (version == 6 || version == 8) {
+      schema = HoodieTestDataGenerator.AVRO_TRIP_LOGICAL_TYPES_SCHEMA_V6;
+      schemaStr = HoodieTestDataGenerator.TRIP_LOGICAL_TYPES_SCHEMA_V6;
+    } else {
+      schema = HoodieTestDataGenerator.AVRO_TRIP_LOGICAL_TYPES_SCHEMA;
+      schemaStr = HoodieTestDataGenerator.TRIP_LOGICAL_TYPES_SCHEMA;
+    }
+
+    StoragePath schemaFile = new StoragePath(directory, "schema.avsc");
+
+    try (Writer writer = new OutputStreamWriter(storage.create(schemaFile))) {
+      writer.write(schema.toString(true));
+      writer.write("\n");
+    }
+
+    HoodieTestDataGenerator datagen = new HoodieTestDataGenerator();
+    StoragePath dataDirectory = new StoragePath(directory, "data");
+    assertTrue(storage.createDirectory(dataDirectory));
+
+    StoragePath propsFile = new StoragePath(directory, "hudi.properties");
+    try (Writer writer = new OutputStreamWriter(storage.create(propsFile))) {
+      writer.write("hoodie.table.name=trips_logical_types_json\n");
+      writer.write("hoodie.datasource.write.table.type=MERGE_ON_READ\n");
+      writer.write("hoodie.datasource.write.recordkey.field=_row_key\n");
+      
writer.write("hoodie.datasource.write.partitionpath.field=partition_path\n");
+      
writer.write("hoodie.datasource.write.keygenerator.class=org.apache.hudi.keygen.SimpleKeyGenerator\n");
+      writer.write("hoodie.datasource.write.precombine.field=timestamp\n");
+      writer.write("hoodie.cleaner.policy=KEEP_LATEST_COMMITS\n");
+      writer.write("hoodie.cleaner.commits.retained=2\n");
+      writer.write("hoodie.upsert.shuffle.parallelism=2\n");
+      writer.write("hoodie.insert.shuffle.parallelism=2\n");
+      writer.write("hoodie.compact.inline=false\n");
+      writer.write("hoodie.streamer.schemaprovider.source.schema.file=" + 
schemaFile.makeQualified(storage.getUri()).toUri().toString() + "\n");
+      writer.write("hoodie.streamer.schemaprovider.target.schema.file=" + 
schemaFile.makeQualified(storage.getUri()).toUri().toString() + "\n");
+      writer.write("hoodie.metadata.index.column.stats.enable=true\n");
+    }
+
+

Review Comment:
   nit: remove redundant empty line



##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/dml/others/TestMergeIntoTable.scala:
##########
@@ -21,7 +21,7 @@ package org.apache.spark.sql.hudi.dml.others
 
 import org.apache.hudi.{DataSourceReadOptions, DataSourceWriteOptions, 
ScalaAssertionSupport}
 import org.apache.hudi.DataSourceWriteOptions.SPARK_SQL_OPTIMIZED_WRITES
-import org.apache.hudi.common.config.{HoodieReaderConfig, HoodieStorageConfig}
+import org.apache.hudi.common.config.{HoodieMetadataConfig, 
HoodieReaderConfig, HoodieStorageConfig}

Review Comment:
   nit: is this import unused?



##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/functional/TestMetadataTableWithSparkDataSource.scala:
##########
@@ -161,7 +161,7 @@ class TestMetadataTableWithSparkDataSource extends 
SparkClientFunctionalTestHarn
     val colRangeMetadataList: 
java.util.List[HoodieColumnRangeMetadata[Comparable[_]]] = new ParquetUtils()
       .readColumnStatsFromMetadata(
         new HoodieHadoopStorage(fileStatuses.get(0).getPath, 
HadoopFSUtils.getStorageConf(jsc().hadoopConfiguration())),
-        fileStatuses.get(0).getPath, Collections.singletonList("begin_lat"))
+        fileStatuses.get(0).getPath, Collections.singletonList("begin_lat"), 
HoodieIndexVersion.V1)

Review Comment:
   Are there functional tests covering `HoodieIndexVersion.V2`, which verify 
the stats similar to this logic by reading parquet stats and compare them with 
the entries in MDT?



##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/feature/index/TestExpressionIndex.scala:
##########
@@ -1548,28 +1550,28 @@ class TestExpressionIndex extends 
HoodieSparkSqlTestBase {
         spark.sql(s"create index idx_to_timestamp_default on $tableName using 
column_stats(date) options(expr='to_timestamp')")
         metaClient = HoodieTableMetaClient.reload(metaClient)
         val toTimestampDefault = resolveExpr(spark, 
unapply(functions.to_timestamp(functions.col("date"))).get, tableSchema)
-        dataFilter = EqualTo(toTimestampDefault, lit(1732924800000000L).expr)
+        dataFilter = EqualTo(toTimestampDefault, 
lit(SparkValueMetadata.convertJavaTypeToSparkType(ValueType.toTimestampMicros(1732924800000000L,
 null), false)).expr)
         verifyFilePruning(opts, dataFilter, metaClient, isDataSkippingExpected 
= true)
         spark.sql(s"drop index idx_to_timestamp_default on $tableName")
 
         spark.sql(s"create index idx_to_timestamp on $tableName using 
column_stats(date) options(expr='to_timestamp', format='yyyy-MM-dd')")
         metaClient = HoodieTableMetaClient.reload(metaClient)
         val toTimestamp = resolveExpr(spark, 
unapply(functions.to_timestamp(functions.col("date"), "yyyy-MM-dd")).get, 
tableSchema)
-        dataFilter = EqualTo(toTimestamp, lit(1732924800000000L).expr)
+        dataFilter = EqualTo(toTimestamp, 
lit(SparkValueMetadata.convertJavaTypeToSparkType(ValueType.toTimestampMicros(1732924800000000L,
 null), false)).expr)
         verifyFilePruning(opts, dataFilter, metaClient, isDataSkippingExpected 
= true)
         spark.sql(s"drop index idx_to_timestamp on $tableName")
 
         spark.sql(s"create index idx_date_add on $tableName using 
column_stats(date) options(expr='date_add', days='10')")
         metaClient = HoodieTableMetaClient.reload(metaClient)
         val dateAdd = resolveExpr(spark, 
unapply(functions.date_add(functions.col("date"), 10)).get, tableSchema)
-        dataFilter = EqualTo(dateAdd, lit(18606).expr)
+        dataFilter = EqualTo(dateAdd, 
lit(HoodieAvroUtils.toJavaDate(18606)).expr)
         verifyFilePruning(opts, dataFilter, metaClient, isDataSkippingExpected 
= true)
         spark.sql(s"drop index idx_date_add on $tableName")
 
         spark.sql(s"create index idx_date_sub on $tableName using 
column_stats(date) options(expr='date_sub', days='10')")
         metaClient = HoodieTableMetaClient.reload(metaClient)
         val dateSub = resolveExpr(spark, 
unapply(functions.date_sub(functions.col("date"), 10)).get, tableSchema)
-        dataFilter = EqualTo(dateSub, lit(18586).expr)
+        dataFilter = EqualTo(dateSub, 
lit(HoodieAvroUtils.toJavaDate(18586)).expr)

Review Comment:
   So the original predicate using long or integer does not work any more?



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