Skip to content
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

Standardize the separator in name #10363

Closed
wants to merge 11 commits into from
Closed
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
182 changes: 74 additions & 108 deletions datafusion-examples/examples/regexp.rs

Large diffs are not rendered by default.

94 changes: 47 additions & 47 deletions datafusion-examples/examples/to_char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ async fn main() -> Result<()> {

assert_batches_eq!(
&[
"+------------------------------+",
"| to_char(t.values,t.patterns) |",
"+------------------------------+",
"| 2020-09-01 |",
"| 2020:09:02 |",
"| 20200903 |",
"| 04-09-2020 |",
"+------------------------------+",
"+-------------------------------+",
"| to_char(t.values, t.patterns) |",
"+-------------------------------+",
"| 2020-09-01 |",
"| 2020:09:02 |",
"| 20200903 |",
"| 04-09-2020 |",
"+-------------------------------+"
],
&result
);
Expand All @@ -83,14 +83,14 @@ async fn main() -> Result<()> {

assert_batches_eq!(
&[
"+------------------------------+",
"| to_char(t.values,t.patterns) |",
"+------------------------------+",
"| 2020-09-01 |",
"| 2020:09:02 |",
"| 20200903 |",
"| 04-09-2020 |",
"+------------------------------+",
"+-------------------------------+",
"| to_char(t.values, t.patterns) |",
"+-------------------------------+",
"| 2020-09-01 |",
"| 2020:09:02 |",
"| 20200903 |",
"| 04-09-2020 |",
"+-------------------------------+"
],
&result
);
Expand All @@ -104,14 +104,14 @@ async fn main() -> Result<()> {

assert_batches_eq!(
&[
"+------------------------------------+",
"| to_char(t.values,Utf8(\"%m-%d-%Y\")) |",
"+------------------------------------+",
"| 09-01-2020 |",
"| 09-02-2020 |",
"| 09-03-2020 |",
"| 09-04-2020 |",
"+------------------------------------+",
"+-------------------------------------+",
"| to_char(t.values, Utf8(\"%m-%d-%Y\")) |",
"+-------------------------------------+",
"| 09-01-2020 |",
"| 09-02-2020 |",
"| 09-03-2020 |",
"| 09-04-2020 |",
"+-------------------------------------+"
],
&result
);
Expand All @@ -125,14 +125,14 @@ async fn main() -> Result<()> {

assert_batches_eq!(
&[
"+-----------------------------------+",
"| arrow_cast(t.values,Utf8(\"Utf8\")) |",
"+-----------------------------------+",
"| 2020-09-01 |",
"| 2020-09-02 |",
"| 2020-09-03 |",
"| 2020-09-04 |",
"+-----------------------------------+",
"+------------------------------------+",
"| arrow_cast(t.values, Utf8(\"Utf8\")) |",
"+------------------------------------+",
"| 2020-09-01 |",
"| 2020-09-02 |",
"| 2020-09-03 |",
"| 2020-09-04 |",
"+------------------------------------+"
],
&result
);
Expand All @@ -146,11 +146,11 @@ async fn main() -> Result<()> {

assert_batches_eq!(
&[
"+-------------------------------------------------------------------------------------------------------------+",
"| to_char(arrow_cast(Utf8(\"2023-08-03 14:38:50Z\"),Utf8(\"Timestamp(Second, None)\")),Utf8(\"%d-%m-%Y %H:%M:%S\")) |",
"+-------------------------------------------------------------------------------------------------------------+",
"| 03-08-2023 14:38:50 |",
"+-------------------------------------------------------------------------------------------------------------+",
"+---------------------------------------------------------------------------------------------------------------+",
"| to_char(arrow_cast(Utf8(\"2023-08-03 14:38:50Z\"), Utf8(\"Timestamp(Second, None)\")), Utf8(\"%d-%m-%Y %H:%M:%S\")) |",
"+---------------------------------------------------------------------------------------------------------------+",
"| 03-08-2023 14:38:50 |",
"+---------------------------------------------------------------------------------------------------------------+"
],
&result
);
Expand All @@ -165,11 +165,11 @@ async fn main() -> Result<()> {

assert_batches_eq!(
&[
"+----------------------------------------------------------------------------+",
"| to_char(arrow_cast(Int64(123456),Utf8(\"Duration(Second)\")),Utf8(\"pretty\")) |",
"+----------------------------------------------------------------------------+",
"| 1 days 10 hours 17 mins 36 secs |",
"+----------------------------------------------------------------------------+",
"+------------------------------------------------------------------------------+",
"| to_char(arrow_cast(Int64(123456), Utf8(\"Duration(Second)\")), Utf8(\"pretty\")) |",
"+------------------------------------------------------------------------------+",
"| 1 days 10 hours 17 mins 36 secs |",
"+------------------------------------------------------------------------------+"
],
&result
);
Expand All @@ -184,11 +184,11 @@ async fn main() -> Result<()> {

assert_batches_eq!(
&[
"+-----------------------------------------------------------------------------+",
"| to_char(arrow_cast(Int64(123456),Utf8(\"Duration(Second)\")),Utf8(\"iso8601\")) |",
"+-----------------------------------------------------------------------------+",
"| PT123456S |",
"+-----------------------------------------------------------------------------+",
"+-------------------------------------------------------------------------------+",
"| to_char(arrow_cast(Int64(123456), Utf8(\"Duration(Second)\")), Utf8(\"iso8601\")) |",
"+-------------------------------------------------------------------------------+",
"| PT123456S |",
"+-------------------------------------------------------------------------------+"
],
&result
);
Expand Down
16 changes: 16 additions & 0 deletions datafusion/common/src/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ macro_rules! assert_batches_eq {
};
}

#[macro_export]
macro_rules! assert_snapshot {
($CHUNKS: expr) => {
let formatted = $crate::arrow::util::pretty::pretty_format_batches_with_options(
$CHUNKS,
&$crate::format::DEFAULT_FORMAT_OPTIONS,
)
.unwrap()
.to_string();

let actual_lines: Vec<&str> = formatted.trim().lines().collect();

insta::assert_yaml_snapshot!(actual_lines);
};
}

Comment on lines +55 to +70
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use this for tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test with insta. Because changing them manually is painful. I did this in datafusion-example, since they are not test.

/// Compares formatted output of a record batch with an expected
/// vector of strings in a way that order does not matter.
/// This is a macro so errors appear on the correct line
Expand Down
1 change: 1 addition & 0 deletions datafusion/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ ctor = { workspace = true }
doc-comment = { workspace = true }
env_logger = { workspace = true }
half = { workspace = true, default-features = true }
insta = { version = "1.38.0", features = ["yaml"] }
paste = "^1.0"
postgres-protocol = "0.6.4"
postgres-types = { version = "0.2.4", features = ["derive", "with-chrono-0_4"] }
Expand Down
4 changes: 2 additions & 2 deletions datafusion/core/src/physical_planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ fn create_function_physical_name(
false => "",
};

let phys_name = format!("{}({}{})", fun, distinct_str, names.join(","));
let phys_name = format!("{}({}{})", fun, distinct_str, names.join(", "));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the changes in this file the only in the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several one, but are all like this


Ok(order_by
.map(|order_by| format!("{} ORDER BY [{}]", phys_name, expr_vec_fmt!(order_by)))
Expand Down Expand Up @@ -274,7 +274,7 @@ fn create_physical_name(e: &Expr, is_first_expr: bool) -> Result<String> {
.iter()
.map(|e| create_physical_name(e, false))
.collect::<Result<Vec<_>>>()?;
Ok(format!("{}({})", fun.name(), names.join(",")))
Ok(format!("{}({})", fun.name(), names.join(", ")))
}
},
Expr::GroupingSet(grouping_set) => match grouping_set {
Expand Down
Loading