Skip to content

Commit

Permalink
Improve MEOS API for PG types (MobilityDB#634)
Browse files Browse the repository at this point in the history
  • Loading branch information
estebanzimanyi authored Oct 17, 2024
1 parent ed0cd7d commit 841a386
Show file tree
Hide file tree
Showing 40 changed files with 168 additions and 90 deletions.
4 changes: 2 additions & 2 deletions meos/examples/02_ais_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ int main(void)
int read = fscanf(file, "%31[^,],%ld,%lf,%lf,%lf\n",
timestamp_buffer, &rec.MMSI, &rec.Latitude, &rec.Longitude, &rec.SOG);
/* Transform the string representing the timestamp into a timestamp value */
rec.T = pg_timestamp_in(timestamp_buffer, -1);
rec.T = timestamp_in(timestamp_buffer, -1);

if (read == 5)
no_records++;
Expand All @@ -116,7 +116,7 @@ int main(void)
/* Print only 1 out of 1000 records */
if (no_records % 1000 == 0)
{
char *t_out = pg_timestamp_out(rec.T);
char *t_out = timestamp_out(rec.T);
/* See above the assumptions made wrt the input data in the file */
sprintf(point_buffer, "SRID=4326;Point(%lf %lf)@%s+00", rec.Longitude,
rec.Latitude, t_out);
Expand Down
4 changes: 2 additions & 2 deletions meos/examples/03_ais_assemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ int main(void)
int read = fscanf(file, "%31[^,],%ld,%lf,%lf,%lf\n",
timestamp_buffer, &rec.MMSI, &rec.Latitude, &rec.Longitude, &rec.SOG);
/* Transform the string representing the timestamp into a timestamp value */
rec.T = pg_timestamp_in(timestamp_buffer, -1);
rec.T = timestamp_in(timestamp_buffer, -1);

if (read == 5)
{
Expand Down Expand Up @@ -186,7 +186,7 @@ int main(void)
* - The coordinates are given in the WGS84 geographic coordinate system
* - The timestamps are given in GMT time zone
*/
char *t_out = pg_timestamp_out(rec.T);
char *t_out = timestamp_out(rec.T);
sprintf(point_buffer, "SRID=4326;Point(%lf %lf)@%s+00", rec.Longitude,
rec.Latitude, t_out);
free(t_out);
Expand Down
6 changes: 3 additions & 3 deletions meos/examples/03_berlinmod_assemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ int main(void)
&rec.tripid, &rec.vehid, date_buffer, &rec.seq, point_buffer,
timestamp_buffer);
/* Transform the string representing the date into a date value */
rec.day = pg_date_in(date_buffer);
rec.day = date_in(date_buffer);
/* Transform the string representing the trip into a temporal value */
rec.point = geom_in(point_buffer, -1);
/* Transform the string representing the timestamp into a timestamp value */
rec.t = pg_timestamp_in(timestamp_buffer, -1);
rec.t = timestamp_in(timestamp_buffer, -1);
/* Transform the string representing the trip into a temporal value */
TInstant *inst = tpointinst_make(rec.point, rec.t);
/* Free the point as it's not needed anymore */
Expand Down Expand Up @@ -238,7 +238,7 @@ int main(void)
for (i = 0; i < no_trips; i++)
{
/* Write line in the CSV file */
char *date_str = pg_date_out(trips[i].day);
char *date_str = date_out(trips[i].day);
size_t length;
/* Encode using server machine endian */
char *trip_str = temporal_as_hexwkb(trips[i].trip, WKB_EXTENDED, &length);
Expand Down
4 changes: 2 additions & 2 deletions meos/examples/04_ais_store.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ main(int argc, char **argv)
int read = fscanf(file, "%32[^,],%ld,%lf,%lf,%lf\n",
text_buffer, &rec.MMSI, &rec.Latitude, &rec.Longitude, &rec.SOG);
/* Transform the string representing the timestamp into a timestamp value */
rec.T = pg_timestamp_in(text_buffer, -1);
rec.T = timestamp_in(text_buffer, -1);

if (read == 5)
{
Expand Down Expand Up @@ -234,7 +234,7 @@ main(int argc, char **argv)
len = sprintf(insert_buffer,
"INSERT INTO public.AISInstants(MMSI, location, SOG) VALUES ");

char *t_out = pg_timestamp_out(rec.T);
char *t_out = timestamp_out(rec.T);
len += sprintf(insert_buffer + len,
"(%ld, 'SRID=4326;Point(%lf %lf)@%s+00', '%lf@%s+00'),",
rec.MMSI, rec.Longitude, rec.Latitude, t_out, rec.SOG, t_out);
Expand Down
4 changes: 2 additions & 2 deletions meos/examples/04_ais_stream_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ main(int argc, char **argv)
int read = fscanf(file, "%32[^,],%ld,%lf,%lf,%lf\n",
text_buffer, &rec.MMSI, &rec.Latitude, &rec.Longitude, &rec.SOG);
/* Transform the string representing the timestamp into a timestamp value */
rec.T = pg_timestamp_in(text_buffer, -1);
rec.T = timestamp_in(text_buffer, -1);

if (read == 5)
no_records++;
Expand Down Expand Up @@ -272,7 +272,7 @@ main(int argc, char **argv)
* - The coordinates are given in the WGS84 geographic coordinate system
* - The timestamps are given in GMT time zone
*/
char *t_out = pg_timestamp_out(rec.T);
char *t_out = timestamp_out(rec.T);
sprintf(point_buffer, "SRID=4326;Point(%lf %lf)@%s+00", rec.Longitude,
rec.Latitude, t_out);
free(t_out);
Expand Down
4 changes: 2 additions & 2 deletions meos/examples/04_ais_stream_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ main(int argc, char **argv)
int read = fscanf(file_in, "%32[^,],%ld,%lf,%lf,%lf\n",
text_buffer, &rec.MMSI, &rec.Latitude, &rec.Longitude, &rec.SOG);
/* Transform the string representing the timestamp into a timestamp value */
rec.T = pg_timestamp_in(text_buffer, -1);
rec.T = timestamp_in(text_buffer, -1);

if (read == 5)
no_records++;
Expand Down Expand Up @@ -188,7 +188,7 @@ main(int argc, char **argv)
* - The coordinates are given in the WGS84 geographic coordinate system
* - The timestamps are given in GMT time zone
*/
char *t_out = pg_timestamp_out(rec.T);
char *t_out = timestamp_out(rec.T);
sprintf(point_buffer, "SRID=4326;Point(%lf %lf)@%s+00", rec.Longitude,
rec.Latitude, t_out);
free(t_out);
Expand Down
6 changes: 3 additions & 3 deletions meos/examples/05_berlinmod_disassemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ int main(void)
int read = fscanf(file, "%d,%d,%10[^,],%d,%170000[^\n]\n",
&tripid, &vehid, date_buffer, &seq, trip_buffer);
/* Transform the string representing the date into a date value */
DateADT day = pg_date_in(date_buffer);
DateADT day = date_in(date_buffer);
/* Transform the string representing the trip into a temporal value */
Temporal *trip = temporal_from_hexwkb(trip_buffer);

Expand Down Expand Up @@ -198,9 +198,9 @@ int main(void)
}

/* Write line in the CSV file */
char *date_str = pg_date_out(trips[min_trip].day);
char *date_str = date_out(trips[min_trip].day);
char *geom_str = geo_as_ewkt((GSERIALIZED *) &min_inst->value, 6);
char *time_str = pg_timestamptz_out(min_inst->t);
char *time_str = timestamptz_out(min_inst->t);
fprintf(file,"%d,%d,%s,%d,%s,%s\n", trips[min_trip].vehid,
trips[min_trip].vehid, date_str, trips[min_trip].seq, geom_str, time_str);
free(date_str); free(geom_str); free(time_str); free(min_inst);
Expand Down
10 changes: 5 additions & 5 deletions meos/examples/07_berlinmod_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ int main(void)
true, &no_trip_tiles);
/* Compute the (value and time) tiles for speed of trips */
TBox *speed_extent = tbox_in("TBox XT([0, 35),[2020-06-01, 2020-06-05))");
Interval *duration = pg_interval_in("1 day", -1);
TimestampTz torigin = pg_timestamptz_in("2020-06-01", -1);
Interval *duration = interval_in("1 day", -1);
TimestampTz torigin = timestamptz_in("2020-06-01", -1);
TBox *speed_tiles = tfloatbox_value_time_tiles(speed_extent, 10.0, duration,
0.0, torigin, &no_speed_tiles);
/* Variables for tiling the trips and their speeds */
Expand Down Expand Up @@ -221,10 +221,10 @@ int main(void)
memset(&intervalzero, 0, sizeof(Interval));
for (i = 0; i < no_trip_tiles; i++)
{
if (pg_interval_cmp(&trip_splits[k].duration, &intervalzero) != 0)
if (interval_cmp(&trip_splits[k].duration, &intervalzero) != 0)
{
char *stbox_str = stbox_out(&trip_tiles[k], 0);
char *interval_str = pg_interval_out(&trip_splits[k].duration);
char *interval_str = interval_out(&trip_splits[k].duration);
printf("Tile: %d, Box: %s, Count: %d, Duration: %s, Distance: %f\n",
i, stbox_str, trip_splits[k].count, interval_str,
trip_splits[k].distance);
Expand All @@ -244,7 +244,7 @@ int main(void)
{
char *span_str = floatspan_out(&speed_tiles[k].span, 0);
char *tstzspan_str = tstzspan_out(&speed_tiles[k].period);
char *interval_str = pg_interval_out(&speed_splits[k].duration);
char *interval_str = interval_out(&speed_splits[k].duration);
printf("Tile: %d, Span: %s, Period: %s, Count: %d, Duration: %s\n",
i, span_str, tstzspan_str, speed_splits[k].count, interval_str);
free(span_str); free(tstzspan_str); free(interval_str);
Expand Down
4 changes: 2 additions & 2 deletions meos/examples/08_berlinmod_simplify.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ int main(void)
&trips[i].tripId, &trips[i].vehId, date_buffer, &trips[i].seq,
trip_buffer);
/* Transform the string representing the date into a date value */
trips[i].day = pg_date_in(date_buffer);
trips[i].day = date_in(date_buffer);
/* Transform the string representing the trip into a temporal value */
trips[i].trip = temporal_from_hexwkb(trip_buffer);

Expand Down Expand Up @@ -147,7 +147,7 @@ int main(void)
{
trips_dp[i] = temporal_simplify_dp(trips[i].trip, DELTA_DISTANCE, false);
trips_sed[i] = temporal_simplify_dp(trips[i].trip, DELTA_DISTANCE, true);
char *day_str = pg_date_out(trips[i].day);
char *day_str = date_out(trips[i].day);
printf("Vehicle: %d, Date: %s, Seq: %d, No. of instants: %d, "
"No. of instants DP: %d, No. of instants SED: %d\n",
trips[i].vehId, day_str, trips[i].seq,
Expand Down
6 changes: 3 additions & 3 deletions meos/examples/09_berlinmod_aggregate.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@ int main(void)
/* Variable keeping the current aggregate state */
SkipList *state = NULL;
STBox *extent = NULL;
Interval *interval = pg_interval_in("1 hour", -1);
TimestampTz origin = pg_timestamptz_in("2020-06-01", -1);
Interval *interval = interval_in("1 hour", -1);
TimestampTz origin = timestamptz_in("2020-06-01", -1);

/* Continue reading the file */
do
{
int read = fscanf(file, "%d,%d,%10[^,],%d,%170000[^\n]\n",
&trip_rec.tripid, &trip_rec.vehid, date_buffer, &trip_rec.seq, trip_buffer);
/* Transform the string representing the date into a date value */
DateADT day = pg_date_in(date_buffer);
DateADT day = date_in(date_buffer);
trip_rec.day = day;
/* Transform the string representing the trip into a temporal value */
trip_rec.trip = temporal_from_hexwkb(trip_buffer);
Expand Down
4 changes: 2 additions & 2 deletions meos/examples/ais_assemble_full.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ int main(void)
switch (field)
{
case 0:
rec.T = pg_timestamp_in(token, -1);
rec.T = timestamp_in(token, -1);
if (rec.T != 0)
has_t = true;
break;
Expand Down Expand Up @@ -283,7 +283,7 @@ int main(void)
/* Create an Trip instant from the record */
if (has_lat && has_long)
{
char *t_out = pg_timestamp_out(rec.T);
char *t_out = timestamp_out(rec.T);
sprintf(point_buffer, "SRID=4326;Point(%lf %lf)@%s+00", rec.Longitude,
rec.Latitude, t_out);
free(t_out);
Expand Down
4 changes: 2 additions & 2 deletions meos/examples/ais_expand.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ int main(void)
int read = fscanf(file, "%31[^,],%ld,%lf,%lf,%lf\n",
timestamp_buffer, &rec.MMSI, &rec.Latitude, &rec.Longitude, &rec.SOG);
/* Transform the string representing the timestamp into a timestamp value */
rec.T = pg_timestamp_in(timestamp_buffer, -1);
rec.T = timestamp_in(timestamp_buffer, -1);

if (read == 5)
no_records++;
Expand Down Expand Up @@ -168,7 +168,7 @@ int main(void)
* - The coordinates are given in the WGS84 geographic coordinate system
* - The timestamps are given in GMT time zone
*/
char *t_out = pg_timestamp_out(rec.T);
char *t_out = timestamp_out(rec.T);
sprintf(inst_buffer, "SRID=4326;Point(%lf %lf)@%s", rec.Longitude,
rec.Latitude, t_out);
free(t_out);
Expand Down
4 changes: 2 additions & 2 deletions meos/examples/ais_expand_full.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ int main(void)
switch (field)
{
case 0:
rec.T = pg_timestamp_in(token, -1);
rec.T = timestamp_in(token, -1);
if (rec.T != 0)
has_t = true;
break;
Expand Down Expand Up @@ -277,7 +277,7 @@ int main(void)
/* Create an Trip instant from the record */
if (has_lat && has_long)
{
char *t_out = pg_timestamp_out(rec.T);
char *t_out = timestamp_out(rec.T);
sprintf(point_buffer, "SRID=4326;Point(%lf %lf)@%s+00", rec.Longitude,
rec.Latitude, t_out);
free(t_out);
Expand Down
6 changes: 3 additions & 3 deletions meos/examples/ais_generalize.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ int main(void)
free(temp);

/* Minimum tdelta simplification */
Interval *secs1 = pg_interval_in("1 second", -1);
Interval *secs10 = pg_interval_in("10 seconds", -1);
Interval *secs1 = interval_in("1 second", -1);
Interval *secs10 = interval_in("10 seconds", -1);
temp = temporal_simplify_min_tdelta(trips[i].trip, secs1);
min_tdelta_1 += temporal_mem_size(temp);
no_min_tdelta_1 += temporal_num_instants(temp);
Expand All @@ -224,7 +224,7 @@ int main(void)
free(temp);

/* Tprecision simplification */
TimestampTz origin = pg_timestamp_in("2000-01-01", -1);
TimestampTz origin = timestamp_in("2000-01-01", -1);
temp = temporal_tprecision(trips[i].trip, secs1, origin);
tprec_1s += temporal_mem_size(temp);
no_tprec_1s += temporal_num_instants(temp);
Expand Down
4 changes: 2 additions & 2 deletions meos/examples/stbox_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ int main(void)

/* Initialize values for tiling */
STBox *box = stbox_in("STBOX XT(((1,1),(10,10)),[2020-03-01, 2020-03-10])");
Interval *interv = pg_interval_in("5 days", -1);
Interval *interv = interval_in("5 days", -1);
GSERIALIZED *sorigin = geom_in("Point(0 0 0)", -1);
TimestampTz torigin = pg_timestamptz_in("2020-03-01", -1);
TimestampTz torigin = timestamptz_in("2020-03-01", -1);

/* Perform tiling */
STBox *boxes;
Expand Down
4 changes: 2 additions & 2 deletions meos/examples/tbox_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ int main(void)
TBox *box = intspan ?
tbox_in("TBOXINT XT([1,10],[2020-03-01, 2020-03-10])") :
tbox_in("TBOXFLOAT XT([1,10],[2020-03-01, 2020-03-10])");
Interval *interv = pg_interval_in("5 days", -1);
TimestampTz torigin = pg_timestamptz_in("2020-03-01", -1);
Interval *interv = interval_in("5 days", -1);
TimestampTz torigin = timestamptz_in("2020-03-01", -1);

/* Perform tiling */
TBox *boxes;
Expand Down
4 changes: 2 additions & 2 deletions meos/examples/tfloat_assemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ int main(void)
/* Sequence constructed from the input instants */
Temporal *seq = NULL;
/* Interval to add */
Interval *oneday = pg_interval_in("1 day", -1);
Interval *oneday = interval_in("1 day", -1);
/* Iterator variable */
int i;
/* Seed the random number generator with the current time in seconds. */
srandom (time (0));

TimestampTz t = pg_timestamptz_in("1999-12-31", -1);
TimestampTz t = timestamptz_in("1999-12-31", -1);
for (i = 0; i < MAX_INSTANTS; i++)
{
t = add_timestamptz_interval(t, oneday);
Expand Down
4 changes: 2 additions & 2 deletions meos/examples/tfloat_expand.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ int main(void)
/* Expandable sequence */
Temporal *seq = NULL;
/* Interval to add */
Interval *oneday = pg_interval_in("1 day", -1);
Interval *oneday = interval_in("1 day", -1);
/* Iterator variable */
int i;

TimestampTz t = pg_timestamptz_in("1999-12-31", -1);
TimestampTz t = timestamptz_in("1999-12-31", -1);
for (i = 0; i < MAX_INSTANTS; i++)
{
t = add_timestamptz_interval(t, oneday);
Expand Down
6 changes: 3 additions & 3 deletions meos/examples/tfloat_tile.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ int main(void)
meos_initialize();

Temporal *tfloat = tfloat_in("[1@2020-03-01, 10@2020-03-10]");
Interval *interv = pg_interval_in("2 days", -1);
Interval *interv = interval_in("2 days", -1);
double vorigin = 0.0;
TimestampTz torigin = pg_timestamptz_in("2020-03-01", -1);
TimestampTz torigin = timestamptz_in("2020-03-01", -1);

bool valuesplit = true; /* Set this parameter to enable/disable value split */
bool timesplit = true; /* Set this parameter to enable/disable time split */
Expand Down Expand Up @@ -87,7 +87,7 @@ int main(void)
int i;
for (i = 0; i < count; i++)
{
char *time_str = timesplit ? pg_timestamptz_out(time_bins[i]) : "";
char *time_str = timesplit ? timestamptz_out(time_bins[i]) : "";
char *temp_str = tfloat_out(result[i], 3);
if (valuesplit)
snprintf(output_buffer, sizeof(output_buffer), "%f, %s%s%s\n",
Expand Down
6 changes: 3 additions & 3 deletions meos/examples/tpoint_assemble.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ int main(void)
/* Sequence constructed from the input instants */
Temporal *seq = NULL;
/* Interval to add */
Interval *oneday = pg_interval_in("1 day", -1);
Interval *oneday = interval_in("1 day", -1);
/* Iterator variable */
int i;

printf("Reading the instants (one '*' marker every %d instants)\n",
NO_INSTANTS_BATCH);

TimestampTz t = pg_timestamptz_in("1999-12-31", -1);
TimestampTz t = timestamptz_in("1999-12-31", -1);
for (i = 0; i < MAX_INSTANTS; i++)
{
if (i % NO_INSTANTS_BATCH == 0)
Expand All @@ -92,7 +92,7 @@ int main(void)
fflush(stdout);
}
t = add_timestamptz_interval(t, oneday);
char *time_str = pg_timestamptz_out(t);
char *time_str = timestamptz_out(t);
int value = i % 2 + 1;
#if GEODETIC == true
sprintf(inst_buffer, "SRID=4326;Point(%d %d)@%s", value, value, time_str);
Expand Down
Loading

0 comments on commit 841a386

Please sign in to comment.