use of com.google.firestore.v1beta1.Value in project cel-java by projectnessie.
the class ConformanceServiceImpl method valueToRefValue.
/**
* ValueToRefValue converts between exprpb.Value and ref.Val.
*/
static Val valueToRefValue(TypeAdapter adapter, Value v) {
switch(v.getKindCase()) {
case NULL_VALUE:
return NullT.NullValue;
case BOOL_VALUE:
return boolOf(v.getBoolValue());
case INT64_VALUE:
return intOf(v.getInt64Value());
case UINT64_VALUE:
return uintOf(v.getUint64Value());
case DOUBLE_VALUE:
return doubleOf(v.getDoubleValue());
case STRING_VALUE:
return stringOf(v.getStringValue());
case BYTES_VALUE:
return bytesOf(v.getBytesValue().toByteArray());
case OBJECT_VALUE:
Any any = v.getObjectValue();
return adapter.nativeToValue(any);
case MAP_VALUE:
MapValue m = v.getMapValue();
Map<Val, Val> entries = new HashMap<>();
for (Entry entry : m.getEntriesList()) {
Val key = valueToRefValue(adapter, entry.getKey());
Val pb = valueToRefValue(adapter, entry.getValue());
entries.put(key, pb);
}
return adapter.nativeToValue(entries);
case LIST_VALUE:
ListValue l = v.getListValue();
List<Val> elts = l.getValuesList().stream().map(el -> valueToRefValue(adapter, el)).collect(Collectors.toList());
return adapter.nativeToValue(elts);
case TYPE_VALUE:
String typeName = v.getTypeValue();
Type tv = Types.getTypeByName(typeName);
if (tv != null) {
return tv;
}
return newObjectTypeValue(typeName);
default:
throw new IllegalArgumentException("unknown value " + v.getKindCase());
}
}
use of com.google.firestore.v1beta1.Value in project auto-data-tokenize by GoogleCloudPlatform.
the class RecordUnflattener method unflatten.
/**
* Returns an AVRO record by unflattening the FlatRecord through JSON unflattener.
*/
public GenericRecord unflatten(FlatRecord flatRecord) {
Map<String, Object> jsonValueMap = Maps.newHashMap();
for (Map.Entry<String, Value> entry : flatRecord.getValuesMap().entrySet()) {
var valueProcessor = new ValueProcessor(entry);
jsonValueMap.put(valueProcessor.cleanKey(), valueProcessor.convertedValue());
}
String unflattenedRecordJson = new JsonUnflattener(jsonValueMap).unflatten();
return convertJsonToAvro(schema, unflattenedRecordJson);
}
use of com.google.firestore.v1beta1.Value in project auto-data-tokenize by GoogleCloudPlatform.
the class ContactsFlatRecordSampleGenerator method buildContactRecords.
public ImmutableList<FlatRecord> buildContactRecords(int count) {
ImmutableList.Builder<FlatRecord> recordListBuilder = ImmutableList.builder();
for (int i = 0; i < count; i++) {
HashMap<String, Value> valuesMap = Maps.newHashMap();
HashMap<String, String> flatKeyMap = Maps.newHashMap();
valuesMap.put("$.name", Value.newBuilder().setStringValue(randomName()).build());
flatKeyMap.put("$.name", "$.name");
final int numbers = new Random().nextInt(10);
for (int n = 0; n < numbers; n++) {
String key = "$.contacts[" + n + "].contact.number";
flatKeyMap.put(key, "$.contacts.contact.number");
valuesMap.put(key, Value.newBuilder().setStringValue(randomPhoneNumber(10)).build());
}
final int emails = new Random().nextInt(5);
for (int n = 0; n < emails; n++) {
String key = "$.emails[" + n + "]";
flatKeyMap.put(key, "$.emails");
valuesMap.put(key, Value.newBuilder().setStringValue(randomName()).build());
}
recordListBuilder.add(flatRecordBuilder().putAllValues(valuesMap).putAllFlatKeySchema(flatKeyMap).build());
}
return recordListBuilder.build();
}
use of com.google.firestore.v1beta1.Value in project firebase-android-sdk by firebase.
the class Target method getLowerBound.
/**
* Returns a lower bound of field values that can be used as a starting point to scan the index
* defined by {@code fieldIndex}. Returns {@code null} if no lower bound exists.
*/
@Nullable
public Bound getLowerBound(FieldIndex fieldIndex) {
List<Value> values = new ArrayList<>();
boolean inclusive = true;
// For each segment, retrieve a lower bound if there is a suitable filter or startAt.
for (FieldIndex.Segment segment : fieldIndex.getDirectionalSegments()) {
Value segmentValue = null;
boolean segmentInclusive = true;
// Process all filters to find a value for the current field segment
for (FieldFilter fieldFilter : getFieldFiltersForPath(segment.getFieldPath())) {
Value filterValue = null;
boolean filterInclusive = true;
switch(fieldFilter.getOperator()) {
case LESS_THAN:
case LESS_THAN_OR_EQUAL:
filterValue = Values.getLowerBound(fieldFilter.getValue().getValueTypeCase());
break;
case EQUAL:
case IN:
case GREATER_THAN_OR_EQUAL:
filterValue = fieldFilter.getValue();
break;
case GREATER_THAN:
filterValue = fieldFilter.getValue();
filterInclusive = false;
break;
case NOT_EQUAL:
case NOT_IN:
filterValue = Values.MIN_VALUE;
break;
default:
}
if (max(segmentValue, filterValue) == filterValue) {
segmentValue = filterValue;
segmentInclusive = filterInclusive;
}
}
// if we can narrow the scope.
if (startAt != null) {
for (int i = 0; i < orderBys.size(); ++i) {
OrderBy orderBy = this.orderBys.get(i);
if (orderBy.getField().equals(segment.getFieldPath())) {
Value cursorValue = startAt.getPosition().get(i);
if (max(segmentValue, cursorValue) == cursorValue) {
segmentValue = cursorValue;
segmentInclusive = startAt.isInclusive();
}
break;
}
}
}
if (segmentValue == null) {
// No lower bound exists
return null;
}
values.add(segmentValue);
inclusive &= segmentInclusive;
}
return new Bound(values, inclusive);
}
use of com.google.firestore.v1beta1.Value in project firebase-android-sdk by firebase.
the class Target method getUpperBound.
/**
* Returns an upper bound of field values that can be used as an ending point when scanning the
* index defined by {@code fieldIndex}. Returns {@code null} if no upper bound exists.
*/
@Nullable
public Bound getUpperBound(FieldIndex fieldIndex) {
List<Value> values = new ArrayList<>();
boolean inclusive = true;
// For each segment, retrieve an upper bound if there is a suitable filter or endAt.
for (FieldIndex.Segment segment : fieldIndex.getDirectionalSegments()) {
@Nullable Value segmentValue = null;
boolean segmentInclusive = true;
// Process all filters to find a value for the current field segment
for (FieldFilter fieldFilter : getFieldFiltersForPath(segment.getFieldPath())) {
Value filterValue = null;
boolean filterInclusive = true;
switch(fieldFilter.getOperator()) {
case GREATER_THAN_OR_EQUAL:
case GREATER_THAN:
filterValue = Values.getUpperBound(fieldFilter.getValue().getValueTypeCase());
filterInclusive = false;
break;
case EQUAL:
case IN:
case LESS_THAN_OR_EQUAL:
filterValue = fieldFilter.getValue();
break;
case LESS_THAN:
filterValue = fieldFilter.getValue();
filterInclusive = false;
break;
case NOT_EQUAL:
case NOT_IN:
filterValue = Values.MAX_VALUE;
break;
default:
}
if (min(segmentValue, filterValue) == filterValue) {
segmentValue = filterValue;
segmentInclusive = filterInclusive;
}
}
// if we can narrow the scope.
if (endAt != null) {
for (int i = 0; i < orderBys.size(); ++i) {
OrderBy orderBy = this.orderBys.get(i);
if (orderBy.getField().equals(segment.getFieldPath())) {
Value cursorValue = endAt.getPosition().get(i);
if (min(segmentValue, cursorValue) == cursorValue) {
segmentValue = cursorValue;
segmentInclusive = endAt.isInclusive();
}
break;
}
}
}
if (segmentValue == null) {
// No upper bound exists
return null;
}
values.add(segmentValue);
inclusive &= segmentInclusive;
}
return new Bound(values, inclusive);
}
Aggregations