refactor: Clean up code by using `lit` and `lit_timestamp_nano` rather than `Expr::Literal(ScalarValue(Some(...)))` (#3427)
parent
6d20ce1f9e
commit
80c048528c
|
@ -1910,7 +1910,7 @@ impl<'a> ExprRewriter for FieldValueRewriter<'a> {
|
|||
op,
|
||||
right: right.as_expr(),
|
||||
});
|
||||
return Ok(Expr::Literal(ScalarValue::Boolean(Some(true))));
|
||||
return Ok(lit(true));
|
||||
}
|
||||
}
|
||||
expr
|
||||
|
@ -1954,7 +1954,7 @@ impl<'a> ExprRewriter for FieldColumnRewriter<'a> {
|
|||
|
||||
if let Expr::Literal(ScalarValue::Utf8(Some(name))) = &**right {
|
||||
self.field_projections.insert(name.to_owned());
|
||||
return Ok(Expr::Literal(ScalarValue::Boolean(Some(true))));
|
||||
return Ok(lit(true));
|
||||
}
|
||||
}
|
||||
expr
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
|
||||
use std::sync::Arc;
|
||||
|
||||
use datafusion::{
|
||||
logical_plan::{col, Expr, LogicalPlan, LogicalPlanBuilder},
|
||||
scalar::ScalarValue,
|
||||
};
|
||||
use datafusion::logical_plan::{col, lit_timestamp_nano, LogicalPlan, LogicalPlanBuilder};
|
||||
use observability_deps::tracing::{debug, trace};
|
||||
use schema::{sort::SortKey, Schema, TIME_COLUMN_NAME};
|
||||
|
||||
|
@ -204,8 +201,7 @@ impl ReorgPlanner {
|
|||
trace!(output_schema=?schema, "Setting sort key on schema for split plan");
|
||||
|
||||
// time <= split_time
|
||||
let ts_literal = Expr::Literal(ScalarValue::TimestampNanosecond(Some(split_time), None));
|
||||
let split_expr = col(TIME_COLUMN_NAME).lt_eq(ts_literal);
|
||||
let split_expr = col(TIME_COLUMN_NAME).lt_eq(lit_timestamp_nano(split_time));
|
||||
|
||||
let plan = plan_builder.build().context(BuildingPlan)?;
|
||||
|
||||
|
|
|
@ -4036,10 +4036,7 @@ west,host-c,pro,10,6
|
|||
assert_eq!(result, to_map(vec![]));
|
||||
}
|
||||
|
||||
use datafusion::{
|
||||
logical_plan::{col, Expr},
|
||||
scalar::ScalarValue,
|
||||
};
|
||||
use datafusion::logical_plan::{col, lit, lit_timestamp_nano};
|
||||
use std::convert::TryFrom;
|
||||
|
||||
#[test]
|
||||
|
@ -4047,50 +4044,47 @@ west,host-c,pro,10,6
|
|||
let cases = vec![
|
||||
(
|
||||
// a = 22
|
||||
col("a").eq(Expr::Literal(ScalarValue::Int64(Some(22)))),
|
||||
col("a").eq(lit(22_i64)),
|
||||
BinaryExpr::from(("a", "=", 22_i64)),
|
||||
),
|
||||
(
|
||||
// a > 10
|
||||
col("a").gt(Expr::Literal(ScalarValue::Int64(Some(10)))),
|
||||
col("a").gt(lit(10_i64)),
|
||||
BinaryExpr::from(("a", ">", 10_i64)),
|
||||
),
|
||||
(
|
||||
// 100 = c
|
||||
Expr::Literal(ScalarValue::Int64(Some(100))).eq(col("c")),
|
||||
lit(100_i64).eq(col("c")),
|
||||
BinaryExpr::from(("c", "=", 100_i64)),
|
||||
),
|
||||
(
|
||||
// 100 != c
|
||||
Expr::Literal(ScalarValue::Int64(Some(100))).not_eq(col("c")),
|
||||
lit(100_i64).not_eq(col("c")),
|
||||
BinaryExpr::from(("c", "!=", 100_i64)),
|
||||
),
|
||||
(
|
||||
// 100 < c
|
||||
Expr::Literal(ScalarValue::Int64(Some(100))).lt(col("c")),
|
||||
lit(100_i64).lt(col("c")),
|
||||
BinaryExpr::from(("c", ">", 100_i64)),
|
||||
),
|
||||
(
|
||||
// 100 <= c
|
||||
Expr::Literal(ScalarValue::Int64(Some(100))).lt_eq(col("c")),
|
||||
lit(100_i64).lt_eq(col("c")),
|
||||
BinaryExpr::from(("c", ">=", 100_i64)),
|
||||
),
|
||||
(
|
||||
// 100 >= c
|
||||
Expr::Literal(ScalarValue::Int64(Some(100))).gt_eq(col("c")),
|
||||
lit(100_i64).gt_eq(col("c")),
|
||||
BinaryExpr::from(("c", "<=", 100_i64)),
|
||||
),
|
||||
(
|
||||
// 100 > c
|
||||
Expr::Literal(ScalarValue::Int64(Some(100))).gt(col("c")),
|
||||
lit(100_i64).gt(col("c")),
|
||||
BinaryExpr::from(("c", "<", 100_i64)),
|
||||
),
|
||||
(
|
||||
// a = timestamp(100000)
|
||||
col("a").eq(Expr::Literal(ScalarValue::TimestampNanosecond(
|
||||
Some(1000000),
|
||||
None,
|
||||
))),
|
||||
col("a").eq(lit_timestamp_nano(1000000)),
|
||||
BinaryExpr::from(("a", "=", 1000000_i64)),
|
||||
),
|
||||
];
|
||||
|
@ -4102,8 +4096,7 @@ west,host-c,pro,10,6
|
|||
// Error cases
|
||||
let cases = vec![
|
||||
// 33 = 33
|
||||
Expr::Literal(ScalarValue::Int64(Some(33)))
|
||||
.eq(Expr::Literal(ScalarValue::Int64(Some(33)))),
|
||||
lit(33i64).eq(lit(33i64)),
|
||||
// a > b
|
||||
col("a").gt(col("b")),
|
||||
];
|
||||
|
|
Loading…
Reference in New Issue