bobbai00 commented on code in PR #9646:
URL: https://github.com/apache/texera/pull/9646#discussion_r4689866132


##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/visualization/RuntimeStandaloneParitySpec.scala:
##########
@@ -0,0 +1,481 @@
+/*
+ * 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.visualization
+
+import com.fasterxml.jackson.databind.JsonNode
+import org.apache.texera.amber.operator.visualization.bulletChart.{
+  BulletChartOpDesc,
+  BulletChartStepDefinition
+}
+import org.apache.texera.amber.operator.visualization.continuousErrorBands.{
+  BandConfig,
+  ContinuousErrorBandsOpDesc
+}
+import org.apache.texera.amber.operator.visualization.lineChart.LineMode
+import 
org.apache.texera.amber.operator.visualization.networkGraph.NetworkGraphOpDesc
+import org.apache.texera.amber.operator.visualization.treeplot.TreePlotOpDesc
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.apache.texera.amber.util.PythonTestSupport.{
+  NeedsPythonPackages,
+  canImport,
+  configuredPython,
+  withDriver
+}
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+import scala.jdk.CollectionConverters._
+
+/**
+  * Runs the Python four charts generate for the operator, and the script each 
one
+  * exports, over the same tables.
+  *
+  * Both paths of these charts are assembled from shared Python fragments, and 
a
+  * fragment that reads a name its caller never bound still compiles: only 
running
+  * it fails. Each case runs both paths and expects the same figures, or the 
same
+  * refusal; the values pinned below keep the two from drifting together. Every
+  * value typed into a setting carries a quote, which the operator decodes at
+  * runtime and the exported script has to spell as an escaped literal.
+  */
+class RuntimeStandaloneParitySpec extends AnyFlatSpec with Matchers {
+
+  private def networkGraph: NetworkGraphOpDesc = {
+    val op = new NetworkGraphOpDesc
+    op.source = "from node"
+    op.destination = "to's \"node\""
+    op.title = "Friends \"graph\""
+    op
+  }
+
+  private def bulletChart: BulletChartOpDesc = {
+    val op = new BulletChartOpDesc
+    op.value = "it's \"score\""
+    op.deltaReference = Some(50)
+    op.thresholdValue = Some(80)
+    // The second step runs backwards, so it is reported rather than drawn; 
the last
+    // has no end, so it reaches neither script.
+    op.steps = Seq(
+      new BulletChartStepDefinition(Some(0), Some(40)),
+      new BulletChartStepDefinition(Some(60), Some(40)),
+      new BulletChartStepDefinition(Some(40), Some(100)),
+      new BulletChartStepDefinition(Some(100), None)
+    ).asJava
+    op
+  }
+
+  private def treePlot: TreePlotOpDesc = {
+    val op = new TreePlotOpDesc
+    op.edgeListColumn = "edge \"pairs\""
+    op
+  }
+
+  private def errorBands: ContinuousErrorBandsOpDesc = {
+    val named = new BandConfig
+    named.xValue = "t"
+    named.yValue = "mean \"v\""
+    named.yUpper = "hi"
+    named.yLower = "lo"
+    named.name = "band's one"
+    named.color = "#ff0000"
+    named.fillColor = "rgba(255, 0, 0, 0.2)"
+    named.mode = LineMode.LINE
+    // Left unnamed and uncoloured: named after its y column, in plotly's own 
colours.
+    val unnamed = new BandConfig
+    unnamed.xValue = "t"
+    unnamed.yValue = "other"
+    unnamed.yUpper = "other_hi"
+    unnamed.yLower = "other_lo"
+    val op = new ContinuousErrorBandsOpDesc
+    op.xLabel = "Time \"s\""
+    op.yLabel = "it's y"
+    op.bands = Seq(named, unnamed).asJava
+    op
+  }
+
+  /** Both paths of every chart, keyed by the names the driver's tables use. 
The
+    * exported script gets the imports the translator writes above it.
+    */
+  private def jobs: String = {
+    val charts: Seq[(String, PythonVisualizationOpDesc)] = Seq(
+      "network_graph" -> networkGraph,
+      "bullet_chart" -> bulletChart,
+      "tree_plot" -> treePlot,
+      "error_bands" -> errorBands
+    )
+    val root = objectMapper.createObjectNode()
+    charts.foreach {
+      case (name, op) =>
+        val imports = "import pandas as pd" +: op.standaloneImports()
+        root
+          .putObject(name)
+          .put("operator", op.generatePythonCode())
+          .put("script", (imports :+ 
op.generateStandaloneCode()).mkString("\n"))
+    }
+    objectMapper.writeValueAsString(root)
+  }
+
+  /** What one path left for one table: the figures it drew, the reason on any 
error
+    * page, the step errors listed under its charts, and the traceback if it 
raised.
+    */
+  private case class Drawn(
+      figures: Seq[JsonNode],
+      reasons: Seq[String],
+      stepErrors: Seq[String],
+      failure: Option[String]
+  )
+
+  private case class Outcome(operator: Drawn, script: Drawn)
+
+  private def drawn(node: JsonNode): Drawn =
+    Drawn(
+      node.get("figures").asScala.toSeq,
+      node.get("reasons").asScala.map(_.asText).toSeq,
+      node.get("stepErrors").asScala.map(_.asText).toSeq,
+      Option(node.get("failure")).filterNot(_.isNull).map(_.asText)
+    )
+
+  /** Every case's outcome by `chart/case`. One run for the whole suite, so 
pandas,
+    * plotly and networkx are imported once.
+    */
+  private lazy val outcomes: Map[String, Outcome] = {
+    val python = configuredPython().getOrElse(
+      cancel("No runnable python executable (udf.conf python.path, python3, 
python, py)")
+    )
+    if (!canImport(python, "pandas", "plotly", "networkx")) {
+      cancel(s"'$python' cannot import pandas, plotly and networkx; skipping 
runtime verification")

Review Comment:
   **Advisory:**
   
   A missing networkx cancels all ten cases, so a CI image without it would 
drop the parity guard for all four charts and still pass. networkx is pinned in 
no requirements file; CI only gets it transitively. The check that makes these 
cancels safe 
([PythonCodeRawInvalidTextSpec.scala:340](https://github.com/apache/texera/blob/a234e15d0d561c4a1de614186e12feeabe1a47d0/common/workflow-operator/src/test/scala/org/apache/texera/amber/util/PythonCodeRawInvalidTextSpec.scala#L340-L358))
 fails amber-integration for pandas and plotly only. Only the NetworkGraph code 
imports networkx, inside each path's `try` (lines 404 and 420), so without it 
in the gate a missing module fails just those two cases, loudly.
   ```suggestion
       if (!canImport(python, "pandas", "plotly")) {
         cancel(s"'$python' cannot import pandas and plotly; skipping runtime 
verification")
   ```



##########
common/workflow-operator/src/test/scala/org/apache/texera/amber/operator/visualization/RuntimeStandaloneParitySpec.scala:
##########
@@ -0,0 +1,481 @@
+/*
+ * 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.visualization
+
+import com.fasterxml.jackson.databind.JsonNode
+import org.apache.texera.amber.operator.visualization.bulletChart.{
+  BulletChartOpDesc,
+  BulletChartStepDefinition
+}
+import org.apache.texera.amber.operator.visualization.continuousErrorBands.{
+  BandConfig,
+  ContinuousErrorBandsOpDesc
+}
+import org.apache.texera.amber.operator.visualization.lineChart.LineMode
+import 
org.apache.texera.amber.operator.visualization.networkGraph.NetworkGraphOpDesc
+import org.apache.texera.amber.operator.visualization.treeplot.TreePlotOpDesc
+import org.apache.texera.amber.util.JSONUtils.objectMapper
+import org.apache.texera.amber.util.PythonTestSupport.{
+  NeedsPythonPackages,
+  canImport,
+  configuredPython,
+  withDriver
+}
+import org.scalatest.flatspec.AnyFlatSpec
+import org.scalatest.matchers.should.Matchers
+
+import scala.jdk.CollectionConverters._
+
+/**
+  * Runs the Python four charts generate for the operator, and the script each 
one
+  * exports, over the same tables.
+  *
+  * Both paths of these charts are assembled from shared Python fragments, and 
a
+  * fragment that reads a name its caller never bound still compiles: only 
running
+  * it fails. Each case runs both paths and expects the same figures, or the 
same
+  * refusal; the values pinned below keep the two from drifting together. Every
+  * value typed into a setting carries a quote, which the operator decodes at
+  * runtime and the exported script has to spell as an escaped literal.

Review Comment:
   **Polish:**
   
   "Every value typed into a setting carries a quote" (repeated in the 
description) is not what the fixtures do. `source` is `"from node"` (line 61), 
and the band columns `t`, `hi` and `lo` carry none either (lines 91-94). This 
matters for `source`: NetworkGraph spells it with its own `sourceLit` 
([NetworkGraphOpDesc.scala:110](https://github.com/apache/texera/blob/a234e15d0d561c4a1de614186e12feeabe1a47d0/common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/visualization/networkGraph/NetworkGraphOpDesc.scala#L110)),
 so no case exercises that literal's escaping. Giving `source` a quote and 
narrowing the sentence would make it true.



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