Skip to content

fix(amber): stop JSONL scan reading null as text - #8740

Open
CaroFernando wants to merge 2 commits into
apache:mainfrom
CaroFernando:fix/jsonl-null
Open

CaroFernando wants to merge 2 commits into
apache:mainfrom
CaroFernando:fix/jsonl-null

Conversation

@CaroFernando

@CaroFernando CaroFernando commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

When a JSONL file has a JSON null in a row, the JSONL File Scan reads it as
the literal text "null". That happens because JSONToMap writes every value
node into the map using asText(), and for NullNode that returns "null". One
null in a column then breaks schema inference: it can't parse "null" as a
number, so the column falls back to STRING and the cell shows the word null.

This PR makes JSONToMap keep the key of a NullNode but map it to a Scala null,
in both places it can show up: object fields and array elements in flatten
mode. Keeping the key matters for schema inference, which builds the column
list from the keys it sees in the sample: a key that is null on every sampled
row still becomes a column, so a later row's value for it is not lost. At
runtime the executor already reads a null value the same way as a missing key,
as an empty cell, and during schema inference the other rows decide the type.

So for the example in the issue:

{"a":1} {"a":null} used to give column a as STRING with values "1" and "null"
it now gives INTEGER with values 1 and an empty cell

The Python export of the JSONL source (#8704) copied the old behavior on
purpose: _texera_json_text turned a null into "null" so the exported script
matched the executor. It now returns None like the executor, and
texera_helpers/__init__.py is regenerated from it.

A column that is null on every sampled row is typed INTEGER, which is what
inferSchemaFromRows does for an all-null column, so a later text value in it is
skipped. That already happens in the CSV scan and is tracked in #8791; this PR
leaves it to that issue.

The two tests in JSONUtilsSpec that expected the string "null" were written
on purpose to pin the old behavior until a fix came along, so they are
updated here.

Any related issues, documentation, discussions?

Closes #8674
Related to #8791

How was this PR tested?

New tests:

  • JSONUtilsSpec: a null keeps its key with a null value, at top level, nested
    under flatten, and inside a flattened array.
  • JSONLScanSourceOpExecSpec: {"v":1} and {"v":null} give INTEGER with an
    empty cell; a key that is null on all 100 sampled lines keeps its column, and
    line 101's {"b":5} lands in it.
  • JSONLScanSourceOpDescSpec: the exported Python script reads a null as None
    for an INTEGER column and a STRING column, matching the executor.
TEXERA_HELPERS_WRITE=1 sbt "WorkflowOperator/testOnly org.apache.texera.amber.operator.StandaloneHelpersSpec"
sbt "WorkflowCore/testOnly org.apache.texera.amber.util.JSONUtilsSpec"
sbt "WorkflowOperator/testOnly org.apache.texera.amber.operator.source.scan.json.*"
sbt WorkflowCore/test
sbt WorkflowOperator/test
sbt "WorkflowCompilingService/testOnly org.apache.texera.amber.translator.* org.apache.texera.service.resource.WorkflowToPythonResourceSpec"
sbt scalafmtAll

WorkflowCore 891 passed; WorkflowOperator 3118 passed, 1 canceled (the
LargeBinary read, which needs an S3 endpoint); translator and
WorkflowToPythonResourceSpec 135 passed.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude

@Yicong-Huang Yicong-Huang added release/v1.3 back porting to release/v1.3 release/v1.2 back porting to release/v1.2 labels Sep 29, 2026
@github-actions
github-actions Bot requested review from mengw15 and xuang7 September 29, 2026 03:14
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Backport auto-label report

This fix: PR was checked against each actively-supported release branch. A release/* label nominates a backport target; the branch's release manager approving this PR is what sends the fix there. The required Backport Approvals check stays red until every label below is approved, so each manager either approves or removes their own label — which is why the labels left on a merged PR are exactly the branches it reached.

Release branch Analysis
🚫 release/v1.3 Label was removed earlier (opt-out); not re-added. Re-add it by hand if this fix should be backported here after all — the branch's release manager then has to approve before this PR can merge.
🚫 release/v1.2 Label was removed earlier (opt-out); not re-added. Re-add it by hand if this fix should be backported here after all — the branch's release manager then has to approve before this PR can merge.

Auto-label run.

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • Contributors with relevant context: @aglinxinyuan, @eugenegujing, @kz930
    You can notify them by mentioning @aglinxinyuan, @eugenegujing, @kz930 in a comment.

@codecov-commenter

codecov-commenter commented Sep 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.68%. Comparing base (cb1d619) to head (bfe10ff).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #8740   +/-   ##
=========================================
  Coverage     91.68%   91.68%           
- Complexity     5132     5134    +2     
=========================================
  Files          1305     1305           
  Lines         58229    58230    +1     
  Branches       7600     7601    +1     
=========================================
+ Hits          53385    53389    +4     
+ Misses         2937     2936    -1     
+ Partials       1907     1905    -2     
Flag Coverage Δ *Carryforward flag
access-control-service 77.44% <ø> (ø)
agent-service 99.56% <ø> (ø) Carriedforward from cb1d619
amber 85.78% <100.00%> (+0.01%) ⬆️
computing-unit-managing-service 63.83% <ø> (ø)
config-service 87.50% <ø> (ø)
file-service 82.16% <ø> (ø)
frontend 96.43% <ø> (ø) Carriedforward from cb1d619
notebook-migration-service 83.77% <ø> (ø)
pyamber 98.38% <ø> (ø) Carriedforward from cb1d619
result-service 86.48% <ø> (ø)
workflow-compiling-service 80.90% <ø> (ø)

*This pull request uses carry forward flags. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Benchmark changes need a look

🟢 2 better · 🔴 5 worse · ⚪ 8 noise (<±5%) · 0 without baseline

Compared against main cb1d619 benchmarked on this same runner, so the delta is largely free of cross-runner hardware noise. The "7d avg" column still reflects the gh-pages dashboard. Treat <±5% as noise unless repeated.

Dashboard · Run

config throughput MB/s latency max Δ latest / 7d
🔴 bs=10 sw=10 sl=64 579 0.354 17,079/23,351/23,351 us 🔴 +21.8% / 🔴 +64.6%
⚪ bs=100 sw=10 sl=64 1,282 0.782 76,744/93,917/93,917 us ⚪ within ±5% / 🟢 -11.6%
🔴 bs=1000 sw=10 sl=64 1,436 0.877 696,643/765,761/765,761 us 🔴 +5.1% / 🟢 -18.5%
Baseline details

Latest main cb1d619 from same runner

config metric PR latest main 7d avg Δ latest Δ 7d
bs=10 sw=10 sl=64 throughput 579 tuples/sec 616 tuples/sec 900.3 tuples/sec -6.0% -35.7%
bs=10 sw=10 sl=64 MB/s 0.354 MB/s 0.376 MB/s 0.549 MB/s -5.9% -35.6%
bs=10 sw=10 sl=64 p50 17,079 us 14,023 us 11,014 us +21.8% +55.1%
bs=10 sw=10 sl=64 p95 23,351 us 24,726 us 14,189 us -5.6% +64.6%
bs=10 sw=10 sl=64 p99 23,351 us 24,726 us 17,391 us -5.6% +34.3%
bs=100 sw=10 sl=64 throughput 1,282 tuples/sec 1,330 tuples/sec 1,187 tuples/sec -3.6% +8.0%
bs=100 sw=10 sl=64 MB/s 0.782 MB/s 0.812 MB/s 0.724 MB/s -3.7% +8.0%
bs=100 sw=10 sl=64 p50 76,744 us 76,179 us 86,789 us +0.7% -11.6%
bs=100 sw=10 sl=64 p95 93,917 us 90,213 us 94,657 us +4.1% -0.8%
bs=100 sw=10 sl=64 p99 93,917 us 90,213 us 104,753 us +4.1% -10.3%
bs=1000 sw=10 sl=64 throughput 1,436 tuples/sec 1,476 tuples/sec 1,219 tuples/sec -2.7% +17.8%
bs=1000 sw=10 sl=64 MB/s 0.877 MB/s 0.901 MB/s 0.744 MB/s -2.7% +17.9%
bs=1000 sw=10 sl=64 p50 696,643 us 675,255 us 846,616 us +3.2% -17.7%
bs=1000 sw=10 sl=64 p95 765,761 us 728,597 us 887,594 us +5.1% -13.7%
bs=1000 sw=10 sl=64 p99 765,761 us 728,597 us 940,017 us +5.1% -18.5%
Raw CSV
config_idx,batch_size,schema_width,string_len,num_batches,total_ms,total_tuples,total_bytes,tuples_per_sec,mb_per_sec,lat_p50_us,lat_p95_us,lat_p99_us
0,10,10,64,20,345.29,200,128000,579,0.354,17078.55,23350.90,23350.90
1,100,10,64,20,1560.11,2000,1280000,1282,0.782,76743.97,93917.42,93917.42
2,1000,10,64,20,13925.47,20000,12800000,1436,0.877,696643.04,765760.95,765760.95

renovate-bot pushed a commit to renovate-bot/apache-_-texera that referenced this pull request Nov 5, 2026
…ython (apache#8704)

### What changes were proposed in this PR?

The JSON Lines and Arrow sources implement `StandaloneCodeGenerator`, so
an exported script starts from the same data the workflow did.

Arrow is read into pandas' nullable dtypes rather than its numpy ones.
Arrow says of every value whether it is there, and a numpy column has
nowhere to put that: a missing double and a stored NaN both land on NaN,
and a missing integer costs the column its integer type. The engine
reads the file's own answer, so a set operation keeps a NaN row a null
row does not match, a holed integer column is still made of integers,
and a long past 2^53 is not rounded on its way through a float. The
other sources state the types they need one at a time, their formats
having no way to say it once.

A file also states the width and the sign of each of its numbers, and
Texera has no column narrower than a double or a 32-bit integer. A
single-precision or 16-bit column was arriving null, the parse having no
case for the Float and Short those vectors hand back, and an unsigned
one arrived as the -1 its storage counts down to. Each now reads as the
Texera type that holds it, an unsigned 32-bit column as a long and an
unsigned 64-bit one refused for want of a wider one, and the script
normalizes the same widths so a later sum comes to the same number on
both sides. This is the rule the Parquet source already follows. The end
of an exported Arrow window is counted in Long, as the CSV readers count
theirs.

A timestamp is read as the engine reads one. The engine hands each field
to DateParserUtils, so a row states its own format, any year reads, an
offset is moved to the local zone, and the reading is cut to the
millisecond. pandas' date parsing does none of that. So JSONL reads the
column as text and converts it with the helper apache#8597 adds.

This PR also changes the engine. `ArrowUtils` handed a TIMESTAMP column
to a Python worker as an Arrow millisecond timestamp labelled UTC. A
Python operator saw an aware datetime cut to the millisecond, and a year
past 2262 overflowed. It is now a zoneless microsecond timestamp. That
is what Texera's own Python side declares for a TIMESTAMP
(`pa.timestamp("us")`), and what an exported script holds. Two things a
user can see change. A Python UDF now receives a naive datetime instead
of one in UTC. A result downloaded as an Arrow file now carries a
zoneless microsecond timestamp column instead of a UTC millisecond one.
A TIMESTAMP parameter a Python UDF declares is now parsed the same way,
as a naive wall clock with any offset moved to the machine's zone, so it
compares with a row's instead of raising.

### Any related issues, documentation, discussions?

Part of apache#8325, step 12b; that issue lists the set in order. It uses
apache#8341's shared source code and apache#8597's timestamp helpers.

Its JSON Lines export reads a JSON `null` as the text `"null"`, as the
engine does today (apache#8674). If apache#8740 merges first, that part changes to
read a null before this one merges.

Closes apache#8702, the task this change is the whole of.

It also finishes apache#8602, where a scan window of no rows left the type
inference nothing to read and JSONL declared a schema of no columns.
apache#8341 fixes the CSV half.

Closes apache#8602.

### How was this PR tested?

Each operator asserts the block it emits in its own spec, and the Arrow
spec runs the engine's own executor and the generated script over the
same file. The engine change is covered in both ArrowUtilsSpec files,
which include a round trip on either side of the nanosecond range, and
in the Python tests of the timestamp parser. Once the verification
lands, every operator is also run both ways on every configuration its
schema offers; this branch is cut from main and does not carry that
machinery, so those runs are not on this diff's CI.

Arrow is the one worth calling out. Its column of timestamps only
matches once apache#7672 is in: before that the engine read the file's numbers
through the JVM's zone while `pd.read_feather` read the wall clock the
file states, and the two differed by whatever the machine was set to.
That change has since landed.

### Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Opus 5)

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
@mengw15 mengw15 removed the release/v1.3 back porting to release/v1.3 label Nov 9, 2026
@xuang7

xuang7 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Removing release/v1.2: cleaning the nulls in the source file works around it.

@xuang7 xuang7 removed the release/v1.2 back porting to release/v1.2 label Nov 16, 2026
@kz930

kz930 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Looks right to me, and the JSONL scan is the only caller. One case gets worse: a key that is null in all 100 sampled rows now drops out of the schema, so a later {"b": 5} is lost without a warning, where before it was kept as STRING. Keeping the key with a null value (result(absoluteKey) = if (child.isNull) null else child.asText()) keeps the column and still gives an empty cell; I checked both with a 101-line file.

@kz930

kz930 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

@CaroFernando could you take a look at the null-key suggestion above?

JSONUtils.JSONToMap turned a JSON null into the literal string
"null" (NullNode.asText()), so one null widened the whole column
to STRING during schema inference and the cell held the text null.

Nulls now produce no map entry, so the JSONL scan operator treats
them as missing values: schema inference stays numeric and the
cell is empty.

Closes apache#8674
Dropping a null's key lost the column when a key was null on every
sampled row, so a later row's value for it was gone. JSONToMap now
keeps the key and maps it to null, which the scan reads as an empty
cell the same way it reads a missing key.

The Python export of the JSONL source copied the old "null" text, so
_texera_json_text now returns None for a null as well, and
texera_helpers/__init__.py is regenerated from it.
@CaroFernando

Copy link
Copy Markdown
Contributor Author

@kz930 Thanks for catching this. A null now keeps its key with a null value, so the column survives; your 101-line case is now a test. I also rebased onto main and made the Python export (#8704) read a null as None to match.

An all-null sampled column is still typed INTEGER. That comes from inferSchemaFromRows and already affects the CSV scan, which is tracked in #8791.

@kz930

kz930 commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Thanks, I checked the change and the null case now works for me. @mengw15 @xuang7 could you take a look when you have time?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSONL File Scan reads a JSON null as the text "null"

6 participants