Skip to content

Add Date type to InPredicate#4794

Closed
isadikov wants to merge 1 commit intofacebookincubator:mainfrom
isadikov:add_date_to_in
Closed

Add Date type to InPredicate#4794
isadikov wants to merge 1 commit intofacebookincubator:mainfrom
isadikov:add_date_to_in

Conversation

@isadikov
Copy link
Contributor

@isadikov isadikov commented May 1, 2023

This PR adds support for Date types in InPredicate expression.

This allows to run queries like this:

SELECT * FROM table WHERE date in (DATE '2022-01-01', DATE '2022-02-01');
SELECT * FROM orders WHERE cast(orderdate as date) in (DATE '2000-06-30', DATE '2000-09-27')

Without this patch, the query above would fail with

VeloxRuntimeError: Scalar function in not registered with arguments: (DATE, ARRAY<DATE>)

Note: the fix itself is very small, most of the code changes are for unit tests because DuckDB test code did not handle date literals.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 1, 2023
@netlify
Copy link

netlify bot commented May 1, 2023

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit 5cce89b
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/648a2b32f7c2300009060c81

@isadikov
Copy link
Contributor Author

isadikov commented May 7, 2023

@kgpai It seems the changes in the PR #4461 misreport the signature changes. My PR adds a new signature and does not update the existing ones so the signature test should pass but it fails instead: https://app.circleci.com/pipelines/github/facebookincubator/velox/24232/workflows/cba6d1ef-e3ac-4fc9-a9f2-8c414a6a61e7/jobs/153843.

Can you have a look and follow up on this? Is there a way to override the failure?

@mbasmanova
Copy link
Contributor

@kgpai Krishna, would you help take a look?

@kgpai
Copy link
Contributor

kgpai commented May 9, 2023

Hi @isadikov , The error says that in has two implementations for (date, array(date)-> boolean . Going through your PR to see if thats the case.

@kgpai
Copy link
Contributor

kgpai commented May 9, 2023

Give me a few hours to replicate this problem locally so I can debug this problem.

@kgpai
Copy link
Contributor

kgpai commented May 9, 2023

I see these signatures on CircleCI for

"in": ["(date,array(date)) -> boolean", "(timestamp,array(timestamp)) -> boolean", "(varchar,array(varchar)) -> boolean", "(boolean,array(boolean)) -> boolean", "(real,array(real)) -> boolean", "(bigint,array(bigint)) -> boolean", "(double,array(double)) -> boolean", "(integer,array(integer)) -> boolean", "(smallint,array(smallint)) -> boolean", "(tinyint,array(tinyint)) -> boolean", "(tinyint,array(tinyint)) -> boolean", "(tinyint,array(unknown)) -> boolean", "(smallint,array(smallint)) -> boolean", "(smallint,array(unknown)) -> boolean", "(integer,array(integer)) -> boolean", "(integer,array(unknown)) -> boolean", "(bigint,array(bigint)) -> boolean", "(bigint,array(unknown)) -> boolean", "(varchar,array(varchar)) -> boolean", "(varchar,array(unknown)) -> boolean", "(varbinary,array(varbinary)) -> boolean", "(varbinary,array(unknown)) -> boolean", "(date,array(date)) -> boolean", "(date,array(unknown)) -> boolean"] 

"(date,array(date)) -> boolean" is both at start and end , however I dint see this when I built this locally on my mac.
Digging more..

@kgpai
Copy link
Contributor

kgpai commented May 9, 2023

I have identified the problem, I will send a PR asap which after landing you can rebase against to fix this.

@isadikov
Copy link
Contributor Author

isadikov commented May 9, 2023

Great, thanks!

facebook-github-bot pushed a commit that referenced this pull request May 9, 2023
Summary:
We need to namespace signatures that are imported so that we can differentiate between spark and presto signatures.  Currently PR: #4794 has a problem where it considers the spark and presto signature for dates in `in predicate` to be similar.

Pull Request resolved: #4883

Reviewed By: Yuhta

Differential Revision: D45705225

Pulled By: kgpai

fbshipit-source-id: 6392943e6af3fe9acfdb6cc3d1b911266e4d633a
@kgpai
Copy link
Contributor

kgpai commented May 9, 2023

@isadikov Can you rebase against main and retry ?

@isadikov
Copy link
Contributor Author

isadikov commented May 9, 2023

Yes, I will rebase, thanks for fixing the issue!

@isadikov isadikov force-pushed the add_date_to_in branch 2 times, most recently from 4e24e59 to 08331dc Compare May 16, 2023 20:47
@isadikov isadikov force-pushed the add_date_to_in branch 3 times, most recently from 66d33a0 to b7d0a39 Compare May 17, 2023 06:54
@isadikov isadikov force-pushed the add_date_to_in branch 2 times, most recently from 7eb5676 to e533fca Compare May 17, 2023 20:41
@isadikov isadikov requested a review from majetideepak May 17, 2023 20:42
Copy link
Collaborator

@majetideepak majetideepak left a comment

Choose a reason for hiding this comment

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

Thanks, @isadikov

@majetideepak majetideepak marked this pull request as ready for review May 18, 2023 07:06
@isadikov
Copy link
Contributor Author

@mbasmanova Could you review this PR? Thanks!

VELOX_USER_CHECK(
!values.empty(),
"IN predicate expects at least one non-null value in the in-list");
if (values.size() == 1) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is already handled in createBigintValues

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I removed this part.

@isadikov
Copy link
Contributor Author

@Yuhta I addressed your comments, could you review this PR? Thanks.

@isadikov isadikov force-pushed the add_date_to_in branch 2 times, most recently from 3fa1498 to 9b78a5f Compare June 4, 2023 21:46
@isadikov
Copy link
Contributor Author

isadikov commented Jun 7, 2023

@Yuhta Could you review this PR again? Thanks.

@Yuhta Yuhta self-requested a review June 7, 2023 22:46
@isadikov
Copy link
Contributor Author

@Yuhta Would you be able to take another look at the PR? Thanks.

@Yuhta
Copy link
Contributor

Yuhta commented Jun 15, 2023

We probably need to hold on this one until #5015 is merged

@aditi-pandit
Copy link
Collaborator

Hi @Yuhta : I'm fine with this going ahead of #5015 as it is blocking TPC-DS. I will merge these changes into that PR. Please go ahead with the merge.

@facebook-github-bot
Copy link
Contributor

@Yuhta has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

ExpressionType::VALUE_CONSTANT) {
auto constExpr =
dynamic_cast<ConstantExpression*>(castExpr->child.get());
auto value =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please check constExpr is non-null before de-referencing it in the next line. We should ensure that cast is not over any other expression here.

@facebook-github-bot
Copy link
Contributor

@Yuhta merged this pull request in 24c20be.

yiweiHeOSS pushed a commit to yiweiHeOSS/velox that referenced this pull request Jul 15, 2023
Summary:
We need to namespace signatures that are imported so that we can differentiate between spark and presto signatures.  Currently PR: facebookincubator#4794 has a problem where it considers the spark and presto signature for dates in `in predicate` to be similar.

Pull Request resolved: facebookincubator#4883

Reviewed By: Yuhta

Differential Revision: D45705225

Pulled By: kgpai

fbshipit-source-id: 6392943e6af3fe9acfdb6cc3d1b911266e4d633a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants