Skip to content

Commit e574603

Browse files
committed
Add test for logical plan pretty-printing
1 parent 3db5082 commit e574603

1 file changed

Lines changed: 33 additions & 7 deletions

File tree

datafusion/core/tests/extension_types/pretty_print_data_frames.rs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@ use arrow_schema::{DataType, Field, Schema, SchemaRef};
44
use datafusion::dataframe::DataFrame;
55
use datafusion::error::Result;
66
use datafusion::prelude::SessionContext;
7+
use datafusion_common::metadata::FieldMetadata;
8+
use datafusion_common::ScalarValue;
9+
use datafusion_expr::{col, lit_with_metadata};
710
use insta::assert_snapshot;
811
use std::sync::Arc;
912

1013
fn test_schema() -> SchemaRef {
11-
Arc::new(Schema::new(vec![Field::new(
12-
"my_uuids",
13-
DataType::FixedSizeBinary(16),
14-
false,
15-
)
16-
.with_extension_type(Uuid)]))
14+
Arc::new(Schema::new(vec![uuid_field()]))
15+
}
16+
17+
fn uuid_field() -> Field {
18+
Field::new("my_uuids", DataType::FixedSizeBinary(16), false).with_extension_type(Uuid)
1719
}
1820

1921
async fn create_test_table() -> Result<DataFrame> {
@@ -36,7 +38,7 @@ async fn create_test_table() -> Result<DataFrame> {
3638
}
3739

3840
#[tokio::test]
39-
async fn test_pretty_print_extension_types() -> Result<()> {
41+
async fn test_pretty_print_logical_plan() -> Result<()> {
4042
let result = create_test_table().await?.to_string().await?;
4143

4244
assert_snapshot!(
@@ -53,3 +55,27 @@ async fn test_pretty_print_extension_types() -> Result<()> {
5355

5456
Ok(())
5557
}
58+
59+
#[tokio::test]
60+
async fn test_pretty_print_extension_types() -> Result<()> {
61+
let scalar = ScalarValue::FixedSizeBinary(
62+
16,
63+
Some(vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 5, 6]),
64+
);
65+
let literal =
66+
lit_with_metadata(scalar, Some(FieldMetadata::new_from_field(&uuid_field())));
67+
68+
let df = create_test_table()
69+
.await?
70+
.filter(col("my_uuids").eq(literal))?;
71+
72+
assert_snapshot!(
73+
df.logical_plan(),
74+
@r#"
75+
Filter: test.my_uuids = FixedSizeBinary(16, "0,1,2,3,4,5,6,7,8,9,0,1,2,3,5,6") FieldMetadata { inner: {"ARROW:extension:name": "arrow.uuid"} }
76+
TableScan: test
77+
"#
78+
);
79+
80+
Ok(())
81+
}

0 commit comments

Comments
 (0)