carloea2 commented on code in PR #4024:
URL: https://github.com/apache/texera/pull/4024#discussion_r2512954032
##########
common/workflow-core/src/main/scala/org/apache/amber/core/tuple/Tuple.scala:
##########
@@ -112,6 +112,29 @@ case class Tuple @JsonCreator() (
object Tuple {
+ /** Build a Tuple from (name -> value) pairs, coercing values to the schema
types. */
+ def of(schema: Schema, values: (String, Any)*): Tuple = {
+ val nameToValue: Map[String, Any] = values.toMap
+ val coercedFields: Array[Any] =
+ schema.getAttributes.map { attribute =>
+ val rawValue: Any = nameToValue.getOrElse(attribute.getName, null)
+ AttributeTypeUtils.parseField(rawValue, attribute.getType, force =
true)
+ }.toArray
+ Tuple(schema, coercedFields)
+ }
+
+ /** Build a Tuple without coercion.
+ * Uses the builder’s runtime type checks; values must already match the
schema’s field classes.
+ * Missing attributes (or unknown attribute names) will cause an error.
+ */
+ def ofStrict(schema: Schema, values: (String, Any)*): Tuple =
Review Comment:
I believe for testing operators is useful since it enforces the types
although is not vital.
--
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]