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


##########
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:
   Done in 1800148615 — `paramSpec` is abstract again, so a parameter enum 
without one fails to compile; `ParamSpec.Empty` is gone and `TestParam` is the 
one-liner.



##########
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:
   Done in 6b3553d784 — `compareValues` keeps its five primitive cases, so the 
file matches `main` again. A tuple-free `AttributeTypeUtils.compare` would help 
aggregation too, but it lives in `workflow-core`, outside this PR.



##########
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:
   Done in af04787bdf — `SourceOperatorDescriptor.sourcePhysicalOp` takes the 
exec class name, `parallelizable` and the output schema, and replaces all six, 
plus the same copies in `URLFetcherOpDesc` and the AsterixDB/MySQL/PostgreSQL 
sources. Arrow and Parquet pass `inferSchema()`, since their `sourceSchema()` 
is `null`; d822b5c2bf pins that in both specs.



##########
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:
   Done in 6982bafef9 — `includeComment` is gone. The other knobs stay so all 
37 charts keep their exact text here; normalizing it would let them, and 
`standaloneError`, fold into one renderer.



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