diff --git a/src/commands/split_column.rs b/src/commands/split_column.rs index b8f7be311e..49ca80926a 100644 --- a/src/commands/split_column.rs +++ b/src/commands/split_column.rs @@ -8,6 +8,8 @@ use log::trace; struct SplitColumnArgs { separator: Tagged, rest: Vec>, + #[serde(rename(deserialize = "collapse-empty"))] + collapse_empty: bool, } pub struct SplitColumn; @@ -28,12 +30,13 @@ impl WholeStreamCommand for SplitColumn { fn signature(&self) -> Signature { Signature::build("split-column") .required("separator", SyntaxType::Any) + .switch("collapse-empty") .rest() } } fn split_column( - SplitColumnArgs { separator, rest }: SplitColumnArgs, + SplitColumnArgs { separator, rest, collapse_empty}: SplitColumnArgs, RunnableContext { input, name, .. }: RunnableContext, ) -> Result { Ok(input @@ -43,8 +46,8 @@ fn split_column( let splitter = separator.replace("\\n", "\n"); trace!("splitting with {:?}", splitter); - let split_result: Vec<_> = if splitter.chars().all(|c| c.is_whitespace()) { - s.split(&splitter).filter(|s| *s != "").collect() + let split_result: Vec<_> = if collapse_empty { + s.split(&splitter).filter(|s| !s.is_empty()).collect() } else { s.split(&splitter).collect() };