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

provide native implementations for scalar functions sys.degrees(rad) and sys.radians(deg) #6814

Closed
monetdb-team opened this issue Nov 30, 2020 · 0 comments
Labels
enhancement New feature or request SQL

Comments

@monetdb-team
Copy link

Date: 2020-01-29 17:28:54 +0100
From: Martin van Dinther <<martin.van.dinther>>
To: SQL devs <>
Version: 11.35.9 (Nov2019-SP1)
CC: @PedroTadim

Last updated: 2020-10-19 11:06:19 +0200

Comment 27531

Date: 2020-01-29 17:28:54 +0100
From: Martin van Dinther <<martin.van.dinther>>

User-Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64; rv:70.0) Gecko/20100101 Firefox/70.0
Build Identifier:

The scalar functions sys.degrees(rad) and sys.radians(deg) are currently implemented as SQL system functions (in sql/scripts/10_math.sql).
CREATE FUNCTION degrees(r double) RETURNS double RETURN r180/pi();
CREATE FUNCTION radians(d double) RETURNS double RETURN d
pi()/180;

This implies that when using them from any schema other than sys, you must include the sys. prefix, else you get an error.
Error: SELECT: no such unary operator 'degrees(decimal)'
Error: SELECT: no such unary operator 'radians(decimal)'

It would be more user friendly if this sys. prefix in SQL queries would not be needed, as is the case with all the other trigonometric functions.
This can be achieved by implementing the function logic in C (as done for sin(x), cos(x)) and removing the SQL implementation.
Possibly the native C implementations would also be faster and more efficient (less overhead).

Reproducible: Always

Steps to Reproduce:

select current_schema;
-- sys
set schema profiler;
select current_schema;
-- profiler
select degrees(0.5);
-- SELECT: no such unary operator 'degrees(decimal)'
select degrees(2);
-- SELECT: no such unary operator 'degrees(tinyint)'
select radians(45.0);
-- SELECT: no such unary operator 'radians(decimal)'
select sys.degrees(0.5), sys.degrees(2), sys.radians(45);

Actual Results:

sql>select current_schema;
+------+
| L2 |
+======+
| sys |
+------+
1 tuple
sql>set schema profiler;
operation successful
sql>select current_schema;
+----------+
| L2 |
+==========+
| profiler |
+----------+
1 tuple
sql>select degrees(0.5);
SELECT: no such unary operator 'degrees(decimal)'
sql>select degrees(2);
SELECT: no such unary operator 'degrees(tinyint)'
sql>select radians(45.0);
SELECT: no such unary operator 'radians(decimal)'
sql>select sys.degrees(0.5), sys.degrees(2), sys.radians(45);
+--------------------------+--------------------------+--------------------------+
| L2 | L4 | L6 |
+==========================+==========================+==========================+
| 28.64788975654116 | 114.59155902616465 | 0.7853981633974483 |
+--------------------------+--------------------------+--------------------------+
1 tuple

Expected Results:

Allow functions degrees() and radians() to be called without sys. prefix when current schema is not sys.

Comment 27605

Date: 2020-03-17 20:12:28 +0100
From: Martin van Dinther <<martin.van.dinther>>

See also https://www.monetdb.org/bugzilla/show_bug.cgi?id=3553

Comment 27780

Date: 2020-06-03 11:09:42 +0200
From: Martin van Dinther <<martin.van.dinther>>

Further optimizations possible:
180/pi() can be replaced with constant: 57.295779513082320876798154814105
pi()/180 can be replaced with constant: 0.01745329251994329576923690768489

Comment 27871

Date: 2020-06-23 09:27:37 +0200
From: MonetDB Mercurial Repository <>

Changeset 4c270abe4e2d made by Pedro Ferreira pedro.ferreira@monetdbsolutions.com in the MonetDB repo, refers to this bug.

For complete details, see https//devmonetdborg/hg/MonetDB?cmd=changeset;node=4c270abe4e2d

Changeset description:

Removed 10_math.sql script. Mada functions degree and radians SQL compliant, ie without schema. This fixes bug #6814
@monetdb-team monetdb-team added enhancement New feature or request SQL labels Nov 30, 2020
@sjoerdmullender sjoerdmullender added this to the Ancient Release milestone Feb 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request SQL
Projects
None yet
Development

No branches or pull requests

2 participants