tech.ytsaurus.client.request.AbstractLookupRowsRequest Maven / Gradle / Ivy
package tech.ytsaurus.client.request;
import java.util.Optional;
import javax.annotation.Nullable;
import tech.ytsaurus.client.ApiServiceUtil;
import tech.ytsaurus.client.rpc.RpcClientRequestBuilder;
import tech.ytsaurus.core.YtTimestamp;
import tech.ytsaurus.rpc.TRequestHeader;
import tech.ytsaurus.rpcproxy.TReqLookupRows;
import tech.ytsaurus.rpcproxy.TReqVersionedLookupRows;
/**
* Base class for lookup rows requests.
*
* Users use one of the inheritors of this class.
*
*
* @see
* lookup_rows documentation
*
*/
public abstract class AbstractLookupRowsRequest<
TBuilder extends AbstractLookupRowsRequest.Builder,
TRequest extends AbstractLookupRowsRequest>
extends AbstractLookupRequest {
@Nullable
protected final YtTimestamp timestamp;
@Nullable
protected final YtTimestamp retentionTimestamp;
@Nullable
protected final ReplicaConsistency replicaConsistency;
protected AbstractLookupRowsRequest(Builder, ?> builder) {
super(builder);
this.timestamp = builder.timestamp;
this.retentionTimestamp = builder.retentionTimestamp;
this.replicaConsistency = builder.replicaConsistency;
}
/**
* Get timestamp parameter.
*
* @see AbstractLookupRowsRequest.Builder#setTimestamp(YtTimestamp)
*/
public Optional getTimestamp() {
return Optional.ofNullable(timestamp);
}
/**
* Get retention-timestamp parameter.
*
* @see AbstractLookupRowsRequest.Builder#setRetentionTimestamp(YtTimestamp)
*/
public Optional getRetentionTimestamp() {
return Optional.ofNullable(retentionTimestamp);
}
/**
* Get replica-consistency parameter.
*
* @see AbstractLookupRowsRequest.Builder#setReplicaConsistency(ReplicaConsistency)
*/
public Optional getReplicaConsistency() {
return Optional.ofNullable(replicaConsistency);
}
/**
* Internal method: prepare request to send over network.
*/
public HighLevelRequest asLookupRowsWritable() {
//noinspection Convert2Diamond
return new HighLevelRequest() {
@Override
public String getArgumentsLogString() {
return AbstractLookupRowsRequest.this.getArgumentsLogString();
}
@Override
public void writeHeaderTo(TRequestHeader.Builder header) {
AbstractLookupRowsRequest.this.writeHeaderTo(header);
}
/**
* Internal method: prepare request to send over network.
*/
@Override
public void writeTo(RpcClientRequestBuilder builder) {
builder.body().setPath(getPath());
builder.body().addAllColumns(getLookupColumns());
builder.body().setKeepMissingRows(getKeepMissingRows());
if (getTimestamp().isPresent()) {
builder.body().setTimestamp(getTimestamp().get().getValue());
}
if (getRetentionTimestamp().isPresent()) {
builder.body().setRetentionTimestamp(getRetentionTimestamp().get().getValue());
}
if (getReplicaConsistency().isPresent()) {
builder.body().setReplicaConsistency(getReplicaConsistency().get().getProtoValue());
}
builder.body().setRowsetDescriptor(ApiServiceUtil.makeRowsetDescriptor(getSchema()));
serializeRowsetTo(builder.attachments());
}
};
}
/**
* Internal method: prepare request to send over network.
*/
public HighLevelRequest asVersionedLookupRowsWritable() {
//noinspection Convert2Diamond
return new HighLevelRequest() {
@Override
public String getArgumentsLogString() {
return AbstractLookupRowsRequest.this.getArgumentsLogString();
}
@Override
public void writeHeaderTo(TRequestHeader.Builder header) {
AbstractLookupRowsRequest.this.writeHeaderTo(header);
}
/**
* Internal method: prepare request to send over network.
*/
@Override
public void writeTo(RpcClientRequestBuilder builder) {
builder.body().setPath(getPath());
builder.body().addAllColumns(getLookupColumns());
builder.body().setKeepMissingRows(getKeepMissingRows());
if (getTimestamp().isPresent()) {
builder.body().setTimestamp(getTimestamp().get().getValue());
}
builder.body().setRowsetDescriptor(ApiServiceUtil.makeRowsetDescriptor(getSchema()));
serializeRowsetTo(builder.attachments());
}
};
}
/**
* Base class for builders of LookupRows requests.
*/
public abstract static class Builder<
TBuilder extends Builder,
TRequest extends AbstractLookupRowsRequest, TRequest>>
extends AbstractLookupRequest.Builder {
@Nullable
private YtTimestamp timestamp;
@Nullable
private YtTimestamp retentionTimestamp;
@Nullable
private ReplicaConsistency replicaConsistency;
/**
* Construct empty builder.
*/
public Builder() {
}
/**
* Set version of a table to be used for lookup request.
*/
public TBuilder setTimestamp(@Nullable YtTimestamp timestamp) {
this.timestamp = timestamp;
return self();
}
/**
* Set lower boundary for value timestamps to be returned.
* I.e. values that were written before this timestamp are ignored and not returned.
*/
public TBuilder setRetentionTimestamp(@Nullable YtTimestamp retentionTimestamp) {
this.retentionTimestamp = retentionTimestamp;
return self();
}
/**
* Set requested read consistency for chaos replicas.
*/
public TBuilder setReplicaConsistency(@Nullable ReplicaConsistency replicaConsistency) {
this.replicaConsistency = replicaConsistency;
return self();
}
/**
* Get value of timestamp parameter.
*
* @see #setTimestamp parameter
*/
public Optional getTimestamp() {
return Optional.ofNullable(timestamp);
}
/**
* Get value of retention-timestamp parameter.
*
* @see #setRetentionTimestamp
*/
public Optional getRetentionTimestamp() {
return Optional.ofNullable(retentionTimestamp);
}
/**
* Get value of requested read consistency for chaos replicas.
*
* @see #setReplicaConsistency
*/
public Optional getReplicaConsistency() {
return Optional.ofNullable(replicaConsistency);
}
}
}