Skip to content

BarChart: empty categoryColumn is treated as a real column, breaking px.bar #6792

Description

@kz930

What happened?

BarChartOpDesc.categoryColumn declares a JSON default of "No Selection" but its Scala field initializer is the empty string:

common/workflow-operator/src/main/scala/org/apache/texera/amber/operator/visualization/barChart/BarChartOpDesc.scala

@JsonProperty(defaultValue = "No Selection", required = false)
...
var categoryColumn: EncodableString = ""      // Scala default is "", not "No Selection"

generatePythonCode decides whether a category column was chosen by comparing only against "No Selection":

var isCategoryColumn = "False"
if (categoryColumn != "No Selection")
  isCategoryColumn = "True"

When categoryColumn is empty — the Scala default, reached whenever the field is absent from the deserialized JSON (defaultValue is schema metadata and is not applied to the Scala var) — "" != "No Selection" is true, so isCategoryColumn = "True". The generated code then passes the empty column name to px.bar(color=...):

color=self.decode_python_template('') if True else None    # -> color=""  ->  px.bar(color="")

px.bar(color="") raises a KeyError/ValueError at runtime, so a bar chart with no category selected fails.

Expected: an unset/empty categoryColumn yields color=None (no category grouping).

How to reproduce?

A — user-facing: Add a Bar Chart operator, set only Value and Fields (leave the Category column unset), and run. The chart fails at runtime instead of rendering without a category.

B — confirmed against main's operator directly: construct BarChartOpDesc with value = "score", fields = "name", and categoryColumn left at its default (""), then call generatePythonCode(). The emitted call contains:

color=self.decode_python_template('') if True else None

i.e. isCategoryColumn is True for the empty column, so color is set to the empty-string column name → px.bar(color="").

Proposed fix: also guard against the empty value:

if (categoryColumn.nonEmpty && categoryColumn != "No Selection")
  isCategoryColumn = "True"

so an unset/empty categoryColumn yields color=None.

Version/Branch

1.3.0-incubating-SNAPSHOT (main)

Commit Hash (Optional)

No response

What browsers are you seeing the problem on?

No response

Relevant log output

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions