-
-
Notifications
You must be signed in to change notification settings - Fork 48
Fixed reading multine strings in CSV files #1740
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
Conversation
Flow PHP - BenchmarksResults 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.828mb +0.36% | 443.738ms +1.96% | ±0.75% +2937.01% |
| ExcelExtractorBench | bench_extract_10k_ods | 1 | 3 | 65.540mb +0.00% | 1.050s -0.88% | ±0.77% -20.53% |
| ExcelExtractorBench | bench_extract_10k_xlsx | 1 | 3 | 67.585mb +0.00% | 1.683s -2.90% | ±0.91% -60.70% |
| JsonExtractorBench | bench_extract_10k | 1 | 3 | 5.437mb +0.01% | 1.147s -1.30% | ±1.24% +185.57% |
| ParquetExtractorBench | bench_extract_10k | 1 | 3 | 86.398mb +0.00% | 884.377ms -0.85% | ±1.66% +139.99% |
| TextExtractorBench | bench_extract_10k | 1 | 3 | 4.568mb +0.03% | 43.865ms +3.88% | ±2.87% +342.07% |
| XmlExtractorBench | bench_extract_10k | 1 | 3 | 4.553mb +0.03% | 602.740ms -0.30% | ±2.04% +233.84% |
+-----------------------+------------------------+------+-----+-----------------+------------------+------------------+
Transformers+---------------------------------+--------------------------+------+-----+------------------+-----------------+----------------+
| benchmark | subject | revs | its | mem_peak | mode | rstdev |
+---------------------------------+--------------------------+------+-----+------------------+-----------------+----------------+
| RenameEachEntryTransformerBench | bench_transform_10k_rows | 1 | 3 | 18.563mb +0.01% | 71.242ms -0.57% | ±0.40% -35.26% |
| RenameEntryTransformerBench | bench_transform_10k_rows | 1 | 3 | 123.302mb +0.00% | 65.033ms -1.62% | ±0.92% +66.42% |
+---------------------------------+--------------------------+------+-----+------------------+-----------------+----------------+
Loaders+--------------------+----------------+------+-----+------------------+-----------------+------------------+
| benchmark | subject | revs | its | mem_peak | mode | rstdev |
+--------------------+----------------+------+-----+------------------+-----------------+------------------+
| CSVLoaderBench | bench_load_10k | 1 | 3 | 62.490mb +0.03% | 87.186ms +1.21% | ±2.43% +60.97% |
| JsonLoaderBench | bench_load_10k | 1 | 3 | 80.586mb +0.00% | 99.726ms -3.14% | ±1.86% +1154.91% |
| ParquetLoaderBench | bench_load_10k | 1 | 3 | 166.298mb +0.00% | 1.996s -0.70% | ±1.07% +505.09% |
| TextLoaderBench | bench_load_10k | 1 | 3 | 17.869mb +0.01% | 30.192ms +0.18% | ±0.93% +31.81% |
+--------------------+----------------+------+-----+------------------+-----------------+------------------+
Building Blocks+-------------------+----------------------------+------+-----+------------------+------------------+-----------------+
| benchmark | subject | revs | its | mem_peak | mode | rstdev |
+-------------------+----------------------------+------+-----+------------------+------------------+-----------------+
| TypeDetectorBench | bench_type_detector | 1 | 3 | 42.513mb +0.00% | 405.047ms -0.04% | ±0.77% -16.17% |
| TypeDetectorBench | bench_type_detector | 1 | 3 | 11.571mb +0.01% | 82.244ms +0.18% | ±0.97% +117.46% |
| EntryFactoryBench | bench_entry_factory | 1 | 3 | 105.983mb +0.00% | 652.668ms +1.04% | ±0.81% -47.57% |
| EntryFactoryBench | bench_entry_factory | 1 | 3 | 55.258mb +0.00% | 323.040ms -1.29% | ±1.06% +264.09% |
| EntryFactoryBench | bench_entry_factory | 1 | 3 | 14.844mb +0.01% | 69.080ms -0.59% | ±0.43% -26.84% |
| RowsBench | bench_chunk_10_on_10k | 2 | 3 | 93.454mb +0.00% | 3.183ms -1.48% | ±2.70% -10.94% |
| RowsBench | bench_diff_left_1k_on_10k | 2 | 3 | 110.824mb +0.00% | 237.151ms -0.15% | ±1.10% +327.49% |
| RowsBench | bench_diff_right_1k_on_10k | 2 | 3 | 93.544mb +0.00% | 23.920ms -0.08% | ±0.56% -33.43% |
| RowsBench | bench_drop_1k_on_10k | 2 | 3 | 94.328mb +0.00% | 1.232ms -2.84% | ±1.79% +9.87% |
| RowsBench | bench_drop_right_1k_on_10k | 2 | 3 | 94.328mb +0.00% | 1.240ms -2.40% | ±2.64% +202.80% |
| RowsBench | bench_entries_on_10k | 2 | 3 | 92.489mb +0.00% | 3.117ms -2.49% | ±2.49% +167.83% |
| RowsBench | bench_filter_on_10k | 2 | 3 | 93.018mb +0.00% | 15.181ms -3.85% | ±1.56% +70.68% |
| RowsBench | bench_find_on_10k | 2 | 3 | 93.018mb +0.00% | 15.225ms -3.04% | ±2.34% +2.10% |
| RowsBench | bench_find_one_on_10k | 10 | 3 | 91.707mb +0.00% | 1.806μs +0.68% | ±2.57% -3.64% |
| RowsBench | bench_first_on_10k | 10 | 3 | 91.707mb +0.00% | 0.400μs 0.00% | ±0.00% 0.00% |
| RowsBench | bench_flat_map_on_1k | 2 | 3 | 100.767mb +0.00% | 14.234ms -1.48% | ±0.47% -49.37% |
| RowsBench | bench_map_on_10k | 2 | 3 | 130.194mb +0.00% | 65.951ms +1.07% | ±0.67% +135.99% |
| RowsBench | bench_merge_1k_on_10k | 2 | 3 | 93.538mb +0.00% | 1.472ms +34.57% | ±0.41% -7.61% |
| RowsBench | bench_partition_by_on_10k | 2 | 3 | 96.907mb +0.00% | 62.687ms +1.68% | ±1.58% -1.14% |
| RowsBench | bench_remove_on_10k | 2 | 3 | 94.591mb +0.00% | 3.759ms +10.91% | ±3.64% +300.34% |
| RowsBench | bench_sort_asc_on_1k | 2 | 3 | 92.069mb +0.00% | 40.564ms +1.99% | ±0.29% -72.32% |
| RowsBench | bench_sort_by_on_1k | 2 | 3 | 92.069mb +0.00% | 39.673ms +0.05% | ±0.25% -83.01% |
| RowsBench | bench_sort_desc_on_1k | 2 | 3 | 92.069mb +0.00% | 40.129ms +1.57% | ±1.14% -38.89% |
| RowsBench | bench_sort_entries_on_1k | 2 | 3 | 94.150mb +0.00% | 8.035ms -0.38% | ±1.33% +267.78% |
| RowsBench | bench_sort_on_1k | 2 | 3 | 91.900mb +0.00% | 29.349ms -0.44% | ±1.40% +37.64% |
| RowsBench | bench_take_1k_on_10k | 10 | 3 | 91.707mb +0.00% | 13.836μs -21.89% | ±2.02% -43.25% |
| RowsBench | bench_take_right_1k_on_10k | 10 | 3 | 91.707mb +0.00% | 15.430μs -11.91% | ±1.51% +21.96% |
| RowsBench | bench_unique_on_1k | 2 | 3 | 110.825mb +0.00% | 237.726ms -2.77% | ±0.35% -44.19% |
+-------------------+----------------------------+------+-----+------------------+------------------+-----------------+
|
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## 1.x #1740 +/- ##
==========================================
+ Coverage 81.26% 81.31% +0.04%
==========================================
Files 715 717 +2
Lines 19901 19949 +48
==========================================
+ Hits 16173 16221 +48
Misses 3728 3728
🚀 New features to boost your workflow:
|
src/adapter/etl-adapter-csv/src/Flow/ETL/Adapter/CSV/CSVExtractor.php
Outdated
Show resolved
Hide resolved
| $buffer .= $rawLine; | ||
|
|
||
| if (!\str_contains($buffer, $this->enclosure)) { | ||
| yield $this->removeBOM && $lineNumber === 0 ? $this->removeBOMFromLine(\rtrim($buffer, "\r\n")) : rtrim($buffer, "\r\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the BOM check be only on line zero? There is no point in repeating the check on every line, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See this comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's how it works now, it checks if removeBOM is needed and if it's needed then it checks if the line number is 0 (first line).
| foreach ($stream->readLines(length: $this->charactersReadInLine) as $rawLine) { | ||
| $buffer .= $rawLine; | ||
|
|
||
| if (!\str_contains($buffer, $this->enclosure)) { | ||
| yield $this->removeBOM && $lineNumber === 0 ? $this->removeBOMFromLine(\rtrim($buffer, "\r\n")) : rtrim($buffer, "\r\n"); | ||
| $lineNumber++; | ||
| $buffer = ''; | ||
| } else { | ||
| if ($this->isCompleteCSVRecord($buffer)) { | ||
| yield $this->removeBOM && $lineNumber === 0 ? $this->removeBOMFromLine(\rtrim($buffer, "\r\n")) : \rtrim($buffer, "\r\n"); | ||
| $lineNumber++; | ||
| $buffer = ''; | ||
| } else { | ||
| $buffer .= "\n"; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if ($buffer !== '') { | ||
| yield $this->removeBOM && $lineNumber === 0 ? $this->removeBOMFromLine(\rtrim($buffer, "\r\n")) : \rtrim($buffer, "\r\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like this, probably:
| foreach ($stream->readLines(length: $this->charactersReadInLine) as $rawLine) { | |
| $buffer .= $rawLine; | |
| if (!\str_contains($buffer, $this->enclosure)) { | |
| yield $this->removeBOM && $lineNumber === 0 ? $this->removeBOMFromLine(\rtrim($buffer, "\r\n")) : rtrim($buffer, "\r\n"); | |
| $lineNumber++; | |
| $buffer = ''; | |
| } else { | |
| if ($this->isCompleteCSVRecord($buffer)) { | |
| yield $this->removeBOM && $lineNumber === 0 ? $this->removeBOMFromLine(\rtrim($buffer, "\r\n")) : \rtrim($buffer, "\r\n"); | |
| $lineNumber++; | |
| $buffer = ''; | |
| } else { | |
| $buffer .= "\n"; | |
| } | |
| } | |
| } | |
| if ($buffer !== '') { | |
| yield $this->removeBOM && $lineNumber === 0 ? $this->removeBOMFromLine(\rtrim($buffer, "\r\n")) : \rtrim($buffer, "\r\n"); | |
| foreach ($stream->readLines(length: $this->charactersReadInLine) as $rawLine) { | |
| if ($this->removeBOM && $lineNumber === 0) { | |
| $rawLine = $this->removeBOMFromLine($rawLine); | |
| } | |
| $buffer .= $rawLine; | |
| if (!\str_contains($buffer, $this->enclosure)) { | |
| yield rtrim($buffer, "\r\n"); | |
| $lineNumber++; | |
| $buffer = ''; | |
| } else { | |
| if ($this->isCompleteCSVRecord($buffer)) { | |
| yield \rtrim($buffer, "\r\n"); | |
| $lineNumber++; | |
| $buffer = ''; | |
| } else { | |
| $buffer .= "\n"; | |
| } | |
| } | |
| } | |
| if ($buffer !== '') { | |
| yield \rtrim($buffer, "\r\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah but line number is not going to be incremented until it's full line, so at the end of the day if the first line contains multi line string, remove BOM will be executed as many times as many lines that multiline string has
Resolves: #1738
Change Log
Added
Fixed
Changed
Removed
Deprecated
Security