-
Notifications
You must be signed in to change notification settings - Fork 30
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
[SQL] Add is_inf, is_nan, log for floats #1344
Conversation
case "log10": | ||
case "ln": | ||
{ | ||
// Cast to Double if the type isn't Decimal | ||
DBSPExpression arg = ops.get(0); | ||
if (!arg.type.is(DBSPTypeDecimal.class)) { | ||
ops.set(0, arg.cast(new DBSPTypeDouble(node, arg.getType().mayBeNull))); | ||
} | ||
return this.compilePolymorphicFunction(call, node, type, ops, 1); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See: #1328
case "log": | ||
{ | ||
// Turn the arguments into Double | ||
for (int i = 0; i < ops.size(); i++) { | ||
DBSPExpression arg = ops.get(i); | ||
ops.set(i, arg.cast(new DBSPTypeDouble(node, arg.getType().mayBeNull))); | ||
} | ||
return this.compilePolymorphicFunction(call, node, type, ops, 1, 2); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We only support log for double as rust_decimal doesn't have a native decimal support for it.
<tr> | ||
<td><code>LOG10(value)</code></td> | ||
<td>The logarithm base 10 of value. Produces a runtime error for values less than or equal to zero.</td> | ||
</tr> | ||
<tr> | ||
<td><code>IS_INF(value)</code></td> | ||
<td>Returns true if the value is infinite.</td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are multiple infinities and NaNs in FP, but maybe we don't have to say that.
...er/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/compiler/frontend/ExpressionCompiler.java
Outdated
Show resolved
Hide resolved
...er/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/compiler/frontend/ExpressionCompiler.java
Show resolved
Hide resolved
...er/SQL-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/functions/FunctionsTest.java
Show resolved
Hide resolved
...er/SQL-compiler/src/main/java/org/dbsp/sqlCompiler/compiler/frontend/ExpressionCompiler.java
Outdated
Show resolved
Hide resolved
/* | ||
-- power -> ensure both parameters have the same type | ||
-- truncate | ||
SELECT f.f1, trunc(f.f1) AS trunc_f1 --> not defined for double |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trunc should work for double. it it doesn't, please file an issue
NaN | NaN | NaN | ||
(22 rows) | ||
|
||
-- ignored some of the tests after the update query |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you have an update query you can probably create a separate table with just the updated versions of the data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move these tests to a second file which initializes the table with the updated contents.
(5 rows) | ||
*/ | ||
// calcite returns: 1008618.49 | ||
@Test @Ignore("fails for calcite optimized version") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure this is a bug really in Calcite. We should investigate. Please file an issue for us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the issue to the ignore comment so we can fix it later
ee7cb52
to
c2e6bb3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks very good.
docs/sql/float.md
Outdated
</tr> | ||
<tr> | ||
<td><code>LOG(value, [, value2])</code></td> | ||
<td>The logarithm of value to base value2, or base e if value2 is not present. Returns `-inf` for value 0. Produces a runtime error for negative numbers.</td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for value2=0.
negative values for either value or value2
Let's call "value2" "base" instead
docs/sql/float.md
Outdated
</tr> | ||
<tr> | ||
<td><code>IS_NAN(value)</code></td> | ||
<td>Returns true if the value is NaN. Note that two NaN values aren't equal.</td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they may be equal.
But there are multiple kinds of NaN, which are not equal to each other.
docs/sql/float.md
Outdated
</tr> | ||
<tr> | ||
<td><code>IS_INF(value)</code></td> | ||
<td>Returns true if the value is infinite. Note that two infinite values aren't necessarily equal.</td> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is + and - infinity.
I think there is one of each, though, and equality works for them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh.
I thought like in maths, some infinities can be larger than others. But that doesn't seem to be true here.
I'll update it.
pub fn sqrt_decimal(left: Decimal) -> F64 { | ||
F64::from(left.sqrt().unwrap().to_f64().unwrap()) | ||
} | ||
|
||
some_polymorphic_function1!(sqrt, decimal, Decimal, F64); | ||
|
||
pub fn sqrt_d(left: F64) -> F64 { | ||
F64::from(left.into_inner().sqrt()) | ||
let left = left.into_inner(); | ||
if left < 0.0 || left.is_nan() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usually is_nan produces is_nan as a result. Is this check necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it doesn't seem necessary. Removed.
...L-compiler/src/test/java/org/dbsp/sqlCompiler/compiler/sql/postgres/PostgresFloat8Tests.java
Show resolved
Hide resolved
* Tests manually adapted from | ||
* https://github.com/postgres/postgres/blob/master/src/test/regress/expected/float8.out | ||
*/ | ||
@SuppressWarnings("JavadocLinkAsPlainText") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you make the comment /* instead of /** you can remove this warning.
} | ||
|
||
/* | ||
-- check edge cases for exp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is wrong with these tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't support those functions yet.
NaN | NaN | NaN | ||
(22 rows) | ||
|
||
-- ignored some of the tests after the update query |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move these tests to a second file which initializes the table with the updated contents.
(5 rows) | ||
*/ | ||
// calcite returns: 1008618.49 | ||
@Test @Ignore("fails for calcite optimized version") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add the issue to the ignore comment so we can fix it later
} | ||
|
||
// Calcite optimized version returns 0 | ||
@Test @Ignore("https://github.com/feldera/feldera/issues/1348") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we fix this test?
I think we agreed that log in base 0 does return 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is fixed.
Fixes: #1363 |
* [SQL] Add import float8 tests from Postgres * [SQL] bugfix: Implement ln for double * [SQL] add more methods for polymorphic function power() * [SQL] Define is_nan, is_inf for both real & double * [SQL] Implement truncate, round, sqrt for double Signed-off-by: Abhinav Gyawali <22275402+abhizer@users.noreply.github.com>
Signed-off-by: Abhinav Gyawali <22275402+abhizer@users.noreply.github.com>
aebbbdf
to
72e45a4
Compare
} | ||
|
||
/* | ||
-- check edge cases for exp --> we don't support exp yet |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added EXP to the list of functions to implement #1265
Is this a user-visible change (yes/no): yes
Fixes: #1328
Fixes: #1326
Fixes: #1351
Fixes: #1348
Fixes: #1363