Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix double encoding of json #1482

Merged
merged 2 commits into from
Feb 17, 2025

Conversation

jmortlock
Copy link
Contributor

@jmortlock jmortlock commented Feb 15, 2025

Change Log

Added

Fixed

  • JSON was being double encoded.

Changed

Removed

Deprecated

Security


Description

I was looking at replacing ArrayEntry with JsonEntry and hit this issue with the JSON serialisation in which it would double encode the JSON result (once in the normaliser, than once more in the loader)

Copy link
Contributor

github-actions bot commented Feb 15, 2025

Flow PHP - Benchmarks

Results of the benchmarks from this PR are compared with the results from 1.x branch.

Extractors
+-----------------------+-------------------+------+-----+-----------------+------------------+-----------------+
| benchmark             | subject           | revs | its | mem_peak        | mode             | rstdev          |
+-----------------------+-------------------+------+-----+-----------------+------------------+-----------------+
| CSVExtractorBench     | bench_extract_10k | 1    | 3   | 4.801mb +0.01%  | 553.020ms +0.47% | ±0.26% -1.09%   |
| JsonExtractorBench    | bench_extract_10k | 1    | 3   | 4.874mb +0.01%  | 1.067s -0.32%    | ±0.44% -41.86%  |
| ParquetExtractorBench | bench_extract_10k | 1    | 3   | 86.319mb +0.00% | 897.734ms -0.03% | ±1.17% +152.07% |
| TextExtractorBench    | bench_extract_10k | 1    | 3   | 4.531mb +0.01%  | 35.728ms -1.80%  | ±0.60% -43.09%  |
| XmlExtractorBench     | bench_extract_10k | 1    | 3   | 4.505mb +0.01%  | 606.794ms +1.40% | ±0.60% -65.49%  |
+-----------------------+-------------------+------+-----+-----------------+------------------+-----------------+
Transformers
+-----------------------------+--------------------------+------+-----+------------------+-----------------+---------------+
| benchmark                   | subject                  | revs | its | mem_peak         | mode            | rstdev        |
+-----------------------------+--------------------------+------+-----+------------------+-----------------+---------------+
| RenameEntryTransformerBench | bench_transform_10k_rows | 1    | 3   | 127.327mb +0.00% | 69.252ms -0.21% | ±0.49% +4.69% |
+-----------------------------+--------------------------+------+-----+------------------+-----------------+---------------+
Loaders
+--------------------+----------------+------+-----+------------------+------------------+------------------+
| benchmark          | subject        | revs | its | mem_peak         | mode             | rstdev           |
+--------------------+----------------+------+-----+------------------+------------------+------------------+
| CSVLoaderBench     | bench_load_10k | 1    | 3   | 64.000mb +0.00%  | 102.795ms -0.75% | ±2.80% +20.46%   |
| JsonLoaderBench    | bench_load_10k | 1    | 3   | 84.347mb +0.00%  | 96.848ms -0.42%  | ±0.40% -7.78%    |
| ParquetLoaderBench | bench_load_10k | 1    | 3   | 161.190mb +0.00% | 20.528s -0.23%   | ±0.18% -48.43%   |
| TextLoaderBench    | bench_load_10k | 1    | 3   | 17.997mb +0.00%  | 30.347ms -2.85%  | ±0.94% +1097.00% |
+--------------------+----------------+------+-----+------------------+------------------+------------------+
Building Blocks
+-------------------+----------------------------+------+-----+------------------+------------------+-----------------+
| benchmark         | subject                    | revs | its | mem_peak         | mode             | rstdev          |
+-------------------+----------------------------+------+-----+------------------+------------------+-----------------+
| EntryFactoryBench | bench_entry_factory        | 1    | 3   | 105.970mb +0.00% | 459.635ms +1.50% | ±1.22% +161.92% |
| EntryFactoryBench | bench_entry_factory        | 1    | 3   | 55.161mb +0.00%  | 230.718ms -0.55% | ±1.04% +398.60% |
| EntryFactoryBench | bench_entry_factory        | 1    | 3   | 14.683mb +0.00%  | 51.637ms +4.41%  | ±0.68% -67.27%  |
| TypeDetectorBench | bench_type_detector        | 1    | 3   | 43.805mb +0.00%  | 369.644ms +2.41% | ±1.62% +169.99% |
| TypeDetectorBench | bench_type_detector        | 1    | 3   | 11.615mb +0.00%  | 73.528ms +0.28%  | ±1.59% +61.16%  |
| RowsBench         | bench_chunk_10_on_10k      | 2    | 3   | 97.014mb +0.00%  | 3.517ms -7.36%   | ±2.48% -30.05%  |
| RowsBench         | bench_diff_left_1k_on_10k  | 2    | 3   | 114.299mb +0.00% | 190.467ms +2.28% | ±0.86% +175.22% |
| RowsBench         | bench_diff_right_1k_on_10k | 2    | 3   | 97.019mb +0.00%  | 19.062ms -0.33%  | ±0.98% -25.37%  |
| RowsBench         | bench_drop_1k_on_10k       | 2    | 3   | 97.888mb +0.00%  | 1.485ms +3.88%   | ±2.01% -42.08%  |
| RowsBench         | bench_drop_right_1k_on_10k | 2    | 3   | 97.888mb +0.00%  | 1.886ms +19.08%  | ±3.11% +72.39%  |
| RowsBench         | bench_entries_on_10k       | 2    | 3   | 96.049mb +0.00%  | 4.351ms -3.55%   | ±3.36% +274.97% |
| RowsBench         | bench_filter_on_10k        | 2    | 3   | 96.578mb +0.00%  | 16.462ms +0.03%  | ±1.02% -37.77%  |
| RowsBench         | bench_find_on_10k          | 2    | 3   | 96.578mb +0.00%  | 16.628ms +1.22%  | ±0.60% -61.60%  |
| RowsBench         | bench_find_one_on_10k      | 10   | 3   | 95.269mb +0.00%  | 1.794μs -5.88%   | ±2.67% +9.43%   |
| RowsBench         | bench_first_on_10k         | 10   | 3   | 95.269mb +0.00%  | 0.400μs 0.00%    | ±0.00% 0.00%    |
| RowsBench         | bench_flat_map_on_1k       | 2    | 3   | 104.487mb +0.00% | 14.461ms -1.20%  | ±0.03% -98.21%  |
| RowsBench         | bench_map_on_10k           | 2    | 3   | 134.555mb +0.00% | 70.347ms -2.83%  | ±1.64% +223.93% |
| RowsBench         | bench_merge_1k_on_10k      | 2    | 3   | 97.098mb +0.00%  | 1.274ms -1.84%   | ±1.39% -55.62%  |
| RowsBench         | bench_partition_by_on_10k  | 2    | 3   | 100.399mb +0.00% | 62.904ms -3.38%  | ±1.77% +152.67% |
| RowsBench         | bench_remove_on_10k        | 2    | 3   | 98.150mb +0.00%  | 3.731ms -2.45%   | ±1.67% -53.83%  |
| RowsBench         | bench_sort_asc_on_1k       | 2    | 3   | 95.561mb +0.00%  | 42.076ms -2.50%  | ±0.60% +37.20%  |
| RowsBench         | bench_sort_by_on_1k        | 2    | 3   | 95.561mb +0.00%  | 42.639ms -3.58%  | ±0.44% -67.39%  |
| RowsBench         | bench_sort_desc_on_1k      | 2    | 3   | 95.561mb +0.00%  | 42.707ms -2.67%  | ±0.27% -48.09%  |
| RowsBench         | bench_sort_entries_on_1k   | 2    | 3   | 97.710mb +0.00%  | 8.279ms +0.80%   | ±0.93% -23.28%  |
| RowsBench         | bench_sort_on_1k           | 2    | 3   | 95.460mb +0.00%  | 29.253ms +0.03%  | ±0.44% -63.09%  |
| RowsBench         | bench_take_1k_on_10k       | 10   | 3   | 95.269mb +0.00%  | 13.083μs -1.29%  | ±1.64% -51.48%  |
| RowsBench         | bench_take_right_1k_on_10k | 10   | 3   | 95.269mb +0.00%  | 15.404μs -4.02%  | ±2.58% -32.88%  |
| RowsBench         | bench_unique_on_1k         | 2    | 3   | 114.300mb +0.00% | 192.249ms +1.81% | ±0.45% +46.84%  |
+-------------------+----------------------------+------+-----+------------------+------------------+-----------------+

