本文整理了Java中com.google.datastore.v1.Query
类的一些代码示例,展示了Query
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query
类的具体详情如下:
包路径:com.google.datastore.v1.Query
类名称:Query
[英]```
A query for entities.
Protobuf type google.datastore.v1.Query
[中]```
A query for entities.
Protobuf类型谷歌。数据存储。v1。查询
代码示例来源:origin: googleapis/google-cloud-java
@java.lang.Override
public Builder newBuilderForType() {
return newBuilder();
}
代码示例来源:origin: googleapis/google-cloud-java
hash = (19 * hash) + getDescriptor().hashCode();
if (getProjectionCount() > 0) {
hash = (37 * hash) + PROJECTION_FIELD_NUMBER;
hash = (53 * hash) + getProjectionList().hashCode();
if (getKindCount() > 0) {
hash = (37 * hash) + KIND_FIELD_NUMBER;
hash = (53 * hash) + getKindList().hashCode();
if (hasFilter()) {
hash = (37 * hash) + FILTER_FIELD_NUMBER;
hash = (53 * hash) + getFilter().hashCode();
if (getOrderCount() > 0) {
hash = (37 * hash) + ORDER_FIELD_NUMBER;
hash = (53 * hash) + getOrderList().hashCode();
if (getDistinctOnCount() > 0) {
hash = (37 * hash) + DISTINCT_ON_FIELD_NUMBER;
hash = (53 * hash) + getDistinctOnList().hashCode();
hash = (53 * hash) + getStartCursor().hashCode();
hash = (37 * hash) + END_CURSOR_FIELD_NUMBER;
hash = (53 * hash) + getEndCursor().hashCode();
hash = (37 * hash) + OFFSET_FIELD_NUMBER;
hash = (53 * hash) + getOffset();
if (hasLimit()) {
hash = (37 * hash) + LIMIT_FIELD_NUMBER;
hash = (53 * hash) + getLimit().hashCode();
代码示例来源:origin: googleapis/google-cloud-java
subBuilder = query_.toBuilder();
query_ = input.readMessage(com.google.datastore.v1.Query.parser(), extensionRegistry);
if (subBuilder != null) {
subBuilder.mergeFrom(query_);
代码示例来源:origin: googleapis/google-cloud-java
@java.lang.Override
public boolean equals(final java.lang.Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof com.google.datastore.v1.Query)) {
return super.equals(obj);
}
com.google.datastore.v1.Query other = (com.google.datastore.v1.Query) obj;
boolean result = true;
result = result && getProjectionList().equals(other.getProjectionList());
result = result && getKindList().equals(other.getKindList());
result = result && (hasFilter() == other.hasFilter());
if (hasFilter()) {
result = result && getFilter().equals(other.getFilter());
}
result = result && getOrderList().equals(other.getOrderList());
result = result && getDistinctOnList().equals(other.getDistinctOnList());
result = result && getStartCursor().equals(other.getStartCursor());
result = result && getEndCursor().equals(other.getEndCursor());
result = result && (getOffset() == other.getOffset());
result = result && (hasLimit() == other.hasLimit());
if (hasLimit()) {
result = result && getLimit().equals(other.getLimit());
}
result = result && unknownFields.equals(other.unknownFields);
return result;
}
代码示例来源:origin: googleapis/google-cloud-java
/**
*
*
* <pre>
* An ending point for the query results. Query cursors are
* returned in query result batches and
* [can only be used to limit the same query](https://cloud.google.com/datastore/docs/concepts/queries#cursors_limits_and_offsets).
* </pre>
*
* <code>bytes end_cursor = 8;</code>
*/
public Builder clearEndCursor() {
endCursor_ = getDefaultInstance().getEndCursor();
onChanged();
return this;
}
代码示例来源:origin: googleapis/google-cloud-java
B mergeFrom(com.google.datastore.v1.Query queryPb) {
if (queryPb.getKindCount() > 0) {
setKind(queryPb.getKind(0).getName());
if (!queryPb.getStartCursor().isEmpty()) {
setStartCursor(new Cursor(queryPb.getStartCursor()));
if (!queryPb.getEndCursor().isEmpty()) {
setEndCursor(new Cursor(queryPb.getEndCursor()));
setOffset(queryPb.getOffset());
if (queryPb.hasLimit()) {
setLimit(queryPb.getLimit().getValue());
if (queryPb.hasFilter()) {
Filter currFilter = Filter.fromPb(queryPb.getFilter());
if (currFilter != null) {
setFilter(currFilter);
for (com.google.datastore.v1.PropertyOrder orderByPb : queryPb.getOrderList()) {
addOrderBy(OrderBy.fromPb(orderByPb));
for (com.google.datastore.v1.Projection projectionPb : queryPb.getProjectionList()) {
addProjection(projectionPb.getProperty().getName());
for (com.google.datastore.v1.PropertyReference distinctOnPb : queryPb.getDistinctOnList()) {
addDistinctOn(distinctOnPb.getName());
代码示例来源:origin: googleapis/google-cloud-java
public Builder mergeFrom(com.google.datastore.v1.Query other) {
if (other == com.google.datastore.v1.Query.getDefaultInstance()) return this;
if (projectionBuilder_ == null) {
if (!other.projection_.isEmpty()) {
if (other.hasFilter()) {
mergeFilter(other.getFilter());
if (other.getStartCursor() != com.google.protobuf.ByteString.EMPTY) {
setStartCursor(other.getStartCursor());
if (other.getEndCursor() != com.google.protobuf.ByteString.EMPTY) {
setEndCursor(other.getEndCursor());
if (other.getOffset() != 0) {
setOffset(other.getOffset());
if (other.hasLimit()) {
mergeLimit(other.getLimit());
代码示例来源:origin: com.google.cloud.datastore/datastore-v1-proto-client
/**
* Create a new {@link Query} given the query and range.
*
* @param lastKey the previous key. If null then assumed to be the beginning.
* @param nextKey the next key. If null then assumed to be the end.
* @param query the desired query.
*/
private Query createSplit(Key lastKey, Key nextKey, Query query) {
if (lastKey == null && nextKey == null) {
return query;
}
List<Filter> keyFilters = new ArrayList<Filter>();
if (query.hasFilter()) {
keyFilters.add(query.getFilter());
}
if (lastKey != null) {
Filter lowerBound = DatastoreHelper.makeFilter(DatastoreHelper.KEY_PROPERTY_NAME,
PropertyFilter.Operator.GREATER_THAN_OR_EQUAL,
DatastoreHelper.makeValue(lastKey)).build();
keyFilters.add(lowerBound);
}
if (nextKey != null) {
Filter upperBound = DatastoreHelper.makeFilter(DatastoreHelper.KEY_PROPERTY_NAME,
PropertyFilter.Operator.LESS_THAN,
DatastoreHelper.makeValue(nextKey)).build();
keyFilters.add(upperBound);
}
return Query.newBuilder(query).setFilter(makeAndFilter(keyFilters)).build();
}
代码示例来源:origin: googleapis/google-cloud-java
output.writeMessage(4, getFilter());
output.writeMessage(12, getLimit());
代码示例来源:origin: com.google.cloud.datastore/datastore-v1-proto-client
/**
* Verifies that the given query can be properly scattered.
*
* @param query the query to verify
* @throws IllegalArgumentException if the query is invalid.
*/
private void validateQuery(Query query) throws IllegalArgumentException {
if (query.getKindCount() != 1) {
throw new IllegalArgumentException("Query must have exactly one kind.");
}
if (query.getOrderCount() != 0) {
throw new IllegalArgumentException("Query cannot have any sort orders.");
}
if (query.hasFilter()) {
validateFilter(query.getFilter());
}
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-io-google-cloud-platform
Query query = context.element();
String namespace = options.getNamespace();
int userLimit = query.hasLimit() ? query.getLimit().getValue() : Integer.MAX_VALUE;
Query.Builder queryBuilder = query.toBuilder();
queryBuilder.setLimit(
Int32Value.newBuilder().setValue(Math.min(userLimit, QUERY_BATCH_LIMIT)));
if (query.hasLimit()) {
verify(
userLimit >= numFetch,
userLimit,
numFetch,
query.getLimit());
userLimit -= numFetch;
代码示例来源:origin: googleapis/google-cloud-java
if (queryBuilder_ == null) {
if (queryTypeCase_ == 3
&& queryType_ != com.google.datastore.v1.Query.getDefaultInstance()) {
queryType_ =
com.google.datastore.v1.Query.newBuilder((com.google.datastore.v1.Query) queryType_)
.mergeFrom(value)
.buildPartial();
代码示例来源:origin: org.apache.beam/beam-sdks-java-io-google-cloud-platform
/** Generate dummy query splits. */
private List<Query> splitQuery(Query query, int numSplits) {
List<Query> queries = new ArrayList<>();
int offsetOfOriginal = query.getOffset();
for (int i = 0; i < numSplits; i++) {
Query.Builder q = Query.newBuilder();
q.addKindBuilder().setName(KIND);
// Making sub-queries unique (and not equal to the original query) by setting different
// offsets.
q.setOffset(++offsetOfOriginal);
queries.add(q.build());
}
return queries;
}
代码示例来源:origin: com.google.cloud.datastore/datastore-v1-proto-client
/**
* Creates a scatter query from the given user query
*
* @param query the user's query.
* @param numSplits the number of splits to create.
*/
private Query.Builder createScatterQuery(Query query, int numSplits) {
// TODO(pcostello): We can potentially support better splits with equality filters in our query
// if there exists a composite index on property, __scatter__, __key__. Until an API for
// metadata exists, this isn't possible. Note that ancestor and inequality queries fall into
// the same category.
Query.Builder scatterPointQuery = Query.newBuilder();
scatterPointQuery.addAllKind(query.getKindList());
scatterPointQuery.addOrder(DatastoreHelper.makeOrder(
DatastoreHelper.SCATTER_PROPERTY_NAME, Direction.ASCENDING));
// There is a split containing entities before and after each scatter entity:
// ||---*------*------*------*------*------*------*---|| = scatter entity
// If we represent each split as a region before a scatter entity, there is an extra region
// following the last scatter point. Thus, we do not need the scatter entities for the last
// region.
scatterPointQuery.getLimitBuilder().setValue((numSplits - 1) * KEYS_PER_SPLIT);
scatterPointQuery.addProjection(Projection.newBuilder().setProperty(
PropertyReference.newBuilder().setName("__key__")));
return scatterPointQuery;
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-io-google-cloud-platform
/**
* Returns a new {@link DatastoreV1.Read} that reads the results of the specified query.
*
* <p><b>Note:</b> Normally, {@code DatastoreIO} will read from Cloud Datastore in parallel
* across many workers. However, when the {@link Query} is configured with a limit using {@link
* Query.Builder#setLimit}, then all results will be read by a single worker in order to ensure
* correct results.
*/
public DatastoreV1.Read withQuery(Query query) {
checkArgument(query != null, "query can not be null");
checkArgument(
!query.hasLimit() || query.getLimit().getValue() > 0,
"Invalid query limit %s: must be positive",
query.getLimit().getValue());
return toBuilder().setQuery(query).build();
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-io-google-cloud-platform
String ourKind = query.getKind(0).getName();
long latestTimestamp = queryLatestStatisticsTimestamp(datastore, namespace);
LOG.info("Latest stats timestamp for kind {} is {}", ourKind, latestTimestamp);
Query.Builder queryBuilder = Query.newBuilder();
if (Strings.isNullOrEmpty(namespace)) {
queryBuilder.addKindBuilder().setName("__Stat_Kind__");
代码示例来源:origin: googleapis/google-cloud-java
public static Builder newBuilder() {
return DEFAULT_INSTANCE.toBuilder();
}
代码示例来源:origin: googleapis/google-cloud-java
/**
*
*
* <pre>
* The maximum number of results to return. Applies after all other
* constraints. Optional.
* Unspecified is interpreted as no limit.
* Must be >= 0 if specified.
* </pre>
*
* <code>.google.protobuf.Int32Value limit = 12;</code>
*/
public com.google.protobuf.Int32ValueOrBuilder getLimitOrBuilder() {
return getLimit();
}
代码示例来源:origin: org.apache.beam/beam-sdks-java-io-google-cloud-platform
@ProcessElement
public void processElement(ProcessContext c) throws Exception {
Query query = c.element();
// If query has a user set limit, then do not split.
if (query.hasLimit()) {
c.output(query);
return;
}
int estimatedNumSplits;
// Compute the estimated numSplits if numSplits is not specified by the user.
if (numSplits <= 0) {
estimatedNumSplits = getEstimatedNumSplits(datastore, query, options.getNamespace());
} else {
estimatedNumSplits = numSplits;
}
LOG.info("Splitting the query into {} splits", estimatedNumSplits);
List<Query> querySplits;
try {
querySplits =
splitQuery(
query, options.getNamespace(), datastore, querySplitter, estimatedNumSplits);
} catch (Exception e) {
LOG.warn("Unable to parallelize the given query: {}", query, e);
querySplits = ImmutableList.of(query);
}
// assign unique keys to query splits.
for (Query subquery : querySplits) {
c.output(subquery);
}
}
代码示例来源:origin: googleapis/google-cloud-java
/**
*
*
* <pre>
* The filter to apply.
* </pre>
*
* <code>.google.datastore.v1.Filter filter = 4;</code>
*/
public com.google.datastore.v1.FilterOrBuilder getFilterOrBuilder() {
return getFilter();
}
内容来源于网络,如有侵权,请联系作者删除!