-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Change default SQL mapping for VARCAHR from Utf8 to Utf8View
#16142
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
Changes from 19 commits
cd288b9
2ec5370
f2e9963
83fe677
0be56a3
18c83db
0bb1d96
0780263
c8295af
3a66192
f44da69
a5eaa28
805d99e
d806b8c
afac8c8
4fe5414
02d725a
2dc6bc5
e54e432
65e0794
b3bb360
9195b6a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,7 @@ use std::hash::Hash; | |
| use std::task::{Context, Poll}; | ||
| use std::{any::Any, collections::BTreeMap, fmt, sync::Arc}; | ||
|
|
||
| use arrow::array::{Array, ArrayRef, StringViewArray}; | ||
| use arrow::{ | ||
| array::{Int64Array, StringArray}, | ||
| datatypes::SchemaRef, | ||
|
|
@@ -100,6 +101,7 @@ use datafusion_optimizer::AnalyzerRule; | |
| use datafusion_physical_plan::execution_plan::{Boundedness, EmissionType}; | ||
|
|
||
| use async_trait::async_trait; | ||
| use datafusion_common::cast::as_string_view_array; | ||
| use futures::{Stream, StreamExt}; | ||
|
|
||
| /// Execute the specified sql and return the resulting record batches | ||
|
|
@@ -796,22 +798,30 @@ fn accumulate_batch( | |
| k: &usize, | ||
| ) -> BTreeMap<i64, String> { | ||
| let num_rows = input_batch.num_rows(); | ||
|
|
||
| // Assuming the input columns are | ||
| // column[0]: customer_id / UTF8 | ||
| // column[0]: customer_id / UTF8 or UTF8View | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like the example would be simpler if it just used
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good suggestion! Thank you @alamb , addressed in latest PR. |
||
| // column[1]: revenue: Int64 | ||
| let customer_id = | ||
| as_string_array(input_batch.column(0)).expect("Column 0 is not customer_id"); | ||
|
|
||
| let customer_id_column = input_batch.column(0); | ||
| let revenue = as_int64_array(input_batch.column(1)).unwrap(); | ||
|
|
||
| for row in 0..num_rows { | ||
| add_row( | ||
| &mut top_values, | ||
| customer_id.value(row), | ||
| revenue.value(row), | ||
| k, | ||
| ); | ||
| let customer_id = match customer_id_column.data_type() { | ||
| arrow::datatypes::DataType::Utf8 => { | ||
| let array = as_string_array(customer_id_column).unwrap(); | ||
| array.value(row) | ||
| } | ||
| arrow::datatypes::DataType::Utf8View => { | ||
| let array = as_string_view_array(customer_id_column).unwrap(); | ||
| array.value(row) | ||
| } | ||
| _ => panic!("Unsupported customer_id type"), | ||
| }; | ||
|
|
||
| add_row(&mut top_values, customer_id, revenue.value(row), k); | ||
| } | ||
|
|
||
| top_values | ||
| } | ||
|
|
||
|
|
@@ -843,11 +853,22 @@ impl Stream for TopKReader { | |
| self.state.iter().rev().unzip(); | ||
|
|
||
| let customer: Vec<&str> = customer.iter().map(|&s| &**s).collect(); | ||
|
|
||
| let customer_array: ArrayRef = match schema.field(0).data_type() { | ||
| arrow::datatypes::DataType::Utf8 => { | ||
| Arc::new(StringArray::from(customer)) | ||
| } | ||
| arrow::datatypes::DataType::Utf8View => { | ||
| Arc::new(StringViewArray::from(customer)) | ||
| } | ||
| other => panic!("Unsupported customer_id output type: {other:?}"), | ||
| }; | ||
|
|
||
| Poll::Ready(Some( | ||
| RecordBatch::try_new( | ||
| schema, | ||
| vec![ | ||
| Arc::new(StringArray::from(customer)), | ||
| Arc::new(customer_array), | ||
| Arc::new(Int64Array::from(revenue)), | ||
| ], | ||
| ) | ||
|
|
||
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.
I think it would be better if we could change the example to maybe just use a
StringViewArrayin the first place (rather than have to cast it here)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.
Good suggestion! Thank you @alamb , addressed in latest PR.