Skip to content

Conversation

@norberttech
Copy link
Member

@norberttech norberttech commented Apr 5, 2025

Change Log

Added

  • ScalarFunctionResult
  • bcmath extension with polyfill

Fixed

  • Merging float definitions with different precisions
  • Merging floats and integer to use float precision
  • Merging lists/maps of floats to use higher precision

Changed

  • Float type toString now display precision

Removed

  • TypeScalarFunctionInterface

Deprecated

Security


Description

In general all ScalarFunctions can return any value mixed. This means that the result of scalar function needs to go through EntryFactory in order to create an entry.

Scalar functions can take their values from:

  • reference - value is going to be taken from entry (we do have access to type)
  • literal - we don't have access to type, just value
  • scalar function - the value is a result of evaluation of another scalar function - we dont have access to type

This means that functions like plus/minus/divide/multiply/mod will always return some float|integer and they wont keep the precision/scale of the input float (if the input was an entry).

In order to fix that, scalar functions can now also return ScalarResult(mixed $value, Type $type) which is pretty much just a wrapper around the value.

This approach is way more flexible that TypedScalarFunction since some return types are dynamic and depends on input arguments, for example ref('id')->cast(type_int()).

The return type of cast depends on the argument.

So now when ScalarResult is returned function can pass over more data, like for example type taken from the input.

But since not all values must come from a entry, all math functions received another argument ScalarFunction|int $scale = 0 which can be used to specify how precise that operation needs to be. Under the hood, scale is passed to the instance of Calculator.

@norberttech norberttech linked an issue Apr 5, 2025 that may be closed by this pull request
@github-actions
Copy link
Contributor

