Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
196 changes: 196 additions & 0 deletions CHANGELOG-old.md

Large diffs are not rendered by default.

273 changes: 98 additions & 175 deletions CHANGELOG.md

Large diffs are not rendered by default.

48 changes: 25 additions & 23 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ exclude = [
]

[workspace.package]
version = "58.0.0"
version = "58.1.0"
homepage = "https://github.com/apache/arrow-rs"
repository = "https://github.com/apache/arrow-rs"
authors = ["Apache Arrow <dev@arrow.apache.org>"]
Expand All @@ -85,35 +85,37 @@ edition = "2024"
rust-version = "1.85"

[workspace.dependencies]
arrow = { version = "58.0.0", path = "./arrow", default-features = false }
arrow-arith = { version = "58.0.0", path = "./arrow-arith" }
arrow-array = { version = "58.0.0", path = "./arrow-array" }
arrow-buffer = { version = "58.0.0", path = "./arrow-buffer" }
arrow-cast = { version = "58.0.0", path = "./arrow-cast" }
arrow-csv = { version = "58.0.0", path = "./arrow-csv" }
arrow-data = { version = "58.0.0", path = "./arrow-data" }
arrow-ipc = { version = "58.0.0", path = "./arrow-ipc" }
arrow-json = { version = "58.0.0", path = "./arrow-json" }
arrow-ord = { version = "58.0.0", path = "./arrow-ord" }
arrow-pyarrow = { version = "58.0.0", path = "./arrow-pyarrow" }
arrow-row = { version = "58.0.0", path = "./arrow-row" }
arrow-schema = { version = "58.0.0", path = "./arrow-schema" }
arrow-select = { version = "58.0.0", path = "./arrow-select" }
arrow-string = { version = "58.0.0", path = "./arrow-string" }
parquet = { version = "58.0.0", path = "./parquet", default-features = false }
parquet-geospatial = { version = "58.0.0", path = "./parquet-geospatial" }
parquet-variant = { version = "58.0.0", path = "./parquet-variant" }
parquet-variant-json = { version = "58.0.0", path = "./parquet-variant-json" }
parquet-variant-compute = { version = "58.0.0", path = "./parquet-variant-compute" }
arrow = { version = "58.1.0", path = "./arrow", default-features = false }
arrow-arith = { version = "58.1.0", path = "./arrow-arith" }
arrow-array = { version = "58.1.0", path = "./arrow-array" }
arrow-buffer = { version = "58.1.0", path = "./arrow-buffer" }
arrow-cast = { version = "58.1.0", path = "./arrow-cast" }
arrow-csv = { version = "58.1.0", path = "./arrow-csv" }
arrow-data = { version = "58.1.0", path = "./arrow-data" }
arrow-ipc = { version = "58.1.0", path = "./arrow-ipc" }
arrow-json = { version = "58.1.0", path = "./arrow-json" }
arrow-ord = { version = "58.1.0", path = "./arrow-ord" }
arrow-pyarrow = { version = "58.1.0", path = "./arrow-pyarrow" }
arrow-row = { version = "58.1.0", path = "./arrow-row" }
arrow-schema = { version = "58.1.0", path = "./arrow-schema" }
arrow-select = { version = "58.1.0", path = "./arrow-select" }
arrow-string = { version = "58.1.0", path = "./arrow-string" }
parquet = { version = "58.1.0", path = "./parquet", default-features = false }
parquet-geospatial = { version = "58.1.0", path = "./parquet-geospatial" }
parquet-variant = { version = "58.1.0", path = "./parquet-variant" }
parquet-variant-json = { version = "58.1.0", path = "./parquet-variant-json" }
parquet-variant-compute = { version = "58.1.0", path = "./parquet-variant-compute" }

chrono = { version = "0.4.40", default-features = false, features = ["clock"] }

simdutf8 = { version = "0.1.5", default-features = false }

criterion = { version = "0.8.0", default-features = false }

insta = { version = "1.46.3", default-features = false }

object_store = { version = "0.13.2", default-features = false }

simdutf8 = { version = "0.1.5", default-features = false }

# release inherited profile keeping debug information and symbols
# for mem/cpu profiling
[profile.profiling]
Expand Down
6 changes: 3 additions & 3 deletions arrow-avro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ arrow-buffer = { workspace = true }
arrow-array = { workspace = true }
arrow-select = { workspace = true, optional = true }

object_store = { version = "0.13", default-features = false, optional = true }
object_store = { workspace = true, optional = true }

bytes = { version = "1.11.0", default-features = false, features = ["std"] }
serde_json = { version = "1.0", default-features = false, features = ["std"] }
Expand All @@ -75,7 +75,7 @@ uuid = "1.17"
indexmap = "2.10"
rand = "0.9"
md5 = { version = "0.8", optional = true }
sha2 = { version = "0.10", optional = true }
sha2 = { version = "0.11", optional = true }
tokio = { version = "1.0", optional = true, default-features = false, features = ["macros", "rt", "io-util"] }

