YannByron commented on code in PR #9068:
URL: https://github.com/apache/hudi/pull/9068#discussion_r1244635574
##########
hudi-spark-datasource/hudi-spark/src/main/scala/org/apache/spark/sql/hudi/command/procedures/HoodieProcedureUtils.scala:
##########
@@ -43,4 +47,74 @@ object HoodieProcedureUtils {
ProcedureArgs(isNamedArgs = true, map, new GenericInternalRow(values))
}
+
+ sealed trait Operation {
+ def value: String
+ def isSchedule: Boolean = this != Execute
+ def isExecute: Boolean = this != Schedule
+ }
+
+ /**
+ * schedule: schedule a new plan
+ */
+ case object Schedule extends Operation {
+ override def value: String = "schedule"
+ }
+
+ /**
+ * execute: if specific instants exist, execute them, otherwise execute all
pending plans
+ */
+ case object Execute extends Operation {
+ override def value: String = "execute"
+ }
+
+ /**
+ * scheduleAndExecute: schedule a new plan and then execute it, if no plan
is generated during
+ * schedule, execute all pending plans
+ */
+ case object ScheduleAndExecute extends Operation {
+ override def value: String = "scheduleandexecute"
+ }
+
+ object Operation {
+ private val ValueToEnumMap: Map[String, Operation with Product with
Serializable] = Seq(Schedule, Execute, ScheduleAndExecute)
+ .map(enum => enum.value -> enum).toMap
+
+ def fromValue(value: String): Operation = {
+ ValueToEnumMap.getOrElse(value, throw new HoodieException(s"Invalid
value ($value)"))
+ }
+ }
+
+ def fileterPendingInstantsAndGetOperation(pendingInstants: Seq[String],
specificInstants: Option[String], op: Option[String]): (Seq[String], Operation)
= {
+ specificInstants match {
+ case Some(inst) =>
+ op match {
+ case Some(o) =>
+ if (!Execute.value.equalsIgnoreCase(o)) {
+ throw new HoodieException("specific instants only can be used in
'execute' op or not specific op")
+ }
+ case _ =>
+ // No op specified, set it as 'execute' with instants specified
+ }
+ (HoodieProcedureUtils.checkAndFilterPendingInstants(pendingInstants,
inst), Execute)
+ case _ =>
+ op match {
+ case Some(o) =>
+ (pendingInstants, Operation.fromValue(o.toLowerCase))
+ case _ =>
+ // No op specified, set it as 'scheduleAndExecute' default
+ (pendingInstants, ScheduleAndExecute)
+ }
Review Comment:
op.map().getOrElse
--
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]