diff --git a/src/commands/_sample/spl.rs b/src/commands/_sample/spl.rs index b695ab6..6471ea7 100644 --- a/src/commands/_sample/spl.rs +++ b/src/commands/_sample/spl.rs @@ -4,7 +4,7 @@ use crate::commands::ConvertCommandRoot; use crate::spl::ast; use crate::spl::ast::ParsedCommandOptions; use crate::spl::parser::{field, token, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::bytes::complete::{tag, tag_no_case}; use nom::combinator::{map, opt}; use nom::multi::many0; diff --git a/src/commands/cmd_add_totals/spl.rs b/src/commands/cmd_add_totals/spl.rs index 243db56..27919be 100644 --- a/src/commands/cmd_add_totals/spl.rs +++ b/src/commands/cmd_add_totals/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Field, ParsedCommandOptions}; use crate::spl::parser::{field, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::combinator::map; use nom::multi::many0; use nom::sequence::pair; diff --git a/src/commands/cmd_bin/spl.rs b/src/commands/cmd_bin/spl.rs index 0de8c21..28ee06f 100644 --- a/src/commands/cmd_bin/spl.rs +++ b/src/commands/cmd_bin/spl.rs @@ -1,8 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; -use crate::spl::ast; -use crate::spl::ast::{FieldOrAlias, ParsedCommandOptions, TimeSpan}; +use crate::spl::ast::*; use crate::spl::parser::{aliased_field, field}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::branch::alt; use nom::combinator::{into, map}; use nom::sequence::pair; @@ -59,12 +58,8 @@ impl TryFrom for BinCommandOptions { fn try_from(value: ParsedCommandOptions) -> Result { Ok(Self { - span: value.get_span_option("span")?.map(|span| match span { - ast::SplSpan::TimeSpan(s) => s, - }), - min_span: value.get_span_option("minspan")?.map(|span| match span { - ast::SplSpan::TimeSpan(s) => s, - }), + span: value.get_span_option("span")?, + min_span: value.get_span_option("minspan")?, bins: value.get_int_option("bins")?, start: value.get_int_option("start")?, end: value.get_int_option("end")?, @@ -122,12 +117,12 @@ mod tests { Ok(( "", BinCommand { - field: _alias("bar", ast::Field::from("foo")).into(), - span: Some(ast::TimeSpan { + field: _alias("bar", Field::from("foo")).into(), + span: Some(TimeSpan { value: 30, scale: "minutes".into() }), - min_span: Some(ast::TimeSpan { + min_span: Some(TimeSpan { value: 5, scale: "minutes".into() }), diff --git a/src/commands/cmd_collect/spl.rs b/src/commands/cmd_collect/spl.rs index a5e9ade..f91bf1a 100644 --- a/src/commands/cmd_collect/spl.rs +++ b/src/commands/cmd_collect/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Field, ParsedCommandOptions}; use crate::spl::parser::field_list0; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use anyhow::anyhow; use nom::combinator::map; use nom::sequence::pair; diff --git a/src/commands/cmd_convert/spl.rs b/src/commands/cmd_convert/spl.rs index 4f3e3fc..ececc06 100644 --- a/src/commands/cmd_convert/spl.rs +++ b/src/commands/cmd_convert/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Field, ParsedCommandOptions}; use crate::spl::parser::{field, token, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::bytes::complete::{tag, tag_no_case}; use nom::combinator::{map, opt}; use nom::multi::many0; diff --git a/src/commands/cmd_dedup/spl.rs b/src/commands/cmd_dedup/spl.rs index f700fb9..dce555b 100644 --- a/src/commands/cmd_dedup/spl.rs +++ b/src/commands/cmd_dedup/spl.rs @@ -3,7 +3,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast; use crate::spl::ast::{Field, ParsedCommandOptions}; use crate::spl::parser::{field, int, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::branch::alt; use nom::bytes::complete::{tag, tag_no_case}; use nom::combinator::{map, opt, verify}; diff --git a/src/commands/cmd_eval/spl.rs b/src/commands/cmd_eval/spl.rs index ba9bdcf..3f79cc9 100644 --- a/src/commands/cmd_eval/spl.rs +++ b/src/commands/cmd_eval/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Expr, Field, ParsedCommandOptions}; use crate::spl::parser::{comma_separated_list0, expr, field, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::bytes::complete::tag; use nom::combinator::map; use nom::sequence::separated_pair; diff --git a/src/commands/cmd_event_stats/spl.rs b/src/commands/cmd_event_stats/spl.rs index c3d90b8..083fc37 100644 --- a/src/commands/cmd_event_stats/spl.rs +++ b/src/commands/cmd_event_stats/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Expr, Field, ParsedCommandOptions}; use crate::spl::parser::{field_list0, stats_call, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::bytes::complete::tag_no_case; use nom::combinator::{map, opt}; use nom::sequence::{preceded, tuple}; diff --git a/src/commands/cmd_fields/spl.rs b/src/commands/cmd_fields/spl.rs index 5581306..4415724 100644 --- a/src/commands/cmd_fields/spl.rs +++ b/src/commands/cmd_fields/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Field, ParsedCommandOptions}; use crate::spl::parser::{field_list1, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::branch::alt; use nom::bytes::complete::tag; use nom::combinator::{map, opt}; diff --git a/src/commands/cmd_fill_null/spl.rs b/src/commands/cmd_fill_null/spl.rs index fb98125..36bb323 100644 --- a/src/commands/cmd_fill_null/spl.rs +++ b/src/commands/cmd_fill_null/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Field, ParsedCommandOptions}; use crate::spl::parser::{double_quoted, field, token, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::branch::alt; use nom::bytes::complete::tag; use nom::combinator::{into, map, opt}; diff --git a/src/commands/cmd_format/spl.rs b/src/commands/cmd_format/spl.rs index 32b2f17..62f7924 100644 --- a/src/commands/cmd_format/spl.rs +++ b/src/commands/cmd_format/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::ParsedCommandOptions; use crate::spl::parser::{double_quoted, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::combinator::{map, opt}; use nom::sequence::{pair, tuple}; use nom::IResult; diff --git a/src/commands/cmd_head/spl.rs b/src/commands/cmd_head/spl.rs index 22331c3..eee436d 100644 --- a/src/commands/cmd_head/spl.rs +++ b/src/commands/cmd_head/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{BoolValue, Expr, ParsedCommandOptions}; use crate::spl::parser::{bool_, expr, int, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::branch::alt; use nom::bytes::complete::tag_no_case; use nom::combinator::{map, opt}; diff --git a/src/commands/cmd_input_lookup/spl.rs b/src/commands/cmd_input_lookup/spl.rs index 75ef441..4f73643 100644 --- a/src/commands/cmd_input_lookup/spl.rs +++ b/src/commands/cmd_input_lookup/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Expr, ParsedCommandOptions}; use crate::spl::parser::{expr, token, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::bytes::complete::tag_no_case; use nom::combinator::{map, opt}; use nom::sequence::{preceded, tuple}; diff --git a/src/commands/cmd_join/spl.rs b/src/commands/cmd_join/spl.rs index f68e3d9..d4536d7 100644 --- a/src/commands/cmd_join/spl.rs +++ b/src/commands/cmd_join/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Field, ParsedCommandOptions, Pipeline}; use crate::spl::parser::{field_list1, sub_search}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::combinator::map; use nom::sequence::tuple; use nom::IResult; diff --git a/src/commands/cmd_lookup/spl.rs b/src/commands/cmd_lookup/spl.rs index 16a9fa1..88575d9 100644 --- a/src/commands/cmd_lookup/spl.rs +++ b/src/commands/cmd_lookup/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{FieldLike, ParsedCommandOptions}; use crate::spl::parser::{aliased_field, comma_or_space_separated_list1, field, token, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::branch::alt; use nom::bytes::complete::tag_no_case; use nom::character::complete::multispace1; diff --git a/src/commands/cmd_make_results/spl.rs b/src/commands/cmd_make_results/spl.rs index cb74dbf..b9d42de 100644 --- a/src/commands/cmd_make_results/spl.rs +++ b/src/commands/cmd_make_results/spl.rs @@ -1,6 +1,6 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::ParsedCommandOptions; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::combinator::map; use nom::IResult; use pyo3::prelude::*; diff --git a/src/commands/cmd_map/spl.rs b/src/commands/cmd_map/spl.rs index 2849984..cb3569a 100644 --- a/src/commands/cmd_map/spl.rs +++ b/src/commands/cmd_map/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{ParsedCommandOptions, Pipeline}; use crate::spl::parser::quoted_search; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::combinator::map; use nom::sequence::pair; use nom::IResult; diff --git a/src/commands/cmd_multi_search/spl.rs b/src/commands/cmd_multi_search/spl.rs index 9ed3763..69428f3 100644 --- a/src/commands/cmd_multi_search/spl.rs +++ b/src/commands/cmd_multi_search/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{ParsedCommandOptions, Pipeline}; use crate::spl::parser::{sub_search, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::combinator::map; use nom::multi::many_m_n; use nom::IResult; diff --git a/src/commands/cmd_mv_combine/spl.rs b/src/commands/cmd_mv_combine/spl.rs index c9966bb..ff6bd68 100644 --- a/src/commands/cmd_mv_combine/spl.rs +++ b/src/commands/cmd_mv_combine/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Field, ParsedCommandOptions}; use crate::spl::parser::{double_quoted, field, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::bytes::complete::{tag, tag_no_case}; use nom::combinator::{map, opt}; use nom::sequence::{pair, preceded}; diff --git a/src/commands/cmd_mv_expand/spl.rs b/src/commands/cmd_mv_expand/spl.rs index fd8e4d5..943e123 100644 --- a/src/commands/cmd_mv_expand/spl.rs +++ b/src/commands/cmd_mv_expand/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Field, ParsedCommandOptions}; use crate::spl::parser::{field, int, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::bytes::complete::{tag, tag_no_case}; use nom::combinator::{map, opt}; use nom::sequence::{pair, preceded}; diff --git a/src/commands/cmd_rare/spl.rs b/src/commands/cmd_rare/spl.rs index ba8208a..f6441b6 100644 --- a/src/commands/cmd_rare/spl.rs +++ b/src/commands/cmd_rare/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Field, ParsedCommandOptions}; use crate::spl::parser::{field_list0, int, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::bytes::complete::tag_no_case; use nom::combinator::{map, opt}; use nom::sequence::{preceded, tuple}; diff --git a/src/commands/cmd_regex/spl.rs b/src/commands/cmd_regex/spl.rs index aef174b..845232f 100644 --- a/src/commands/cmd_regex/spl.rs +++ b/src/commands/cmd_regex/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Field, ParsedCommandOptions}; use crate::spl::parser::{double_quoted, field, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::branch::alt; use nom::bytes::complete::tag; use nom::combinator::{map, opt}; diff --git a/src/commands/cmd_rename/spl.rs b/src/commands/cmd_rename/spl.rs index 62861cd..cc691c6 100644 --- a/src/commands/cmd_rename/spl.rs +++ b/src/commands/cmd_rename/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Alias, ParsedCommandOptions}; use crate::spl::parser::{aliased_field, comma_separated_list1}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::combinator::map; use nom::IResult; use pyo3::prelude::*; diff --git a/src/commands/cmd_return/spl.rs b/src/commands/cmd_return/spl.rs index 5fd4b12..cf85f8a 100644 --- a/src/commands/cmd_return/spl.rs +++ b/src/commands/cmd_return/spl.rs @@ -2,7 +2,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast; use crate::spl::ast::{FieldOrAlias, IntValue, ParsedCommandOptions}; use crate::spl::parser::{field, field_and_value, int, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::branch::alt; use nom::bytes::complete::tag; use nom::combinator::{map, opt}; diff --git a/src/commands/cmd_rex/spl.rs b/src/commands/cmd_rex/spl.rs index bcfe5b0..5798754 100644 --- a/src/commands/cmd_rex/spl.rs +++ b/src/commands/cmd_rex/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::ParsedCommandOptions; use crate::spl::parser::double_quoted; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use anyhow::ensure; use nom::combinator::map; use nom::sequence::pair; diff --git a/src/commands/cmd_s_path/spl.rs b/src/commands/cmd_s_path/spl.rs index 5c8aed0..3e78c0d 100644 --- a/src/commands/cmd_s_path/spl.rs +++ b/src/commands/cmd_s_path/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::ParsedCommandOptions; use crate::spl::parser::{field, string, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::bytes::complete::tag_no_case; use nom::combinator::{map, opt}; use nom::sequence::{preceded, tuple}; diff --git a/src/commands/cmd_search/spl.rs b/src/commands/cmd_search/spl.rs index 5182f83..eb9cc46 100644 --- a/src/commands/cmd_search/spl.rs +++ b/src/commands/cmd_search/spl.rs @@ -3,7 +3,7 @@ use crate::spl::ast::{Expr, ParsedCommandOptions}; use crate::spl::operators; use crate::spl::operators::OperatorSymbolTrait; use crate::spl::parser::{combine_all_expressions, comma_or_space_separated_list1, expr}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::branch::alt; use nom::bytes::complete::tag_no_case; use nom::character::complete::{multispace0, multispace1}; diff --git a/src/commands/cmd_sort/spl.rs b/src/commands/cmd_sort/spl.rs index b7a3b7d..9bf8d85 100644 --- a/src/commands/cmd_sort/spl.rs +++ b/src/commands/cmd_sort/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Expr, ParsedCommandOptions}; use crate::spl::parser::{comma_separated_list1, expr, int, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::branch::alt; use nom::bytes::complete::{tag, tag_no_case}; use nom::combinator::{map, opt}; diff --git a/src/commands/cmd_stats/spl.rs b/src/commands/cmd_stats/spl.rs index c0f0888..165fe3e 100644 --- a/src/commands/cmd_stats/spl.rs +++ b/src/commands/cmd_stats/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Expr, Field, ParsedCommandOptions}; use crate::spl::parser::{bool_, field_list1, stats_call, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::bytes::complete::{tag, tag_no_case}; use nom::combinator::{map, opt}; use nom::sequence::{pair, preceded, tuple}; diff --git a/src/commands/cmd_stream_stats/spl.rs b/src/commands/cmd_stream_stats/spl.rs index 24e2f29..44f0e82 100644 --- a/src/commands/cmd_stream_stats/spl.rs +++ b/src/commands/cmd_stream_stats/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Expr, Field, ParsedCommandOptions}; use crate::spl::parser::{field_list0, stats_call, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::bytes::complete::tag_no_case; use nom::combinator::{map, opt}; use nom::sequence::{preceded, tuple}; diff --git a/src/commands/cmd_t_stats/spl.rs b/src/commands/cmd_t_stats/spl.rs index c2edd74..dff9ff6 100644 --- a/src/commands/cmd_t_stats/spl.rs +++ b/src/commands/cmd_t_stats/spl.rs @@ -4,7 +4,7 @@ use crate::spl::parser::{ comma_or_space_separated_list1, field, field_in, logical_expression, space_separated_list1, time_span, token, ws, }; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::branch::alt; use nom::bytes::complete::{tag, tag_no_case}; use nom::character::complete::multispace1; diff --git a/src/commands/cmd_table/spl.rs b/src/commands/cmd_table/spl.rs index 06a10c1..020d9dc 100644 --- a/src/commands/cmd_table/spl.rs +++ b/src/commands/cmd_table/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Field, ParsedCommandOptions}; use crate::spl::parser::field_list1; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::combinator::map; use nom::IResult; use pyo3::prelude::*; diff --git a/src/commands/cmd_tail/spl.rs b/src/commands/cmd_tail/spl.rs index d20f673..f0187e9 100644 --- a/src/commands/cmd_tail/spl.rs +++ b/src/commands/cmd_tail/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::ParsedCommandOptions; use crate::spl::parser::int; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::combinator::map; use nom::IResult; use pyo3::prelude::*; diff --git a/src/commands/cmd_top/spl.rs b/src/commands/cmd_top/spl.rs index 74e11a2..61ae62b 100644 --- a/src/commands/cmd_top/spl.rs +++ b/src/commands/cmd_top/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Field, ParsedCommandOptions}; use crate::spl::parser::{field_list1, int, ws}; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::bytes::complete::tag_no_case; use nom::combinator::{map, opt}; use nom::sequence::{preceded, tuple}; diff --git a/src/commands/cmd_where/spl.rs b/src/commands/cmd_where/spl.rs index 31ed71b..ccf73dc 100644 --- a/src/commands/cmd_where/spl.rs +++ b/src/commands/cmd_where/spl.rs @@ -1,7 +1,7 @@ use crate::commands::spl::{SplCommand, SplCommandOptions}; use crate::spl::ast::{Expr, ParsedCommandOptions}; use crate::spl::parser::logical_expression; -use crate::spl::python::impl_pyclass; +use crate::spl::python::*; use nom::combinator::map; use nom::IResult; use pyo3::prelude::*; diff --git a/src/functions/mod.rs b/src/functions/mod.rs index 5073748..9dd4e8a 100644 --- a/src/functions/mod.rs +++ b/src/functions/mod.rs @@ -52,7 +52,7 @@ impl TryFrom for String { ast::Constant::SnapTime(_) => { bail!("No default conversion from {:?} to String", const_) } - ast::Constant::SplSpan(_) => { + ast::Constant::TimeSpan(_) => { bail!("No default conversion from {:?} to String", const_) } ast::Constant::Field(ast::Field(val)) => Ok(val.clone()), diff --git a/src/pyspark/transpiler/expr.rs b/src/pyspark/transpiler/expr.rs index 005e34f..75bcdfc 100644 --- a/src/pyspark/transpiler/expr.rs +++ b/src/pyspark/transpiler/expr.rs @@ -154,9 +154,9 @@ impl TryFrom for Expr { ast::Constant::SnapTime(ast::SnapTime { .. }) => { bail!("Unimplemented value in field-in rhs: {:?}", const_) } - ast::Constant::SplSpan(ast::SplSpan::TimeSpan(ast::TimeSpan { - .. - })) => bail!("Unimplemented value in field-in rhs: {:?}", const_), + ast::Constant::TimeSpan(ast::TimeSpan { .. }) => { + bail!("Unimplemented value in field-in rhs: {:?}", const_) + } ast::Constant::Field(ast::Field(val)) => { Ok(column_like!([c.clone()] == [Raw::from(val.clone())])) } diff --git a/src/spl/ast.rs b/src/spl/ast.rs index 978d4ec..07953b1 100644 --- a/src/spl/ast.rs +++ b/src/spl/ast.rs @@ -195,7 +195,7 @@ case class Pipeline(commands: Seq[Command]) use crate::commands::cmd_add_totals::spl::AddTotalsCommand; use crate::commands::cmd_bin::spl::BinCommand; use crate::commands::cmd_collect::spl::CollectCommand; -use crate::commands::cmd_convert::spl::{ConvertCommand, FieldConversion}; +use crate::commands::cmd_convert::spl::ConvertCommand; use crate::commands::cmd_dedup::spl::DedupCommand; use crate::commands::cmd_eval::spl::EvalCommand; use crate::commands::cmd_event_stats::spl::EventStatsCommand; @@ -243,45 +243,21 @@ pub struct NullValue(); #[pyclass(frozen, eq, hash)] pub struct BoolValue(pub bool); -impl> From for BoolValue { - fn from(value: T) -> Self { - BoolValue(value.into()) - } -} - /// Syntax tree element representing an integer literal value. #[derive(Debug, PartialEq, Clone, Hash)] #[pyclass(frozen, eq, hash)] pub struct IntValue(pub i64); -impl> From for IntValue { - fn from(value: T) -> Self { - IntValue(value.into()) - } -} - /// Syntax tree element representing a floating-point literal value. #[derive(Debug, PartialEq, Clone, FloatHash)] #[pyclass(frozen, eq, hash)] pub struct DoubleValue(pub f64); -impl> From for DoubleValue { - fn from(value: T) -> Self { - DoubleValue(value.into()) - } -} - /// Syntax tree element representing a string literal value. #[derive(Debug, PartialEq, Clone, Hash)] #[pyclass(frozen, eq, hash)] pub struct StrValue(pub String); -impl From for StrValue { - fn from(value: T) -> Self { - StrValue(value.to_string()) - } -} - /// Syntax tree element representing a duration with a value and a scale. /// /// # Fields @@ -312,42 +288,18 @@ pub struct SnapTime { #[pyclass(frozen, eq, hash)] pub struct Field(pub String); -impl From for Field { - fn from(value: S) -> Field { - Field(value.to_string()) - } -} - #[derive(Debug, PartialEq, Clone, Hash)] #[pyclass(frozen, eq, hash)] pub struct Wildcard(pub String); -impl From for Wildcard { - fn from(value: S) -> Wildcard { - Wildcard(value.to_string()) - } -} - #[derive(Debug, PartialEq, Clone, Hash)] #[pyclass(frozen, eq, hash)] pub struct Variable(pub String); -impl From for Variable { - fn from(value: S) -> Variable { - Variable(value.to_string()) - } -} - #[derive(Debug, PartialEq, Clone, Hash)] #[pyclass(frozen, eq, hash)] pub struct IPv4CIDR(pub String); -impl From for IPv4CIDR { - fn from(value: S) -> IPv4CIDR { - IPv4CIDR(value.to_string()) - } -} - #[derive(Debug, PartialEq, Clone, Hash)] #[pyclass(frozen, eq, hash)] pub struct FV { @@ -464,9 +416,9 @@ impl ParsedCommandOptions { .map(|v| v.unwrap_or(default.to_string())) } - pub fn get_span_option(&self, key: &str) -> Result, anyhow::Error> { + pub fn get_span_option(&self, key: &str) -> Result, anyhow::Error> { match self.inner.get(key) { - Some(Constant::SplSpan(span)) => Ok(Some(span.clone())), + Some(Constant::TimeSpan(span)) => Ok(Some(span.clone())), Some(_) => Err(anyhow!("not a span")), None => Ok(None), } @@ -494,15 +446,6 @@ pub struct AliasedField { pub alias: String, } -impl From for Alias { - fn from(value: AliasedField) -> Self { - Alias { - expr: Box::new(value.field.into()), - name: value.alias, - } - } -} - #[derive(Debug, PartialEq, Clone, Hash)] #[pyclass(frozen, eq, hash)] pub struct Binary { @@ -559,18 +502,19 @@ pub enum TimeModifier { Latest(SnapTime), } -/// A pipeline is a chain of commands where data is passed and processed by each command in turn. #[derive(Debug, PartialEq, Clone, Hash)] #[pyclass(frozen, eq, hash)] -pub struct Pipeline { - #[pyo3(get)] - pub commands: Vec, +pub struct FormattedTimeModifier { + pub format: String, + pub time_modifier: TimeModifier, } +/// A pipeline is a chain of commands where data is passed and processed by each command in turn. #[derive(Debug, PartialEq, Clone, Hash)] #[pyclass(frozen, eq, hash)] -pub enum SplSpan { - TimeSpan(TimeSpan), +pub struct Pipeline { + #[pyo3(get)] + pub commands: Vec, } #[derive(Debug, PartialEq, Clone, Hash)] @@ -582,7 +526,7 @@ pub enum Constant { Double(DoubleValue), Str(StrValue), SnapTime(SnapTime), - SplSpan(SplSpan), + TimeSpan(TimeSpan), Field(Field), Wildcard(Wildcard), Variable(Variable), @@ -621,174 +565,11 @@ pub enum Expr { Call(Call), FieldIn(FieldIn), Alias(Alias), - FieldConversion(FieldConversion), - TimeModifier(String, TimeModifier), + TimeModifier(FormattedTimeModifier), SearchModifier(SearchModifier), SubSearch(Pipeline), } -impl From for Constant { - fn from(val: TimeSpan) -> Self { - Constant::SplSpan(SplSpan::TimeSpan(val)) - } -} -impl From for Constant { - fn from(val: BoolValue) -> Self { - Constant::Bool(val) - } -} -impl From for Constant { - fn from(val: IntValue) -> Self { - Constant::Int(val) - } -} -impl From for Constant { - fn from(val: DoubleValue) -> Self { - Constant::Double(val) - } -} -impl From for Constant { - fn from(val: StrValue) -> Self { - Constant::Str(val) - } -} -impl From for Constant { - fn from(val: SnapTime) -> Self { - Constant::SnapTime(val) - } -} -impl From for Constant { - fn from(val: Field) -> Self { - Constant::Field(val) - } -} -impl From for Constant { - fn from(val: Wildcard) -> Self { - Constant::Wildcard(val) - } -} -impl From for Constant { - fn from(val: Variable) -> Self { - Constant::Variable(val) - } -} -impl From for Constant { - fn from(val: IPv4CIDR) -> Self { - Constant::IPv4CIDR(val) - } -} - -impl From for Expr { - fn from(val: Constant) -> Self { - Expr::Leaf(LeafExpr::Constant(val)) - } -} -impl From for Expr { - fn from(val: TimeSpan) -> Self { - >::into(val).into() - } -} -impl From for Expr { - fn from(val: BoolValue) -> Self { - >::into(val).into() - } -} -impl From for Expr { - fn from(val: IntValue) -> Self { - Expr::Leaf(LeafExpr::Constant(val.into())) - } -} -impl From for Expr { - fn from(val: DoubleValue) -> Self { - Expr::Leaf(LeafExpr::Constant(val.into())) - } -} -impl From for Expr { - fn from(val: StrValue) -> Self { - Expr::Leaf(LeafExpr::Constant(val.into())) - } -} -impl From for Expr { - fn from(val: SnapTime) -> Self { - Expr::Leaf(LeafExpr::Constant(val.into())) - } -} -impl From for Expr { - fn from(val: Field) -> Self { - Expr::Leaf(LeafExpr::Constant(val.into())) - } -} -impl From for Expr { - fn from(val: Wildcard) -> Self { - Expr::Leaf(LeafExpr::Constant(val.into())) - } -} -impl From for Expr { - fn from(val: Variable) -> Self { - Expr::Leaf(LeafExpr::Constant(val.into())) - } -} -impl From for Expr { - fn from(val: IPv4CIDR) -> Self { - Expr::Leaf(LeafExpr::Constant(val.into())) - } -} -impl From for Expr { - fn from(val: FV) -> Self { - Expr::Leaf(LeafExpr::FV(val)) - } -} -impl From for Expr { - fn from(val: FB) -> Self { - Expr::Leaf(LeafExpr::FB(val)) - } -} -impl From for Expr { - fn from(val: FC) -> Self { - Expr::Leaf(LeafExpr::FC(val)) - } -} -impl From for Expr { - fn from(val: AliasedField) -> Self { - Expr::AliasedField(val) - } -} -impl From for Expr { - fn from(val: Binary) -> Self { - Expr::Binary(val) - } -} -impl From for Expr { - fn from(val: Unary) -> Self { - Expr::Unary(val) - } -} -impl From for Expr { - fn from(val: Call) -> Self { - Expr::Call(val) - } -} -impl From for Expr { - fn from(val: FieldIn) -> Self { - Expr::FieldIn(val) - } -} -impl From for Expr { - fn from(val: Alias) -> Self { - Expr::Alias(val) - } -} -impl From for Expr { - fn from(val: FieldConversion) -> Self { - Expr::FieldConversion(val) - } -} -impl From for Expr { - fn from(val: SearchModifier) -> Self { - Expr::SearchModifier(val) - } -} - #[derive(Debug, PartialEq, Clone, Hash)] #[pyclass(frozen, eq, hash)] pub enum FieldLike { @@ -798,27 +579,6 @@ pub enum FieldLike { Alias(Alias), } -impl From for FieldLike { - fn from(val: Field) -> Self { - FieldLike::Field(val) - } -} -impl From for FieldLike { - fn from(val: Wildcard) -> Self { - FieldLike::Wildcard(val) - } -} -impl From for FieldLike { - fn from(val: AliasedField) -> Self { - FieldLike::AliasedField(val) - } -} -impl From for FieldLike { - fn from(val: Alias) -> Self { - FieldLike::Alias(val) - } -} - #[derive(Debug, PartialEq, Clone, Hash)] #[pyclass(frozen, eq, hash)] pub enum FieldOrAlias { @@ -826,22 +586,6 @@ pub enum FieldOrAlias { Alias(Alias), } -impl From for FieldOrAlias { - fn from(val: Field) -> Self { - FieldOrAlias::Field(val) - } -} -impl From for FieldOrAlias { - fn from(val: Alias) -> Self { - FieldOrAlias::Alias(val) - } -} -impl From for FieldOrAlias { - fn from(val: AliasedField) -> Self { - FieldOrAlias::Alias(val.into()) - } -} - #[allow(clippy::enum_variant_names)] #[derive(Debug, PartialEq, Clone, Hash)] #[pyclass(frozen, eq, hash)] @@ -880,47 +624,4 @@ pub enum Command { TopCommand(TopCommand), TStatsCommand(TStatsCommand), WhereCommand(WhereCommand), - // Pipeline(Pipeline), } - -// macro_rules! trivial_enum_from_type { -// ($cls:ident : $enum_tp:ident) => { -// impl From<$cls> for $enum_tp { -// fn from(val: $cls) -> Self { -// $enum_tp::$cls(val) -// } -// } -// }; -// } - -// trivial_enum_from_type!(AddTotalsCommand: Command); -// trivial_enum_from_type!(BinCommand: Command); -// trivial_enum_from_type!(CollectCommand: Command); -// trivial_enum_from_type!(ConvertCommand: Command); -// trivial_enum_from_type!(DedupCommand: Command); -// trivial_enum_from_type!(EvalCommand: Command); -// trivial_enum_from_type!(EventStatsCommand: Command); -// trivial_enum_from_type!(FieldsCommand: Command); -// trivial_enum_from_type!(FillNullCommand: Command); -// trivial_enum_from_type!(FormatCommand: Command); -// trivial_enum_from_type!(HeadCommand: Command); -// trivial_enum_from_type!(InputLookupCommand: Command); -// trivial_enum_from_type!(JoinCommand: Command); -// trivial_enum_from_type!(LookupCommand: Command); -// trivial_enum_from_type!(MakeResultsCommand: Command); -// trivial_enum_from_type!(MapCommand: Command); -// trivial_enum_from_type!(MultiSearchCommand: Command); -// trivial_enum_from_type!(MvCombineCommand: Command); -// trivial_enum_from_type!(MvExpandCommand: Command); -// trivial_enum_from_type!(RegexCommand: Command); -// trivial_enum_from_type!(RenameCommand: Command); -// trivial_enum_from_type!(ReturnCommand: Command); -// trivial_enum_from_type!(RexCommand: Command); -// trivial_enum_from_type!(SearchCommand: Command); -// trivial_enum_from_type!(SortCommand: Command); -// trivial_enum_from_type!(StatsCommand: Command); -// trivial_enum_from_type!(StreamStatsCommand: Command); -// trivial_enum_from_type!(TableCommand: Command); -// trivial_enum_from_type!(TopCommand: Command); -// trivial_enum_from_type!(TStatsCommand: Command); -// trivial_enum_from_type!(WhereCommand: Command); diff --git a/src/spl/ast_impls.rs b/src/spl/ast_impls.rs new file mode 100644 index 0000000..bfdfee6 --- /dev/null +++ b/src/spl/ast_impls.rs @@ -0,0 +1,296 @@ +use crate::spl::ast::{ + Alias, AliasedField, Binary, BoolValue, Call, Constant, DoubleValue, Expr, Field, FieldIn, + FieldLike, FieldOrAlias, FormattedTimeModifier, IPv4CIDR, IntValue, LeafExpr, SearchModifier, + SnapTime, StrValue, TimeSpan, Unary, Variable, Wildcard, FB, FC, FV, +}; + +impl> From for BoolValue { + fn from(value: T) -> Self { + BoolValue(value.into()) + } +} + +impl> From for IntValue { + fn from(value: T) -> Self { + IntValue(value.into()) + } +} + +impl> From for DoubleValue { + fn from(value: T) -> Self { + DoubleValue(value.into()) + } +} + +impl From for StrValue { + fn from(value: T) -> Self { + StrValue(value.to_string()) + } +} + +impl From for Field { + fn from(value: S) -> Field { + Field(value.to_string()) + } +} + +impl From for Wildcard { + fn from(value: S) -> Wildcard { + Wildcard(value.to_string()) + } +} + +impl From for Variable { + fn from(value: S) -> Variable { + Variable(value.to_string()) + } +} + +impl From for IPv4CIDR { + fn from(value: S) -> IPv4CIDR { + IPv4CIDR(value.to_string()) + } +} + +impl From for Alias { + fn from(value: AliasedField) -> Self { + Alias { + expr: Box::new(value.field.into()), + name: value.alias, + } + } +} + +impl From for Constant { + fn from(val: TimeSpan) -> Self { + Constant::TimeSpan(val) + } +} + +impl From for Constant { + fn from(val: BoolValue) -> Self { + Constant::Bool(val) + } +} + +impl From for Constant { + fn from(val: IntValue) -> Self { + Constant::Int(val) + } +} + +impl From for Constant { + fn from(val: DoubleValue) -> Self { + Constant::Double(val) + } +} + +impl From for Constant { + fn from(val: StrValue) -> Self { + Constant::Str(val) + } +} + +impl From for Constant { + fn from(val: SnapTime) -> Self { + Constant::SnapTime(val) + } +} + +impl From for Constant { + fn from(val: Field) -> Self { + Constant::Field(val) + } +} + +impl From for Constant { + fn from(val: Wildcard) -> Self { + Constant::Wildcard(val) + } +} + +impl From for Constant { + fn from(val: Variable) -> Self { + Constant::Variable(val) + } +} + +impl From for Constant { + fn from(val: IPv4CIDR) -> Self { + Constant::IPv4CIDR(val) + } +} + +impl From for Expr { + fn from(val: Constant) -> Self { + Expr::Leaf(LeafExpr::Constant(val)) + } +} + +impl From for Expr { + fn from(val: TimeSpan) -> Self { + >::into(val).into() + } +} + +impl From for Expr { + fn from(val: BoolValue) -> Self { + >::into(val).into() + } +} + +impl From for Expr { + fn from(val: IntValue) -> Self { + Expr::Leaf(LeafExpr::Constant(val.into())) + } +} + +impl From for Expr { + fn from(val: DoubleValue) -> Self { + Expr::Leaf(LeafExpr::Constant(val.into())) + } +} + +impl From for Expr { + fn from(val: StrValue) -> Self { + Expr::Leaf(LeafExpr::Constant(val.into())) + } +} + +impl From for Expr { + fn from(val: SnapTime) -> Self { + Expr::Leaf(LeafExpr::Constant(val.into())) + } +} + +impl From for Expr { + fn from(val: Field) -> Self { + Expr::Leaf(LeafExpr::Constant(val.into())) + } +} + +impl From for Expr { + fn from(val: Wildcard) -> Self { + Expr::Leaf(LeafExpr::Constant(val.into())) + } +} + +impl From for Expr { + fn from(val: Variable) -> Self { + Expr::Leaf(LeafExpr::Constant(val.into())) + } +} + +impl From for Expr { + fn from(val: IPv4CIDR) -> Self { + Expr::Leaf(LeafExpr::Constant(val.into())) + } +} + +impl From for Expr { + fn from(val: FV) -> Self { + Expr::Leaf(LeafExpr::FV(val)) + } +} + +impl From for Expr { + fn from(val: FB) -> Self { + Expr::Leaf(LeafExpr::FB(val)) + } +} + +impl From for Expr { + fn from(val: FC) -> Self { + Expr::Leaf(LeafExpr::FC(val)) + } +} + +impl From for Expr { + fn from(val: AliasedField) -> Self { + Expr::AliasedField(val) + } +} + +impl From for Expr { + fn from(val: Binary) -> Self { + Expr::Binary(val) + } +} + +impl From for Expr { + fn from(val: Unary) -> Self { + Expr::Unary(val) + } +} + +impl From for Expr { + fn from(val: Call) -> Self { + Expr::Call(val) + } +} + +impl From for Expr { + fn from(val: FieldIn) -> Self { + Expr::FieldIn(val) + } +} + +impl From for Expr { + fn from(val: Alias) -> Self { + Expr::Alias(val) + } +} + +impl From for Expr { + fn from(val: FormattedTimeModifier) -> Self { + Expr::TimeModifier(val) + } +} + +impl From for Expr { + fn from(val: SearchModifier) -> Self { + Expr::SearchModifier(val) + } +} + +impl From for FieldLike { + fn from(val: Field) -> Self { + FieldLike::Field(val) + } +} + +impl From for FieldLike { + fn from(val: Wildcard) -> Self { + FieldLike::Wildcard(val) + } +} + +impl From for FieldLike { + fn from(val: AliasedField) -> Self { + FieldLike::AliasedField(val) + } +} + +impl From for FieldLike { + fn from(val: Alias) -> Self { + FieldLike::Alias(val) + } +} + +impl From for FieldOrAlias { + fn from(val: Field) -> Self { + FieldOrAlias::Field(val) + } +} + +impl From for FieldOrAlias { + fn from(val: Alias) -> Self { + FieldOrAlias::Alias(val) + } +} + +impl From for FieldOrAlias { + fn from(val: AliasedField) -> Self { + FieldOrAlias::Alias(val.into()) + } +} diff --git a/src/spl/mod.rs b/src/spl/mod.rs index 3d296f3..f7d0a26 100644 --- a/src/spl/mod.rs +++ b/src/spl/mod.rs @@ -1,4 +1,5 @@ pub mod ast; +mod ast_impls; pub mod macros; pub mod operators; pub(crate) mod parser; diff --git a/src/spl/parser.rs b/src/spl/parser.rs index bc175ee..81719a8 100644 --- a/src/spl/parser.rs +++ b/src/spl/parser.rs @@ -625,9 +625,7 @@ pub fn literal(input: &str) -> IResult<&str, ast::Constant> { map(all_consuming(str_value), ast::Constant::Str), map(all_consuming(variable), ast::Constant::Variable), map(all_consuming(relative_time), ast::Constant::SnapTime), - map(all_consuming(time_span), |v| { - ast::Constant::SplSpan(ast::SplSpan::TimeSpan(v)) - }), + map(all_consuming(time_span), ast::Constant::TimeSpan), map(all_consuming(double), ast::Constant::Double), map(all_consuming(int), ast::Constant::Int), map(all_consuming(bool_), ast::Constant::Bool), @@ -640,20 +638,18 @@ pub fn constant(input: &str) -> IResult<&str, ast::Constant> { let (remaining, content) = recognize(alt((double_quoted, single_quoted, token_with_extras)))(input)?; let (_, parsed_value) = alt(( - map(all_consuming(ipv4_cidr), ast::Constant::IPv4CIDR), + into(all_consuming(ipv4_cidr)), map(all_consuming(ipv4_addr), |s| ast::Constant::Str(s.into())), map(all_consuming(ipv6_addr), |s| ast::Constant::Str(s.into())), - map(all_consuming(relative_time), ast::Constant::SnapTime), - map(all_consuming(time_span), |v| { - ast::Constant::SplSpan(ast::SplSpan::TimeSpan(v)) - }), - map(all_consuming(wildcard), ast::Constant::Wildcard), - map(all_consuming(str_value), ast::Constant::Str), - map(all_consuming(variable), ast::Constant::Variable), - map(all_consuming(double), ast::Constant::Double), - map(all_consuming(int), ast::Constant::Int), - map(all_consuming(field), ast::Constant::Field), - map(all_consuming(bool_), ast::Constant::Bool), + into(all_consuming(relative_time)), + into(all_consuming(time_span)), + into(all_consuming(wildcard)), + into(all_consuming(str_value)), + into(all_consuming(variable)), + into(all_consuming(double)), + into(all_consuming(int)), + into(all_consuming(field)), + into(all_consuming(bool_)), ))(content)?; Ok((remaining, parsed_value)) } @@ -1486,7 +1482,13 @@ pub fn time_opts(input: &str) -> IResult<&str, Vec> { pair(time_format, space_separated_list1(time_modifier)), |(fmt, mods)| { mods.into_iter() - .map(|time_mod| ast::Expr::TimeModifier(fmt.into(), time_mod)) + .map(|time_modifier| { + ast::FormattedTimeModifier { + format: fmt.into(), + time_modifier, + } + .into() + }) .collect() }, )(input) @@ -2064,10 +2066,10 @@ mod tests { }, ast::FC { field: "h".into(), - value: ast::Constant::SplSpan(ast::SplSpan::TimeSpan(ast::TimeSpan { + value: ast::Constant::TimeSpan(ast::TimeSpan { value: -15, scale: "minutes".to_string() - })) + }) }, ast::FC { field: "i".into(), diff --git a/src/spl/python.rs b/src/spl/python.rs index 33677a7..0460f10 100644 --- a/src/spl/python.rs +++ b/src/spl/python.rs @@ -30,22 +30,6 @@ macro_rules! impl_pyclass { } } }; - ($name: path {$(|$arg: ident : $arg_tp: ty| $conv: expr),*}) => { - #[pymethods] - impl $name { - #[allow(clippy::too_many_arguments)] - #[new] - fn new($( $arg: $arg_tp ),*) -> Self { - Self { $( $arg : (|$arg: $arg_tp| $conv)($arg) ),* } - } - - fn __repr__(&self) -> String { - format!("{:?}", self) - } - - $other - } - }; } pub(crate) use impl_pyclass; @@ -55,6 +39,10 @@ impl_pyclass!(ast::BoolValue { bool }); impl_pyclass!(ast::IntValue { i64 }); impl_pyclass!(ast::StrValue { String }); impl_pyclass!(ast::DoubleValue { f64 }); +impl_pyclass!(ast::TimeSpan { + value: i64, + scale: String +}); impl_pyclass!(ast::SnapTime { span: Option, snap: String, snap_offset: Option }); impl_pyclass!(ast::Field { String }); impl_pyclass!(ast::Wildcard { String }); @@ -157,6 +145,7 @@ pub fn ast(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; m.add_class::()?; m.add_class::()?; + m.add_class::()?; m.add_class::()?; m.add_class::()?; m.add_class::()?; @@ -205,7 +194,6 @@ pub fn ast(m: &Bound<'_, PyModule>) -> PyResult<()> { m.add_class::()?; m.add_class::()?; - m.add_class::()?; m.add_class::()?; m.add_class::()?; m.add_class::()?;