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

Add round, ceil, floor, truncate to the In-Database Column type #6988

Merged
merged 89 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
bbc5cff
one test
GregoryTravis Jun 7, 2023
e6bed7b
function_name
GregoryTravis Jun 7, 2023
347b46e
expression_spec
GregoryTravis Jun 7, 2023
c78560d
gmt test
GregoryTravis Jun 7, 2023
2fa1846
sl
GregoryTravis Jun 7, 2023
8291ce3
Merge branch 'develop' into wip/gmt/6886-truncate
GregoryTravis Jun 7, 2023
b16d9ee
trunc tests
GregoryTravis Jun 8, 2023
be81b60
ceil floor
GregoryTravis Jun 8, 2023
3b486b9
by hand rounding, sqlite parser stack overflow
GregoryTravis Jun 8, 2023
9fe0841
wip
GregoryTravis Jun 8, 2023
f649b73
pg maybe smaller
GregoryTravis Jun 8, 2023
2f68d35
works in sqlite too
GregoryTravis Jun 8, 2023
7f7324b
col math works
GregoryTravis Jun 9, 2023
9c4e0ff
clean up
GregoryTravis Jun 12, 2023
abaab2a
tests, cast to int column
GregoryTravis Jun 12, 2023
e20161a
rounding tests
GregoryTravis Jun 12, 2023
f42285e
round expression spec
GregoryTravis Jun 12, 2023
d802271
int in int out
GregoryTravis Jun 13, 2023
f05f9e3
full col tests
GregoryTravis Jun 13, 2023
ccda6aa
round to float
GregoryTravis Jun 13, 2023
4ff6fa7
dp out of range
GregoryTravis Jun 13, 2023
5b41821
const tests
GregoryTravis Jun 13, 2023
93f4403
rename to const, name test
GregoryTravis Jun 13, 2023
c60d354
nulls
GregoryTravis Jun 13, 2023
a25e3d5
remove pow_flip
GregoryTravis Jun 13, 2023
5283255
make trunc, ceil, floor generic
GregoryTravis Jun 13, 2023
4aed89c
do not restrict const arg
GregoryTravis Jun 14, 2023
50b78eb
Merge branch 'develop' into wip/gmt/6886-truncate
GregoryTravis Jun 14, 2023
fbecfd8
review
GregoryTravis Jun 14, 2023
593982b
nan/inf docs
GregoryTravis Jun 14, 2023
3ff04b5
changelog
GregoryTravis Jun 14, 2023
05fc15e
decimal too
GregoryTravis Jun 14, 2023
3fe8280
restore deleted test, restore integrity check
GregoryTravis Jun 15, 2023
31874a8
const not an op, using make_constant
GregoryTravis Jun 15, 2023
9256930
wip
GregoryTravis Jun 15, 2023
03f3e05
in-mem const
GregoryTravis Jun 15, 2023
78aa29f
share with eval exp
GregoryTravis Jun 15, 2023
92b4d49
factor out dp check
GregoryTravis Jun 15, 2023
8d19564
only test decimal on pg-like
GregoryTravis Jun 15, 2023
91d58b2
column arithmetic for in-mem too
GregoryTravis Jun 15, 2023
ea10375
wip
GregoryTravis Jun 15, 2023
b7b6d3e
symmetric
GregoryTravis Jun 15, 2023
e8dbf9f
symmetric for in-mem
GregoryTravis Jun 16, 2023
218f2e2
symmetric for db
GregoryTravis Jun 16, 2023
570756d
wip
GregoryTravis Jun 16, 2023
afd21ac
integer impl
GregoryTravis Jun 19, 2023
b0c771e
wip
GregoryTravis Jun 19, 2023
bbd7033
col col
GregoryTravis Jun 19, 2023
e891c44
unstable
GregoryTravis Jun 19, 2023
511a627
review
GregoryTravis Jun 19, 2023
9769faf
pg/sl return type
GregoryTravis Jun 20, 2023
41bd417
more type checks for in-mem
GregoryTravis Jun 20, 2023
4d0627b
input check for in-mem round
GregoryTravis Jun 21, 2023
0ad7ef4
use make_function
GregoryTravis Jun 21, 2023
0a350c2
wip
GregoryTravis Jun 21, 2023
d6fe5ce
wrapper
GregoryTravis Jun 22, 2023
395a3b6
round_decimal
GregoryTravis Jun 22, 2023
10fa61c
sl
GregoryTravis Jun 22, 2023
086fb18
round etc return types
GregoryTravis Jun 26, 2023
c6fed25
rename round_with
GregoryTravis Jun 26, 2023
6351dce
cleanup
GregoryTravis Jun 26, 2023
c27b52d
docs
GregoryTravis Jun 26, 2023
314546d
decimal test
GregoryTravis Jun 26, 2023
7fcb5c7
specialize
GregoryTravis Jun 26, 2023
3bac313
remove max_long test
GregoryTravis Jun 26, 2023
05620e4
p flag for dp restriction
GregoryTravis Jun 26, 2023
307f9f0
rs too
GregoryTravis Jun 26, 2023
021a2f4
return type tests
GregoryTravis Jun 26, 2023
6ed5154
bankers
GregoryTravis Jun 26, 2023
519f329
cleanup
GregoryTravis Jun 26, 2023
c6d7974
merge
GregoryTravis Jun 26, 2023
934f974
Merge branch 'develop' into wip/gmt/6886-truncate
GregoryTravis Jun 27, 2023
35fe5b1
literal for dp
GregoryTravis Jun 27, 2023
076172a
changelog chronological
GregoryTravis Jun 27, 2023
3a9b1d7
review
GregoryTravis Jun 27, 2023
819e75f
undo changelog
GregoryTravis Jun 27, 2023
bfce3b7
precision too high
GregoryTravis Jun 27, 2023
e13e178
Merge branch 'develop' into wip/gmt/6886-truncate
GregoryTravis Jun 27, 2023
9d3f548
wip
GregoryTravis Jun 28, 2023
4895366
trunc
GregoryTravis Jun 28, 2023
6342238
DoubleLongMapOpWithSpecialNumericHandling
GregoryTravis Jun 28, 2023
c22364e
wip
GregoryTravis Jun 28, 2023
7b16564
fmt
GregoryTravis Jun 28, 2023
2ca4084
Merge branch 'develop' into wip/gmt/6886-truncate
GregoryTravis Jun 28, 2023
bc6f8fa
precision limit tests
GregoryTravis Jun 29, 2023
9905ac3
fixed
GregoryTravis Jun 29, 2023
74f00d3
cleanup
GregoryTravis Jun 29, 2023
40d2376
epsilon
GregoryTravis Jun 29, 2023
9ff2ef6
another epsilon
GregoryTravis Jun 30, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions distribution/lib/Standard/Table/0.0.0-dev/src/Data/Column.enso
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,16 @@ type Column
If `decimal_places` is outside the range -15..15 (inclusive), an
`Illegal_Argument` error is thrown.