Copy link

codecov bot commented Feb 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.08%. Comparing base (f978f9e) to head (66ac51c).
Report is 2 commits behind head on 1.x.

Additional details and impacted files
@@           Coverage Diff           @@
##              1.x    #1482   +/-   ##
=======================================
  Coverage   83.08%   83.08%           
=======================================
  Files         666      666           
  Lines       17899    17899           
=======================================
  Hits        14871    14871           
  Misses       3028     3028           
Components Coverage Δ
etl 85.84% <ø> (ø)
cli 86.73% <ø> (ø)
lib-array-dot 94.53% <ø> (ø)
lib-azure-sdk 62.56% <ø> (ø)
lib-doctrine-dbal-bulk 97.43% <ø> (ø)
lib-filesystem 76.75% <ø> (ø)
lib-parquet 84.33% <ø> (ø)
lib-parquet-viewer 82.02% <ø> (ø)
lib-rdsl 87.09% <ø> (ø)
lib-snappy 90.69% <ø> (ø)
bridge-filesystem-async-aws 90.38% <ø> (ø)
bridge-filesystem-azure 89.92% <ø> (ø)
bridge-monolog-http 96.38% <ø> (ø)
symfony-http-foundation 77.10% <ø> (ø)
adapter-chartjs 86.45% <ø> (ø)
adapter-csv 89.57% <ø> (ø)
adapter-doctrine 88.68% <ø> (ø)
adapter-elasticsearch 97.19% <ø> (ø)
adapter-google-sheet 78.04% <ø> (ø)
adapter-http 59.15% <ø> (ø)
adapter-json 90.62% <100.00%> (ø)
adapter-logger 53.84% <ø> (ø)
adapter-meilisearch 97.75% <ø> (ø)
adapter-parquet 80.85% <ø> (ø)
adapter-text 84.44% <ø> (ø)
adapter-xml 83.15% <ø> (ø)

@stloyd
Copy link
Member

stloyd commented Feb 15, 2025

I would say that this is tricky, cause you may want to double encode json inside json in some edge cases as well.

@jmortlock
Copy link
Contributor Author

Then ArrayEntry still has a place?

What are the scenarios where we need to double encode? You could just use a string type in that case?

@norberttech
Copy link
Member

Then ArrayEntry still has a place?

No, array entry was entirely removed and it's not coming back, JsonEntry holds an array under the hood.

I don't see any good reason to keep double encoding, this behavior is a leftover, but I might be missing something

@stloyd you have any specific scenarios in your head?

@norberttech norberttech merged commit 2b3e452 into flow-php:1.x Feb 17, 2025
21 checks passed
@norberttech
Copy link
Member

I merged it for now as I don't yet see how double encoding can be useful, but feel free to ping me if you can think about anything, we can still revert that change or parametrize it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants