File: data_generator.xml

package info (click to toggle)
mobilitydb 1.3.0~alpha-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 118,528 kB
  • sloc: ansic: 166,361; sql: 99,983; xml: 22,860; yacc: 447; makefile: 200; lex: 151; sh: 142
file content (680 lines) | stat: -rw-r--r-- 35,243 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
<?xml version="1.0" encoding="UTF-8"?>
<!--
   ****************************************************************************
    MobilityDB Manual
    Copyright(c) MobilityDB Contributors

    This documentation is licensed under a Creative Commons Attribution-Share
    Alike 3.0 License: https://creativecommons.org/licenses/by-sa/3.0/
   ****************************************************************************
-->
<appendix xml:id="data_generator">
	<title>Synthetic Data Generator</title>
	<para>
		In many circumstances, it is necessary to have a test dataset to evaluate alternative implementation approaches or to perform benchmarks. It is often required that such a data set have particular requirements in size or in the intrinsic characteristics of its data. Even if a real-world dataset could be available, it may be not ideal for such experiments for multiple reasons. Therefore, a synthetic data generator that could be customized to produce data according to the given requirements is often the best solution. Obviously, experiments with synthetic data should be complemented with experiments with real-world data to have a thorough understanding of the problem at hand.
	</para>

	<para>
		MobilityDB provides a simple synthetic data generator that can be used for such purposes. In particular, such a data generator was used for generating the database used for the regression tests in MobilityDB. The data generator is programmed in PL/pgSQL so it can be easily customized. It is located in the directory <varname>datagen</varname> in the repository. In this appendix, we briefly introduce the basic functionality of the generator. We first list the functions generating random values for the various PostgreSQL, PostGIS, and MobilityDB data types, and then give examples how to use these functions for generating tables of such values. The parameters of the functions are not specified, refer to the source files where detailed explanations about the various parameters can be found.
	</para>

	<sect1>
		<title>Generator for PostgreSQL Types</title>
			<itemizedlist>
				<listitem>
					<para><varname>random_bool</varname>: Generate a random boolean</para>
				</listitem>
				<listitem>
					<para><varname>random_int</varname>: Generate a random integer</para>
				</listitem>
				<listitem>
					<para><varname>random_int_array</varname>: Generate a random array of integers</para>
				</listitem>
				<listitem>
					<para><varname>random_int4range</varname>: Generate a random integer range</para>
				</listitem>
				<listitem>
					<para><varname>random_float</varname>: Generate a random float</para>
				</listitem>
				<listitem>
					<para><varname>random_float_array</varname>: Generate a random array of floats</para>
				</listitem>
				<listitem>
					<para><varname>random_text</varname>: Generate a random text</para>
				</listitem>
				<listitem>
					<para><varname>random_timestamptz</varname>: Generate a random timestamp with time zone</para>
				</listitem>
				<listitem>
					<para><varname>random_timestamptz_array</varname>: Generate a random array of timestamps with time zone</para>
				</listitem>
				<listitem>
					<para><varname>random_minutes</varname>: Generate a random interval of minutes</para>
				</listitem>
				<listitem>
					<para><varname>random_tstzrange</varname>: Generate a random timestamp with time zone range</para>
				</listitem>
				<listitem>
					<para><varname>random_tstzrange_array</varname>: Generate a random array of timestamp with time zone ranges</para>
				</listitem>
			</itemizedlist>
	</sect1>

	<sect1>
		<title>Generator for PostGIS Types</title>
			<itemizedlist>
				<listitem>
					<para><varname>random_geom_point</varname>: Generate a random 2D geometric point</para>
				</listitem>
				<listitem>
					<para><varname>random_geom_point3D</varname>: Generate a random 3D geometric point</para>
				</listitem>
				<listitem>
					<para><varname>random_geog_point</varname>: Generate a random 2D geographic point</para>
				</listitem>
				<listitem>
					<para><varname>random_geog_point3D</varname>: Generate a random 3D geographic point</para>
				</listitem>
				<listitem>
					<para><varname>random_geom_point_array</varname>: Generate a random array of 2D geometric points</para>
				</listitem>
				<listitem>
					<para><varname>random_geom_point3D_array</varname>: Generate a random array of 3D geometric points</para>
				</listitem>
				<listitem>
					<para><varname>random_geog_point_array</varname>: Generate a random array of 2D geographic points</para>
				</listitem>
				<listitem>
					<para><varname>random_geog_point3D_array</varname>: Generate a random array of 3D geographic points</para>
				</listitem>
				<listitem>
					<para><varname>random_geom_linestring</varname>: Generate a random geometric 2D linestring</para>
				</listitem>
				<listitem>
					<para><varname>random_geom_linestring3D</varname>: Generate a random geometric 3D linestring</para>
				</listitem>
				<listitem>
					<para><varname>random_geog_linestring</varname>: Generate a random geographic 2D linestring</para>
				</listitem>
				<listitem>
					<para><varname>random_geog_linestring3D</varname>: Generate a random geographic 3D linestring</para>
				</listitem>
				<listitem>
					<para><varname>random_geom_polygon</varname>: Generate a random geometric 2D polygon without holes</para>
				</listitem>
				<listitem>
					<para><varname>random_geom_polygon3D</varname>: Generate a random geometric 3D polygon without holes</para>
				</listitem>
				<listitem>
					<para><varname>random_geog_polygon</varname>: Generate a random geographic 2D polygon without holes</para>
				</listitem>
				<listitem>
					<para><varname>random_geog_polygon3D</varname>: Generate a random geographic 3D polygon without holes</para>
				</listitem>
				<listitem>
					<para><varname>random_geom_multipoint</varname>: Generate a random geometric 2D multipoint</para>
				</listitem>
				<listitem>
					<para><varname>random_geom_multipoint3D</varname>: Generate a random geometric 3D multipoint</para>
				</listitem>
				<listitem>
					<para><varname>random_geog_multipoint</varname>: Generate a random geographic 2D multipoint</para>
				</listitem>
				<listitem>
					<para><varname>random_geog_multipoint3D</varname>: Generate a random geographic 3D multipoint</para>
				</listitem>
				<listitem>
					<para><varname>random_geom_multilinestring</varname>: Generate a random geometric 2D multilinestring</para>
				</listitem>
				<listitem>
					<para><varname>random_geom_multilinestring3D</varname>: Generate a random geometric 3D multilinestring</para>
				</listitem>
				<listitem>
					<para><varname>random_geog_multilinestring</varname>: Generate a random geographic 2D multilinestring</para>
				</listitem>
				<listitem>
					<para><varname>random_geog_multilinestring3D</varname>: Generate a random geographic 3D multilinestring</para>
				</listitem>
				<listitem>
					<para><varname>random_geom_multipolygon</varname>: Generate a random geometric 2D multipolygon without holes</para>
				</listitem>
				<listitem>
					<para><varname>random_geom_multipolygon3D</varname>: Generate a random geometric 3D multipolygon without holes</para>
				</listitem>
				<listitem>
					<para><varname>random_geog_multipolygon</varname>: Generate a random geographic 2D multipolygon without holes</para>
				</listitem>
				<listitem>
					<para><varname>random_geog_multipolygon3D</varname>: Generate a random geographic 3D multipolygon without holes</para>
				</listitem>
			</itemizedlist>
	</sect1>

	<sect1>
		<title>Generator for MobilityDB Span, Time, and Box Types</title>

			<itemizedlist>
				<listitem>
					<para><varname>random_intspan</varname>: Generate a random integer span</para>
				</listitem>
				<listitem>
					<para><varname>random_floatspan</varname>: Generate a random float span</para>
				</listitem>
				<listitem>
					<para><varname>random_tstzspan</varname>: Generate a random <varname>tstzspan</varname></para>
				</listitem>
				<listitem>
					<para><varname>random_tstzspan_array</varname>: Generate a random array of <varname>tstzspan</varname> values</para>
				</listitem>
				<listitem>
					<para><varname>random_tstzset</varname>: Generate a random <varname>tstzset</varname></para>
				</listitem>
				<listitem>
					<para><varname>random_tstzspanset</varname>: Generate a random <varname>tstzspanset</varname></para>
				</listitem>
				<listitem>
					<para><varname>random_tbox</varname>: Generate a random <varname>tbox</varname></para>
				</listitem>
				<listitem>
					<para><varname>random_stbox</varname>: Generate a random 2D <varname>stbox</varname></para>
				</listitem>
				<listitem>
					<para><varname>random_stbox3D</varname>: Generate a random 3D <varname>stbox</varname></para>
				</listitem>
				<listitem>
					<para><varname>random_geodstbox</varname>: Generate a random 2D geodetic <varname>stbox</varname></para>
				</listitem>
				<listitem>
					<para><varname>random_geodstbox3D</varname>: Generate a random 3D geodetic <varname>stbox</varname></para>
				</listitem>
			</itemizedlist>
	</sect1>

	<sect1>
		<title>Generator for MobilityDB Temporal Types</title>

			<itemizedlist>
				<listitem>
					<para><varname>random_tbool_inst</varname>: Generate a random temporal Boolean of instant subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tint_inst</varname>: Generate a random temporal integer of instant subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tfloat_inst</varname>: Generate a random temporal float of instant subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_ttext_inst</varname>: Generate a random temporal text of instant subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tgeompoint_inst</varname>: Generate a random temporal geometric 2D point of instant subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tgeompoint3D_inst</varname>: Generate a random temporal geometric 3D point of instant subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tgeogpoint_inst</varname>: Generate a random temporal geographic 2D point of instant subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tgeogpoint3D_inst</varname>: Generate a random temporal geographic 3D point of instant subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tbool_discseq</varname>: Generate a random temporal Boolean of sequence subtype and discrete interpolation</para>
				</listitem>
				<listitem>
					<para><varname>random_tint_discseq</varname>: Generate a random temporal integer of sequence subtype and discrete interpolation</para>
				</listitem>
				<listitem>
					<para><varname>random_tfloat_discseq</varname>: Generate a random temporal float of sequence subtype and discrete interpolation</para>
				</listitem>
				<listitem>
					<para><varname>random_ttext_discseq</varname>: Generate a random temporal text of sequence subtype and discrete interpolation</para>
				</listitem>
				<listitem>
					<para><varname>random_tgeompoint_discseq</varname>: Generate a random temporal geometric 2D point of sequence subtype and discrete interpolation</para>
				</listitem>
				<listitem>
					<para><varname>random_tgeompoint3D_discseq</varname>: Generate a random temporal geometric 3D point of sequence subtype and discrete interpolation</para>
				</listitem>
				<listitem>
					<para><varname>random_tgeogpoint_discseq</varname>: Generate a random temporal geographic 2D point of sequence subtype and discrete interpolation</para>
				</listitem>
				<listitem>
					<para><varname>random_tgeogpoint3D_discseq</varname>: Generate a random temporal geographic 3D point of sequence subtype and discrete interpolation</para>
				</listitem>
				<listitem>
					<para><varname>random_tbool_seq</varname>: Generate a random temporal Boolean of sequence subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tint_seq</varname>: Generate a random temporal integer of sequence subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tfloat_seq</varname>: Generate a random temporal float of sequence subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_ttext_seq</varname>: Generate a random temporal text of sequence subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tgeompoint_seq</varname>: Generate a random temporal geometric 2D point of sequence subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tgeompoint3D_seq</varname>: Generate a random temporal geometric 3D point of sequence subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tgeogpoint_seq</varname>: Generate a random temporal geographic 2D point of sequence subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tgeogpoint3D_seq</varname>: Generate a random temporal geographic 3D point of sequence subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tbool_seqset</varname>: Generate a random temporal Boolean of sequence set subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tint_seqset</varname>: Generate a random temporal integer of sequence set subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tfloat_seqset</varname>: Generate a random temporal float of sequence set subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_ttext_seqset</varname>: Generate a random temporal text of sequence set subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tgeompoint_seqset</varname>: Generate a random temporal geometric 2D point of sequence set subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tgeompoint3D_seqset</varname>: Generate a random temporal geometric 3D point of sequence set subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tgeogpoint_seqset</varname>: Generate a random temporal geographic 2D point of sequence set subtype</para>
				</listitem>
				<listitem>
					<para><varname>random_tgeogpoint3D_seqset</varname>: Generate a random temporal geographic 3D point of sequence set subtype</para>
				</listitem>
			</itemizedlist>

	</sect1>

	<sect1>
		<title>Generation of Tables with Random Values</title>

		<para>
			The files <varname>create_test_tables_temporal.sql</varname> and <varname>create_test_tables_tpoint.sql</varname> provide usage examples for the functions generating random values listed above. For example, the first file defines the following function.
		</para>

		<programlisting language="sql" xml:space="preserve" format="linespecific">
CREATE OR REPLACE FUNCTION create_test_tables_temporal(size integer DEFAULT 100)
RETURNS text AS $$
DECLARE
  perc integer;
BEGIN
perc := size * 0.01;
IF perc &lt; 1 THEN perc := 1; END IF;

-- ... Table generation ...

RETURN 'The End';
END;
$$ LANGUAGE 'plpgsql';
</programlisting>
		<para>
			The function has a <varname>size</varname> parameter that defines the number of rows in the tables. If not provided, it creates by default tables of 100 rows. The function defines a variable <varname>perc</varname> that computes the 1% of the size of the tables. This parameter is used, for example, for generating tables having 1% of null values. We illustrate next some of the commands generating tables.
		</para>

		<para>
			The creation of a table <varname>tbl_float</varname> containing random <varname>float</varname> values in the range [0,100] with 1% of null values is given next.
		</para>
		<programlisting language="sql" xml:space="preserve" format="linespecific">
CREATE TABLE tbl_float AS
/* Add perc NULL values */
SELECT k, NULL AS f
FROM generate_series(1, perc) AS k UNION
SELECT k, random_float(0, 100)
FROM generate_series(perc+1, size) AS k;
</programlisting>

		<para>
			The creation of a table <varname>tbl_tbox</varname> containing random <varname>tbox</varname> values where the bounds for values are in the range [0,100] and the bounds for timestamps are in the range [2001-01-01, 2001-12-31] is given next.
		</para>
		<programlisting language="sql" xml:space="preserve" format="linespecific">
CREATE TABLE tbl_tbox AS
/* Add perc NULL values */
SELECT k, NULL AS b
FROM generate_series(1, perc) AS k UNION
SELECT k, random_tbox(0, 100, '2001-01-01', '2001-12-31', 10, 10)
FROM generate_series(perc+1, size) AS k;
</programlisting>

		<para>
			The creation of a table <varname>tbl_floatspan</varname> containing random <varname>floatspan</varname> values where the bounds for values are in the range [0,100] and the maximum difference between the lower and the upper bounds is 10 is given next.
		</para>
		<programlisting language="sql" xml:space="preserve" format="linespecific">
CREATE TABLE tbl_floatspan AS
/* Add perc NULL values */
SELECT k, NULL AS f
FROM generate_series(1, perc) AS k UNION
SELECT k, random_floatspan(0, 100, 10)
FROM generate_series(perc+1, size) AS k;
</programlisting>

		<para>
			The creation of a table <varname>tbl_tstzset</varname> containing random <varname>tstzset</varname> values having between 5 and 10 timestamps where the timestamps are in the range [2001-01-01, 2001-12-31] and the maximum interval between consecutive timestamps is 10 minutes is given next.
		</para>
		<programlisting language="sql" xml:space="preserve" format="linespecific">
CREATE TABLE tbl_tstzset AS
/* Add perc NULL values */
SELECT k, NULL AS ts
FROM generate_series(1, perc) AS k UNION
SELECT k, random_tstzset('2001-01-01', '2001-12-31', 10, 5, 10)
FROM generate_series(perc+1, size) AS k;
</programlisting>

		<para>
			The creation of a table <varname>tbl_tstzspan</varname> containing random <varname>tstzspan</varname> values where the timestamps are in the range [2001-01-01, 2001-12-31] and the maximum difference between the lower and the upper bounds is 10 minutes is given next.
		</para>
		<programlisting language="sql" xml:space="preserve" format="linespecific">