[dev-dependencies]
Expand All @@ -93,7 +93,7 @@ futures = "0.3.31"
async-stream = "0.3.6"
apache-avro = "0.21.0"
num-bigint = "0.4"
object_store = { version = "0.13", default-features = false, features = ["fs"] }
object_store = { workspace = true, features = ["fs"] }
once_cell = "1.21.3"
half = { version = "2.1", default-features = false }
tokio = { version = "1.0", default-features = false, features = ["macros", "rt-multi-thread", "io-util", "fs"] }
Expand Down
10 changes: 8 additions & 2 deletions arrow-buffer/src/buffer/mutable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,13 @@ impl MutableBuffer {

/// Clear all existing data from this buffer.
pub fn clear(&mut self) {
self.len = 0
self.len = 0;
#[cfg(feature = "pool")]
{
if let Some(reservation) = self.reservation.lock().unwrap().as_mut() {
reservation.resize(self.len);
}
}
}

/// Returns the data stored in this buffer as a slice.
Expand Down Expand Up @@ -1371,7 +1377,7 @@ mod tests {
assert_eq!(pool.used(), 40);

// Truncate to zero
buffer.truncate(0);
buffer.clear();
assert_eq!(buffer.len(), 0);
assert_eq!(pool.used(), 0);
}
Expand Down
55 changes: 49 additions & 6 deletions arrow-cast/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ pub struct FormatOptions<'a> {
duration_format: DurationFormat,
/// Show types in visual representation batches
types_info: bool,
/// Whether string values should be quoted
quoted_strings: bool,
/// Formatter factory used to instantiate custom [`ArrayFormatter`]s. This allows users to
/// provide custom formatters.
formatter_factory: Option<&'a dyn ArrayFormatterFactory>,
Expand All @@ -102,6 +104,7 @@ impl PartialEq for FormatOptions<'_> {
&& self.time_format == other.time_format
&& self.duration_format == other.duration_format
&& self.types_info == other.types_info
&& self.quoted_strings == other.quoted_strings
&& match (self.formatter_factory, other.formatter_factory) {
(Some(f1), Some(f2)) => std::ptr::eq(f1, f2),
(None, None) => true,
Expand All @@ -123,6 +126,7 @@ impl Hash for FormatOptions<'_> {
self.time_format.hash(state);
self.duration_format.hash(state);
self.types_info.hash(state);
self.quoted_strings.hash(state);
self.formatter_factory
.map(|f| f as *const dyn ArrayFormatterFactory)
.hash(state);
Expand All @@ -142,6 +146,7 @@ impl<'a> FormatOptions<'a> {
time_format: None,
duration_format: DurationFormat::ISO8601,
types_info: false,
quoted_strings: false,
formatter_factory: None,
}
}
Expand Down Expand Up @@ -217,6 +222,17 @@ impl<'a> FormatOptions<'a> {
Self { types_info, ..self }
}

/// Sets whether string values should be quoted
///
/// When `true`, strings are formatted using [`Debug`]-style with double quotes and escaping.
/// Defaults to `false`
pub const fn with_quoted_strings(self, quoted_strings: bool) -> Self {
Self {
quoted_strings,
..self
}
}

/// Overrides the [`ArrayFormatterFactory`] used to instantiate custom [`ArrayFormatter`]s.
///
/// Using [`None`] causes pretty-printers to use the default [`ArrayFormatter`]s.
Expand Down Expand Up @@ -276,6 +292,11 @@ impl<'a> FormatOptions<'a> {
self.types_info
}

/// Returns whether string values should be quoted.
pub const fn quoted_strings(&self) -> bool {
self.quoted_strings
}

/// Returns the [`ArrayFormatterFactory`] used to instantiate custom [`ArrayFormatter`]s.
pub const fn formatter_factory(&self) -> Option<&'a dyn ArrayFormatterFactory> {
self.formatter_factory
Expand Down Expand Up @@ -1081,16 +1102,38 @@ impl Display for MillisecondsFormatter<'_> {
}
}

