use of com.google.firestore.v1beta1.Value in project semantic-metrics by spotify.
the class FastForwardReporter method reportDistribution.
private void reportDistribution(final com.spotify.ffwd.v1.Metric metric, final Distribution distribution) {
ByteString byteString = distribution.getValueAndFlush();
Value value = Value.distributionValue(byteString);
send(metric.value(value));
}
use of com.google.firestore.v1beta1.Value in project appengine-java-standard by GoogleCloudPlatform.
the class DataTypeTranslator method toV1Value.
private static Value.Builder toV1Value(@Nullable Object value) {
boolean indexed = true;
boolean forceIndexedEmbeddedEntity = false;
if (value instanceof WrappedValue) {
WrappedValue wrappedValue = (WrappedValue) value;
indexed = wrappedValue.isIndexed();
forceIndexedEmbeddedEntity = wrappedValue.getForceIndexedEmbeddedEntity();
value = wrappedValue.getValue();
}
if (value instanceof Collection<?>) {
Collection<?> values = (Collection<?>) value;
if (values.isEmpty()) {
if (DatastoreServiceConfig.getEmptyListSupport()) {
return Value.newBuilder().setExcludeFromIndexes(!indexed).setArrayValue(ArrayValue.getDefaultInstance());
} else {
// null and empty list is lost.
return toV1Value(null, indexed, forceIndexedEmbeddedEntity);
}
} else {
Value.Builder valueBuilder = Value.newBuilder();
for (Object listValue : values) {
valueBuilder.getArrayValueBuilder().addValues(toV1Value(listValue, indexed, forceIndexedEmbeddedEntity));
}
return valueBuilder;
}
} else {
return toV1Value(value, indexed, forceIndexedEmbeddedEntity);
}
}
use of com.google.firestore.v1beta1.Value in project appengine-java-standard by GoogleCloudPlatform.
the class DataTypeTranslator method addPropertyToMap.
private static void addPropertyToMap(String name, Value value, Map<String, @Nullable Object> map) {
boolean isOrContainsIndexedEntityValue = false;
boolean indexed;
Object result;
if (DatastoreServiceConfig.getEmptyListSupport() && value.getValueTypeCase() == Value.ValueTypeCase.ARRAY_VALUE && value.getArrayValue().getValuesCount() == 0) {
result = new ArrayList<Object>();
indexed = !value.getExcludeFromIndexes();
} else if (value.getArrayValue().getValuesCount() > 0) {
indexed = false;
// Must be ArrayList for backwards compatibility.
ArrayList<@Nullable Object> resultList = new ArrayList<>(value.getArrayValue().getValuesCount());
for (Value subValue : value.getArrayValue().getValuesList()) {
if (subValue.getValueTypeCase() == ValueTypeCase.ARRAY_VALUE) {
throw new IllegalArgumentException("Invalid Entity PB: list within a list.");
}
result = getValue(subValue);
if (!subValue.getExcludeFromIndexes()) {
// This is not optimal but it's needed to be "bug compatible" with v3.
indexed = true;
if (result instanceof EmbeddedEntity) {
isOrContainsIndexedEntityValue = true;
}
}
resultList.add(result);
}
result = resultList;
} else {
// Empty list becomes null.
indexed = !value.getExcludeFromIndexes();
result = getValue(value);
if (indexed && result instanceof EmbeddedEntity) {
isOrContainsIndexedEntityValue = true;
}
}
if (isOrContainsIndexedEntityValue) {
result = new WrappedValueImpl(result, true, true);
} else if (!indexed) {
result = new UnindexedValue(result);
}
map.put(name, result);
}
use of com.google.firestore.v1beta1.Value in project java-firestore by googleapis.
the class UserDataConverter method decodeValue.
static Object decodeValue(FirestoreRpcContext<?> rpcContext, Value v) {
Value.ValueTypeCase typeCase = v.getValueTypeCase();
switch(typeCase) {
case NULL_VALUE:
return null;
case BOOLEAN_VALUE:
return v.getBooleanValue();
case INTEGER_VALUE:
return v.getIntegerValue();
case DOUBLE_VALUE:
return v.getDoubleValue();
case TIMESTAMP_VALUE:
return Timestamp.fromProto(v.getTimestampValue());
case STRING_VALUE:
return v.getStringValue();
case BYTES_VALUE:
return Blob.fromByteString(v.getBytesValue());
case REFERENCE_VALUE:
String pathName = v.getReferenceValue();
return new DocumentReference(rpcContext, ResourcePath.create(pathName));
case GEO_POINT_VALUE:
return new GeoPoint(v.getGeoPointValue().getLatitude(), v.getGeoPointValue().getLongitude());
case ARRAY_VALUE:
List<Object> list = new ArrayList<>();
List<Value> lv = v.getArrayValue().getValuesList();
for (Value iv : lv) {
list.add(decodeValue(rpcContext, iv));
}
return list;
case MAP_VALUE:
Map<String, Object> outputMap = new HashMap<>();
Map<String, Value> inputMap = v.getMapValue().getFieldsMap();
for (Map.Entry<String, Value> entry : inputMap.entrySet()) {
outputMap.put(entry.getKey(), decodeValue(rpcContext, entry.getValue()));
}
return outputMap;
default:
throw FirestoreException.forInvalidArgument(String.format("Unknown Value Type: %s", typeCase));
}
}
use of com.google.firestore.v1beta1.Value in project java-firestore by googleapis.
the class Query method encodeValue.
private Value encodeValue(FieldPath fieldPath, Object value) {
Object sanitizedObject = CustomClassMapper.serialize(value);
Value encodedValue = UserDataConverter.encodeValue(fieldPath, sanitizedObject, UserDataConverter.ARGUMENT);
if (encodedValue == null) {
throw FirestoreException.forInvalidArgument("Cannot use Firestore sentinels in FieldFilter or cursors");
}
return encodedValue;
}
Aggregations