CREATE TABLE tbl_tstzspan AS
/* Add perc NULL values */
SELECT k, NULL AS p
FROM generate_series(1, perc) AS k UNION
SELECT k, random_tstzspan('2001-01-01', '2001-12-31', 10)
FROM generate_series(perc+1, size) AS k;
</programlisting>

		<para>
			The creation of a table <varname>tbl_geom_point</varname> containing random <varname>geometry</varname> 2D point values, where the x and y coordinates are in the range [0, 100] and in SRID 3812 is given next.
		</para>
		<programlisting language="sql" xml:space="preserve" format="linespecific">
CREATE TABLE tbl_geom_point AS
SELECT 1 AS k, geometry 'SRID=3812;point empty' AS g UNION
SELECT k, random_geom_point(0, 100, 0, 100, 3812)
FROM generate_series(2, size) k;
</programlisting>
		<para>
			Notice that the table contains an empty point value. If the SRID is not given it is set by default to 0.
		</para>

		<para>
			The creation of a table <varname>tbl_geog_point3D</varname> containing random <varname>geography</varname> 3D point values, where the x, y, and z coordinates are, respectively, in the ranges [-10, 32], [35, 72], and [0, 1000] and in SRID 7844 is given next.
		</para>
		<programlisting language="sql" xml:space="preserve" format="linespecific">
CREATE TABLE tbl_geog_point3D AS
SELECT 1 AS k, geography 'SRID=7844;pointZ empty' AS g UNION
SELECT k, random_geog_point3D(-10, 32, 35, 72, 0, 1000, 7844)
FROM generate_series(2, size) k;
</programlisting>
		<para>
			Notice that latitude and longitude values are chosen to approximately cover continental Europe. If the SRID is not given it is set by default to 4326.
		</para>

		<para>
			The creation of a table <varname>tbl_geom_linestring</varname> containing random <varname>geometry</varname> 2D linestring values having between 5 and 10 vertices, where the x and y coordinates are in the range [0, 100] and in SRID 3812 and the maximum difference between consecutive coordinate values is 10 units in the underlying SRID is given next.
		</para>
		<programlisting language="sql" xml:space="preserve" format="linespecific">
CREATE TABLE tbl_geom_linestring AS
SELECT 1 AS k, geometry 'linestring empty' AS g UNION
SELECT k, random_geom_linestring(0, 100, 0, 100, 10, 5, 10, 3812)
FROM generate_series(2, size) k;
</programlisting>

		<para>
			The creation of a table <varname>tbl_geom_linestring</varname> containing random <varname>geometry</varname> 2D linestring values having between 5 and 10 vertices, where the x and y coordinates are in the range [0, 100] and the maximum difference between consecutive coordinate values is 10 units in the underlying SRID is given next.
		</para>
		<programlisting language="sql" xml:space="preserve" format="linespecific">
CREATE TABLE tbl_geom_linestring AS
SELECT 1 AS k, geometry 'linestring empty' AS g UNION
SELECT k, random_geom_linestring(0, 100, 0, 100, 10, 5, 10)
FROM generate_series(2, size) k;
</programlisting>

		<para>
			The creation of a table <varname>tbl_geom_polygon3D</varname> containing random <varname>geometry</varname> 3D polygon values without holes, having between 5 and 10 vertices, where the x, y, and z coordinates are in the range [0, 100] and the maximum difference between consecutive coordinate values is 10 units in the underlying SRID is given next.
		</para>
		<programlisting language="sql" xml:space="preserve" format="linespecific">
CREATE TABLE tbl_geom_polygon3D AS
SELECT 1 AS k, geometry 'polygon Z empty' AS g UNION
SELECT k, random_geom_polygon3D(0, 100, 0, 100, 0, 100, 10, 5, 10)
FROM generate_series(2, size) k;
</programlisting>

		<para>
			The creation of a table <varname>tbl_geom_multipoint</varname> containing random <varname>geometry</varname> 2D multipoint values having between 5 and 10 points, where the x and y coordinates are in the range [0, 100] and the maximum difference between consecutive coordinate values is 10 units in the underlying SRID is given next.
		</para>
		<programlisting language="sql" xml:space="preserve" format="linespecific">
CREATE TABLE tbl_geom_multipoint AS
SELECT 1 AS k, geometry 'multipoint empty' AS g UNION
SELECT k, random_geom_multipoint(0, 100, 0, 100, 10, 5, 10)
FROM generate_series(2, size) k;
</programlisting>

		<para>
			The creation of a table <varname>tbl_geog_multilinestring</varname> containing random <varname>geography</varname> 2D multilinestring values having between 5 and 10 linestrings, each one having between 5 and 10 vertices, where the x and y coordinates are, respectively, in the ranges [-10, 32] and [35, 72], and the maximum difference between consecutive coordinate values is 10 is given next.
		</para>
		<programlisting language="sql" xml:space="preserve" format="linespecific">
CREATE TABLE tbl_geog_multilinestring AS
SELECT 1 AS k, geography 'multilinestring empty' AS g UNION
SELECT k, random_geog_multilinestring(-10, 32, 35, 72, 10, 5, 10, 5, 10)
FROM generate_series(2, size) k;
</programlisting>

		<para>
			The creation of a table <varname>tbl_geometry3D</varname> containing random <varname>geometry</varname> 3D values of various types is given next. This function requires that the tables for the various geometry types have been created previously.
		</para>
		<programlisting language="sql" xml:space="preserve" format="linespecific">
CREATE TABLE tbl_geometry3D (
  k serial PRIMARY KEY,
  g geometry);
INSERT INTO tbl_geometry3D(g)
(SELECT g FROM tbl_geom_point3D ORDER BY k LIMIT (size * 0.1)) UNION ALL
(SELECT g FROM tbl_geom_linestring3D ORDER BY k LIMIT (size * 0.1)) UNION ALL
(SELECT g FROM tbl_geom_polygon3D ORDER BY k LIMIT (size * 0.2)) UNION ALL
(SELECT g FROM tbl_geom_multipoint3D ORDER BY k LIMIT (size * 0.2)) UNION ALL
(SELECT g FROM tbl_geom_multilinestring3D ORDER BY k LIMIT (size * 0.2)) UNION ALL
(SELECT g FROM tbl_geom_multipolygon3D ORDER BY k LIMIT (size * 0.2));
</programlisting>

		<para>
			The creation of a table <varname>tbl_tbool_inst</varname> containing random <varname>tbool</varname> values of instant subtype where the timestamps are in the range [2001-01-01, 2001-12-31] is given next.
		</para>
		<programlisting language="sql" xml:space="preserve" format="linespecific">
CREATE TABLE tbl_tbool_inst AS
/* Add perc NULL values */
SELECT k, NULL AS inst
FROM generate_series(1, perc) AS k UNION
SELECT k, random_tbool_inst('2001-01-01', '2001-12-31')
FROM generate_series(perc+1, size) k;
/* Add perc duplicates */
UPDATE tbl_tbool_inst t1
SET inst = (SELECT inst FROM tbl_tbool_inst t2 WHERE t2.k = t1.k+perc)
WHERE k in (SELECT i FROM generate_series(1 + 2*perc, 3*perc) i);
/* Add perc rows with the same timestamp */
UPDATE tbl_tbool_inst t1
SET inst = (SELECT tboolinst(random_bool(), getTimestamp(inst))
  FROM tbl_tbool_inst t2 WHERE t2.k = t1.k+perc)
WHERE k in (SELECT i FROM generate_series(1 + 4*perc, 5*perc) i);
</programlisting>
		<para>
			As can be seen above, the table has a percentage of null values, of duplicates, and of rows with the same timestamp.
		</para>

		<para>
			The creation of a table <varname>tbl_tint_discseq</varname> containing random <varname>tint</varname> values of sequence subtype and discrete interpolation having between 5 and 10 timestamps where the integer values are in the range [0, 100], the timestamps are in the range [2001-01-01, 2001-12-31], the maximum difference between two consecutive values is 10, and the maximum interval between two consecutive instants is 10 minutes is given next.
		</para>
		<programlisting language="sql" xml:space="preserve" format="linespecific">
CREATE TABLE tbl_tint_discseq AS
/* Add perc NULL values */
SELECT k, NULL AS ti
FROM generate_series(1, perc) AS k UNION
SELECT k, random_tint_discseq(0, 100, '2001-01-01', '2001-12-31', 10, 10, 5, 10) AS ti
FROM generate_series(perc+1, size) k;
/* Add perc duplicates */
UPDATE tbl_tint_discseq t1
SET ti = (SELECT ti FROM tbl_tint_discseq t2 WHERE t2.k = t1.k+perc)
WHERE k in (SELECT i FROM generate_series(1 + 2*perc, 3*perc) i);
/* Add perc rows with the same timestamp */
UPDATE tbl_tint_discseq t1
SET ti = (SELECT ti + random_int(1, 2) FROM tbl_tint_discseq t2 WHERE t2.k = t1.k+perc)
WHERE k in (SELECT i FROM generate_series(1 + 4*perc, 5*perc) i);
/* Add perc rows that meet */
UPDATE tbl_tint_discseq t1
SET ti = (SELECT shift(ti, endTimestamp(ti)-startTimestamp(ti))
  FROM tbl_tint_discseq t2 WHERE t2.k = t1.k+perc)
WHERE t1.k in (SELECT i FROM generate_series(1 + 6*perc, 7*perc) i);
/* Add perc rows that overlap */
UPDATE tbl_tint_discseq t1
SET ti = (SELECT shift(ti, date_trunc('minute',(endTimestamp(ti)-startTimestamp(ti))/2))
  FROM tbl_tint_discseq t2 WHERE t2.k = t1.k+2)
WHERE t1.k in (SELECT i FROM generate_series(1 + 8*perc, 9*perc) i);
</programlisting>
		<para>
			As can be seen above, the table has a percentage of null values, of duplicates, of rows with the same timestamp, of rows that meet, and of rows that overlap.
		</para>

		<para>
			The creation of a table <varname>tbl_tfloat_seq</varname> containing random <varname>tfloat</varname> values of sequence subtype having between 5 and 10 timestamps where the <varname>float</varname> values are in the range [0, 100], the timestamps are in the range [2001-01-01, 2001-12-31], the maximum difference between two consecutive values is 10, and the maximum interval between two consecutive instants is 10 minutes is given next.
		</para>
		<programlisting language="sql" xml:space="preserve" format="linespecific">
