kazdy commented on code in PR #8729: URL: https://github.com/apache/hudi/pull/8729#discussion_r1217660242
########## hudi-spark-datasource/hudi-spark3.2plus-common/src/main/scala/org/apache/spark/sql/catalyst/plans/logcal/HoodieTableChanges.scala: ########## @@ -0,0 +1,91 @@ +/* + * 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.hudi.common.util.ValidationUtils.checkState +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 HoodieTableChangesOptionsParser { + def parseOptions(exprs: Seq[Expression], funcName: String): (String, Map[String, String]) = { + val args = exprs.map(_.eval().toString) + + if (args.size < 3) { + throw new AnalysisException(s"Too few arguments for function `$funcName`") Review Comment: AFAIK TVF in Spark unlike procedures doesn't support named arguments natively. Looking at Spark docs: https://spark.apache.org/docs/latest/sql-ref-syntax-qry-select-tvf.html there are none that have named arguments. So to handle everything in one TVF it would look like this: ``` hudi_table_changes('path', 'my/table', 'latest_state', '12345678') hudi_table_changes('table', 'myTable', 'cdc', '12345678') ``` Or I would need to work against what Spark offers and parse named arguments myself to have: ``` hudi_table_changes('path=my/table', 'type=latest_state', 'beginInstantTime=12345678') hudi_table_changes('table=myTable', 'type=cdc', 'beginInstantTime=12345678') ``` This does not feel like the right thing to do. I wanted it to be as easy to use as it can be, just pass arguments. In the case of path and table I can't assume what will be passed by the user and it would be hard to infer this from the input, but latest_state or cdc I can so I could do it easily and introduce this flag. To be honest I was thinking in the other direction, to split cdc and latest_state to separate functions: ``` hudi_table_changes('table', 'earliest', '123456789') hudi_table_changes_by_path('my/table', 'earliest', '123456789') hudi_table_cdc_changes('table', 'earliest', '123456789') hudi_table_cdc_changes_by_path('my/table', 'earliest', '123456789') ``` -- 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]
