| layout | api-command | |||
|---|---|---|---|---|
| language | Java | |||
| permalink | api/java/union/ | |||
| command | union | |||
| io |
|
{% apibody %} stream.union(sequence[, sequence, ...]) → stream array.union(sequence[, sequence, ...]) → array r.union(stream, sequence[, sequence, ...]) → stream r.union(array, sequence[, sequence, ...]) → array {% endapibody %}
Merge two or more sequences.
The interleave optArg controls how the sequences will be merged:
true: results will be mixed together; this is the fastest setting, but ordering of elements is not guaranteed. (This is the default.)false: input sequences will be appended to one another, left to right."field_name": a string will be taken as the name of a field to perform a merge-sort on. The input sequences must be ordered before being passed tounion.- function: the
interleaveoptArg can take a function whose argument is the current row, and whose return value is a value to perform a merge-sort on.
Example: Construct a stream of all heroes.
r.table("marvel").union(r.table("dc")).run(conn);Example: Combine four arrays into one.
r.expr(r.array(1, 2)).union(r.array(3, 4), r.array(5, 6), r.array(7, 8, 9)).run(conn);
// Result:
[1, 2, 3, 4, 5, 6, 7, 8, 9]Example: Create a changefeed from the first example.
r.table("marvel").union(r.table("dc")).changes().run(conn);Now, when any heroes are added, modified or deleted from either table, a change notification will be sent out.
Example: Merge-sort the tables of heroes, ordered by name.
r.table("marvel").orderBy("name")
.union(r.table("dc").orderBy("name")).optArg("interleave", "name")
.run(conn);