[ https://issues.apache.org/jira/browse/HUDI-2243?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17390303#comment-17390303 ]
ASF GitHub Bot commented on HUDI-2243: -------------------------------------- pengzhiwei2018 commented on a change in pull request #3360: URL: https://github.com/apache/hudi/pull/3360#discussion_r679670801 ########## File path: hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/functional/TestTimeTravelQuery.scala ########## @@ -0,0 +1,206 @@ +/* + * 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.functional + +import org.apache.hudi.{DataSourceReadOptions, DataSourceWriteOptions} +import org.apache.hudi.DataSourceWriteOptions.{KEYGENERATOR_CLASS_OPT_KEY, PARTITIONPATH_FIELD_OPT_KEY, PRECOMBINE_FIELD_OPT_KEY, RECORDKEY_FIELD_OPT_KEY} +import org.apache.hudi.common.model.HoodieTableType +import org.apache.hudi.config.HoodieWriteConfig +import org.apache.hudi.keygen.{ComplexKeyGenerator, NonpartitionedKeyGenerator} +import org.apache.hudi.testutils.HoodieClientTestBase +import org.apache.spark.sql.{Row, SaveMode, SparkSession} +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.{AfterEach, BeforeEach} +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource + +class TestTimeTravelQuery extends HoodieClientTestBase { + var spark: SparkSession =_ + val commonOpts = Map( + "hoodie.insert.shuffle.parallelism" -> "4", + "hoodie.upsert.shuffle.parallelism" -> "4", + "hoodie.bulkinsert.shuffle.parallelism" -> "2", + "hoodie.delete.shuffle.parallelism" -> "1", + DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY.key -> "_row_key", + DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY.key -> "partition", + DataSourceWriteOptions.PRECOMBINE_FIELD_OPT_KEY.key -> "timestamp", + HoodieWriteConfig.TABLE_NAME.key -> "hoodie_test" + ) + + @BeforeEach override def setUp() { + initPath() + initSparkContexts() + spark = sqlContext.sparkSession + initTestDataGenerator() + initFileSystem() + } + + @AfterEach override def tearDown() = { + cleanupSparkContexts() + cleanupTestDataGenerator() + cleanupFileSystem() + } + + @ParameterizedTest + @EnumSource(value = classOf[HoodieTableType]) + def testTimeTravelQuery(tableType: HoodieTableType): Unit = { + initMetaClient(tableType) + val _spark = spark + import _spark.implicits._ + + // First write + val df1 = Seq((1, "a1", 10, 1000)).toDF("id", "name", "value", "version") + df1.write.format("org.apache.hudi") + .options(commonOpts) + .option(DataSourceWriteOptions.TABLE_TYPE_OPT_KEY.key, tableType.name()) + .option(RECORDKEY_FIELD_OPT_KEY.key, "id") + .option(PRECOMBINE_FIELD_OPT_KEY.key, "version") + .option(PARTITIONPATH_FIELD_OPT_KEY.key, "") + .option(KEYGENERATOR_CLASS_OPT_KEY.key, classOf[NonpartitionedKeyGenerator].getName) + .mode(SaveMode.Overwrite) + .save(basePath) + + val firstCommit = metaClient.getActiveTimeline.filterCompletedInstants().lastInstant().get().getTimestamp + + // Second write + val df2 = Seq((1, "a1", 12, 1001)).toDF("id", "name", "value", "version") + df2.write.format("org.apache.hudi") + .options(commonOpts) + .option(DataSourceWriteOptions.TABLE_TYPE_OPT_KEY.key, DataSourceWriteOptions.COW_TABLE_TYPE_OPT_VAL) + .option(RECORDKEY_FIELD_OPT_KEY.key, "id") + .option(PRECOMBINE_FIELD_OPT_KEY.key, "version") + .option(PARTITIONPATH_FIELD_OPT_KEY.key, "") + .option(KEYGENERATOR_CLASS_OPT_KEY.key, classOf[NonpartitionedKeyGenerator].getName) + .mode(SaveMode.Append) + .save(basePath) + metaClient.reloadActiveTimeline() + val secondCommit = metaClient.getActiveTimeline.filterCompletedInstants().lastInstant().get().getTimestamp + + // Third write Review comment: Yes, I think so. It should be the same behavior with query the latest instant. ########## File path: hudi-common/src/main/java/org/apache/hudi/common/table/view/TableFileSystemView.java ########## @@ -58,6 +58,11 @@ */ Stream<HoodieBaseFile> getLatestBaseFiles(); + /** Review comment: make sense! ########## File path: hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/hudi/functional/TestTimeTravelQuery.scala ########## @@ -0,0 +1,206 @@ +/* + * 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.functional + +import org.apache.hudi.{DataSourceReadOptions, DataSourceWriteOptions} +import org.apache.hudi.DataSourceWriteOptions.{KEYGENERATOR_CLASS_OPT_KEY, PARTITIONPATH_FIELD_OPT_KEY, PRECOMBINE_FIELD_OPT_KEY, RECORDKEY_FIELD_OPT_KEY} +import org.apache.hudi.common.model.HoodieTableType +import org.apache.hudi.config.HoodieWriteConfig +import org.apache.hudi.keygen.{ComplexKeyGenerator, NonpartitionedKeyGenerator} +import org.apache.hudi.testutils.HoodieClientTestBase +import org.apache.spark.sql.{Row, SaveMode, SparkSession} +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.{AfterEach, BeforeEach} +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.EnumSource + +class TestTimeTravelQuery extends HoodieClientTestBase { + var spark: SparkSession =_ + val commonOpts = Map( + "hoodie.insert.shuffle.parallelism" -> "4", + "hoodie.upsert.shuffle.parallelism" -> "4", + "hoodie.bulkinsert.shuffle.parallelism" -> "2", + "hoodie.delete.shuffle.parallelism" -> "1", + DataSourceWriteOptions.RECORDKEY_FIELD_OPT_KEY.key -> "_row_key", + DataSourceWriteOptions.PARTITIONPATH_FIELD_OPT_KEY.key -> "partition", + DataSourceWriteOptions.PRECOMBINE_FIELD_OPT_KEY.key -> "timestamp", + HoodieWriteConfig.TABLE_NAME.key -> "hoodie_test" + ) + + @BeforeEach override def setUp() { + initPath() + initSparkContexts() + spark = sqlContext.sparkSession + initTestDataGenerator() + initFileSystem() + } + + @AfterEach override def tearDown() = { + cleanupSparkContexts() + cleanupTestDataGenerator() + cleanupFileSystem() + } + + @ParameterizedTest + @EnumSource(value = classOf[HoodieTableType]) + def testTimeTravelQuery(tableType: HoodieTableType): Unit = { + initMetaClient(tableType) + val _spark = spark + import _spark.implicits._ + + // First write + val df1 = Seq((1, "a1", 10, 1000)).toDF("id", "name", "value", "version") + df1.write.format("org.apache.hudi") + .options(commonOpts) + .option(DataSourceWriteOptions.TABLE_TYPE_OPT_KEY.key, tableType.name()) + .option(RECORDKEY_FIELD_OPT_KEY.key, "id") + .option(PRECOMBINE_FIELD_OPT_KEY.key, "version") + .option(PARTITIONPATH_FIELD_OPT_KEY.key, "") + .option(KEYGENERATOR_CLASS_OPT_KEY.key, classOf[NonpartitionedKeyGenerator].getName) + .mode(SaveMode.Overwrite) + .save(basePath) + + val firstCommit = metaClient.getActiveTimeline.filterCompletedInstants().lastInstant().get().getTimestamp + + // Second write + val df2 = Seq((1, "a1", 12, 1001)).toDF("id", "name", "value", "version") + df2.write.format("org.apache.hudi") + .options(commonOpts) + .option(DataSourceWriteOptions.TABLE_TYPE_OPT_KEY.key, DataSourceWriteOptions.COW_TABLE_TYPE_OPT_VAL) Review comment: Good catch! -- 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: commits-unsubscr...@hudi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org > Support Time Travel Query For Hoodie Table > ------------------------------------------ > > Key: HUDI-2243 > URL: https://issues.apache.org/jira/browse/HUDI-2243 > Project: Apache Hudi > Issue Type: Bug > Components: Spark Integration > Reporter: pengzhiwei > Assignee: pengzhiwei > Priority: Major > Labels: pull-request-available > > Support time travel query for hoodie table for both COW and MOR table. -- This message was sent by Atlassian Jira (v8.3.4#803005)