github-actions bot commented Apr 5, 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.883mb +1.48%  | 611.149ms -5.71% | ±0.40% -3.12%   |
| JsonExtractorBench    | bench_extract_10k | 1    | 3   | 4.957mb +1.46%  | 1.140s +0.48%    | ±0.53% -47.49%  |
| ParquetExtractorBench | bench_extract_10k | 1    | 3   | 86.470mb +0.02% | 917.708ms -0.28% | ±0.27% -71.72%  |
| TextExtractorBench    | bench_extract_10k | 1    | 3   | 4.606mb +0.15%  | 38.654ms -1.06%  | ±0.91% +9.37%   |
| XmlExtractorBench     | bench_extract_10k | 1    | 3   | 4.581mb +0.13%  | 605.292ms +0.15% | ±1.07% +167.52% |
+-----------------------+-------------------+------+-----+-----------------+------------------+-----------------+
Transformers
+-----------------------------+--------------------------+------+-----+------------------+-----------------+----------------+
| benchmark                   | subject                  | revs | its | mem_peak         | mode            | rstdev         |
+-----------------------------+--------------------------+------+-----+------------------+-----------------+----------------+
| RenameEntryTransformerBench | bench_transform_10k_rows | 1    | 3   | 127.405mb +0.00% | 68.963ms -4.94% | ±0.90% +13.50% |
+-----------------------------+--------------------------+------+-----+------------------+-----------------+----------------+
Loaders
+--------------------+----------------+------+-----+------------------+------------------+-----------------+
| benchmark          | subject        | revs | its | mem_peak         | mode             | rstdev          |
+--------------------+----------------+------+-----+------------------+------------------+-----------------+
| CSVLoaderBench     | bench_load_10k | 1    | 3   | 64.050mb +0.01%  | 101.610ms -4.57% | ±1.05% +153.38% |
| JsonLoaderBench    | bench_load_10k | 1    | 3   | 84.432mb +0.20%  | 98.049ms -2.96%  | ±0.57% -29.14%  |
| ParquetLoaderBench | bench_load_10k | 1    | 3   | 161.284mb +0.01% | 20.982s -2.01%   | ±0.34% -30.79%  |
| TextLoaderBench    | bench_load_10k | 1    | 3   | 18.138mb +0.04%  | 31.429ms -0.90%  | ±1.20% +13.69%  |
+--------------------+----------------+------+-----+------------------+------------------+-----------------+
Building Blocks
+-------------------+----------------------------+------+-----+------------------+------------------+-----------------+
| benchmark         | subject                    | revs | its | mem_peak         | mode             | rstdev          |
+-------------------+----------------------------+------+-----+------------------+------------------+-----------------+
| TypeDetectorBench | bench_type_detector        | 1    | 3   | 43.920mb +0.02%  | 374.932ms +2.31% | ±0.34% -2.64%   |
| TypeDetectorBench | bench_type_detector        | 1    | 3   | 11.730mb +0.06%  | 75.612ms +2.15%  | ±0.79% +12.10%  |
| EntryFactoryBench | bench_entry_factory        | 1    | 3   | 106.034mb +0.01% | 540.050ms +0.84% | ±1.57% +178.20% |
| EntryFactoryBench | bench_entry_factory        | 1    | 3   | 55.224mb +0.01%  | 267.383ms +0.32% | ±1.04% +19.08%  |
| EntryFactoryBench | bench_entry_factory        | 1    | 3   | 14.746mb +0.05%  | 58.779ms +0.35%  | ±1.46% +63.98%  |
| RowsBench         | bench_chunk_10_on_10k      | 2    | 3   | 97.067mb +0.01%  | 3.799ms -7.45%   | ±2.22% -8.65%   |
| RowsBench         | bench_diff_left_1k_on_10k  | 2    | 3   | 114.423mb +0.01% | 187.674ms +0.93% | ±0.31% -72.57%  |
| RowsBench         | bench_diff_right_1k_on_10k | 2    | 3   | 97.143mb +0.01%  | 19.064ms +0.41%  | ±0.54% -31.93%  |
| RowsBench         | bench_drop_1k_on_10k       | 2    | 3   | 97.942mb +0.01%  | 1.796ms -8.55%   | ±1.59% -50.84%  |
| RowsBench         | bench_drop_right_1k_on_10k | 2    | 3   | 97.942mb +0.01%  | 1.922ms -23.26%  | ±1.57% -50.82%  |
| RowsBench         | bench_entries_on_10k       | 2    | 3   | 96.103mb +0.01%  | 5.572ms -4.79%   | ±0.90% -59.17%  |
| RowsBench         | bench_filter_on_10k        | 2    | 3   | 96.632mb +0.01%  | 16.398ms -8.92%  | ±0.26% -92.13%  |
| RowsBench         | bench_find_on_10k          | 2    | 3   | 96.632mb +0.01%  | 16.680ms -4.71%  | ±1.50% +36.20%  |
| RowsBench         | bench_find_one_on_10k      | 10   | 3   | 95.323mb +0.01%  | 1.806μs -9.70%   | ±2.57% +0.00%   |
| RowsBench         | bench_first_on_10k         | 10   | 3   | 95.323mb +0.01%  | 0.500μs 0.00%    | ±0.00% 0.00%    |
| RowsBench         | bench_flat_map_on_1k       | 2    | 3   | 104.541mb +0.01% | 16.530ms -2.87%  | ±3.28% +137.14% |
| RowsBench         | bench_map_on_10k           | 2    | 3   | 134.608mb +0.00% | 75.053ms -5.16%  | ±1.73% +43.85%  |
| RowsBench         | bench_merge_1k_on_10k      | 2    | 3   | 97.151mb +0.01%  | 1.964ms -6.58%   | ±0.94% -73.03%  |
| RowsBench         | bench_partition_by_on_10k  | 2    | 3   | 100.522mb +0.01% | 63.558ms -3.71%  | ±0.98% +194.10% |
| RowsBench         | bench_remove_on_10k        | 2    | 3   | 98.204mb +0.01%  | 4.202ms -6.95%   | ±2.88% +28.38%  |
| RowsBench         | bench_sort_asc_on_1k       | 2    | 3   | 95.685mb +0.01%  | 42.446ms +0.23%  | ±1.09% -43.15%  |
| RowsBench         | bench_sort_by_on_1k        | 2    | 3   | 95.685mb +0.01%  | 41.680ms -5.58%  | ±1.05% -29.42%  |
| RowsBench         | bench_sort_desc_on_1k      | 2    | 3   | 95.685mb +0.01%  | 42.788ms -3.29%  | ±1.71% -13.43%  |
| RowsBench         | bench_sort_entries_on_1k   | 2    | 3   | 97.763mb +0.01%  | 8.236ms -0.02%   | ±0.88% -21.61%  |
| RowsBench         | bench_sort_on_1k           | 2    | 3   | 95.513mb +0.01%  | 29.987ms -1.27%  | ±0.40% -82.44%  |
| RowsBench         | bench_take_1k_on_10k       | 10   | 3   | 95.323mb +0.01%  | 14.833μs -23.87% | ±2.75% -2.86%   |
| RowsBench         | bench_take_right_1k_on_10k | 10   | 3   | 95.323mb +0.01%  | 15.983μs -29.48% | ±1.34% -35.17%  |
| RowsBench         | bench_unique_on_1k         | 2    | 3   | 114.424mb +0.01% | 188.778ms +0.08% | ±0.48% -46.38%  |
+-------------------+----------------------------+------+-----+------------------+------------------+-----------------+

