aglinxinyuan commented on code in PR #9515:
URL: https://github.com/apache/texera/pull/9515#discussion_r4596496001


##########
common/workflow-core/src/main/scala/org/apache/texera/amber/util/ArrowUtils.scala:
##########
@@ -74,37 +74,43 @@ object ArrowUtils extends LazyLogging {
     val arrowSchema = vectorSchemaRoot.getSchema
     val schema = toTexeraSchema(arrowSchema)
 
-    Tuple
-      .builder(schema)
-      .addSequentially(
-        vectorSchemaRoot.getFieldVectors.asScala.zipWithIndex.map {
-          case (fieldVector: FieldVector, index: Int) =>
-            val value: AnyRef = fieldVector.getObject(rowIndex)
-            try {
-              // Use the attribute type from the schema (which includes 
metadata)
-              // instead of deriving it from the Arrow type
-              val attributeType = schema.getAttributes(index).getType
-              // A timestamp and an unsigned integer are the types whose field
-              // says more than the schema does, so they are the only ones that
-              // read the field: an unsigned column arrives as INTEGER or LONG.
-              attributeType match {
-                case AttributeType.TIMESTAMP => wallClockOf(value, 
fieldVector.getField.getType)
-                case AttributeType.INTEGER | AttributeType.LONG =>
-                  AttributeTypeUtils.parseField(
-                    unsignedValueOf(value, fieldVector.getField.getType),
-                    attributeType
-                  )
-                case _ => AttributeTypeUtils.parseField(value, attributeType)
-              }
-            } catch {
-              case e: Exception =>
-                logger.warn("Caught error during parsing Arrow value back to 
Texera value", e)
-                null
-            }
-
-        }.toArray
-      )
-      .build()
+    val fieldVectors = vectorSchemaRoot.getFieldVectors
+    val fieldValues = new Array[Any](fieldVectors.size())
+    val vectors = fieldVectors.iterator()
+    val attributes = schema.getAttributes.iterator
+    var index = 0
+    while (vectors.hasNext) {
+      val fieldVector = vectors.next()
+      val value: AnyRef = fieldVector.getObject(rowIndex)
+      val fieldValue =
+        try {
+          // Use the attribute type from the schema (which includes metadata)
+          // instead of deriving it from the Arrow type. Preserve the indexed
+          // lookup's error when the vector list is wider than the schema.
+          val attribute = if (attributes.hasNext) attributes.next() else 
schema.getAttributes(index)

Review Comment:
   Done in 9efd195ade — it takes `attributes.next().getType` now. Agreed that 
converting the schema once per `VectorSchemaRoot` is the bigger win; leaving 
that as a follow-up so this PR stays scoped.
   



##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/machineLearning/Scorer/MachineLearningScorerOpDesc.scala:
##########
@@ -134,34 +142,36 @@ class MachineLearningScorerOpDesc extends 
PythonOperatorDescriptor with Standalo
     * classification target even though a continuous one is not, and the schema
     * cannot tell the two apart.
     */
+  private def requireScoredColumn(

Review Comment:
   Done in 9efd195ade — `requireScoredColumn` now sits below 
`validateScoredColumns`, so the scaladoc is back on the right method.
   



##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/machineLearning/Scorer/MachineLearningScorerOpDesc.scala:
##########
@@ -174,12 +184,15 @@ class MachineLearningScorerOpDesc extends 
PythonOperatorDescriptor with Standalo
         // A matching pair can still be one sklearn refuses as labels. Bytes 
fail
         // every metric. Timestamps only fail the per-class ones, since 
Accuracy
         // just counts equal rows.
-        val perClass = classificationMetrics.filterNot(_ == 
classificationMetricsFnc.accuracy)
+        // Keep validation of a null metrics list ahead of schema construction.
+        val perClass =
+          if (classificationMetrics == null || actualType == 
AttributeType.TIMESTAMP)

Review Comment:
   Done in 9efd195ade — switched to your shape, so only timestamps build the 
per-class list, and the null-metrics case still gets its NPE from 
`getOutputSchemas`.
   



##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/machineLearning/Scorer/MachineLearningScorerOpDesc.scala:
##########
@@ -194,21 +207,23 @@ class MachineLearningScorerOpDesc extends 
PythonOperatorDescriptor with Standalo
       inputSchemas: Map[PortIdentity, Schema]
   ): Map[PortIdentity, Schema] = {
     validateScoredColumns(inputSchemas)
-    val metrics = if (isRegression) {
-      regressionMetrics.map(_.getName())
-    } else {
-      classificationMetrics.map(_.getName())
-    }
-    val baseSchema = if (!isRegression) {
-      Schema(List(new Attribute("Class", AttributeType.STRING)))
-    } else {
-      Schema(List())
+    val metricNames =
+      if (isRegression) regressionMetrics.map(_.getName())
+      else classificationMetrics.map(_.getName())
+    val builder = List.newBuilder[Attribute]
+    val seenNames = mutable.HashSet.empty[String]
+    if (!isRegression) {
+      seenNames += "class"
+      builder += new Attribute("Class", AttributeType.STRING)
     }
-
-    val outputSchema = metrics.foldLeft(baseSchema) { (currentSchema, 
metricName) =>
-      currentSchema.add(new Attribute(metricName, AttributeType.DOUBLE))
+    metricNames.foreach { metricName =>
+      if (!seenNames.add(metricName.toLowerCase)) {
+        throw new RuntimeException(s"Attribute name '$metricName' already 
exists in the schema")

Review Comment:
   Done in 9efd195ade — back to the `Schema.add` fold, so the duplicate rule 
and its message live only in `Schema`.
   



##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/udf/java/JavaUdfUiParameterInjectorSpec.scala:
##########
@@ -226,6 +226,18 @@ class JavaUdfUiParameterInjectorSpec extends AnyFlatSpec 
with Matchers {
       executor.close()
     }
   }
+
+  it should "preserve unicode and mixed line endings while rejecting 
uninitialized or multi-field injections" in {

Review Comment:
   Done in 9efd195ade — renamed it to "preserve unicode escapes and mixed line 
endings", since the multi-declarator refusal is already in the loop above.
   



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