impl<O: OffsetSizeTrait> DisplayIndex for &GenericStringArray<O> {
fn write(&self, idx: usize, f: &mut dyn Write) -> FormatResult {
write!(f, "{}", self.value(idx))?;
impl<'a, O: OffsetSizeTrait> DisplayIndexState<'a> for &'a GenericStringArray<O> {
type State = bool;

fn prepare(&self, options: &FormatOptions<'a>) -> Result<Self::State, ArrowError> {
Ok(options.quoted_strings())
}

fn write(&self, state: &Self::State, idx: usize, f: &mut dyn Write) -> FormatResult {
let value = self.value(idx);
if *state {
write!(f, "{:?}", value)?;
} else {
write!(f, "{}", value)?;
}
Ok(())
}
}

impl DisplayIndex for &StringViewArray {
fn write(&self, idx: usize, f: &mut dyn Write) -> FormatResult {
write!(f, "{}", self.value(idx))?;
impl<'a> DisplayIndexState<'a> for &'a StringViewArray {
type State = bool;

fn prepare(&self, options: &FormatOptions<'a>) -> Result<Self::State, ArrowError> {
Ok(options.quoted_strings())
}

fn write(&self, state: &Self::State, idx: usize, f: &mut dyn Write) -> FormatResult {
let value = self.value(idx);
if *state {
write!(f, "{:?}", value)?;
} else {
write!(f, "{}", value)?;
}
Ok(())
}
}
Expand Down
154 changes: 154 additions & 0 deletions arrow-cast/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1665,4 +1665,158 @@ mod tests {
.unwrap();
insta::assert_snapshot!(error, @"Invalid argument error: Expected the same number of columns in a record batch (1) as the number of fields (2) in the schema");
}

#[test]
fn test_quoted_strings() {
let schema = Arc::new(Schema::new(vec![Field::new(
"strings",
DataType::Utf8,
true,
)]));

let string_array = StringArray::from(vec![
Some("hello"),
Some("world"),
Some(""),
Some("tab\there"),
Some("newline\ntest"),
Some("quote\"test"),
Some("backslash\\test"),
None,
]);

let batch = RecordBatch::try_new(schema.clone(), vec![Arc::new(string_array)]).unwrap();

let options_none = FormatOptions::new().with_null("NULL");
let table = pretty_format_batches_with_options(std::slice::from_ref(&batch), &options_none)
.unwrap()
.to_string();

insta::assert_snapshot!(table, @"
+----------------+
| strings |
+----------------+
| hello |
| world |
| |
| tab here |
| newline |
| test |
| quote\"test |
| backslash\\test |
| NULL |
+----------------+
");

let options_quoted = FormatOptions::new()
.with_null("NULL")
.with_quoted_strings(true);

let table = pretty_format_batches_with_options(&[batch], &options_quoted)
.unwrap()
.to_string();

insta::assert_snapshot!(table, @r#"
+-------------------+
| strings |
+-------------------+
| "hello" |
| "world" |
| "" |
| "tab\there" |
| "newline\ntest" |
| "quote\"test" |
| "backslash\\test" |
| NULL |
+-------------------+
"#);
}

#[test]
fn test_string_view_quoted() {
let schema = Arc::new(Schema::new(vec![Field::new(
"view_strings",
DataType::Utf8View,
true,
)]));

let mut builder = StringViewBuilder::new();
builder.append_value("hello");
builder.append_null();
builder.append_value("quote\"test");

let array: ArrayRef = Arc::new(builder.finish());
let batch = RecordBatch::try_new(schema, vec![array]).unwrap();

let options = FormatOptions::new().with_quoted_strings(true);

let table = pretty_format_batches_with_options(&[batch], &options)
.unwrap()
.to_string();

insta::assert_snapshot!(table, @"
+---------------+
| view_strings |
+---------------+
| \"hello\" |
| |
| \"quote\\\"test\" |
+---------------+
");
}

#[test]
fn test_quoted_strings_in_struct() {
let string_builder = StringBuilder::new();
let mut name_builder = string_builder;
name_builder.append_value("Alice");
name_builder.append_value("");
name_builder.append_value("Bob");

let fields = vec![Field::new("name", DataType::Utf8, false)];
let mut struct_builder = StructBuilder::new(fields, vec![Box::new(name_builder)]);
struct_builder.append(true);
struct_builder.append(true);
struct_builder.append(true);

let struct_array = struct_builder.finish();

let schema = Arc::new(Schema::new(vec![Field::new(
"person",
struct_array.data_type().clone(),
false,
)]));

let batch = RecordBatch::try_new(schema, vec![Arc::new(struct_array)]).unwrap();

let options_none = FormatOptions::new();
let table = pretty_format_batches_with_options(std::slice::from_ref(&batch), &options_none)
.unwrap()
.to_string();

insta::assert_snapshot!(table, @"
+---------------+
| person |
+---------------+
| {name: Alice} |
| {name: } |
| {name: Bob} |
+---------------+
");

let options_quoted = FormatOptions::new().with_quoted_strings(true);
let table = pretty_format_batches_with_options(&[batch], &options_quoted)
.unwrap()
.to_string();

insta::assert_snapshot!(table, @"
+-----------------+
| person |
+-----------------+
| {name: \"Alice\"} |
| {name: \"\"} |
| {name: \"Bob\"} |
+-----------------+
");
}
}
4 changes: 2 additions & 2 deletions arrow-data/src/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,8 @@ impl<'a> MutableArrayData<'a> {
};

let nulls = match data.data_type {
// RunEndEncoded and Null arrays cannot have top-level null bitmasks
DataType::RunEndEncoded(_, _) | DataType::Null => None,
// RunEndEncoded, Null, and Union arrays cannot have top-level null bitmasks
DataType::RunEndEncoded(_, _) | DataType::Null | DataType::Union(_, _) => None,
_ => data
.null_buffer
.map(|nulls| {
Expand Down
Loading