Skip to content

The returned type of abs is error. #1335

Closed

Description

@liukun4515

Describe the bug

In the pg database, the abs support varchar data type

But the result in the datafusion is

❯ select abs('123');
Plan("Coercion from [Utf8] to the signature Uniform(1, [Float64, Float32]) failed.")
❯

In other size, the returned type of abs is the input type.

If the input type is int, the returned type must be the int.

If the result data is out of range, PG will throw error message.

postgres=# SELECT abs(-2147483648);
ERROR:  integer out of range
postgres=#

but in the datafusion, it convert the -2147483648 to INT64

❯ SELECT abs(-2147483648);
+-------------------------+
| abs(Int64(-2147483648)) |
+-------------------------+
| 2147483648              |
+-------------------------+

To Reproduce
execute the sql

❯ select abs('123');
Plan("Coercion from [Utf8] to the signature Uniform(1, [Float64, Float32]) failed.")
❯

Expected behavior

postgres=# select abs('123');
 abs
-----
 123
(1 row)

the result of type is always double

Additional context

Activity

  1. liukun4515 commented on Nov 19, 2021

    @liukun4515
    ContributorAuthor

    Please assign this issue to me.

  2. changed the title [-]Error result type for ABS functions[/-] [+]ABS can support the varchar type[/+] on Nov 24, 2021
  3. changed the title [-]ABS can support the varchar type[/-] [+]ABS can't support the varchar type[/+] on Nov 24, 2021
  4. changed the title [-]ABS can't support the varchar type[/-] [+]The returned type of abs is error.[/+] on Nov 26, 2021
  5. alamb commented on Jan 28, 2023

    @alamb
    Contributor

    https://github.com/apache/arrow-datafusion/pull/5086/files#r1089553803 -- @melgenek noticed that abs(decimal) appears to be resolved as a float rather than decimal

  6. alamb commented on Jun 11, 2023

    @alamb
    Contributor

    I am going to close this one as I can't figure out what this ticket is tracking

    I think the current error message is pretty straightforward:

    ❯ select abs('123');
    Error during planning: No function matches the given name and argument types 'abs(Utf8)'. You might need to add explicit type casts.
    	Candidate functions:
    	abs(Float64/Float32)

    I am not sure what this issue is tracking any more. Is the requested feature to support automatically cocercing strings to some type?

    If so I'll open a new specific ticket for that

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

Metadata

Metadata

Assignees

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