doris icon indicating copy to clipboard operation
doris copied to clipboard

[feature](nereids): SimplifyCastRule

Open jackwener opened this issue 3 years ago • 1 comments

Proposed changes

Issue Number: close #xxx

Problem summary

  • Remove redundant cast like
    • cast(1 as int) -> 1.
  • Merge cast like
    • cast(cast(1 as bigint) as string) -> cast(1 as string).

Checklist(Required)

  1. Does it affect the original behavior:
    • [x] Yes
    • [ ] No
    • [ ] I don't know
  2. Has unit tests been added:
    • [x] Yes
    • [ ] No
    • [ ] No Need
  3. Has document been added or modified:
    • [ ] Yes
    • [ ] No
    • [x] No Need
  4. Does it need to update dependencies:
    • [ ] Yes
    • [x] No
  5. Are there any changes that cannot be rolled back:
    • [ ] Yes (If Yes, please explain WHY)
    • [x] No

Further comments

If this is a relatively large or complex change, kick off the discussion at [email protected] by explaining why you chose the solution you did and what alternatives you considered, etc...

jackwener avatar Aug 09 '22 14:08 jackwener

The following two casts are not equivalent.

mysql> select cast(cast("1990-09-01 1:00:00" as datetime) as int); +-----------------------------------------------------+ | CAST(CAST('1990-09-01 1:00:00' AS DATETIME) AS INT) | +-----------------------------------------------------+ | -1977439664 | +-----------------------------------------------------+ 1 row in set (0.01 sec)

mysql> select cast("1990-09-01 1:00:00" as int); +-----------------------------------+ | CAST('1990-09-01 1:00:00' AS INT) | +-----------------------------------+ | NULL | +-----------------------------------+ 1 row in set (0.01 sec)

englefly avatar Aug 10 '22 09:08 englefly

PR approved by at least one committer and no changes requested.

github-actions[bot] avatar Aug 15 '22 04:08 github-actions[bot]

PR approved by anyone and no changes requested.

github-actions[bot] avatar Aug 15 '22 04:08 github-actions[bot]