Skip to content

Bug: to_char Function Returns NULL for Valid DATE Values in DataFusion #14969

@kosiew

Description

@kosiew

Describe the bug

The to_char function in DataFusion returns NULL when formatting valid DATE values

To Reproduce

cargo run -p datafusion-cli -- -c "SELECT to_char(date_column, '%Y-%m-%d') FROM (VALUES (NULL), (DATE '2020-09-01')) AS t(date_column)"

+-----------------------------------------+
| to_char(t.date_column,Utf8("%Y-%m-%d")) |
+-----------------------------------------+
| NULL                                    |
| NULL                                    |
+-----------------------------------------+

Expected behavior

+-----------------------------------------+
| to_char(t.date_column,Utf8("%Y-%m-%d")) |
+-----------------------------------------+
| NULL                                    |
| 2020-09-01                              |
+-----------------------------------------+

Additional context

I discovered this bug while trying to add this slt test

SELECT to_char(date_column, '%Y-%m-%d')
FROM (VALUES 
    (DATE '2020-09-01'),
    (NULL)
) AS t(date_column);

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions