Skip to content

PreCastLitInComparisonExpressions should use ExprRewriter and supported nested expressions #3259

@andygrove

Description

@andygrove

Is your feature request related to a problem or challenge? Please describe what you are trying to do.
PreCastLitInComparisonExpressions does not use ExprRewriter so does not support some nested expressions, such as aliased expressions.

Failing test to demonstrate the issue. It works if the aliases are removed.

  #[test]
  fn nested() {
      let schema = expr_test_schema();
      // c1 < INT64(16) -> c1 < cast(INT32(16))
      // the 16 is within the range of MAX(int32) and MIN(int32), we can cast the 16 to int32(16)
      let expr_lt = col("c1").lt(lit(ScalarValue::Int64(Some(16)))).alias("x");
      let expected = col("c1").lt(lit(ScalarValue::Int32(Some(16)))).alias("x");
      assert_eq!(optimize_test(expr_lt, &schema), expected);
  }

Describe the solution you'd like
Use ExprRewriter and support nested expressions.

Describe alternatives you've considered
None

Additional context
None

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions