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

Restored original behavior of DOMElementValue function combined with XPath #1220

Conversation

norberttech
Copy link
Member

Change Log

Added

Fixed

  • DOMElementValue behavior when used on a XPath scalar function result
  • DOMElementAttributeValue behavior when used on a XPath scalar function result

Changed

Removed

Deprecated

Security


Description

Long story short this PR is a fix for a bug I introduced when I changed the result of XPath.
In general XPath should always return an array, and it used to return single node when it array had one element.
Since DOMElementValue and DOMElementAttributeValue expects DOMElement it would require to add some kind of ->first() function on xpath results.
Instead, DOMElementValue and DOMElementAttributeValue will now try to check if value is an array of DOMElement's and take the first one when available which restores the original behavior.

Copy link
Contributor

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.540mb +0.02%  | 507.915ms -0.16% | ±0.36% -42.70% |
| JsonExtractorBench    | bench_extract_10k | 1    | 3   | 4.654mb +0.02%  | 1.077s -1.07%    | ±1.72% +82.52% |
| ParquetExtractorBench | bench_extract_10k | 1    | 3   | 29.111mb +0.00% | 432.388ms -0.81% | ±0.43% -40.76% |
| TextExtractorBench    | bench_extract_10k | 1    | 3   | 4.296mb +0.02%  | 33.517ms +0.58%  | ±1.06% +60.70% |
| XmlExtractorBench     | bench_extract_10k | 1    | 3   | 4.286mb +0.02%  | 760.727ms +2.01% | ±3.03% +93.17% |
+-----------------------+-------------------+------+-----+-----------------+------------------+----------------+
Transformers
+-----------------------------+--------------------------+------+-----+------------------+-----------------+-----------------+
| benchmark                   | subject                  | revs | its | mem_peak         | mode            | rstdev          |
+-----------------------------+--------------------------+------+-----+------------------+-----------------+-----------------+
| RenameEntryTransformerBench | bench_transform_10k_rows | 1    | 3   | 116.572mb +0.00% | 59.516ms +0.22% | ±0.98% +131.67% |
+-----------------------------+--------------------------+------+-----+------------------+-----------------+-----------------+
Loaders
+--------------------+----------------+------+-----+------------------+------------------+-----------------+
| benchmark          | subject        | revs | its | mem_peak         | mode             | rstdev          |
+--------------------+----------------+------+-----+------------------+------------------+-----------------+
| CSVLoaderBench     | bench_load_10k | 1    | 3   | 54.737mb +0.00%  | 140.497ms +0.38% | ±1.21% +221.50% |
| JsonLoaderBench    | bench_load_10k | 1    | 3   | 90.347mb +0.00%  | 116.703ms -1.52% | ±0.97% -41.06%  |
| ParquetLoaderBench | bench_load_10k | 1    | 3   | 124.465mb +0.00% | 1.228s +0.11%    | ±0.18% -89.43%  |
| TextLoaderBench    | bench_load_10k | 1    | 3   | 17.487mb +0.00%  | 44.574ms +0.08%  | ±0.05% -97.82%  |
+--------------------+----------------+------+-----+------------------+------------------+-----------------+
Building Blocks
+-------------------------+----------------------------+------+-----+------------------+------------------+-----------------+
| benchmark               | subject                    | revs | its | mem_peak         | mode             | rstdev          |
+-------------------------+----------------------------+------+-----+------------------+------------------+-----------------+
| NativeEntryFactoryBench | bench_entry_factory        | 1    | 3   | 107.415mb +0.00% | 472.540ms +1.39% | ±0.22% -85.83%  |
| NativeEntryFactoryBench | bench_entry_factory        | 1    | 3   | 55.773mb +0.00%  | 233.858ms -7.33% | ±1.16% -54.02%  |
| NativeEntryFactoryBench | bench_entry_factory        | 1    | 3   | 14.612mb +0.01%  | 51.455ms +1.29%  | ±0.71% -21.95%  |
| RowsBench               | bench_chunk_10_on_10k      | 2    | 3   | 87.329mb +0.00%  | 3.797ms +14.48%  | ±1.41% +13.84%  |
| RowsBench               | bench_diff_left_1k_on_10k  | 2    | 3   | 102.933mb +0.00% | 185.703ms -3.48% | ±0.96% -33.06%  |
| RowsBench               | bench_diff_right_1k_on_10k | 2    | 3   | 85.653mb +0.00%  | 18.751ms -0.19%  | ±0.84% +31.15%  |
| RowsBench               | bench_drop_1k_on_10k       | 2    | 3   | 88.569mb +0.00%  | 2.097ms +22.72%  | ±3.03% +227.82% |
| RowsBench               | bench_drop_right_1k_on_10k | 2    | 3   | 88.569mb +0.00%  | 1.793ms +2.80%   | ±1.71% -9.69%   |
| RowsBench               | bench_entries_on_10k       | 2    | 3   | 85.681mb +0.00%  | 2.909ms +1.68%   | ±0.70% -51.03%  |
| RowsBench               | bench_filter_on_10k        | 2    | 3   | 86.210mb +0.00%  | 16.602ms -5.04%  | ±2.67% +3.36%   |
| RowsBench               | bench_find_on_10k          | 2    | 3   | 86.210mb +0.00%  | 16.446ms -6.48%  | ±1.32% -25.44%  |
| RowsBench               | bench_find_one_on_10k      | 10   | 3   | 84.113mb +0.00%  | 1.900μs +18.30%  | ±0.00% -100.00% |
| RowsBench               | bench_first_on_10k         | 10   | 3   | 84.113mb +0.00%  | 0.400μs +33.33%  | ±0.00% +0.00%   |
| RowsBench               | bench_flat_map_on_1k       | 2    | 3   | 93.464mb +0.00%  | 12.614ms -2.80%  | ±3.33% +554.12% |
| RowsBench               | bench_map_on_10k           | 2    | 3   | 122.835mb +0.00% | 62.736ms +2.08%  | ±0.48% -2.93%   |
| RowsBench               | bench_merge_1k_on_10k      | 2    | 3   | 86.729mb +0.00%  | 1.364ms -22.29%  | ±0.39% -49.31%  |
| RowsBench               | bench_partition_by_on_10k  | 2    | 3   | 90.085mb +0.00%  | 60.052ms -0.29%  | ±0.94% -50.51%  |
| RowsBench               | bench_remove_on_10k        | 2    | 3   | 88.831mb +0.00%  | 4.314ms -0.67%   | ±2.69% +19.03%  |
| RowsBench               | bench_sort_asc_on_1k       | 2    | 3   | 84.263mb +0.00%  | 39.696ms -4.07%  | ±1.59% +133.86% |
| RowsBench               | bench_sort_by_on_1k        | 2    | 3   | 84.264mb +0.00%  | 39.120ms -1.92%  | ±0.51% -20.56%  |
| RowsBench               | bench_sort_desc_on_1k      | 2    | 3   | 84.263mb +0.00%  | 39.004ms -0.82%  | ±0.43% -72.87%  |
| RowsBench               | bench_sort_entries_on_1k   | 2    | 3   | 86.555mb +0.00%  | 7.474ms +2.91%   | ±0.30% -31.58%  |
| RowsBench               | bench_sort_on_1k           | 2    | 3   | 84.113mb +0.00%  | 28.804ms +0.52%  | ±0.35% -45.94%  |
| RowsBench               | bench_take_1k_on_10k       | 10   | 3   | 84.113mb +0.00%  | 13.312μs -0.06%  | ±0.71% -24.97%  |
| RowsBench               | bench_take_right_1k_on_10k | 10   | 3   | 84.113mb +0.00%  | 15.900μs -0.99%  | ±0.51% -66.72%  |
| RowsBench               | bench_unique_on_1k         | 2    | 3   | 102.934mb +0.00% | 188.969ms -0.62% | ±0.72% +6.35%   |
| TypeDetectorBench       | bench_type_detector        | 1    | 3   | 53.218mb +0.00%  | 385.598ms -0.70% | ±1.46% +47.77%  |
| TypeDetectorBench       | bench_type_detector        | 1    | 3   | 13.484mb +0.01%  | 80.459ms +2.95%  | ±2.96% +333.94% |
+-------------------------+----------------------------+------+-----+------------------+------------------+-----------------+

@norberttech norberttech merged commit 9c0f8a5 into flow-php:1.x Sep 12, 2024
26 checks passed
@norberttech norberttech deleted the 1214-xpath-returning-array-broke-domelementvalue-function branch December 5, 2024 20:18
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.

1 participant