! Precision
As floating-point numbers are inexact, rounding can have unexpected
results near the precision limit (about 15 decimal places), especially
when rounding mid-point values. For example:

Postgres: rounding 1.2222222222222235 to 15 decimal places returns:
1.222222222222224
SQLite: rounding 1.2222222222222235 to 15 decimal places returns:
1.222222222222223

? Negative decimal place counts
Rounding to `n` digits can be thought of as "rounding to the nearest
multiple of 10^(-n)". For negative decimal counts, this results in
Expand Down
14 changes: 13 additions & 1 deletion test/Table_Tests/src/Database/Postgres_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ postgres_specific_spec connection db_name setup =
Test.with_clue "d.value_type="+d.value_type.to_display_text+": " <|
d.value_type.variable_length.should_be_true

Test.group "[PostgreSQL] math functions" <|
Test.group "[PostgreSQL] math functionsasdfasdf" <|
Test.specify "round, trunc, ceil, floor" <|
col = table_builder [["x", [0.1, 0.9, 3.1, 3.9, -0.1, -0.9, -3.1, -3.9]]] . at "x"
col . cast Value_Type.Integer . ceil . value_type . should_equal Value_Type.Float
Expand Down Expand Up @@ -229,6 +229,18 @@ postgres_specific_spec connection db_name setup =
result.to_vector.at 0
do_round n dp=0 use_bankers=False = do_op n (_.round dp use_bankers)

Test.specify "Can round correctly near the precision limit" <|
do_round 1.2222222222222225 15 . should_equal 1.222222222222223
do_round -1.2222222222222225 15 . should_equal -1.222222222222223
do_round 1.2222222222222235 15 . should_equal 1.222222222222224
do_round -1.2222222222222235 15 . should_equal -1.222222222222224

Test.specify "Can round correctly near the precision limit, using banker's rounding" <|
do_round 1.2222222222222225 15 use_bankers=True . should_equal 1.222222222222222
do_round -1.2222222222222225 15 use_bankers=True . should_equal -1.222222222222222
do_round 1.2222222222222235 15 use_bankers=True . should_equal 1.222222222222224
do_round -1.2222222222222235 15 use_bankers=True . should_equal -1.222222222222224

Test.specify "Can handle NaN/Infinity" <|
nan_result = if setup.test_selection.is_nan_and_nothing_distinct then Number.nan else Nothing
ops = [.round, .truncate, .ceil, .floor]
Expand Down
14 changes: 13 additions & 1 deletion test/Table_Tests/src/Database/SQLite_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ sqlite_specific_spec prefix connection setup =
expected_code = code_template.replace "{Tinfo}" tinfo
t.distinct ["strs"] . to_sql . prepare . should_equal [expected_code, []]

Test.group "[PostgreSQL] math functions" <|
Test.group "[PostgreSQL] math functionsasdfasdf" <|
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Test.group "[PostgreSQL] math functionsasdfasdf" <|
Test.group "[PostgreSQL] math functions" <|

please remove these random letters though :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Test.specify "round, trunc, ceil, floor" <|
col = table_builder [["x", [0.1, 0.9, 3.1, 3.9, -0.1, -0.9, -3.1, -3.9]]] . at "x"

Expand Down Expand Up @@ -157,6 +157,18 @@ sqlite_specific_spec prefix connection setup =
result.to_vector.at 0
do_round n dp=0 use_bankers=False = do_op n (_.round dp use_bankers)

Test.specify "Can round correctly near the precision limit" <|
do_round 1.2222222222222225 15 . should_equal 1.222222222222223
do_round -1.2222222222222225 15 . should_equal -1.222222222222223
do_round 1.2222222222222235 15 . should_equal 1.222222222222223
do_round -1.2222222222222235 15 . should_equal -1.222222222222223

Test.specify "Can round correctly near the precision limit, using banker's rounding" <|
do_round 1.2222222222222225 15 use_bankers=True . should_equal 1.222222222222222
do_round -1.2222222222222225 15 use_bankers=True . should_equal -1.222222222222222
do_round 1.2222222222222235 15 use_bankers=True . should_equal 1.222222222222224
do_round -1.2222222222222235 15 use_bankers=True . should_equal -1.222222222222224

Test.specify "Can handle NaN/Infinity" <|
nan_result = if setup.test_selection.is_nan_and_nothing_distinct then Number.nan else Nothing
ops = [.round, .truncate, .ceil, .floor]
Expand Down