CREATE TABLE tbl_tfloat_seq AS
/* Add perc NULL values */
SELECT k, NULL AS seq
FROM generate_series(1, perc) AS k UNION
SELECT k, random_tfloat_seq(0, 100, '2001-01-01', '2001-12-31', 10, 10, 5, 10) AS seq
FROM generate_series(perc+1, size) k;
/* Add perc duplicates */
UPDATE tbl_tfloat_seq t1
SET seq = (SELECT seq FROM tbl_tfloat_seq t2 WHERE t2.k = t1.k+perc)
WHERE k in (SELECT i FROM generate_series(1 + 2*perc, 3*perc) i);
/* Add perc tuples with the same timestamp */
UPDATE tbl_tfloat_seq t1
SET seq = (SELECT seq + random_int(1, 2) FROM tbl_tfloat_seq t2 WHERE t2.k = t1.k+perc)
WHERE k in (SELECT i FROM generate_series(1 + 4*perc, 5*perc) i);
/* Add perc tuples that meet */
UPDATE tbl_tfloat_seq t1
SET seq = (SELECT shift(seq, timespan(seq)) FROM tbl_tfloat_seq t2 WHERE t2.k = t1.k+perc)
WHERE t1.k in (SELECT i FROM generate_series(1 + 6*perc, 7*perc) i);
/* Add perc tuples that overlap */
UPDATE tbl_tfloat_seq t1
SET seq = (SELECT shift(seq, date_trunc('minute',timespan(seq)/2))
  FROM tbl_tfloat_seq t2 WHERE t2.k = t1.k+perc)
WHERE t1.k in (SELECT i FROM generate_series(1 + 8*perc, 9*perc) i);
</programlisting>

		<para>
			The creation of a table <varname>tbl_ttext_seqset</varname> containing random <varname>ttext</varname> values of sequence set subtype having between 5 and 10 sequences, each one having between 5 and 10 timestamps, where the text values have at most 10 characters, the timestamps are in the range [2001-01-01, 2001-12-31], and the maximum interval between two consecutive instants is 10 minutes is given next.
		</para>
		<programlisting language="sql" xml:space="preserve" format="linespecific">
CREATE TABLE tbl_ttext_seqset AS
/* Add perc NULL values */
SELECT k, NULL AS ts
FROM generate_series(1, perc) AS k UNION
SELECT k, random_ttext_seqset('2001-01-01', '2001-12-31', 10, 10, 5, 10, 5, 10) AS ts
FROM generate_series(perc+1, size) AS k;
/* Add perc duplicates */
UPDATE tbl_ttext_seqset t1
SET ts = (SELECT ts FROM tbl_ttext_seqset t2 WHERE t2.k = t1.k+perc)
WHERE k in (SELECT i FROM generate_series(1 + 2*perc, 3*perc) i);
/* Add perc tuples with the same timestamp */
UPDATE tbl_ttext_seqset t1
SET ts = (SELECT ts || text 'A' FROM tbl_ttext_seqset t2 WHERE t2.k = t1.k+perc)
WHERE k in (SELECT i FROM generate_series(1 + 4*perc, 5*perc) i);
/* Add perc tuples that meet */
UPDATE tbl_ttext_seqset t1
SET ts = (SELECT shift(ts, timespan(ts)) FROM tbl_ttext_seqset t2 WHERE t2.k = t1.k+perc)
WHERE t1.k in (SELECT i FROM generate_series(1 + 6*perc, 7*perc) i);
/* Add perc tuples that overlap */
UPDATE tbl_ttext_seqset t1
SET ts = (SELECT shift(ts, date_trunc('minute', timespan(ts)/2))
  FROM tbl_ttext_seqset t2 WHERE t2.k = t1.k+perc)
WHERE t1.k in (SELECT i FROM generate_series(1 + 8*perc, 9*perc) i);
</programlisting>

		<para>
			The creation of a table <varname>tbl_tgeompoint_discseq</varname> containing random <varname>tgeompoint</varname> 2D values of sequence subtype and discrete interpolation having between 5 and 10 instants, where the x and y coordinates are in the range [0, 100] and in SRID 3812, the timestamps are in the range [2001-01-01, 2001-12-31], the maximum difference between successive coordinates is at most 10 units in the underlying SRID, and the maximum interval between two consecutive instants is 10 minutes is given next.
		</para>
		<programlisting language="sql" xml:space="preserve" format="linespecific">
CREATE TABLE tbl_tgeompoint_discseq AS
SELECT k, random_tgeompoint_discseq(0, 100, 0, 100, '2001-01-01', '2001-12-31',
  10, 10, 5, 10, 3812) AS ti
FROM generate_series(1, size) k;
/* Add perc duplicates */
UPDATE tbl_tgeompoint_discseq t1
SET ti = (SELECT ti FROM tbl_tgeompoint_discseq t2 WHERE t2.k = t1.k+perc)
WHERE k IN (SELECT i FROM generate_series(1, perc) i);
/* Add perc tuples with the same timestamp */
UPDATE tbl_tgeompoint_discseq t1
SET ti = (SELECT round(ti,6) FROM tbl_tgeompoint_discseq t2 WHERE t2.k = t1.k+perc)
WHERE k IN (SELECT i FROM generate_series(1 + 2*perc, 3*perc) i);
/* Add perc tuples that meet */
UPDATE tbl_tgeompoint_discseq t1
SET ti = (SELECT shift(ti, endTimestamp(ti)-startTimestamp(ti))
  FROM tbl_tgeompoint_discseq t2 WHERE t2.k = t1.k+perc)
