xiarixiaoyao commented on a change in pull request #4535:
URL: https://github.com/apache/hudi/pull/4535#discussion_r810608840
##########
File path:
hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/analysis/HoodieAnalysis.scala
##########
@@ -133,26 +136,65 @@ case class HoodieAnalysis(sparkSession: SparkSession)
extends Rule[LogicalPlan]
// Convert to CompactionShowHoodiePathCommand
case CompactionShowOnPath(path, limit) =>
CompactionShowHoodiePathCommand(path, limit)
- case _=> plan
+ // Convert to HoodieCallProcedureCommand
+ case CallCommand(name, args) =>
+ val procedure: Option[Procedure] = loadProcedure(name)
+ val input = buildProcedureArgs(args)
+ CallProcedureHoodieCommand(procedure.get, input)
+ case _ => plan
+ }
+ }
+
+ private def loadProcedure(name: Seq[String]): Option[Procedure] = {
+ val procedure: Option[Procedure] = if (name.nonEmpty) {
+ val builder = HoodieProcedures.newBuilder(name.last)
+ if (builder != null) {
+ Option.apply(builder.build)
+ } else {
+ throw new AnalysisException(s"procedure: ${name.last} is not exists")
+ }
+ } else {
+ Option.empty
}
+ procedure
+ }
+
+ private def buildProcedureArgs(exprs: Seq[CallArgument]): ProcedureArgs = {
+ val values = new Array[Any](exprs.size)
+ var isNamedArgs: Boolean = false
+ val map = new util.LinkedHashMap[String, Int]()
+ for (index <- exprs.indices) {
+ exprs(index) match {
+ case expr: NamedArgument =>
+ map.put(expr.name, index)
+ values(index) = expr.expr.eval()
+ isNamedArgs = true
+ case _ =>
+ map.put(index.toString, index)
+ values(index) = exprs(index).expr.eval()
+ isNamedArgs = false
+ }
Review comment:
Will there be some nameArgs and some positionArgs exists in
callArgument at same time ?
--
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]