You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "getChan (via GitHub)" <gi...@apache.org> on 2024/07/21 10:39:45 UTC
[PR] Fix : `signum` function bug when `0.0` input [datafusion]
getChan opened a new pull request, #11580:
URL: https://github.com/apache/datafusion/pull/11580
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
-->
Closes #11557
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
-->
1. add signum function unit test
2. move `signum_order` function from monotonicity.rs to signum.rs
3. signum function implementation by new code. not `make_udf_function!` macro
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
4. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
-->
Add some unit tests.
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api change` label.
-->
no
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Fix : `signum` function bug when `0.0` input [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #11580:
URL: https://github.com/apache/datafusion/pull/11580#issuecomment-2247887349
Thanks @getChan @andygrove and @Throne3d
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Fix : `signum` function bug when `0.0` input [datafusion]
Posted by "Throne3d (via GitHub)" <gi...@apache.org>.
Throne3d commented on PR #11580:
URL: https://github.com/apache/datafusion/pull/11580#issuecomment-2244205992
Here are the values I get for Spark 3.5.1:
```python
data = ["-1", "1", "0", "-0.0", "0.0", "1.0", "-1.0"]
df = spark.createDataFrame([(datum,) for datum in data], "col1 string")
df.collect()
# [Row(col1='-1'), Row(col1='1'), Row(col1='0'), Row(col1='-0.0'), Row(col1='0.0'), Row(col1='1.0'), Row(col1='-1.0')]
pprint.pprint(df.selectExpr("col1", "signum(cast(col1 as float)) as result").collect())
# [Row(col1='-1', result=-1.0),
# Row(col1='1', result=1.0),
# Row(col1='0', result=0.0),
# Row(col1='-0.0', result=-0.0),
# Row(col1='0.0', result=0.0),
# Row(col1='1.0', result=1.0),
# Row(col1='-1.0', result=-1.0)]
```
So it seems like -0.0 in Spark should specifically return -0.0 in the signum function, not -1, right?
Literals seem to be treated as Decimal instead, which doesn't make the distinction between negative and positive zero, so those don't see the same behavior - I'd guess that's what caused the specific results listed for Spark in https://github.com/apache/datafusion/issues/11557#issuecomment-2241473321:
```py
spark.sql("""SELECT -1, 1, 0, -0.0, 0.0, 1.0, -1.0""").collect()
# [Row(-1=-1, 1=1, 0=0, 0.0=Decimal('0.0'), 0.0=Decimal('0.0'), 1.0=Decimal('1.0'), -1.0=Decimal('-1.0'))]
spark.sql("""SELECT signum(-1), signum(1), signum(0), signum(-0.0), signum(0.0), signum(1.0), signum(-1.0)""").collect()
# [Row(SIGNUM(-1)=-1.0, SIGNUM(1)=1.0, SIGNUM(0)=0.0, SIGNUM(0.0)=0.0, SIGNUM(0.0)=0.0, SIGNUM(1.0)=1.0, SIGNUM(-1.0)=-1.0)]
```
For Postgres 16.3, this behavior looks correct for both `decimal` and `float` though!
```sql
postgres=# WITH tab(datum) AS (VALUES ('-1'), ('1'), ('0'), ('-0.0'), ('0.0'), ('1.0'), ('-1.0'))
SELECT *, cast(datum as decimal) decimal, cast(datum as float) float, sign(cast(datum as decimal)) sign_decimal, sign(cast(datum as float)) sign_float FROM tab;
datum | decimal | float | sign_decimal | sign_float
-------+---------+-------+--------------+------------
-1 | -1 | -1 | -1 | -1
1 | 1 | 1 | 1 | 1
0 | 0 | 0 | 0 | 0
-0.0 | 0.0 | -0 | 0 | 0
0.0 | 0.0 | 0 | 0 | 0
1.0 | 1.0 | 1 | 1 | 1
-1.0 | -1.0 | -1 | -1 | -1
(7 rows)```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Fix : `signum` function bug when `0.0` input [datafusion]
Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #11580:
URL: https://github.com/apache/datafusion/pull/11580
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org