codope commented on code in PR #10355:
URL: https://github.com/apache/hudi/pull/10355#discussion_r1430359231


##########
hudi-spark-datasource/hudi-spark-common/src/main/scala/org/apache/hudi/DefaultSource.scala:
##########
@@ -222,6 +222,10 @@ object DefaultSource {
     val isCdcQuery = queryType == QUERY_TYPE_INCREMENTAL_OPT_VAL &&
       
parameters.get(INCREMENTAL_FORMAT.key).contains(INCREMENTAL_FORMAT_CDC_VAL)
     val isMultipleBaseFileFormatsEnabled = 
metaClient.getTableConfig.isMultipleBaseFileFormatsEnabled
+    val createTimeLineRln = parameters.get("CREATE_TL_RELN")

Review Comment:
   What does this parameter do? Also, better to define it in `DataSourceOptions`



##########
hudi-common/src/main/java/org/apache/hudi/common/util/CommitUtils.java:
##########
@@ -123,6 +126,20 @@ private static HoodieCommitMetadata 
buildMetadataFromStats(List<HoodieWriteStat>
     return commitMetadata;
   }
 
+  public static Option<HoodieCommitMetadata> 
buildMetadataFromInstant(HoodieDefaultTimeline timeline, HoodieInstant instant) 
{

Review Comment:
   probably better to inline this method. Just do below wherever needed:
   ```
   HoodieCommitMetadata commitMetadata = 
HoodieCommitMetadata.fromBytes(completedInstants.getInstantDetails(instant).get(),
 HoodieCommitMetadata.class);
   ```



##########
hudi-spark-datasource/hudi-spark/src/test/scala/org/apache/spark/sql/hudi/TestHoodieTableValuedFunction.scala:
##########
@@ -348,4 +348,66 @@ class TestHoodieTableValuedFunction extends 
HoodieSparkSqlTestBase {
       }
     }
   }
+
+  test(s"Test hudi_query_timeline") {
+    if (HoodieSparkUtils.gteqSpark3_2) {
+      withTempDir { tmp =>
+        Seq(
+          ("cow", true),
+          ("mor", true),
+          ("cow", false),
+          ("mor", false)
+        ).foreach { parameters =>
+          val tableType = parameters._1
+          val isTableId = parameters._2
+          val tableName = generateTableName
+          val tablePath = s"${tmp.getCanonicalPath}/$tableName"
+          val identifier = if (isTableId) tableName else tablePath
+          spark.sql("set hoodie.sql.insert.mode = non-strict")
+          spark.sql(
+            s"""
+               |create table $tableName (
+               |  id int,
+               |  name string,
+               |  price double,
+               |  ts long
+               |) using hudi
+               |tblproperties (
+               |  type = '$tableType',
+               |  primaryKey = 'id',
+               |  preCombineField = 'ts'
+               |)
+               |location '$tablePath'
+               |""".stripMargin
+          )
+
+          spark.sql(
+            s"""
+               | insert into $tableName
+               | values (1, 'a1', 10, 1000), (2, 'a2', 20, 1000), (3, 'a3', 
30, 1000)
+               | """.stripMargin
+          )
+          spark.sql(s"select * from hudi_query_timeline('$identifier', 
'true')").show(false);
+
+          spark.sql(
+            s"""
+               | insert into $tableName
+               | values (1, 'a1_1', 10, 1100), (2, 'a2_2', 20, 1100), (3, 
'a3_3', 30, 1100)
+               | """.stripMargin
+          )
+          spark.sql(s"select * from hudi_query_timeline('$identifier', 
'true')").show(false);
+
+          spark.sql(
+            s"""
+               | insert into $tableName
+               | values (1, 'a1_1', 10, 1200), (2, 'a2_2', 20, 1200), (3, 
'a3_3', 30, 1200)
+               | """.stripMargin
+          )
+          spark.sql(
+            s"select action, state from hudi_query_timeline('$identifier', 
'true') where totalfilesupdated > 0 "

Review Comment:
   let's also assert the result of this sql



##########
hudi-spark-datasource/hudi-spark3.2plus-common/src/main/scala/org/apache/spark/sql/hudi/analysis/HoodieSpark32PlusAnalysis.scala:
##########
@@ -104,6 +104,21 @@ case class HoodieSpark32PlusResolveReferences(spark: 
SparkSession) extends Rule[
           catalogTable.location.toString))
         LogicalRelation(relation, catalogTable)
       }
+    case HoodieQueryTimeline(args) =>

Review Comment:
   please also check other `Analysis` classes for different Spark versions. May 
have to do this in those classes too.



##########
hudi-spark-datasource/hudi-spark3.2plus-common/src/main/scala/org/apache/spark/sql/catalyst/plans/logcal/HoodieQueryTimeline.scala:
##########
@@ -0,0 +1,69 @@
+/*
+ * 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.sql.catalyst.plans.logcal
+
+import org.apache.spark.sql.AnalysisException
+import org.apache.spark.sql.catalyst.expressions.{Attribute, Expression}
+import org.apache.spark.sql.catalyst.plans.logical.LeafNode
+
+object HoodieQueryTimelineOptionsParser {
+  def parseOptions(exprs: Seq[Expression], funcName: String): (String, 
Map[String, String]) = {
+    val args = exprs.map(_.eval().toString)
+
+    if (args.size < 1 || args.size > 2) {
+      throw new AnalysisException(s"Expect arguments (table_name or 
table_path, [true|false]) for function `$funcName`")
+    }
+
+    val identifier = args.head
+    val archivedTimeline = args.drop(1).headOption
+
+    val archivedTimelineOpt = archivedTimeline match {
+      case Some(x) => x match {
+        case "true" | "TRUE" => Map("ARCHIVED_TIMELINE" -> "true")
+        case _ => Map("ARCHIVED_TIMELINE" -> "false")
+      }
+      case _ => Map("ARCHIVED_TIMELINE" -> "false")
+    }
+
+    (identifier, archivedTimelineOpt + ("CREATE_TL_RELN" -> "true"))
+  }
+
+}
+
+
+case class HoodieQueryTimeline(args: Seq[Expression]) extends LeafNode {
+
+  override def output: Seq[Attribute] = Nil
+
+  override lazy val resolved: Boolean = false
+
+}
+
+object HoodieQueryTimeline {

Review Comment:
   rename to `HoodieTimelineTableValuedFunction`? Otherwise this sounds like 
another implementation of `HoodieTimeline` interface which it isn't.



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

Reply via email to