Builds a request for columns of data to read from a Kiji table.
You can instantiate a KijiDataRequestBuilder using the {@link KijiDataRequest#builder()} method.
{@link KijiDataRequest} objects are immutable; this object helps you constructthem. With a KijiDataRequest builder, you can set various properties that affect the data request as a whole (for example, the timestamp interval to retrieve). You can also use the {@link #newColumnsDef()} method of this object to get instances of{@link KijiDataRequestBuilder.ColumnsDef}, which allow you to define a set of columns that are part of a data request, and their retrieval properties.
A KijiDataRequestBuilder.ColumnsDef object has two types of methods: methods starting with with...
define properties associated with some columns. The add()
methods then attach specific columns to the data request being built, using the properties previously specified. You may call add()
or addFamily()
multiple times. You may not overwrite the value of a property like maxVersions once it's already been set.
It is an error to change properties within a column request (e.g., call {@link KijiDataRequestBuilder.ColumnsDef#withMaxVersions(int)}) after using the add()
or addFamily()
methods to add columns to the request.
The following behaviors are errors and are not allowed:
- Adding the same column multiple times. This includes definitions like info:name that conflict with requests for the entire info:* family.
- Calling a property-setting method (withTimeRange(), withMaxVersions(), etc) more than once on a given KijiDataRequestBuilder or {@link KijiDataRequestBuilder.ColumnsDef}. These methods will throw IllegalStateException.
- Changing any properties after calling build() to construct the KijiDataRequest.
- Calling build() more than once.
Usage example
For the common case of reading info:foo, info:bar, info:baz, and products:*:
KijiDataRequestBuilder builder = KijiDataRequest.builder().withTimeRange(t1, t2); builder.newColumnsDef().withMaxVersions(42) .add("info", "foo") .add("info", "bar") .add("info", "baz") .addFamily("products"); KijiDataRequest request = builder.build();
This can also be written as:
final KijiDataRequest request = KijiDataRequest.build() .addColumns(ColumnsDef.create() .withMaxVerions(42) .add("info", "foo") .add("info", "bar") .add("info", "baz") .addFamily("products")) .build();
To add fam1:col1, fam1:col2, and fam2:*, each with different retrieval properties to the same request, do the following:
KijiDataRequestBuilder builder = KijiDataRequest.builder().withTimeRange(t1, t2); builder.newColumnsDef().withMaxVersions(10).withPageSize(p).add("fam1", "col1"); builder.newColumnsDef().add("fam1", "col2"); builder.newColumnsDef().withMaxVersions(42).addFamily("fam2"); KijiDataRequest request = builder.build();