WHERE t1.k IN (SELECT i FROM generate_series(1 + 4*perc, 5*perc) i);
/* Add perc tuples that overlap */
UPDATE tbl_tgeompoint_discseq t1
SET ti = (SELECT shift(ti, date_trunc('minute',(endTimestamp(ti)-startTimestamp(ti))/2))
  FROM tbl_tgeompoint_discseq t2 WHERE t2.k = t1.k+2)
WHERE t1.k IN (SELECT i FROM generate_series(1 + 6*perc, 7*perc) i);
</programlisting>

		<para>
			Finally, the creation of a table <varname>tbl_tgeompoint3D_seqset</varname> containing random <varname>tgeompoint</varname> 3D values of sequence set subtype having between 5 and 10 sequences, each one having between 5 and 10 timestamps, where the x, y, and z coordinates are in the range [0, 100] and in SRID 3812, the timestamps are in the range [2001-01-01, 2001-12-31], the maximum difference between successive coordinates is at most 10 units in the underlying SRID, and the maximum interval between two consecutive instants is 10 minutes is given next.
		</para>
		<programlisting language="sql" xml:space="preserve" format="linespecific">
DROP TABLE IF EXISTS tbl_tgeompoint3D_seqset;
CREATE TABLE tbl_tgeompoint3D_seqset AS
SELECT k, random_tgeompoint3D_seqset(0, 100, 0, 100, 0, 100, '2001-01-01', '2001-12-31',
  10, 10, 5, 10, 5, 10, 3812) AS ts
FROM generate_series(1, size) AS k;
/* Add perc duplicates */
UPDATE tbl_tgeompoint3D_seqset t1
SET ts = (SELECT ts FROM tbl_tgeompoint3D_seqset t2 WHERE t2.k = t1.k+perc)
WHERE k IN (SELECT i FROM generate_series(1, perc) i);
/* Add perc tuples with the same timestamp */
UPDATE tbl_tgeompoint3D_seqset t1
SET ts = (SELECT round(ts,3) FROM tbl_tgeompoint3D_seqset t2 WHERE t2.k = t1.k+perc)
WHERE k IN (SELECT i FROM generate_series(1 + 2*perc, 3*perc) i);
/* Add perc tuples that meet */
UPDATE tbl_tgeompoint3D_seqset t1
SET ts = (SELECT shift(ts, timespan(ts)) FROM tbl_tgeompoint3D_seqset t2 WHERE t2.k = t1.k+perc)
WHERE t1.k IN (SELECT i FROM generate_series(1 + 4*perc, 5*perc) i);
/* Add perc tuples that overlap */
UPDATE tbl_tgeompoint3D_seqset t1
SET ts = (SELECT shift(ts, date_trunc('minute', timespan(ts)/2))
  FROM tbl_tgeompoint3D_seqset t2 WHERE t2.k = t1.k+perc)
WHERE t1.k IN (SELECT i FROM generate_series(1 + 6*perc, 7*perc) i);
</programlisting>
	</sect1>

	<sect1>
	<title>Generator for Temporal Network Point Types</title>
		<itemizedlist>
			<listitem>
				<para><varname>random_fraction</varname>: Generate a random fraction in the range [0,1]</para>
			</listitem>
			<listitem>
				<para><varname>random_npoint</varname>: Generate a random network point</para>
			</listitem>
			<listitem>
				<para><varname>random_nsegment</varname>: Generate a random network segment</para>
			</listitem>
			<listitem>
				<para><varname>random_tnpoint_inst</varname>: Generate a random temporal network point of instant subtype</para>
			</listitem>
			<listitem>
				<para><varname>random_tnpoint_discseq</varname>: Generate a random temporal network point of sequence subtype and discrete interpolation</para>
			</listitem>
			<listitem>
				<para><varname>random_tnpoint_seq</varname>: Generate a random temporal network point of sequence subtype and linear or step interpolation</para>
			</listitem>
			<listitem>
				<para><varname>random_tnpoint_seqset</varname>: Generate a random temporal network point of sequence set subtype</para>
			</listitem>
		</itemizedlist>

		<para>
			The file
			<varname>/datagen/npoint/create_test_tables_tnpoint.sql</varname>
			provide usage examples for the functions generating random values listed above.
		</para>
	</sect1>
</appendix>