use of com.google.storage.onestore.v3.OnestoreEntity.Index.Property in project appengine-java-standard by GoogleCloudPlatform.
the class DataTypeTranslator method getPropertyValue.
/**
* Returns the value for the property as its canonical type.
*
* @param property a not {@code null} property
* @return {@code null} if no value was set for {@code property}
*/
@Nullable
public static Object getPropertyValue(Property property) {
int meaningInt = property.getMeaning();
PropertyValue value = property.getValue();
if (meaningInt == 0) {
// The value has no meaning. Check possible types, most likely first.
for (Type<?> type : TYPES_WITHOUT_MEANING_IN_EXPECTED_FREQUENCY_ORDER) {
if (type.hasValue(value)) {
return type.getValue(value);
}
}
// The value is null or malformed.
} else if ((meaningInt > 0) && (meaningInt < MEANING_INT_TO_TYPE.length)) {
// The value has a meaning. Check that meaning's type.
Type<?> type = MEANING_INT_TO_TYPE[meaningInt];
if ((type != null) && type.hasValue(value)) {
return type.getValue(value);
}
// The value is malformed.
} else {
// The value is malformed.
}
return null;
}
use of com.google.storage.onestore.v3.OnestoreEntity.Index.Property in project appengine-java-standard by GoogleCloudPlatform.
the class IndexComponentsOnlyQuery method categorizeQuery.
private void categorizeQuery() {
Set<String> ineqProps = Sets.newHashSet();
hasKeyProperty = false;
for (Filter filter : query.filters()) {
String propName = filter.getProperty(0).getName();
switch(filter.getOpEnum()) {
case EQUAL:
equalityProps.add(propName);
break;
case EXISTS:
existsProps.add(propName);
break;
case GREATER_THAN:
case GREATER_THAN_OR_EQUAL:
case LESS_THAN:
case LESS_THAN_OR_EQUAL:
ineqProps.add(propName);
break;
case CONTAINED_IN_REGION:
containmentProps.add(propName);
break;
default:
throw new IllegalArgumentException("Unable to categorize query using filter operator " + filter.getOp());
}
if (propName.equals(Entity.KEY_RESERVED_PROPERTY)) {
hasKeyProperty = true;
}
}
// Add the inequality filter properties, if any.
if (query.orderSize() == 0 && !ineqProps.isEmpty()) {
// We do not add an index property for the inequality filter because
// it will be taken care of when we add the sort on that same property
// down below.
orderProps.add(new Property().setName(ineqProps.iterator().next()));
}
groupByProps.addAll(query.groupByPropertyNames());
// If a property is included in the group by, its existance will be satisfied.
existsProps.removeAll(groupByProps);
// Add orders.
for (Order order : query.orders()) {
if (order.getProperty().equals(Entity.KEY_RESERVED_PROPERTY)) {
hasKeyProperty = true;
}
// If a property is in the ordering, it has already been satisfied.
groupByProps.remove(order.getProperty());
orderProps.add(new Property().setName(order.getProperty()).setDirection(order.getDirection()));
}
}
use of com.google.storage.onestore.v3.OnestoreEntity.Index.Property in project appengine-java-standard by GoogleCloudPlatform.
the class LocalDatastoreService method applyGroupByProperties.
/**
* Creates a new List of entities after applying group by properties.
*
* @param queryEntities a sorted list of entities.
* @param query the current query.
* @return a new list of entities with unique properties.
*/
private List<EntityProto> applyGroupByProperties(List<EntityProto> queryEntities, Query query) {
Set<String> groupByProperties = Sets.newHashSet(query.groupByPropertyNames());
// Nothing to do if there are no group by properties.
if (groupByProperties.isEmpty()) {
return queryEntities;
}
Set<NameValue> lastEntity = Sets.newHashSet();
List<EntityProto> results = Lists.newArrayList();
for (EntityProto entity : queryEntities) {
boolean isFirst = false;
for (Property prop : entity.propertys()) {
if (groupByProperties.contains(prop.getName()) && !lastEntity.contains(NameValue.of(prop.getName(), prop.getValue()))) {
isFirst = true;
break;
}
}
if (isFirst) {
results.add(entity);
// Set lastEntity to be the new set of properties.
lastEntity.clear();
for (Property prop : entity.propertys()) {
if (groupByProperties.contains(prop.getName())) {
lastEntity.add(NameValue.of(prop.getName(), prop.getValue()));
}
}
}
}
return results;
}
use of com.google.storage.onestore.v3.OnestoreEntity.Index.Property in project appengine-java-standard by GoogleCloudPlatform.
the class LocalDatastoreService method validateAndProcessEntityProto.
private void validateAndProcessEntityProto(EntityProto entity) {
validatePathForPut(entity.getKey());
for (Property prop : entity.propertys()) {
validateAndProcessProperty(prop);
validateLengthLimit(prop);
}
for (Property prop : entity.rawPropertys()) {
validateAndProcessProperty(prop);
validateRawPropLengthLimit(prop);
}
}
use of com.google.storage.onestore.v3.OnestoreEntity.Index.Property in project appengine-java-standard by GoogleCloudPlatform.
the class LocalDatastoreService method validateRawPropLengthLimit.
private void validateRawPropLengthLimit(Property property) {
String name = property.getName();
PropertyValue value = property.getValue();
if (!value.hasStringValue() || !property.hasMeaning()) {
return;
}
if (property.getMeaningEnum() == Property.Meaning.BLOB || property.getMeaningEnum() == Property.Meaning.ENTITY_PROTO || property.getMeaningEnum() == Property.Meaning.TEXT) {
if (value.getStringValueAsBytes().length > MAX_BLOB_LENGTH) {
throw newError(ErrorCode.BAD_REQUEST, "Property " + name + " is too long. It cannot exceed " + MAX_BLOB_LENGTH + " bytes.");
}
}
}
Aggregations