@codecov
Copy link

codecov bot commented Apr 5, 2025

Codecov Report

Attention: Patch coverage is 92.08861% with 25 lines in your changes missing coverage. Please review.

Project coverage is 83.26%. Comparing base (384e702) to head (8519165).
Report is 2 commits behind head on 1.x.

✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##              1.x    #1577      +/-   ##
==========================================
+ Coverage   83.13%   83.26%   +0.13%     
==========================================
  Files         695      702       +7     
  Lines       18898    19012     +114     
==========================================
+ Hits        15710    15831     +121     
+ Misses       3188     3181       -7     
Components Coverage Δ
etl 86.47% <92.08%> (+0.29%) ⬆️
cli 84.59% <ø> (ø)
lib-array-dot 94.53% <ø> (ø)
lib-azure-sdk 62.56% <ø> (ø)
lib-doctrine-dbal-bulk 90.11% <ø> (ø)
lib-filesystem 78.02% <ø> (ø)
lib-parquet 84.36% <ø> (ø)
lib-parquet-viewer 82.02% <ø> (ø)
lib-snappy 90.69% <ø> (-0.47%) ⬇️
bridge-filesystem-async-aws 90.38% <ø> (ø)
bridge-filesystem-azure 89.92% <ø> (ø)
bridge-monolog-http 96.38% <ø> (ø)
symfony-http-foundation 74.41% <ø> (ø)
adapter-chartjs 86.45% <ø> (ø)
adapter-csv 89.57% <ø> (ø)
adapter-doctrine 89.14% <ø> (ø)
adapter-elasticsearch 97.19% <ø> (ø)
adapter-google-sheet 78.04% <ø> (ø)
adapter-http 59.15% <ø> (ø)
adapter-json 90.62% <ø> (ø)
adapter-logger 53.84% <ø> (ø)
adapter-meilisearch 97.75% <ø> (ø)
adapter-parquet 80.85% <ø> (ø)
adapter-text 84.44% <ø> (ø)
adapter-xml 83.15% <ø> (ø)
🚀 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 added size: XL and removed size: S labels Apr 5, 2025
@norberttech norberttech merged commit adf9044 into 1.x Apr 6, 2025
35 of 37 checks passed
@norberttech norberttech deleted the 1576-handling-floats branch April 6, 2025 17:58
$scale = 6;
}

var_dump(\json_encode(['scale' => $scale, 'left_scale' => $leftScale, 'right_scale' => $rightScale, 'left_value' => $leftValue, 'right_value' => $rightValue]));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug left in

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

haha it happens to me way too often! Going to add that extension now 🤣

Thats why I release on a schedule, to give myself time to fix those kind of mistakes 🙈

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.

Handling Floats

3 participants