mengw15 commented on code in PR #3774:
URL: https://github.com/apache/texera/pull/3774#discussion_r2392830829


##########
core/workflow-operator/src/main/scala/edu/uci/ics/amber/operator/stablemergesort/StableMergeSortOpDesc.scala:
##########
@@ -0,0 +1,109 @@
+/*
+* 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 edu.uci.ics.amber.operator.stablemergesort
+
+import com.fasterxml.jackson.annotation.{JsonProperty, JsonPropertyDescription}
+import com.kjetland.jackson.jsonSchema.annotations.{JsonSchemaInject, 
JsonSchemaTitle}
+import edu.uci.ics.amber.core.executor.OpExecWithClassName
+import edu.uci.ics.amber.core.virtualidentity.{ExecutionIdentity, 
WorkflowIdentity}
+import edu.uci.ics.amber.core.workflow.{InputPort, OutputPort, PhysicalOp}
+import edu.uci.ics.amber.operator.LogicalOp
+import edu.uci.ics.amber.operator.metadata.annotations.AutofillAttributeName
+import edu.uci.ics.amber.operator.metadata.{OperatorGroupConstants, 
OperatorInfo}
+import edu.uci.ics.amber.util.JSONUtils.objectMapper
+
+import java.util
+import java.util.Locale
+import scala.jdk.CollectionConverters._
+
+class StableMergeSortOpDesc extends LogicalOp {
+
+  import StableMergeSortOpDesc._
+
+  @JsonProperty(value = "keys", required = true)
+  @JsonSchemaTitle("Sort Keys")
+  @JsonPropertyDescription("List of attributes to sort by with ordering 
preferences.")
+  var keys: util.List[StableSortKey] = new util.ArrayList[StableSortKey]()
+
+  /**
+   * Validate operator parameters during compilation (schema propagation phase 
in the framework).
+   */
+  private def validate(): Unit = {
+    require(keys != null && !keys.isEmpty, "StableMergeSort requires at least 
one sort key.")
+    keys.asScala.foreach { k =>
+      val order = 
Option(k.order).map(_.toLowerCase(Locale.ROOT)).getOrElse("asc")
+      require(order == "asc" || order == "desc", s"Unsupported sort order 
'$order'.")
+      val nulls = 
Option(k.nulls).map(_.toLowerCase(Locale.ROOT)).getOrElse("last")
+      require(nulls == "first" || nulls == "last", s"Unsupported nulls 
placement '$nulls'.")
+    }
+  }
+
+  override def getPhysicalOp(
+                              workflowId: WorkflowIdentity,
+                              executionId: ExecutionIdentity
+                            ): PhysicalOp = {
+    validate() // compile-time validation
+    PhysicalOp
+      .oneToOnePhysicalOp(
+        workflowId,
+        executionId,
+        operatorIdentifier,
+        OpExecWithClassName(
+          "edu.uci.ics.amber.operator.stablemergesort.StableMergeSortOpExec",
+          objectMapper.writeValueAsString(this)
+        )
+      )
+      .withInputPorts(operatorInfo.inputPorts)
+      .withOutputPorts(operatorInfo.outputPorts)
+  }
+
+  override def operatorInfo: OperatorInfo =
+    OperatorInfo(
+      "Stable Merge Sort",
+      "Stable per-partition sort with multi-key ordering (incremental 
run-stack merge).",
+      OperatorGroupConstants.SORT_GROUP,
+      List(InputPort()),
+      List(OutputPort(blocking = true))
+    )
+}
+
+object StableMergeSortOpDesc {
+
+  class StableSortKey {
+
+    @JsonProperty(value = "attribute", required = true)
+    @JsonSchemaTitle("Attribute")
+    @JsonPropertyDescription("Attribute to sort by.")

Review Comment:
   please follow other operators' convention, remove the . at the end



##########
core/workflow-operator/src/main/scala/edu/uci/ics/amber/operator/stablemergesort/StableMergeSortOpDesc.scala:
##########
@@ -0,0 +1,109 @@
+/*
+* 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 edu.uci.ics.amber.operator.stablemergesort
+
+import com.fasterxml.jackson.annotation.{JsonProperty, JsonPropertyDescription}
+import com.kjetland.jackson.jsonSchema.annotations.{JsonSchemaInject, 
JsonSchemaTitle}
+import edu.uci.ics.amber.core.executor.OpExecWithClassName
+import edu.uci.ics.amber.core.virtualidentity.{ExecutionIdentity, 
WorkflowIdentity}
+import edu.uci.ics.amber.core.workflow.{InputPort, OutputPort, PhysicalOp}
+import edu.uci.ics.amber.operator.LogicalOp
+import edu.uci.ics.amber.operator.metadata.annotations.AutofillAttributeName
+import edu.uci.ics.amber.operator.metadata.{OperatorGroupConstants, 
OperatorInfo}
+import edu.uci.ics.amber.util.JSONUtils.objectMapper
+
+import java.util
+import java.util.Locale
+import scala.jdk.CollectionConverters._
+
+class StableMergeSortOpDesc extends LogicalOp {
+
+  import StableMergeSortOpDesc._
+
+  @JsonProperty(value = "keys", required = true)
+  @JsonSchemaTitle("Sort Keys")
+  @JsonPropertyDescription("List of attributes to sort by with ordering 
preferences.")
+  var keys: util.List[StableSortKey] = new util.ArrayList[StableSortKey]()
+
+  /**
+   * Validate operator parameters during compilation (schema propagation phase 
in the framework).
+   */
+  private def validate(): Unit = {
+    require(keys != null && !keys.isEmpty, "StableMergeSort requires at least 
one sort key.")
+    keys.asScala.foreach { k =>
+      val order = 
Option(k.order).map(_.toLowerCase(Locale.ROOT)).getOrElse("asc")
+      require(order == "asc" || order == "desc", s"Unsupported sort order 
'$order'.")
+      val nulls = 
Option(k.nulls).map(_.toLowerCase(Locale.ROOT)).getOrElse("last")
+      require(nulls == "first" || nulls == "last", s"Unsupported nulls 
placement '$nulls'.")
+    }
+  }
+
+  override def getPhysicalOp(
+                              workflowId: WorkflowIdentity,
+                              executionId: ExecutionIdentity
+                            ): PhysicalOp = {
+    validate() // compile-time validation
+    PhysicalOp
+      .oneToOnePhysicalOp(
+        workflowId,
+        executionId,
+        operatorIdentifier,
+        OpExecWithClassName(
+          "edu.uci.ics.amber.operator.stablemergesort.StableMergeSortOpExec",
+          objectMapper.writeValueAsString(this)
+        )
+      )
+      .withInputPorts(operatorInfo.inputPorts)
+      .withOutputPorts(operatorInfo.outputPorts)
+  }
+
+  override def operatorInfo: OperatorInfo =
+    OperatorInfo(
+      "Stable Merge Sort",
+      "Stable per-partition sort with multi-key ordering (incremental 
run-stack merge).",
+      OperatorGroupConstants.SORT_GROUP,
+      List(InputPort()),
+      List(OutputPort(blocking = true))
+    )
+}
+
+object StableMergeSortOpDesc {
+
+  class StableSortKey {
+
+    @JsonProperty(value = "attribute", required = true)
+    @JsonSchemaTitle("Attribute")
+    @JsonPropertyDescription("Attribute to sort by.")
+    @AutofillAttributeName
+    var attribute: String = _
+
+    @JsonProperty("order")
+    @JsonSchemaTitle("Order")
+    @JsonPropertyDescription("Sort order: asc for ascending or desc for 
descending.")

Review Comment:
   same as above



##########
core/workflow-operator/src/main/scala/edu/uci/ics/amber/operator/stablemergesort/StableMergeSortOpDesc.scala:
##########
@@ -0,0 +1,109 @@
+/*
+* 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 edu.uci.ics.amber.operator.stablemergesort
+
+import com.fasterxml.jackson.annotation.{JsonProperty, JsonPropertyDescription}
+import com.kjetland.jackson.jsonSchema.annotations.{JsonSchemaInject, 
JsonSchemaTitle}
+import edu.uci.ics.amber.core.executor.OpExecWithClassName
+import edu.uci.ics.amber.core.virtualidentity.{ExecutionIdentity, 
WorkflowIdentity}
+import edu.uci.ics.amber.core.workflow.{InputPort, OutputPort, PhysicalOp}
+import edu.uci.ics.amber.operator.LogicalOp
+import edu.uci.ics.amber.operator.metadata.annotations.AutofillAttributeName
+import edu.uci.ics.amber.operator.metadata.{OperatorGroupConstants, 
OperatorInfo}
+import edu.uci.ics.amber.util.JSONUtils.objectMapper
+
+import java.util
+import java.util.Locale
+import scala.jdk.CollectionConverters._
+
+class StableMergeSortOpDesc extends LogicalOp {
+
+  import StableMergeSortOpDesc._
+
+  @JsonProperty(value = "keys", required = true)
+  @JsonSchemaTitle("Sort Keys")
+  @JsonPropertyDescription("List of attributes to sort by with ordering 
preferences.")
+  var keys: util.List[StableSortKey] = new util.ArrayList[StableSortKey]()
+
+  /**
+   * Validate operator parameters during compilation (schema propagation phase 
in the framework).
+   */
+  private def validate(): Unit = {
+    require(keys != null && !keys.isEmpty, "StableMergeSort requires at least 
one sort key.")
+    keys.asScala.foreach { k =>
+      val order = 
Option(k.order).map(_.toLowerCase(Locale.ROOT)).getOrElse("asc")
+      require(order == "asc" || order == "desc", s"Unsupported sort order 
'$order'.")
+      val nulls = 
Option(k.nulls).map(_.toLowerCase(Locale.ROOT)).getOrElse("last")
+      require(nulls == "first" || nulls == "last", s"Unsupported nulls 
placement '$nulls'.")
+    }
+  }
+
+  override def getPhysicalOp(
+                              workflowId: WorkflowIdentity,
+                              executionId: ExecutionIdentity
+                            ): PhysicalOp = {
+    validate() // compile-time validation
+    PhysicalOp
+      .oneToOnePhysicalOp(
+        workflowId,
+        executionId,
+        operatorIdentifier,
+        OpExecWithClassName(
+          "edu.uci.ics.amber.operator.stablemergesort.StableMergeSortOpExec",
+          objectMapper.writeValueAsString(this)
+        )
+      )
+      .withInputPorts(operatorInfo.inputPorts)
+      .withOutputPorts(operatorInfo.outputPorts)
+  }
+
+  override def operatorInfo: OperatorInfo =
+    OperatorInfo(
+      "Stable Merge Sort",
+      "Stable per-partition sort with multi-key ordering (incremental 
run-stack merge).",
+      OperatorGroupConstants.SORT_GROUP,
+      List(InputPort()),
+      List(OutputPort(blocking = true))
+    )
+}
+
+object StableMergeSortOpDesc {
+
+  class StableSortKey {
+
+    @JsonProperty(value = "attribute", required = true)
+    @JsonSchemaTitle("Attribute")
+    @JsonPropertyDescription("Attribute to sort by.")
+    @AutofillAttributeName
+    var attribute: String = _
+
+    @JsonProperty("order")
+    @JsonSchemaTitle("Order")
+    @JsonPropertyDescription("Sort order: asc for ascending or desc for 
descending.")
+    @JsonSchemaInject(json = """{"enum": ["asc", "desc"]}""")
+    var order: String = "asc"
+
+    @JsonProperty("nulls")
+    @JsonSchemaTitle("Nulls")
+    @JsonPropertyDescription("Placement of null values: first or last.")

Review Comment:
   same as above



##########
core/workflow-operator/src/main/scala/edu/uci/ics/amber/operator/stablemergesort/StableMergeSortOpDesc.scala:
##########
@@ -0,0 +1,109 @@
+/*
+* 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 edu.uci.ics.amber.operator.stablemergesort
+
+import com.fasterxml.jackson.annotation.{JsonProperty, JsonPropertyDescription}
+import com.kjetland.jackson.jsonSchema.annotations.{JsonSchemaInject, 
JsonSchemaTitle}
+import edu.uci.ics.amber.core.executor.OpExecWithClassName
+import edu.uci.ics.amber.core.virtualidentity.{ExecutionIdentity, 
WorkflowIdentity}
+import edu.uci.ics.amber.core.workflow.{InputPort, OutputPort, PhysicalOp}
+import edu.uci.ics.amber.operator.LogicalOp
+import edu.uci.ics.amber.operator.metadata.annotations.AutofillAttributeName
+import edu.uci.ics.amber.operator.metadata.{OperatorGroupConstants, 
OperatorInfo}
+import edu.uci.ics.amber.util.JSONUtils.objectMapper
+
+import java.util
+import java.util.Locale
+import scala.jdk.CollectionConverters._
+
+class StableMergeSortOpDesc extends LogicalOp {
+
+  import StableMergeSortOpDesc._
+
+  @JsonProperty(value = "keys", required = true)
+  @JsonSchemaTitle("Sort Keys")
+  @JsonPropertyDescription("List of attributes to sort by with ordering 
preferences.")
+  var keys: util.List[StableSortKey] = new util.ArrayList[StableSortKey]()
+
+  /**
+   * Validate operator parameters during compilation (schema propagation phase 
in the framework).
+   */
+  private def validate(): Unit = {
+    require(keys != null && !keys.isEmpty, "StableMergeSort requires at least 
one sort key.")
+    keys.asScala.foreach { k =>
+      val order = 
Option(k.order).map(_.toLowerCase(Locale.ROOT)).getOrElse("asc")
+      require(order == "asc" || order == "desc", s"Unsupported sort order 
'$order'.")
+      val nulls = 
Option(k.nulls).map(_.toLowerCase(Locale.ROOT)).getOrElse("last")
+      require(nulls == "first" || nulls == "last", s"Unsupported nulls 
placement '$nulls'.")
+    }
+  }
+
+  override def getPhysicalOp(
+                              workflowId: WorkflowIdentity,
+                              executionId: ExecutionIdentity
+                            ): PhysicalOp = {
+    validate() // compile-time validation

Review Comment:
   consider remove this



##########
core/workflow-operator/src/main/scala/edu/uci/ics/amber/operator/stablemergesort/StableMergeSortOpDesc.scala:
##########
@@ -0,0 +1,109 @@
+/*
+* 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 edu.uci.ics.amber.operator.stablemergesort
+
+import com.fasterxml.jackson.annotation.{JsonProperty, JsonPropertyDescription}
+import com.kjetland.jackson.jsonSchema.annotations.{JsonSchemaInject, 
JsonSchemaTitle}
+import edu.uci.ics.amber.core.executor.OpExecWithClassName
+import edu.uci.ics.amber.core.virtualidentity.{ExecutionIdentity, 
WorkflowIdentity}
+import edu.uci.ics.amber.core.workflow.{InputPort, OutputPort, PhysicalOp}
+import edu.uci.ics.amber.operator.LogicalOp
+import edu.uci.ics.amber.operator.metadata.annotations.AutofillAttributeName
+import edu.uci.ics.amber.operator.metadata.{OperatorGroupConstants, 
OperatorInfo}
+import edu.uci.ics.amber.util.JSONUtils.objectMapper
+
+import java.util
+import java.util.Locale
+import scala.jdk.CollectionConverters._
+
+class StableMergeSortOpDesc extends LogicalOp {
+
+  import StableMergeSortOpDesc._
+
+  @JsonProperty(value = "keys", required = true)
+  @JsonSchemaTitle("Sort Keys")
+  @JsonPropertyDescription("List of attributes to sort by with ordering 
preferences.")

Review Comment:
   please follow other operators' convention, remove the . at the end



##########
core/workflow-operator/src/main/scala/edu/uci/ics/amber/operator/stablemergesort/StableMergeSortOpExec.scala:
##########
@@ -0,0 +1,156 @@
+
+/*
+* 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 edu.uci.ics.amber.operator.stablemergesort
+
+import edu.uci.ics.amber.core.executor.OperatorExecutor
+import edu.uci.ics.amber.core.tuple.{AttributeType, Schema, Tuple, TupleLike}
+import 
edu.uci.ics.amber.operator.stablemergesort.StableMergeSortOpDesc.StableSortKey
+import edu.uci.ics.amber.util.JSONUtils.objectMapper
+
+import java.sql.Timestamp
+import java.util.Locale
+import scala.collection.mutable.ArrayBuffer
+import scala.jdk.CollectionConverters._
+
+class StableMergeSortOpExec(descString: String) extends OperatorExecutor {
+
+  private val desc: StableMergeSortOpDesc =
+    objectMapper.readValue(descString, classOf[StableMergeSortOpDesc])
+
+  private val configuredKeys: List[StableSortKey] = desc.keys.asScala.toList
+
+  private case class ResolvedKey(
+                                  index: Int,
+                                  attributeType: AttributeType,
+                                  descending: Boolean,
+                                  nullsFirst: Boolean
+                                )
+
+  private var inputSchema: Schema = _
+  private var resolved: Array[ResolvedKey] = _
+
+  // Incremental run stack: runs(level) holds a sorted run of size 2^level, or 
null if empty
+  private var runs: ArrayBuffer[ArrayBuffer[Tuple]] = _
+
+  override def open(): Unit = {
+    runs = ArrayBuffer.empty[ArrayBuffer[Tuple]]
+  }
+
+  override def close(): Unit = {
+    if (runs != null) runs.clear()
+  }
+
+  override def processTuple(tuple: Tuple, port: Int): Iterator[TupleLike] = {
+    if (inputSchema == null) {
+      inputSchema = tuple.getSchema
+      resolved = resolveKeys(inputSchema)
+    }
+    // each incoming tuple is a size-1 sorted run
+    val run = ArrayBuffer[Tuple](tuple)
+    pushRun(run)
+    Iterator.empty
+  }
+
+  override def onFinish(port: Int): Iterator[TupleLike] = {
+    if (runs.isEmpty) return Iterator.empty
+    // fold-merge from left (earliest chunks) to right (latest), preserving 
chronology
+    var acc = runs(0)
+    var i = 1
+    while (i < runs.length) {
+      acc = mergeRuns(acc, runs(i))
+      i += 1
+    }
+    acc.iterator
+  }
+
+  private def resolveKeys(schema: Schema): Array[ResolvedKey] = {
+    configuredKeys.map { k =>
+      val idx = schema.getIndex(k.attribute)
+      val at  = schema.getAttribute(k.attribute).getType
+      val ord = 
Option(k.order).map(_.toLowerCase(Locale.ROOT)).getOrElse("asc")
+      val nul = 
Option(k.nulls).map(_.toLowerCase(Locale.ROOT)).getOrElse("last")
+      ResolvedKey(
+        index = idx,
+        attributeType = at,
+        descending = (ord == "desc"),
+        nullsFirst = (nul == "first")
+      )
+    }.toArray
+  }
+
+
+  private def pushRun(initial: ArrayBuffer[Tuple]): Unit = {
+    // treat 'runs' as a chronological stack: append new run to end
+    runs.append(initial)
+    // while the top two runs have equal size, merge them into one (older run 
first)
+    while (runs.length >= 2 && runs(runs.length - 1).size == runs(runs.length 
- 2).size) {
+      val right = runs.remove(runs.length - 1) // newest
+      val left  = runs.remove(runs.length - 1) // older
+      val merged = mergeRuns(left, right)      // stable: left items come 
before right when equal
+      runs.append(merged)
+    }
+  }
+
+  private def mergeRuns(left: ArrayBuffer[Tuple], right: ArrayBuffer[Tuple]): 
ArrayBuffer[Tuple] = {
+    val out = new ArrayBuffer[Tuple](left.size + right.size)
+    var i = 0
+    var j = 0
+    while (i < left.size && j < right.size) {
+      if (compareTuples(left(i), right(j)) <= 0) {
+        out += left(i); i += 1
+      } else {
+        out += right(j); j += 1
+      }
+    }
+    while (i < left.size) { out += left(i); i += 1 }
+    while (j < right.size) { out += right(j); j += 1 }
+    out
+  }
+
+  private def compareTuples(a: Tuple, b: Tuple): Int = {

Review Comment:
   seems like there is a bug relate to NULL
   <img width="949" height="527" alt="Screenshot 2025-09-30 at 3 08 05 PM" 
src="https://github.com/user-attachments/assets/635c93bd-3724-4388-a480-15cde2d03905";
 />
   



##########
core/workflow-operator/src/main/scala/edu/uci/ics/amber/operator/stablemergesort/StableMergeSortOpDesc.scala:
##########
@@ -0,0 +1,109 @@
+/*
+* 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 edu.uci.ics.amber.operator.stablemergesort
+
+import com.fasterxml.jackson.annotation.{JsonProperty, JsonPropertyDescription}
+import com.kjetland.jackson.jsonSchema.annotations.{JsonSchemaInject, 
JsonSchemaTitle}
+import edu.uci.ics.amber.core.executor.OpExecWithClassName
+import edu.uci.ics.amber.core.virtualidentity.{ExecutionIdentity, 
WorkflowIdentity}
+import edu.uci.ics.amber.core.workflow.{InputPort, OutputPort, PhysicalOp}
+import edu.uci.ics.amber.operator.LogicalOp
+import edu.uci.ics.amber.operator.metadata.annotations.AutofillAttributeName
+import edu.uci.ics.amber.operator.metadata.{OperatorGroupConstants, 
OperatorInfo}
+import edu.uci.ics.amber.util.JSONUtils.objectMapper
+
+import java.util
+import java.util.Locale
+import scala.jdk.CollectionConverters._
+
+class StableMergeSortOpDesc extends LogicalOp {
+
+  import StableMergeSortOpDesc._
+
+  @JsonProperty(value = "keys", required = true)
+  @JsonSchemaTitle("Sort Keys")
+  @JsonPropertyDescription("List of attributes to sort by with ordering 
preferences.")
+  var keys: util.List[StableSortKey] = new util.ArrayList[StableSortKey]()
+
+  /**
+   * Validate operator parameters during compilation (schema propagation phase 
in the framework).
+   */
+  private def validate(): Unit = {

Review Comment:
   consider remove this. this does not match with our convention of checking 
validation. if u want to do this kind of validation, please check how other 
operators does this. for example: 
   
   // type constraint: value can only be numeric
   @JsonSchemaInject(json = """
   {
     "attributeTypeRules": {
       "value": {
         "enum": ["integer", "long", "double"]
       }
     }
   }
   """)



##########
core/workflow-operator/src/main/scala/edu/uci/ics/amber/operator/stablemergesort/StableMergeSortOpDesc.scala:
##########
@@ -0,0 +1,109 @@
+/*
+* 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 edu.uci.ics.amber.operator.stablemergesort
+
+import com.fasterxml.jackson.annotation.{JsonProperty, JsonPropertyDescription}
+import com.kjetland.jackson.jsonSchema.annotations.{JsonSchemaInject, 
JsonSchemaTitle}
+import edu.uci.ics.amber.core.executor.OpExecWithClassName
+import edu.uci.ics.amber.core.virtualidentity.{ExecutionIdentity, 
WorkflowIdentity}
+import edu.uci.ics.amber.core.workflow.{InputPort, OutputPort, PhysicalOp}
+import edu.uci.ics.amber.operator.LogicalOp
+import edu.uci.ics.amber.operator.metadata.annotations.AutofillAttributeName
+import edu.uci.ics.amber.operator.metadata.{OperatorGroupConstants, 
OperatorInfo}
+import edu.uci.ics.amber.util.JSONUtils.objectMapper
+
+import java.util
+import java.util.Locale
+import scala.jdk.CollectionConverters._
+
+class StableMergeSortOpDesc extends LogicalOp {
+
+  import StableMergeSortOpDesc._
+
+  @JsonProperty(value = "keys", required = true)
+  @JsonSchemaTitle("Sort Keys")
+  @JsonPropertyDescription("List of attributes to sort by with ordering 
preferences.")
+  var keys: util.List[StableSortKey] = new util.ArrayList[StableSortKey]()
+
+  /**
+   * Validate operator parameters during compilation (schema propagation phase 
in the framework).
+   */
+  private def validate(): Unit = {
+    require(keys != null && !keys.isEmpty, "StableMergeSort requires at least 
one sort key.")
+    keys.asScala.foreach { k =>
+      val order = 
Option(k.order).map(_.toLowerCase(Locale.ROOT)).getOrElse("asc")
+      require(order == "asc" || order == "desc", s"Unsupported sort order 
'$order'.")
+      val nulls = 
Option(k.nulls).map(_.toLowerCase(Locale.ROOT)).getOrElse("last")
+      require(nulls == "first" || nulls == "last", s"Unsupported nulls 
placement '$nulls'.")
+    }
+  }
+
+  override def getPhysicalOp(
+                              workflowId: WorkflowIdentity,
+                              executionId: ExecutionIdentity
+                            ): PhysicalOp = {
+    validate() // compile-time validation
+    PhysicalOp
+      .oneToOnePhysicalOp(
+        workflowId,
+        executionId,
+        operatorIdentifier,
+        OpExecWithClassName(
+          "edu.uci.ics.amber.operator.stablemergesort.StableMergeSortOpExec",
+          objectMapper.writeValueAsString(this)
+        )
+      )
+      .withInputPorts(operatorInfo.inputPorts)
+      .withOutputPorts(operatorInfo.outputPorts)
+  }
+
+  override def operatorInfo: OperatorInfo =
+    OperatorInfo(
+      "Stable Merge Sort",
+      "Stable per-partition sort with multi-key ordering (incremental 
run-stack merge).",
+      OperatorGroupConstants.SORT_GROUP,
+      List(InputPort()),
+      List(OutputPort(blocking = true))
+    )
+}
+
+object StableMergeSortOpDesc {
+
+  class StableSortKey {

Review Comment:
   if we want to keep both sort, I think maybe we should keep the same sort 
criteria. check SortCriteriaUnit.java. Maybe make some changes, and reuse this



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

Reply via email to