Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Use type date for case expression when there are Date and DateTime args #47902

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

lbrdnk
Copy link
Contributor

@lbrdnk lbrdnk commented Sep 12, 2024

Closes #47887

Description

The issue is that we infer return type for case expression as most specific common ancestor. If the arguments are :type/Date and :type/DateTime the ancestor is :type/Temporal. That results in limited filter picker options.

This PR adds special case for arguments of aforemementioned types. The :type/Date is picked as the expression type.

The question is however, whether the current behavior is really erroneous. To the best of my knowledge there's no way to decide correct argument type in this case, and picking the :type/Date is best effort, that could enable some cases, but may result in error in others.

Following stack (in reverse) is significant for the context (ie. if you are interested in how I got to this specific change):

metabase.lib.util/top-level-expression-clause
metabase.lib.schema.expression/type-of :case
metabase.lib.schema.expression.conditional/best-return-type

How to verify

Describe the steps to verify that the changes are working as expected.

  1. New question -> Sample Dataset -> ...
  2. ...

Demo

Upload a demo video or before/after screenshots if sensible or remove the section

Checklist

  • Tests have been added/updated to cover changes in this PR

@lbrdnk lbrdnk changed the title Use type date for case expression when there are Date and DateTime args [WIP] Use type date for case expression when there are Date and DateTime args Sep 12, 2024
Copy link
Contributor

@ranquild ranquild left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks correct. Let's add tests and merge.

Copy link
Contributor

@metamben metamben left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me, this means that we are saying that all operations that are valid for :type/Date are valid for a case expression containing a :type/DateTime value. If that's true, then :type/Date should be an ancestor of :type/DateTime, and this hack is not needed. If that's not true, then this invites trouble.

I have the feeling we are expecting too much from a single type hierarchy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom column that returns a date is not interpreted as a date filter
3 participants