Skip to content

Commit

Permalink
Add floor and ceil functions to all float-based types (MobilityDB#499)
Browse files Browse the repository at this point in the history
* Rename constants ORDERED/ORDERED_NO -> ORDER_NO/ORDER
  • Loading branch information
estebanzimanyi authored May 25, 2024
1 parent e78c89d commit c32dd4b
Show file tree
Hide file tree
Showing 49 changed files with 737 additions and 148 deletions.
Binary file modified doc/es/mobilitydb-manual.pdf
Binary file not shown.
22 changes: 15 additions & 7 deletions doc/es/reference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -253,23 +253,27 @@

<itemizedlist>
<listitem>
<para><link linkend="setspan_shift"><varname>shift</varname></link>: Desplazar un conjunto o un rango con un valor o intervalo de tiempo</para>
<para><link linkend="setspan_shift"><varname>shift</varname></link>: Desplazar con un valor o intervalo de tiempo</para>
</listitem>

<listitem>
<para><link linkend="setspan_scale"><varname>scale</varname></link>: Escalar un conjunto o un rango con un valor o intervalo de tiempo</para>
<para><link linkend="setspan_scale"><varname>scale</varname></link>: Escalar con un valor o intervalo de tiempo</para>
</listitem>

<listitem>
<para><link linkend="setspan_shiftScale"><varname>shiftScale</varname></link>: Desplazar y escalar un conjunto o un rango con los valores o intervalos de tiempo</para>
<para><link linkend="setspan_shiftScale"><varname>shiftScale</varname></link>: Desplazar y escalar con los valores o intervalos de tiempo</para>
</listitem>

<listitem>
<para><link linkend="floatspan_round"><varname>round</varname></link>: Redondear un conjunto o un rango flotante a un número de decimales</para>
<para><link linkend="floatsetspan_floor"><varname>floor</varname>, <varname>ceil</varname></link>: Redondear al entero inferior o superior</para>
</listitem>

<listitem>
<para><link linkend="floatset_degrees"><varname>degrees</varname>, <varname>radians</varname></link>: Convertir un conjunto flotante a grados o radianes</para>
<para><link linkend="floatspan_round"><varname>round</varname></link>: Redondear a un número de decimales</para>
</listitem>

<listitem>
<para><link linkend="floatset_degrees"><varname>degrees</varname>, <varname>radians</varname></link>: Convertir a grados o radianes</para>
</listitem>

<listitem>
Expand All @@ -281,7 +285,7 @@
</listitem>

<listitem>
<para><link linkend="time_tprecision"><varname>tprecision</varname></link>: Establecer la precisión temporal del valor de tiempo al intervalo con respecto al origen</para>
<para><link linkend="time_tprecision"><varname>tprecision</varname></link>: Establecer la precisión temporal al intervalo con respecto al origen</para>
</listitem>
</itemizedlist>
</sect2>
Expand Down Expand Up @@ -1127,7 +1131,11 @@
</listitem>

<listitem>
<para><link linkend="round"><varname>round</varname></link>: Redondear los valores a un número de posiciones decimales</para>
<para><link linkend="floor"><varname>floor</varname>, <varname>ceil</varname></link>: Redondear al entero inferior o superior</para>
</listitem>

<listitem>
<para><link linkend="round"><varname>round</varname></link>: Redondear a un número de posiciones decimales</para>
</listitem>

<listitem>
Expand Down
30 changes: 24 additions & 6 deletions doc/es/set_span_types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ SELECT timestamps(tstzspanset '{[2001-01-01, 2001-01-03), (2001-01-03, 2001-01-0
<itemizedlist>
<listitem id="setspan_shift">
<indexterm><primary><varname>shift</varname></primary></indexterm>
<para>Desplazar un conjunto o un span con un valor o intervalo de tiempo</para>
<para>Desplazar con un valor o intervalo de tiempo</para>
<para><varname>shift(numbers,base) → numbers</varname></para>
<para><varname>shift(dates,integer) → dates</varname></para>
<para><varname>shift(times,interval) → times</varname></para>
Expand All @@ -728,7 +728,7 @@ SELECT shift(tstzspanset '{[2001-01-01, 2001-01-03], [2001-01-04, 2001-01-05]}',

<listitem id="setspan_scale">
<indexterm><primary><varname>scale</varname></primary></indexterm>
<para>Escalear un conjunto o un rango con un valor o intervalo de tiempo</para>
<para>Escalear con un valor o intervalo de tiempo</para>
<para><varname>scale(numbers,base) → numbers</varname></para>
<para><varname>scale(dates,integer) → dates</varname></para>
<para><varname>scale(times,interval) → times</varname></para>
Expand Down Expand Up @@ -756,7 +756,7 @@ SELECT scale(tstzset '{2001-01-01}', '-1 day');

<listitem id="setspan_shiftScale">
<indexterm><primary><varname>shiftScale</varname></primary></indexterm>
<para>Desplazar y escalear un conjunto o un rango con los valores o intervalos de tiempo</para>
<para>Desplazar y escalear con los valores o intervalos de tiempo</para>
<para><varname>shiftScale(numbers,base,base) → numbers</varname></para>
<para><varname>shiftScale(dates,integer,integer) → dates</varname></para>
<para><varname>shiftScale(times,interval,interval) → times</varname></para>
Expand All @@ -781,9 +781,27 @@ SELECT shiftScale(tstzspanset '{[2001-01-01, 2001-01-03], [2001-01-04, 2001-01-0
</programlisting>
</listitem>

<listitem id="floatspan_round">
<listitem id="floatsetspan_floor">
<indexterm><primary><varname>floor</varname></primary></indexterm>
<indexterm><primary><varname>ceil</varname></primary></indexterm>
<para>Redondear al entero inferior o superior</para>
<para><varname>floor({floatset,floatspans}) → {floatset,floatspans}</varname></para>
<para><varname>ceil({floatset,floatspans}) → {floatset,floatspans}</varname></para>
<programlisting language="sql" xml:space="preserve">
SELECT floor(floatset '{1.5,2.5}');
-- {1, 2}
SELECT ceil(floatspan '[1.5,2.5)');
-- [2, 3)
SELECT floor(floatspan '(1.5, 1.6)');
-- [1, 1]
SELECT ceil(floatspanset '{[1.5, 2.5],[3.5,4.5]}');
-- {[2, 3], [4, 5]}
</programlisting>
</listitem>

<listitem id="floatsetspan_round">
<indexterm><primary><varname>round</varname></primary></indexterm>
<para>Redondear un conjunto o un rango flotante a un número de decimales</para>
<para>Redondear a un número de decimales</para>
<para><varname>round({floatset,floatspans},integer=0) → {floatset,floatspans}</varname></para>
<programlisting language="sql" xml:space="preserve">
SELECT round(floatset '{1.123456789,2.123456789}', 3);
Expand All @@ -800,7 +818,7 @@ SELECT round(floatspanset '{[1.123456789, 2.123456789],[3.123456789,4.123456789]
<listitem id="floatset_degrees">
<indexterm><primary><varname>degrees</varname></primary></indexterm>
<indexterm><primary><varname>radians</varname></primary></indexterm>
<para>Convertir un conjunto flotante a grados o radianes</para>
<para>Convertir a grados o radianes</para>
<para><varname>degrees(floatset, normalize=false) → floatset</varname></para>
<para><varname>radians(floatset) → floatset</varname></para>
<para>El parámetro adicional en la función <varname>degrees</varname> puede ser utilizado para normalizar los valores entre 0 y 360 grados.</para>
Expand Down
16 changes: 15 additions & 1 deletion doc/es/temporal_types_alpha.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,23 @@ SELECT deltaValue(tfloat '{[1.5@2001-01-01, 2@2001-01-02, 1@2001-01-03],
</programlisting>
</listitem>

<listitem id="floor">
<indexterm><primary><varname>floor</varname></primary></indexterm>
<indexterm><primary><varname>ceil</varname></primary></indexterm>
<para>Redondear al entero inferior o superior</para>
<para><varname>floor(tfloat) → tfloat</varname></para>
<para><varname>ceil(tfloat) → tfloat</varname></para>
<programlisting language="sql" xml:space="preserve">
SELECT floor(tfloat '[0.5@2001-01-01, 1.5@2001-01-02]');
-- [0@2001-01-01, 1@2001-01-02]
SELECT ceil(tfloat '[0.5@2001-01-01, 0.6@2001-01-02, 0.7@2001-01-03]');
-- [1@2001-01-01, 1@2001-01-03]
</programlisting>
</listitem>

<listitem id="round">
<indexterm><primary><varname>round</varname></primary></indexterm>
<para>Redondear los valores a un número de posiciones decimales</para>
<para>Redondear a un número de posiciones decimales</para>
<para><varname>round(tfloat,integer=0) → tfloat</varname></para>
<programlisting language="sql" xml:space="preserve">
SELECT round(tfloat '[0.785398163397448@2001-01-01, 2.356194490192345@2001-01-02]', 2);
Expand Down
Binary file modified doc/mobilitydb-manual.pdf
Binary file not shown.
20 changes: 14 additions & 6 deletions doc/reference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -252,23 +252,27 @@

<itemizedlist>
<listitem>
<para><link linkend="setspan_shift"><varname>shift</varname></link>: Shift the set or span by a value or interval</para>
<para><link linkend="setspan_shift"><varname>shift</varname></link>: Shift by a value or interval</para>
</listitem>

<listitem>
<para><link linkend="setspan_scale"><varname>scale</varname></link>: Scale the set or span by a value or interval</para>
<para><link linkend="setspan_scale"><varname>scale</varname></link>: Scale by a value or interval</para>
</listitem>

<listitem>
<para><link linkend="setspan_shiftScale"><varname>shiftScale</varname></link>: Shift and scale the set or span by the values or intervals</para>
<para><link linkend="setspan_shiftScale"><varname>shiftScale</varname></link>: Shift and scale by the values or intervals</para>
</listitem>

<listitem>
<para><link linkend="floatspan_round"><varname>round</varname></link>: Round the bounds of a float set or span to a number of decimal places</para>
<para><link linkend="floatsetspan_floor"><varname>floor</varname>, <varname>ceil</varname></link>: Round down or up to the lowest integer</para>
</listitem>

<listitem>
<para><link linkend="floatset_degrees"><varname>degrees</varname>, <varname>radians</varname></link>: Convert a float set to degrees or radians</para>
<para><link linkend="floatsetspan_round"><varname>round</varname></link>: Round to a number of decimal places</para>
</listitem>

<listitem>
<para><link linkend="floatset_degrees"><varname>degrees</varname>, <varname>radians</varname></link>: Transform to degrees or radians</para>
</listitem>

<listitem>
Expand All @@ -280,7 +284,7 @@
</listitem>

<listitem>
<para><link linkend="time_tprecision"><varname>tprecision</varname></link>: Set the temporal precision of the time value to the interval with respect to the origin</para>
<para><link linkend="time_tprecision"><varname>tprecision</varname></link>: Set the temporal precision to the interval with respect to the origin</para>
</listitem>
</itemizedlist>
</sect2>
Expand Down Expand Up @@ -1094,6 +1098,10 @@
<para><link linkend="deltaValue"><varname>deltaValue</varname></link>: Return the value difference between consecutive instants of the temporal number</para>
</listitem>

<listitem>
<para><link linkend="floor"><varname>floor</varname>, <varname>ceil</varname></link>: Round down or up to the nearest integer</para>
</listitem>

<listitem>
<para><link linkend="round"><varname>round</varname></link>: Round the values to a number of decimal places</para>
</listitem>
Expand Down
30 changes: 24 additions & 6 deletions doc/set_span_types.xml
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ SELECT timestamps(tstzspanset '{[2001-01-01, 2001-01-03), (2001-01-03, 2001-01-0
<itemizedlist>
<listitem id="setspan_shift">
<indexterm><primary><varname>shift</varname></primary></indexterm>
<para>Shift the set or span by a value or interval</para>
<para>Shift by a value or interval</para>
<para><varname>shift(numbers,base) → numbers</varname></para>
<para><varname>shift(dates,integer) → dates</varname></para>
<para><varname>shift(times,interval) → times</varname></para>
Expand All @@ -716,7 +716,7 @@ SELECT shift(tstzspanset '{[2001-01-01, 2001-01-03], [2001-01-04, 2001-01-05]}',

<listitem id="setspan_scale">
<indexterm><primary><varname>scale</varname></primary></indexterm>
<para>Scale the set or span by a value or interval</para>
<para>Scale by a value or interval</para>
<para><varname>scale(numbers,base) → numbers</varname></para>
<para><varname>scale(dates,integer) → dates</varname></para>
<para><varname>scale(times,interval) → times</varname></para>
Expand Down Expand Up @@ -744,7 +744,7 @@ SELECT scale(tstzset '{2001-01-01}', '-1 day');

<listitem id="setspan_shiftScale">
<indexterm><primary><varname>shiftScale</varname></primary></indexterm>
<para>Shift and scale the set or span by the values or intervals</para>
<para>Shift and scale by the values or intervals</para>
<para><varname>shiftScale(numbers,base,base) → numbers</varname></para>
<para><varname>shiftScale(dates,integer,integer) → dates</varname></para>
<para><varname>shiftScale(times,interval,interval) → times</varname></para>
Expand All @@ -769,9 +769,27 @@ SELECT shiftScale(tstzspanset '{[2001-01-01, 2001-01-03], [2001-01-04, 2001-01-0
</programlisting>
</listitem>

<listitem id="floatspan_round">
<listitem id="floatsetspan_floor">
<indexterm><primary><varname>floor</varname></primary></indexterm>
<indexterm><primary><varname>ceil</varname></primary></indexterm>
<para>Round down or up to the nearest integer</para>
<para><varname>floor({floatset,floatspans}) → {floatset,floatspans}</varname></para>
<para><varname>ceil({floatset,floatspans}) → {floatset,floatspans}</varname></para>
<programlisting language="sql" xml:space="preserve">
SELECT floor(floatset '{1.5,2.5}');
-- {1, 2}
SELECT ceil(floatspan '[1.5,2.5)');
-- [2, 3)
SELECT floor(floatspan '(1.5, 1.6)');
-- [1, 1]
SELECT ceil(floatspanset '{[1.5, 2.5],[3.5,4.5]}');
-- {[2, 3], [4, 5]}
</programlisting>
</listitem>

<listitem id="floatsetspan_round">
<indexterm><primary><varname>round</varname></primary></indexterm>
<para>Round a float set, span, or span set to a number of decimal places</para>
<para>Round to a number of decimal places</para>
<para><varname>round({floatset,floatspans},integer=0) → {floatset,floatspans}</varname></para>
<programlisting language="sql" xml:space="preserve">
SELECT round(floatset '{1.123456789,2.123456789}', 3);
Expand All @@ -788,7 +806,7 @@ SELECT round(floatspanset '{[1.123456789, 2.123456789],[3.123456789,4.123456789]
<listitem id="floatset_degrees">
<indexterm><primary><varname>degrees</varname></primary></indexterm>
<indexterm><primary><varname>radians</varname></primary></indexterm>
<para>Convert a flot set to degrees or radians</para>
<para>Convert to degrees or radians</para>
<para><varname>degrees(floatset, normalize=false) → floatset</varname></para>
<para><varname>radians(floatset) → floatset</varname></para>
<para>The additional parameter in the <varname>degrees</varname> function can be used to normalize the values between 0 and 360 degrees.</para>
Expand Down
16 changes: 15 additions & 1 deletion doc/temporal_types_alpha.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,23 @@ SELECT deltaValue(tfloat '{[1.5@2001-01-01, 2@2001-01-02, 1@2001-01-03],
</programlisting>
</listitem>

<listitem id="floor">
<indexterm><primary><varname>floor</varname></primary></indexterm>
<indexterm><primary><varname>ceil</varname></primary></indexterm>
<para>Round up or down to the neareast integer</para>
<para><varname>floor(tfloat) → tfloat</varname></para>
<para><varname>ceil(tfloat) → tfloat</varname></para>
<programlisting language="sql" xml:space="preserve">
SELECT floor(tfloat '[0.5@2001-01-01, 1.5@2001-01-02]');
-- [0@2001-01-01, 1@2001-01-02]
SELECT ceil(tfloat '[0.5@2001-01-01, 0.6@2001-01-02, 0.7@2001-01-03]');
-- [1@2001-01-01, 1@2001-01-03]
</programlisting>
</listitem>

<listitem id="round">
<indexterm><primary><varname>round</varname></primary></indexterm>
<para>Round the values to a number of decimal places</para>
<para>Round to a number of decimal places</para>
<para><varname>round(tfloat,integer=0) → tfloat</varname></para>
<programlisting language="sql" xml:space="preserve">
SELECT round(tfloat '[0.785398163397448@2001-01-01, 2.356194490192345@2001-01-02]', 2);
Expand Down
2 changes: 2 additions & 0 deletions meos/include/general/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <postgres.h>
/* MEOS */
#include <meos.h>
#include "general/temporal.h"
#include "general/meos_catalog.h"

/*****************************************************************************/
Expand Down Expand Up @@ -92,6 +93,7 @@ extern Datum span_incr_bound(Datum upper, meosType basetype);
extern Span *spanarr_normalize(Span *spans, int count, bool sort,
int *newcount);
extern void span_bounds(const Span *s, double *xmin, double *xmax);
extern void floatspan_floor_ceil_iter(Span *s, datum_func1 func);
extern void lower_upper_shift_scale_value(Datum shift, Datum width,
meosType type, bool hasshift, bool haswidth, Datum *lower, Datum *upper);
extern void lower_upper_shift_scale_time(const Interval *shift,
Expand Down
4 changes: 2 additions & 2 deletions meos/include/general/temporal.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@
#define CONTINUOUS false

/** Symbolic constants for sets and for normalizing spans */
#define ORDERED true
#define ORDERED_NO false
#define ORDER true
#define ORDER_NO false

/** Symbolic constants for the output of string elements */
#define QUOTES true
Expand Down
10 changes: 9 additions & 1 deletion meos/include/meos.h
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ extern Span *intspan_make(int lower, int upper, bool lower_inc, bool upper_inc);
extern Set *set_copy(const Set *s);
extern Span *span_copy(const Span *s);
extern SpanSet *spanset_copy(const SpanSet *ss);
extern SpanSet *spanset_make(Span *spans, int count, bool normalize, bool ordered);
extern SpanSet *spanset_make(Span *spans, int count, bool normalize, bool order);
extern Set *textset_make(const text **values, int count);
extern Set *tstzset_make(const TimestampTz *values, int count);
extern Span *tstzspan_make(TimestampTz lower, TimestampTz upper, bool lower_inc, bool upper_inc);
Expand Down Expand Up @@ -629,12 +629,18 @@ extern SpanSet *bigintspanset_shift_scale(const SpanSet *ss, int64 shift, int64
extern Set *dateset_shift_scale(const Set *s, int shift, int width, bool hasshift, bool haswidth);
extern Span *datespan_shift_scale(const Span *s, int shift, int width, bool hasshift, bool haswidth);
extern SpanSet *datespanset_shift_scale(const SpanSet *ss, int shift, int width, bool hasshift, bool haswidth);
extern Set *floatset_ceil(const Set *s);
extern Set *floatset_floor(const Set *s);
extern Set *floatset_degrees(const Set *s, bool normalize);
extern Set *floatset_radians(const Set *s);
extern Set *floatset_round(const Set *s, int maxdd);
extern Set *floatset_shift_scale(const Set *s, double shift, double width, bool hasshift, bool haswidth);
extern Span *floatspan_ceil(const Span *s);
extern Span *floatspan_floor(const Span *s);
extern Span *floatspan_round(const Span *s, int maxdd);
extern Span *floatspan_shift_scale(const Span *s, double shift, double width, bool hasshift, bool haswidth);
extern SpanSet *floatspanset_ceil(const SpanSet *ss);
extern SpanSet *floatspanset_floor(const SpanSet *ss);
extern SpanSet *floatspanset_round(const SpanSet *ss, int maxdd);
extern SpanSet *floatspanset_shift_scale(const SpanSet *ss, double shift, double width, bool hasshift, bool haswidth);
extern Set *geoset_round(const Set *s, int maxdd);
Expand Down Expand Up @@ -1426,6 +1432,8 @@ extern Temporal *temporal_shift_time(const Temporal *temp, const Interval *shift
extern TInstant *temporal_to_tinstant(const Temporal *temp);
extern TSequence *temporal_to_tsequence(const Temporal *temp, char *interp_str);
extern TSequenceSet *temporal_to_tsequenceset(const Temporal *temp, char *interp_str);
extern Temporal *tfloat_floor(const Temporal *temp);
extern Temporal *tfloat_ceil(const Temporal *temp);
extern Temporal *tfloat_degrees(const Temporal *temp, bool normalize);
extern Temporal *tfloat_radians(const Temporal *temp);
extern Temporal *tfloat_round(const Temporal *temp, int maxdd);
Expand Down
Loading

0 comments on commit c32dd4b

Please sign in to comment.