Concourse provides several methods for retrieving data from
records. Each method is designed for a specific access pattern,
and most support optional ordering,
pagination, and
time travel.
The select method returns every value stored for a key (or all
keys) in a record. Because Concourse fields can hold multiple
values simultaneously, select returns a Set of values for
each key.
The get method returns the single most recently added value for
a key in a record. Use get when you only need the current value
and the field is expected to contain a single value.
The browse method returns an inverted view of a key’s data,
mapping each distinct value to the set of records that contain
it. This is useful for understanding the distribution of values
across records.
When different records hold effectively equal values of different
types, browse returns one representative value and maps it to
all of those records. For example, if one record holds 18 and
another holds 18.0, browse maps one of them to both records.
The representative value has one of the types it was written with,
but the representative type that is chosen is undefined and may
change across calls depending upon the total state of the data
under that key. When the enable_canonical_type_coercion setting
is on, browse converts every representative value to its
canonical type instead, so that example returns 18. See
Type Coercion.
The describe method returns the set of keys that currently have
at least one value in a record. Use this to discover which fields
exist in a record without retrieving the actual data.
The holds method checks whether a record currently contains any
data. This is faster than calling describe when you only need
to know if a record exists.
Every record in Concourse has an implicit $id$ key that maps
to the record’s unique identifier. You can use $id$ in read
operations to include the record ID in results.
Navigation keys use dot-separated paths to traverse links and
read data from linked records. See Graph for full
documentation, including
transitive navigation for
recursive graph traversal.
123456789
// Java// Read the "name" of the record linked via "employer"Map<Long,Set<Object>>names=concourse.navigate("employer.name",Lists.newArrayList(1L,2L));// Read every descendant's name via transitive traversalSet<Object>descendants=concourse.select("children*.name",rootRecord);
For mixed-time reads — e.g., a customer’s current
tier alongside their lifetime spend as of last quarter
— attach a [<timestamp>] bracket directly to the key:
1234
// JavaMap<Long,Map<String,Set<Object>>>data=concourse.select("select [tier, lifetime_spend[\"end of last quarter\"]]"+" from 1");
A bracket pins its key independently of any trailing
at/as of on the operation. See
Per-Key Timestamps.
Sometimes a client needs to wait for data that doesn’t exist
yet, such as a worker that waits for a new job. Instead of
polling with repeated reads, you can use an await. Every find,
select, and get that reads current data with a CCL condition
or a Criteria has an await version, such as awaitFind, that
waits on the server until the read returns data or a timeout
passes. The timeout comes first, followed by the same arguments
as the read.
1234
// Java// Wait up to 10 seconds for a pending recordSet<Long>records=concourse.awaitFind(Duration.ofSeconds(10),"status = pending");
If matching data already exists, the await returns it right
away. Otherwise, it returns as soon as a write produces a result.
If the timeout passes first, it returns whatever the read finds
at that time, which may be nothing.
findAndSet, selectAndSet, and getAndSet have await versions
too. They wait the same way, and then do the lookup and the set
atomically. If several clients make the same await on one
server, they’re served in the order they called.
1234
// Java// Wait up to 30 seconds for a pending job, then mark it claimedSet<Long>job=concourse.awaitFindAndSet(Duration.ofSeconds(30),"status = pending",Page.limit(1),"status","claimed");
If a client disconnects while the await version of
findAndSet, selectAndSet, or getAndSet is waiting, the
server may still do the set without anyone getting the
result. So it’s best to set a value that can recover on its
own, such as a lease that expires.
An await fails with an InvalidArgumentException if:
it’s called inside a transaction,
its condition, keys, or order use a key that can’t be written,
such as a navigation key,
its condition compares a key to a function value, or
its timeout is shorter than a millisecond or longer than the
server’s max_await_timeout.
When the server already holds max_open_awaits open awaits, a
new await fails right away with an AwaitLimitException, and you
can retry it later. An await also fails if the caller’s
permission is revoked, or its access token expires, while it
waits. See Configuration.