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

Regression in first_value and last_value coercion #10781

Closed
appletreeisyellow opened this issue Jun 3, 2024 · 3 comments · Fixed by #10783
Closed

Regression in first_value and last_value coercion #10781

appletreeisyellow opened this issue Jun 3, 2024 · 3 comments · Fixed by #10783
Labels
bug Something isn't working

Comments

@appletreeisyellow
Copy link
Contributor

appletreeisyellow commented Jun 3, 2024

Describe the bug

There is a regression in first_value and last_value coercion after #10648 is merged.

The error message looks like: Error during planning: Coercion from [Timestamp(Nanosecond, Some("+00:00"))] to the signature OneOf([ArraySignature(Array), Uniform(1, [Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Float32, Float64])]) failed.

To Reproduce

  1. Pull the latest datafusion and build datafusion-cli locally
  2. Write data
~/datafusion/datafusion-cli$ ./target/debug/datafusion-cli
DataFusion CLI v38.0.0
> CREATE TABLE table1 (
    bar DECIMAL(10,1),
    foo VARCHAR(10),
    time TIMESTAMP WITH TIME ZONE
);

INSERT INTO table1 (bar, foo, time) VALUES
(200.0, 'me', '1970-01-01T00:00:00.000000010Z'),
(1.0, 'me', '1970-01-01T00:00:00.000000030Z'),
(1.0, 'me', '1970-01-01T00:00:00.000000040Z'),
(2.0, 'you', '1970-01-01T00:00:00.000000020Z');

0 row(s) fetched.
Elapsed 0.053 seconds.
  1. Query using first_value and last_value
> SELECT foo, first_value(time ORDER BY time DESC NULLS LAST) AS time FROM table1 GROUP BY foo ORDER BY foo;
type_coercion
caused by
Error during planning: Coercion from [Timestamp(Nanosecond, Some("+00:00"))] to the signature OneOf([ArraySignature(Array), Uniform(1, [Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Float32, Float64])]) failed.

> SELECT foo, last_value(time ORDER BY time DESC NULLS LAST) AS time FROM table1 GROUP BY foo ORDER BY foo;
Error during planning: Error during planning: Coercion from [Timestamp(Nanosecond, Some("+00:00"))] to the signature OneOf([ArraySignature(Array), Uniform(1, [Int8, Int16, Int32, Int64, UInt8, UInt16, UInt32, UInt64, Float32, Float64])]) failed. and No function matches the given name and argument types 'last_value(Timestamp(Nanosecond, Some("+00:00")))'. You might need to add explicit type casts.
        Candidate functions:
        last_value(array)
        last_value(Int8/Int16/Int32/Int64/UInt8/UInt16/UInt32/UInt64/Float32/Float64)

Expected behavior

> SELECT foo, first_value(time ORDER BY time DESC NULLS LAST) AS time FROM table1 GROUP BY foo ORDER BY foo;
+-----+--------------------------------+
| foo | time                           |
+-----+--------------------------------+
| me  | 1970-01-01T00:00:00.000000040Z |
| you | 1970-01-01T00:00:00.000000020Z |
+-----+--------------------------------+
2 row(s) fetched.
Elapsed 0.031 seconds.

> SELECT foo, last_value(time ORDER BY time DESC NULLS LAST) AS time FROM table1 GROUP BY foo ORDER BY foo;
+-----+--------------------------------+
| foo | time                           |
+-----+--------------------------------+
| me  | 1970-01-01T00:00:00.000000010Z |
| you | 1970-01-01T00:00:00.000000020Z |
+-----+--------------------------------+
2 row(s) fetched.
Elapsed 0.022 seconds.

Additional context

No response

@appletreeisyellow appletreeisyellow added the bug Something isn't working label Jun 3, 2024
@appletreeisyellow
Copy link
Contributor Author

Seems like it is fixed in #10703. I'm verifying

@appletreeisyellow
Copy link
Contributor Author

I verified that #10651 fixed the regression. Thank you @jayzhan211!

@appletreeisyellow appletreeisyellow changed the title Regression in first_value coercsion Regression in first_value and last_value coercion Jun 3, 2024
@appletreeisyellow
Copy link
Contributor Author

Reopening this issue since last_value also has the same coercion error. I have updated the issue description and the title to reflect last_value.

I'll put up a fix soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant