Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 23 additions & 19 deletions datafusion-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ fn extract_memory_pool_size(size: &str) -> Result<usize, String> {
#[cfg(test)]
mod tests {
use super::*;
use datafusion::assert_batches_eq;
use datafusion::common::test_util::batches_to_string;
use insta::assert_snapshot;

fn assert_conversion(input: &str, expected: Result<usize, String>) {
let result = extract_memory_pool_size(input);
Expand Down Expand Up @@ -391,21 +392,26 @@ mod tests {
let df = ctx.sql(sql).await?;
let rbs = df.collect().await?;

let excepted = [
"+-------------------------------------------------------------+--------------+--------------------+-----------------------+-----------------+-----------+-------------+------------+----------------+-------+-----------+-----------+------------------+----------------------+-----------------+-----------------+-------------+------------------------------+-------------------+------------------------+------------------+-----------------------+-------------------------+",
"| filename | row_group_id | row_group_num_rows | row_group_num_columns | row_group_bytes | column_id | file_offset | num_values | path_in_schema | type | stats_min | stats_max | stats_null_count | stats_distinct_count | stats_min_value | stats_max_value | compression | encodings | index_page_offset | dictionary_page_offset | data_page_offset | total_compressed_size | total_uncompressed_size |",
"+-------------------------------------------------------------+--------------+--------------------+-----------------------+-----------------+-----------+-------------+------------+----------------+-------+-----------+-----------+------------------+----------------------+-----------------+-----------------+-------------+------------------------------+-------------------+------------------------+------------------+-----------------------+-------------------------+",
"| ../datafusion/core/tests/data/fixed_size_list_array.parquet | 0 | 2 | 1 | 123 | 0 | 125 | 4 | \"f0.list.item\" | INT64 | 1 | 4 | 0 | | 1 | 4 | SNAPPY | [RLE_DICTIONARY, PLAIN, RLE] | | 4 | 46 | 121 | 123 |",
"+-------------------------------------------------------------+--------------+--------------------+-----------------------+-----------------+-----------+-------------+------------+----------------+-------+-----------+-----------+------------------+----------------------+-----------------+-----------------+-------------+------------------------------+-------------------+------------------------+------------------+-----------------------+-------------------------+",
];
assert_batches_eq!(excepted, &rbs);
assert_snapshot!(batches_to_string(&rbs), @r#"
+-------------------------------------------------------------+--------------+--------------------+-----------------------+-----------------+-----------+-------------+------------+----------------+-------+-----------+-----------+------------------+----------------------+-----------------+-----------------+-------------+------------------------------+-------------------+------------------------+------------------+-----------------------+-------------------------+
| filename | row_group_id | row_group_num_rows | row_group_num_columns | row_group_bytes | column_id | file_offset | num_values | path_in_schema | type | stats_min | stats_max | stats_null_count | stats_distinct_count | stats_min_value | stats_max_value | compression | encodings | index_page_offset | dictionary_page_offset | data_page_offset | total_compressed_size | total_uncompressed_size |
+-------------------------------------------------------------+--------------+--------------------+-----------------------+-----------------+-----------+-------------+------------+----------------+-------+-----------+-----------+------------------+----------------------+-----------------+-----------------+-------------+------------------------------+-------------------+------------------------+------------------+-----------------------+-------------------------+
| ../datafusion/core/tests/data/fixed_size_list_array.parquet | 0 | 2 | 1 | 123 | 0 | 125 | 4 | "f0.list.item" | INT64 | 1 | 4 | 0 | | 1 | 4 | SNAPPY | [RLE_DICTIONARY, PLAIN, RLE] | | 4 | 46 | 121 | 123 |
+-------------------------------------------------------------+--------------+--------------------+-----------------------+-----------------+-----------+-------------+------------+----------------+-------+-----------+-----------+------------------+----------------------+-----------------+-----------------+-------------+------------------------------+-------------------+------------------------+------------------+-----------------------+-------------------------+
"#);

// input with double quote
let sql =
"SELECT * FROM parquet_metadata(\"../datafusion/core/tests/data/fixed_size_list_array.parquet\")";
let df = ctx.sql(sql).await?;
let rbs = df.collect().await?;
assert_batches_eq!(excepted, &rbs);
assert_snapshot!(batches_to_string(&rbs), @r#"
+-------------------------------------------------------------+--------------+--------------------+-----------------------+-----------------+-----------+-------------+------------+----------------+-------+-----------+-----------+------------------+----------------------+-----------------+-----------------+-------------+------------------------------+-------------------+------------------------+------------------+-----------------------+-------------------------+
| filename | row_group_id | row_group_num_rows | row_group_num_columns | row_group_bytes | column_id | file_offset | num_values | path_in_schema | type | stats_min | stats_max | stats_null_count | stats_distinct_count | stats_min_value | stats_max_value | compression | encodings | index_page_offset | dictionary_page_offset | data_page_offset | total_compressed_size | total_uncompressed_size |
+-------------------------------------------------------------+--------------+--------------------+-----------------------+-----------------+-----------+-------------+------------+----------------+-------+-----------+-----------+------------------+----------------------+-----------------+-----------------+-------------+------------------------------+-------------------+------------------------+------------------+-----------------------+-------------------------+
| ../datafusion/core/tests/data/fixed_size_list_array.parquet | 0 | 2 | 1 | 123 | 0 | 125 | 4 | "f0.list.item" | INT64 | 1 | 4 | 0 | | 1 | 4 | SNAPPY | [RLE_DICTIONARY, PLAIN, RLE] | | 4 | 46 | 121 | 123 |
+-------------------------------------------------------------+--------------+--------------------+-----------------------+-----------------+-----------+-------------+------------+----------------+-------+-----------+-----------+------------------+----------------------+-----------------+-----------------+-------------+------------------------------+-------------------+------------------------+------------------+-----------------------+-------------------------+
"#);

Ok(())
}
Expand All @@ -421,15 +427,13 @@ mod tests {
let df = ctx.sql(sql).await?;
let rbs = df.collect().await?;

let excepted = [

"+-----------------------------------------------------------------+--------------+--------------------+-----------------------+-----------------+-----------+-------------+------------+----------------+------------+-----------+-----------+------------------+----------------------+-----------------+-----------------+--------------------+--------------------------+-------------------+------------------------+------------------+-----------------------+-------------------------+",
"| filename | row_group_id | row_group_num_rows | row_group_num_columns | row_group_bytes | column_id | file_offset | num_values | path_in_schema | type | stats_min | stats_max | stats_null_count | stats_distinct_count | stats_min_value | stats_max_value | compression | encodings | index_page_offset | dictionary_page_offset | data_page_offset | total_compressed_size | total_uncompressed_size |",
"+-----------------------------------------------------------------+--------------+--------------------+-----------------------+-----------------+-----------+-------------+------------+----------------+------------+-----------+-----------+------------------+----------------------+-----------------+-----------------+--------------------+--------------------------+-------------------+------------------------+------------------+-----------------------+-------------------------+",
"| ../parquet-testing/data/data_index_bloom_encoding_stats.parquet | 0 | 14 | 1 | 163 | 0 | 4 | 14 | \"String\" | BYTE_ARRAY | Hello | today | 0 | | Hello | today | GZIP(GzipLevel(6)) | [BIT_PACKED, RLE, PLAIN] | | | 4 | 152 | 163 |",
"+-----------------------------------------------------------------+--------------+--------------------+-----------------------+-----------------+-----------+-------------+------------+----------------+------------+-----------+-----------+------------------+----------------------+-----------------+-----------------+--------------------+--------------------------+-------------------+------------------------+------------------+-----------------------+-------------------------+"
];
assert_batches_eq!(excepted, &rbs);
assert_snapshot!(batches_to_string(&rbs),@r#"
+-----------------------------------------------------------------+--------------+--------------------+-----------------------+-----------------+-----------+-------------+------------+----------------+------------+-----------+-----------+------------------+----------------------+-----------------+-----------------+--------------------+--------------------------+-------------------+------------------------+------------------+-----------------------+-------------------------+
| filename | row_group_id | row_group_num_rows | row_group_num_columns | row_group_bytes | column_id | file_offset | num_values | path_in_schema | type | stats_min | stats_max | stats_null_count | stats_distinct_count | stats_min_value | stats_max_value | compression | encodings | index_page_offset | dictionary_page_offset | data_page_offset | total_compressed_size | total_uncompressed_size |
+-----------------------------------------------------------------+--------------+--------------------+-----------------------+-----------------+-----------+-------------+------------+----------------+------------+-----------+-----------+------------------+----------------------+-----------------+-----------------+--------------------+--------------------------+-------------------+------------------------+------------------+-----------------------+-------------------------+
| ../parquet-testing/data/data_index_bloom_encoding_stats.parquet | 0 | 14 | 1 | 163 | 0 | 4 | 14 | "String" | BYTE_ARRAY | Hello | today | 0 | | Hello | today | GZIP(GzipLevel(6)) | [BIT_PACKED, RLE, PLAIN] | | | 4 | 152 | 163 |
+-----------------------------------------------------------------+--------------+--------------------+-----------------------+-----------------+-----------+-------------+------------+----------------+------------+-----------+-----------+------------------+----------------------+-----------------+-----------------+--------------------+--------------------------+-------------------+------------------------+------------------+-----------------------+-------------------------+
"#);

Ok(())
}
Expand Down
1 change: 1 addition & 0 deletions datafusion/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ web-time = "1.1.0"

[dev-dependencies]
chrono = { workspace = true }
insta = { workspace = true }
rand = { workspace = true }
73 changes: 34 additions & 39 deletions datafusion/common/src/scalar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use crate::cast::{
as_fixed_size_binary_array, as_fixed_size_list_array,
};
use crate::error::{DataFusionError, Result, _exec_err, _internal_err, _not_impl_err};
use crate::format::DEFAULT_CAST_OPTIONS;
use crate::hash_utils::create_hashes;
use crate::utils::SingleRowListArrayBuilder;
use arrow::array::{
Expand All @@ -58,8 +59,6 @@ use arrow::datatypes::{
UInt8Type, UnionFields, UnionMode, DECIMAL128_MAX_PRECISION,
};
use arrow::util::display::{array_value_to_string, ArrayFormatter, FormatOptions};

use crate::format::DEFAULT_CAST_OPTIONS;
use half::f16;
pub use struct_builder::ScalarStructBuilder;

Expand Down Expand Up @@ -3976,14 +3975,15 @@ mod tests {
as_map_array, as_string_array, as_struct_array, as_uint32_array, as_uint64_array,
};

use crate::assert_batches_eq;
use crate::test_util::batches_to_string;
use arrow::array::{types::Float64Type, NullBufferBuilder};
use arrow::buffer::{Buffer, OffsetBuffer};
use arrow::compute::{is_null, kernels};
use arrow::datatypes::Fields;
use arrow::error::ArrowError;
use arrow::util::pretty::pretty_format_columns;
use chrono::NaiveDate;
use insta::assert_snapshot;
use rand::Rng;

#[test]
Expand Down Expand Up @@ -6910,14 +6910,13 @@ mod tests {

//verify compared to arrow display
let batch = RecordBatch::try_from_iter(vec![("s", arr as _)]).unwrap();
let expected = [
"+-------------+",
"| s |",
"+-------------+",
"| {a: 1, b: } |",
"+-------------+",
];
assert_batches_eq!(&expected, &[batch]);
assert_snapshot!(batches_to_string(&[batch]), @r"
+-------------+
| s |
+-------------+
| {a: 1, b: } |
+-------------+
");
}

#[test]
Expand Down Expand Up @@ -6946,14 +6945,13 @@ mod tests {

//verify compared to arrow display
let batch = RecordBatch::try_from_iter(vec![("s", arr as _)]).unwrap();
let expected = [
"+--------------+",
"| s |",
"+--------------+",
"| {a: 1, b: 2} |",
"+--------------+",
];
assert_batches_eq!(&expected, &[batch]);
assert_snapshot!(batches_to_string(&[batch]), @r"
+--------------+
| s |
+--------------+
| {a: 1, b: 2} |
+--------------+
");
}

#[test]
Expand All @@ -6969,15 +6967,13 @@ mod tests {
//verify compared to arrow display
let batch = RecordBatch::try_from_iter(vec![("s", arr as _)]).unwrap();

#[rustfmt::skip]
let expected = [
"+---+",
"| s |",
"+---+",
"| |",
"+---+",
];
assert_batches_eq!(&expected, &[batch]);
assert_snapshot!(batches_to_string(&[batch]), @r"
+---+
| s |
+---+
| |
+---+
");
}

#[test]
Expand Down Expand Up @@ -7011,17 +7007,16 @@ mod tests {

//verify compared to arrow display
let batch = RecordBatch::try_from_iter(vec![("m", arr as _)]).unwrap();
let expected = [
"+--------------------+",
"| m |",
"+--------------------+",
"| {joe: 1} |",
"| {blogs: 2, foo: 4} |",
"| {} |",
"| |",
"+--------------------+",
];
assert_batches_eq!(&expected, &[batch]);
assert_snapshot!(batches_to_string(&[batch]), @r"
+--------------------+
| m |
+--------------------+
| {joe: 1} |
| {blogs: 2, foo: 4} |
| {} |
| |
+--------------------+
");
}

#[test]
Expand Down
18 changes: 9 additions & 9 deletions datafusion/core/src/execution/context/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ impl SessionContext {
#[cfg(test)]
mod tests {
use super::*;
use crate::assert_batches_eq;
use crate::test_util::{plan_and_collect, populate_csv_partitions};
use datafusion_common::test_util::batches_to_string;
use insta::assert_snapshot;

use tempfile::TempDir;

Expand All @@ -115,14 +116,13 @@ mod tests {
plan_and_collect(&ctx, "SELECT sum(c1), sum(c2), count(*) FROM test").await?;

assert_eq!(results.len(), 1);
let expected = [
"+--------------+--------------+----------+",
"| sum(test.c1) | sum(test.c2) | count(*) |",
"+--------------+--------------+----------+",
"| 10 | 110 | 20 |",
"+--------------+--------------+----------+",
];
assert_batches_eq!(expected, &results);
assert_snapshot!(batches_to_string(&results), @r"
+--------------+--------------+----------+
| sum(test.c1) | sum(test.c2) | count(*) |
+--------------+--------------+----------+
| 10 | 110 | 20 |
+--------------+--------------+----------+
");

Ok(())
}
Expand Down
Loading