Fix a cornor case which dump CaseTestExpr for IS NOT DISTINCT FROM. (#10348)
For below example: ``` CREATE TABLE mytable2 ( key character varying(20) NOT NULL, key_value character varying(50) ) DISTRIBUTED BY (key); CREATE VIEW aaa AS SELECT CASE mytable2.key_value WHEN IS NOT DISTINCT FROM 'NULL'::text THEN 'now'::text::date ELSE to_date(mytable2.key_value::text, 'YYYYMM'::text) END AS t FROM mytable2; ``` mytable2.key_value will cast to type date. For clause `(ARG1) IS NOT DISTINCT FROM (ARG2)`, this leads ARG1 to become a RelabelType node and contains CaseTestExpr node in RelabelType->arg. So when dumping the view, it'll dump extra `CASE_TEST_EXPR` as below ``` select pg_get_viewdef('notdisview3',false); pg_get_viewdef ----------------------------------------------------------------------------- SELECT + CASE mytable2.key_value + WHEN (CASE_TEST_EXPR) IS NOT DISTINCT FROM 'NULL'::text THEN ('now'::text)::date+ ELSE to_date((mytable2.key_value)::text, 'YYYYMM'::text) + END AS t + FROM mytable2; (1 row) ``` I dig into commit a453004e, if left-hand argument for `IS NOT DISTINCT FROM` contains any `CaseTestExpr` node, the left-hand arg should be omitted. `CaseTestExpr` is a placeholder for CASE expression. Reviewed-by: NPaul Guo <paulguo@gmail.com>
Showing
想要评论请 注册 或 登录