kunwp1 commented on code in PR #9518:
URL: https://github.com/apache/texera/pull/9518#discussion_r4649033693
##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/machineLearning/sklearnAdvanced/base/SklearnAdvancedBaseDesc.scala:
##########
@@ -49,10 +49,43 @@ import scala.util.Try
* decide which values the estimator can be given. The two below state that
so the form can
* hold the user to it, rather than leaving it to be discovered when `fit`
raises.
*/
+final case class ParamSpec(
+ name: String,
+ valueType: String,
+ sampleValue: String = "",
+ allowedValues: Array[String] = Array.empty,
+ pattern: String = "",
+ minimum: String = ""
+) {
+ def withPattern(pattern: String): ParamSpec = copy(pattern = pattern)
+
+ def withMinimum(minimum: String): ParamSpec = copy(minimum = minimum)
+}
+
+object ParamSpec {
+ final val Empty: ParamSpec = ParamSpec("", "")
+
+ // Shared pattern for SVM gamma ("scale", "auto", or floating-point literal).
+ final val GammaPattern: String =
+
"^\\s*(?:scale|auto|[-+]?(?:(?:[0-9]+(?:_[0-9]+)*)?\\.(?:[0-9]+(?:_[0-9]+)*)" +
+ "|(?:[0-9]+(?:_[0-9]+)*)\\.?)(?:[eE][-+]?[0-9]+(?:_[0-9]+)*)?)\\s*$"
+
+ @scala.annotation.varargs
+ def of(
+ name: String,
+ valueType: String,
+ sampleValue: String,
+ allowedValues: String*
+ ): ParamSpec =
+ ParamSpec(name, valueType, sampleValue, allowedValues.toArray)
+}
+
trait ParamClass {
- def getName: String
+ def paramSpec: ParamSpec = ParamSpec.Empty
Review Comment:
`paramSpec` used to be effectively required, since each enum had to supply
`getName`/`getType`. With this default, a parameter enum that forgets it still
compiles and generates an empty keyword (`=value`) for the estimator, which
only fails inside `fit`. Leaving it abstract, `def paramSpec: ParamSpec`, keeps
that a compile error. `ParamSpec.Empty` then has no users, and the spec's
`TestParam` becomes one line: `override def paramSpec: ParamSpec =
ParamSpec(name, typ)`.
##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/sort/StableMergeSortOpExec.scala:
##########
@@ -243,34 +244,16 @@ class StableMergeSortOpExec(descString: String) extends
OperatorExecutor {
attrType: AttributeType
): Int =
attrType match {
- case AttributeType.INTEGER =>
- java.lang.Integer.compare(
- leftValue.asInstanceOf[Number].intValue(),
- rightValue.asInstanceOf[Number].intValue()
- )
- case AttributeType.LONG =>
- java.lang.Long.compare(
- leftValue.asInstanceOf[Number].longValue(),
- rightValue.asInstanceOf[Number].longValue()
- )
- case AttributeType.DOUBLE =>
- java.lang.Double.compare(
- leftValue.asInstanceOf[Number].doubleValue(),
- rightValue.asInstanceOf[Number].doubleValue()
- )
- case AttributeType.BOOLEAN =>
- java.lang.Boolean.compare(leftValue.asInstanceOf[Boolean],
rightValue.asInstanceOf[Boolean])
+ case AttributeType.INTEGER | AttributeType.LONG | AttributeType.DOUBLE |
+ AttributeType.BOOLEAN | AttributeType.BINARY =>
+ AttributeTypeUtils.compare(leftValue, rightValue, attrType)
Review Comment:
Same results as before. `AttributeTypeUtils.compare` uses the same
`Integer`/`Long`/`Double`/`Boolean.compare` and `Arrays.compareUnsigned`. But
it starts with `(left, right) match { case (null, null) ... }`, which builds a
`scala.Tuple2` on every call, re-checks nulls this caller has already ruled
out, and is too large for C2 to inline. That now runs on every sort comparison,
N log N times. Either keep the five primitive cases here, or make `compare`
tuple-free (`if (left == null) ... else if (right == null) ...`), which would
also help the aggregation path.
##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/huggingFace/HuggingFaceInferenceOpDescSpec.scala:
##########
@@ -713,8 +714,9 @@ class HuggingFaceInferenceOpDescSpec extends AnyFlatSpec
with Matchers {
it should "report a clear error when a configured image/audio column is
missing from the input table" in {
val code = makeDesc().generatePythonCode()
- code should include("Input Image Column '")
- code should include("Input Audio Column '")
+ code should include("""media_kind = "image" if task in image_tasks""")
+ code should include(""""audio" if task in audio_only_tasks""")
+ code should include("Input {media_kind.title()} Column")
Review Comment:
These used to pin the message users see, `Input Image Column '` / `Input
Audio Column '`. Now they pin the code shape, `Input {media_kind.title()}
Column`, so nothing checks the rendered text any more. It is still the same at
runtime, since `"image".title()` is `"Image"`. AGENTS.md asks a refactor to
leave assertions on user-facing behaviour untouched. Keeping the two literals
(e.g. a small `{"image": "Image", "audio": "Audio"}` label, or spelling both
messages out) would let the old assertions stand.
More broadly, the description says test assertions are unchanged, but
running `main`'s test tree against this PR's code fails 5 HuggingFace cases:
this one, the SSRF fetch, image-only and ASR routing, and the image chat-part
count. I walked the generated Python branch by branch
(`_media_provider_payload`, `_poll_prediction` with both terminal checks, the
merged image/audio input handling and the content-type merge), and it behaves
the same. So these are rewrites of code-shape assertions, but the description
should say so.
##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/visualization/PythonCodeFragment.scala:
##########
@@ -19,11 +19,67 @@
package org.apache.texera.amber.operator.visualization
+import org.apache.texera.amber.pybuilder.PythonTemplateBuilder.pyStringLiteral
+
private[visualization] object PythonCodeFragment {
def render(code: String, indent: Int): String =
code.stripMargin.linesIterator
.map { line =>
if (line.isEmpty) line else (" " * indent) + line
}
.mkString("\n")
+
+ def runtimeError(
+ title: String,
+ plural: Boolean = false,
+ typed: Boolean = false,
+ colonOnly: Boolean = false,
+ singleLineClose: Boolean = false,
+ indent: Int = 4
+ ): String = {
+ val label =
+ if (colonOnly) "Reason" else if (plural) "Reasons are" else "Reason is"
+ val sig = s"def render_error(self, error_msg)${if (typed) " -> str" else
""}:"
+ val pfx = " " * indent
+ val closeInline = if (singleLineClose) "'''.format(error_msg)" else ""
+ val tail =
+ if (singleLineClose) "" else s"\n${" " * (indent +
11)}'''.format(error_msg)"
+ s"""$pfx$sig
+ |$pfx return '''<h1>$title</h1>
+ |$pfx <p>$label: {} </p>$closeInline$tail""".stripMargin
+ }
+
+ def emptyTableGuard(
+ message: String,
+ indent: Int = 8,
+ bodyIndent: Int = 3,
+ doubleQuoted: Boolean = false
+ ): String = {
+ val q = if (doubleQuoted) "\"" else "'"
+ val p0 = " " * indent
+ val pb = " " * (indent + bodyIndent)
+ val msgLit = pyStringLiteral(message)
+ s"""${p0}if table.empty:
+ |${pb}yield {${q}html-content${q}: self.render_error($msgLit)}
+ |${pb}return""".stripMargin
+ }
+
+ def plotlyHtmlYield(
+ indent: Int = 8,
+ includeComment: Boolean = false,
Review Comment:
`includeComment` is never passed, so it can go. More generally, most of the
knobs here (`plural`, `colonOnly`, `singleLineClose`, `bodyIndent`,
`doubleQuoted`, `spacesAroundEq`, `compactDict`) exist to keep each chart's
historic text byte-identical. I checked: all 37 charts generate exactly what
they did on `main`. A later PR that normalises the text could drop most of
them. `StandaloneChartCode.standaloneError` already renders the same
`render_error` body separately.
##########
common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/source/scan/csv/CsvScanSupport.scala:
##########
@@ -0,0 +1,148 @@
+/*
+ * 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 org.apache.texera.amber.operator.source.scan.csv
+
+import org.apache.texera.amber.core.executor.OpExecWithClassName
+import org.apache.texera.amber.core.tuple.{Attribute, AttributeType, Schema}
+import org.apache.texera.amber.core.virtualidentity.{ExecutionIdentity,
WorkflowIdentity}
+import org.apache.texera.amber.core.workflow.{PhysicalOp,
SchemaPropagationFunc}
+import
org.apache.texera.amber.operator.StandaloneCodeGenerator.SourceFilePlaceholder
+import org.apache.texera.amber.operator.source.scan.ScanSourceOpDesc
+import org.apache.texera.amber.pybuilder.PythonTemplateBuilder.pyStringLiteral
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+
+import java.net.URI
+import scala.util.Try
+
+/** Shared physical-op wiring, URI/delimiter resolution, schema building, and
standalone codegen for CSV scans. */
+private[source] object CsvScanSupport {
+
+ def resolveDelimiterChar(customDelimiter: Option[String]): String =
+ customDelimiter.filter(_.nonEmpty).getOrElse(",").charAt(0).toString
+
+ def csvPhysicalOp(
+ desc: ScanSourceOpDesc,
+ workflowId: WorkflowIdentity,
+ executionId: ExecutionIdentity,
+ execClassName: String,
+ parallelizable: Boolean = false
+ ): PhysicalOp = {
+ val base = PhysicalOp
+ .sourcePhysicalOp(
+ workflowId,
+ executionId,
+ desc.operatorIdentifier,
+ OpExecWithClassName(execClassName,
objectMapper.writeValueAsString(desc))
+ )
+ .withInputPorts(desc.operatorInfo.inputPorts)
+ .withOutputPorts(desc.operatorInfo.outputPorts)
+ val withParallel = if (parallelizable) base.withParallelizable(true) else
base
+ withParallel.withPropagateSchema(
Review Comment:
This, `TextSourceOpDesc.buildPhysicalOp` and
`TwitterSourceOpDesc.tweetSourcePhysicalOp` are the same builder:
`sourcePhysicalOp` with `OpExecWithClassName(cls, writeValueAsString(desc))`,
the declared ports, and `sourceSchema()` propagation. `JSONLScanSourceOpDesc`,
`ArrowSourceOpDesc` and `ParquetScanSourceOpDesc` still carry their own copies.
One `protected def` on the source base class taking the exec class name, plus
`.withParallelizable(parallelizable)`, would cover all six. Small, though, so
fine as a follow-up.
--
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]