Uh oh!
There was an error while loading. Please reload this page.
Introduce binary_as_string parquet option, upgrade to arrow/parquet 53.2.0 - #12816
Conversation
binary_as_string parquet optionbinary_as_string parquet optionalamb
commented
Oct 10, 2024
@goldmedal would you be ok if I pushed a change to this PR to temporarily patch arrow-rs to include the fix for apache/arrow-rs#6539 ? Then we could get this PR ready to go (and I could use it to test with string view on by default) |
goldmedal
commented
Oct 10, 2024
Sure. feel free to do it. Thanks! |
alamb
commented
Oct 10, 2024
I pushed the change in d7c3565 I am about out of time to work on this today, but if no one else gets a chance to do this I'll try and polish this PR up tomorrow |
goldmedal
commented
Oct 10, 2024
I would be able to help finish the remaining work before I sleep today. (Ensure this PR works well) |
| field.is_nullable(), | ||
| )) | ||
| } | ||
| (Some(DataType::LargeUtf8), DataType::LargeBinary) => { |
There was a problem hiding this comment.
Actually, this case isn't covered by testing because the Arrow reader always marks BYTE_ARRAY as Utf8 or Binary. I'm not pretty sure if we need it. 🤔
| // string-to-view transformation. So we need all binary types to be coerced to `Utf8View` here. | ||
| ( | ||
| Some(DataType::Utf8View), | ||
| DataType::Binary | DataType::LargeBinary | DataType::BinaryView, |
There was a problem hiding this comment.
Same as above, testing doesn't cover the case for DataType::LargeBinary and DataType::BinaryView.
goldmedal
commented
Oct 10, 2024
@alamb |
alamb
commented
Oct 11, 2024
I am starting to play around with this PR / write some tests. Will post my updates shortly |
alamb
left a comment
There was a problem hiding this comment.
Hi @goldmedal -- I played around with this locally with the hits_partitioned file and I am happy to say it seems to get the correct schema.
I am going to play around with this a bit more / test with some other feature branches
+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| logical_plan | Sort: l DESC NULLS FIRST, fetch=25 |
| | Projection: regexp_replace(hits_partitioned.Referer,Utf8("^https?://(?:www\.)?([^/]+)/.*$"),Utf8("\1")) AS k, avg(character_length(hits_partitioned.Referer)) AS l, count(*) AS c, min(hits_partitioned.Referer) |
| | Filter: count(*) > Int64(100000) |
| | Aggregate: groupBy=[[regexp_replace(hits_partitioned.Referer, Utf8("^https?://(?:www\.)?([^/]+)/.*$"), Utf8("\1"))]], aggr=[[avg(CAST(character_length(hits_partitioned.Referer) AS Float64)), count(Int64(1)) AS count(*), min(hits_partitioned.Referer)]] |
| | Filter: hits_partitioned.Referer != Utf8View("") |
| | TableScan: hits_partitioned projection=[Referer], partial_filters=[hits_partitioned.Referer != Utf8View("")] |
| physical_plan | SortPreservingMergeExec: [l@1 DESC], fetch=25 |
| | SortExec: TopK(fetch=25), expr=[l@1 DESC], preserve_partitioning=[true] |
| | ProjectionExec: expr=[regexp_replace(hits_partitioned.Referer,Utf8("^https?://(?:www\.)?([^/]+)/.*$"),Utf8("\1"))@0 as k, avg(character_length(hits_partitioned.Referer))@1 as l, count(*)@2 as c, min(hits_partitioned.Referer)@3 as min(hits_partitioned.Referer)] |
| | CoalesceBatchesExec: target_batch_size=8192 |
| | FilterExec: count(*)@2 > 100000 |
| | AggregateExec: mode=FinalPartitioned, gby=[regexp_replace(hits_partitioned.Referer,Utf8("^https?://(?:www\.)?([^/]+)/.*$"),Utf8("\1"))@0 as regexp_replace(hits_partitioned.Referer,Utf8("^https?://(?:www\.)?([^/]+)/.*$"),Utf8("\1"))], aggr=[avg(character_length(hits_partitioned.Referer)), count(*), min(hits_partitioned.Referer)] |
| | CoalesceBatchesExec: target_batch_size=8192 |
| | RepartitionExec: partitioning=Hash([regexp_replace(hits_partitioned.Referer,Utf8("^https?://(?:www\.)?([^/]+)/.*$"),Utf8("\1"))@0], 16), input_partitions=16 |
| | AggregateExec: mode=Partial, gby=[regexp_replace(Referer@0, ^https?://(?:www\.)?([^/]+)/.*$, \1) as regexp_replace(hits_partitioned.Referer,Utf8("^https?://(?:www\.)?([^/]+)/.*$"),Utf8("\1"))], aggr=[avg(character_length(hits_partitioned.Referer)), count(*), min(hits_partitioned.Referer)] |
| | CoalesceBatchesExec: target_batch_size=8192 |
| | FilterExec: Referer@0 != |
| | ParquetExec: file_groups={16 groups: [[Users/andrewlamb/Downloads/hits_partitioned/hits_0.parquet:0..122446530, Users/andrewlamb/Downloads/hits_partitioned/hits_1.parquet:0..174965044, Users/andrewlamb/Downloads/hits_partitioned/hits_10.parquet:0..101513258, Users/andrewlamb/Downloads/hits_partitioned/hits_11.parquet:0..118419888, Users/andrewlamb/Downloads/hits_partitioned/hits_12.parquet:0..149514164, ...], [Users/andrewlamb/Downloads/hits_partitioned/hits_14.parquet:108113265..151121699, Users/andrewlamb/Downloads/hits_partitioned/hits_15.parquet:0..103098894, Users/andrewlamb/Downloads/hits_partitioned/hits_16.parquet:0..101067219, Users/andrewlamb/Downloads/hits_partitioned/hits_17.parquet:0..116867853, Users/andrewlamb/Downloads/hits_partitioned/hits_18.parquet:0..133119589, ...], [Users/andrewlamb/Downloads/hits_partitioned/hits_21.parquet:3887560..113455196, Users/andrewlamb/Downloads/hits_partitioned/hits_22.parquet:0..79775901, Users/andrewlamb/Downloads/hits_partitioned/hits_23.parquet:0..79631107, Users/andrewlamb/Downloads/hits_partitioned/hits_24.parquet:0..78257049, Users/andrewlamb/Downloads/hits_partitioned/hits_25.parquet:0..144169728, ...], [Users/andrewlamb/Downloads/hits_partitioned/hits_28.parquet:106905624..162772407, Users/andrewlamb/Downloads/hits_partitioned/hits_29.parquet:0..79213288, Users/andrewlamb/Downloads/hits_partitioned/hits_3.parquet:0..192507052, Users/andrewlamb/Downloads/hits_partitioned/hits_30.parquet:0..124187913, Users/andrewlamb/Downloads/hits_partitioned/hits_31.parquet:0..123065410, ...], [Users/andrewlamb/Downloads/hits_partitioned/hits_35.parquet:54087340..153632381, Users/andrewlamb/Downloads/hits_partitioned/hits_36.parquet:0..92487304, Users/andrewlamb/Downloads/hits_partitioned/hits_37.parquet:0..108247781, Users/andrewlamb/Downloads/hits_partitioned/hits_38.parquet:0..132005180, Users/andrewlamb/Downloads/hits_partitioned/hits_39.parquet:0..103522954, ...], ...]}, projection=[Referer], predicate=Referer@14 != , pruning_predicate=CASE WHEN Referer_null_count@2 = Referer_row_count@3 THEN false ELSE Referer_min@0 != OR != Referer_max@1 END, required_guarantees=[Referer not in ()] |
| | |
+---------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 row(s) fetched.
alamb
commented
Oct 11, 2024
I am running some benchmarks on this PR |
alamb
commented
Oct 13, 2024
Here is the performance of this PR. Some queries are slower, some are faster. I believe once we turn on string view everything will be faster. |
3a62740 to
abce0e9Comparealamb
commented
Oct 13, 2024
I reabased / squashed all the code in this branch so it would be easier to pull in to test in #12092 |
goldmedal
commented
Oct 14, 2024
Thanks @alamb It's interesting 🤔 Before this PR, the casting flow is Now, it's Theoretically, we save the two steps (including the most expensive ones) for it. I have no idea why they would be slower. |
alamb
commented
Oct 14, 2024
It only includes changes made by this PR The results with several other changes are here: #12092 (comment) (and they are all faster 🎉 )
I think the reason it is slower is that there are some operations in the hash grouping code that have specializations for
So while this PR makes the scan faster, the total time is slower as those paths dominated the query path. When they are all put together we get the speedup we have been looking for |
alamb
commented
Oct 14, 2024
Since this PR requires a change to arrow-rs, I think there is no particular rush to merge it in -- I have a few thoughts about how to make the code a bit simpler and hope to propose some changes over the next few days |
alamb
commented
Oct 16, 2024
I am starting to get this PR ready |
| parquet_options.schema_force_view_types = self.common.force_view_types; | ||
| // The hits_partitioned dataset specifies string columns | ||
| // as binary due to how it was written. Force it to strings | ||
| parquet_options.binary_as_string = true; |
There was a problem hiding this comment.
we will have to mirror these options in the actual clickbench run
| Field::new(field.name(), DataType::BinaryView, field.is_nullable()) | ||
| .with_metadata(field.metadata().to_owned()), | ||
| ), | ||
| DataType::Utf8 | DataType::LargeUtf8 => { |
There was a problem hiding this comment.
I reduced repetition of this code by encapsulating creating a new FieldRef from an existing Field in a function. I also think this will avoid the potential loss of metadata
There was a problem hiding this comment.
Thanks! It makes sense to me. 👍
There was a problem hiding this comment.
I plan to try and accelerate this PR along with a new arrow-rs release: apache/arrow-rs#6341
There was a problem hiding this comment.
arrow is released. I think this PR is ready for review
alamb
commented
Oct 24, 2024
Update here is we are on track to release a version of arrow with the required fixes today and then I will merge this PR up and get it ready for review ⏲️ |
binary_as_string parquet optionbinary_as_string parquet option, upgrade to arrow/parquet 53.2.0a20ac87 to
9794e93Compare| "runtime-rng", | ||
| ] } | ||
| arrow = { version = "53.1.0", features = [ | ||
| arrow = { version = "53.2.0", features = [ |
There was a problem hiding this comment.
this update is required to have access to apache/arrow-rs#6539
alamb
left a comment
There was a problem hiding this comment.
I realize it isn't ideal that I am approving a PR that I have most recently worked on. @goldmedal perhaps you can give it a final review to make sure I didn't mess anything else up
| # NB the data is read and displayed a StringView | ||
| query error DataFusion error: SQL error: ParserError\("Expected: an SQL statement, found: Utf8View"\) | ||
| select | ||
| arrow_typeof(binary_col), binary_col, | ||
| arrow_typeof(largebinary_col), largebinary_col, | ||
| arrow_typeof(binaryview_col), binaryview_col | ||
| FROM binary_as_string_both; | ||
| ---- | ||
| Utf8View aaa | ||
| Utf8View bbb | ||
| Utf8View ccc | ||
| Utf8View ddd |
There was a problem hiding this comment.
Do you know why this query fails 🤔 ? It got a ParserError but I think it's a valid SQL.
The test expects this query to fail but it still returns some results with the wrong schema.
The query should have 6 columns per row but It only shows 2.
It's weird. 🤔
There was a problem hiding this comment.
This is an excellent find @goldmedal -- thank you
I debugged it and the issue was there was an extra space before ---- 🤦
----vs
----Fixed in a48dce1
alamb
commented
Oct 25, 2024
Thanks @goldmedal -- that was an excellent catch. I have fixed the issue |
Which issue does this PR close?
Closes#12788 .
Closes#13042
Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?