aglinxinyuan commented on code in PR #9515:
URL: https://github.com/apache/texera/pull/9515#discussion_r4596493833
##########
common/workflow-core/src/main/scala/org/apache/texera/amber/core/tuple/Schema.scala:
##########
@@ -28,6 +28,7 @@ import scala.collection.immutable.ListMap
* Represents the schema of a tuple, consisting of a list of attributes.
* The schema is immutable, and any modifications result in a new Schema
instance.
*/
+@SerialVersionUID(-8380542583803575822L)
Review Comment:
Agreed — with Pekko routing `Serializable` through Kryo, the pins protected
nothing. Done in 9efd195ade: all four are gone (`Schema`, `Tuple`,
`Tuple.Builder`, `MachineLearningScorerOpDesc`), and the description no longer
mentions UIDs.
##########
common/workflow-core/src/main/scala/org/apache/texera/amber/core/tuple/Schema.scala:
##########
@@ -108,12 +109,15 @@ case class Schema @JsonCreator() (
list + (attr.getName -> attr.getType.name())
)
+ private def lowerCaseAttributeNames: Set[String] =
+ attributes.iterator.map(_.getName.toLowerCase).toSet
Review Comment:
Done in 9efd195ade — `add` and `remove` both read `attributeIndex.keySet`
now, so `lowerCaseAttributeNames` is gone.
##########
common/workflow-core/src/main/scala/org/apache/texera/amber/core/tuple/Tuple.scala:
##########
@@ -83,25 +84,44 @@ case class Tuple @JsonCreator() (
this
}
- override def hashCode: Int =
util.Arrays.deepHashCode(getFields.map(_.asInstanceOf[AnyRef]))
+ override def hashCode: Int =
+ util.Arrays.deepHashCode(getFields.clone().asInstanceOf[Array[AnyRef]])
override def equals(obj: Any): Boolean =
obj match {
- case that: Tuple =>
- this.schema == that.schema &&
- this.getFields.zip(that.getFields).forall {
- case (field1: Array[Byte], field2: Array[Byte]) =>
- field1.sameElements(field2) // for Binary, use sameElements
instead of == to compare
- case (field1, field2) =>
- field1 == field2
- }
+ case that: Tuple if this.schema == that.schema =>
+ val leftFields = this.getFields
+ val rightFields = that.getFields
+ val fieldCount = math.min(leftFields.length, rightFields.length)
+ // Capture field references before any user-defined equals can change
either tuple.
+ val leftSnapshot =
util.Arrays.copyOf(leftFields.asInstanceOf[Array[AnyRef]], fieldCount)
+ val rightSnapshot =
util.Arrays.copyOf(rightFields.asInstanceOf[Array[AnyRef]], fieldCount)
+ var index = 0
+ var equal = true
+ while (index < fieldCount && equal) {
+ val left = leftSnapshot(index)
+ val right = rightSnapshot(index)
+ equal =
+ if (left.isInstanceOf[Array[Byte]] &&
right.isInstanceOf[Array[Byte]])
+ util.Arrays.equals(left.asInstanceOf[Array[Byte]],
right.asInstanceOf[Array[Byte]])
+ else
+ left == right
+ index += 1
+ }
+ equal
Review Comment:
Done in 9efd195ade — took your version: `hashCode` hands the fields to
`deepHashCode` as they are, and `equals` compares them in place through
`fieldEquals`, so neither copies the array.
##########
common/workflow-core/src/main/scala/org/apache/texera/amber/core/tuple/Tuple.scala:
##########
@@ -171,20 +189,21 @@ object Tuple {
/**
* Builder class for constructing Tuple instances in a flexible and
controlled manner.
*/
+ @SerialVersionUID(-699268362870086216L)
case class Builder(schema: Schema) {
private val fieldNameMap = mutable.Map.empty[String, Any]
def add(tuple: Tuple, isStrictSchemaMatch: Boolean = true): Builder = {
require(tuple != null, "Tuple cannot be null")
- tuple.getFields.zipWithIndex.foreach {
- case (field, i) =>
- val attribute = tuple.schema.getAttributes(i)
- if (!isStrictSchemaMatch &&
!schema.containsAttribute(attribute.getName)) {
- // Skip if not matching in non-strict mode
- } else {
- add(attribute, tuple.getFields(i))
- }
+ val fieldCount = tuple.getFields.length
+ var index = 0
+ while (index < fieldCount) {
+ val attribute = tuple.schema.getAttributes(index)
+ if (isStrictSchemaMatch ||
schema.containsAttribute(attribute.getName)) {
+ this.add(attribute, tuple.getFields(index))
Review Comment:
Good catch — done in 9efd195ade: `Builder.add(tuple)` now walks the
attributes with one iterator alongside the fields, so it is a single pass.
##########
common/workflow-core/src/main/scala/org/apache/texera/amber/core/tuple/Tuple.scala:
##########
@@ -215,9 +234,12 @@ object Tuple {
def addSequentially(fields: Array[Any]): Builder = {
require(fields != null, "Fields cannot be null")
checkSchemaMatchesFields(schema.getAttributes, fields)
- schema.getAttributes.zip(fields).foreach {
- case (attribute, field) =>
- this.add(attribute, field)
+ val attributes = schema.getAttributes.iterator
+ val values = fields.clone()
+ var index = 0
+ while (attributes.hasNext && index < values.length) {
+ this.add(attributes.next(), values(index))
Review Comment:
Done in 9efd195ade — `addSequentially` is now `fields.foreach(field =>
this.add(attributes.next(), field))`, and `SeqTupleLike.enforceSchema` reads
`getFields` without the clone.
--
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]