Skip to content

Latest commit

 

History

History
51 lines (38 loc) · 1.36 KB

distinct.md

File metadata and controls

51 lines (38 loc) · 1.36 KB
layout api-command
language Java
permalink api/java/distinct/
command distinct
related_commands
map concat_map group
map/
concat_map/
group/

Command syntax

{% apibody %} sequence.distinct() → array table.distinct() → stream r.distinct(sequence) → array r.distinct(table) → stream {% endapibody %}

Description

Removes duplicates from elements in a sequence.

The distinct command can be called on any sequence or table with an index.

{% infobox %} While distinct can be called on a table without an index, the only effect will be to convert the table into a stream; the content of the stream will not be affected. {% endinfobox %}

Example: Which unique villains have been vanquished by Marvel heroes?

r.table("marvel").concatMap(
    hero -> hero.g("villain_list")
).distinct().run(conn);

Example: Topics in a table of messages have a secondary index on them, and more than one message can have the same topic. What are the unique topics in the table?

r.table("messages").distinct().optArg("index", "topics").run(conn);

The above structure is functionally identical to:

r.table("messages").g("topics").distinct().run(conn);

However, the first form (passing the index as an argument to distinct) is faster, and won't run into array limit issues since it's returning a stream.