Search in sources :

Example 31 with Value

use of com.google.firestore.v1beta1.Value in project java-firestore by googleapis.

the class QueryTest method inQueriesFieldsNotUsedInOrderBy.

@Test
public void inQueriesFieldsNotUsedInOrderBy() throws Exception {
    doAnswer(queryResponse()).when(firestoreMock).streamRequest(runQuery.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any());
    // Field "foo" used in `whereIn` should not appear in implicit orderBys in the resulting query.
    query.whereIn(FieldPath.of("foo"), Arrays.<Object>asList("value1", "value2")).startAt(SINGLE_FIELD_SNAPSHOT).get().get();
    Value value = Value.newBuilder().setArrayValue(ArrayValue.newBuilder().addValues(Value.newBuilder().setStringValue("value1").build()).addValues(Value.newBuilder().setStringValue("value2").build()).build()).build();
    RunQueryRequest expectedRequest = query(filter(Operator.IN, "foo", value), order("__name__", Direction.ASCENDING), startAt(reference(DOCUMENT_NAME), true));
    assertEquals(expectedRequest, runQuery.getValue());
}
Also used : RunQueryRequest(com.google.firestore.v1.RunQueryRequest) Value(com.google.firestore.v1.Value) ArrayValue(com.google.firestore.v1.ArrayValue) Test(org.junit.Test)

Example 32 with Value

use of com.google.firestore.v1beta1.Value in project java-firestore by googleapis.

the class QueryTest method withEqualityFilterForDocumentSnapshotCursor.

@Test
public void withEqualityFilterForDocumentSnapshotCursor() {
    doAnswer(queryResponse()).when(firestoreMock).streamRequest(runQuery.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any());
    query.whereEqualTo("foo", "bar").startAt(SINGLE_FIELD_SNAPSHOT).get();
    Value documentBoundary = reference(DOCUMENT_NAME);
    RunQueryRequest queryRequest = query(filter(Operator.EQUAL), order("__name__", StructuredQuery.Direction.ASCENDING), startAt(documentBoundary, true));
    assertEquals(queryRequest, runQuery.getValue());
}
Also used : RunQueryRequest(com.google.firestore.v1.RunQueryRequest) Value(com.google.firestore.v1.Value) ArrayValue(com.google.firestore.v1.ArrayValue) Test(org.junit.Test)

Example 33 with Value

use of com.google.firestore.v1beta1.Value in project java-firestore by googleapis.

the class QueryTest method withInequalityFilterForDocumentSnapshotCursor.

@Test
public void withInequalityFilterForDocumentSnapshotCursor() {
    doAnswer(queryResponse()).when(firestoreMock).streamRequest(runQuery.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any());
    query.whereEqualTo("a", "b").whereGreaterThanOrEqualTo("foo", "bar").whereEqualTo("c", "d").startAt(SINGLE_FIELD_SNAPSHOT).get();
    Value documentBoundary = reference(DOCUMENT_NAME);
    RunQueryRequest queryRequest = query(filter(Operator.EQUAL, "a", "b"), filter(Operator.GREATER_THAN_OR_EQUAL), filter(Operator.EQUAL, "c", "d"), order("foo", Direction.ASCENDING), order("__name__", StructuredQuery.Direction.ASCENDING), startAt(true), startAt(documentBoundary, true));
    assertEquals(queryRequest, runQuery.getValue());
}
Also used : RunQueryRequest(com.google.firestore.v1.RunQueryRequest) Value(com.google.firestore.v1.Value) ArrayValue(com.google.firestore.v1.ArrayValue) Test(org.junit.Test)

Example 34 with Value

use of com.google.firestore.v1beta1.Value in project java-firestore by googleapis.

the class QueryTest method withDocumentIdAndDocumentSnapshotCursor.

@Test
public void withDocumentIdAndDocumentSnapshotCursor() {
    doAnswer(queryResponse()).when(firestoreMock).streamRequest(runQuery.capture(), streamObserverCapture.capture(), Matchers.<ServerStreamingCallable>any());
    query.orderBy(FieldPath.documentId()).startAt(SINGLE_FIELD_SNAPSHOT).get();
    Value documentBoundary = reference(DOCUMENT_NAME);
    RunQueryRequest queryRequest = query(order("__name__", StructuredQuery.Direction.ASCENDING), startAt(documentBoundary, true));
    assertEquals(queryRequest, runQuery.getValue());
}
Also used : RunQueryRequest(com.google.firestore.v1.RunQueryRequest) Value(com.google.firestore.v1.Value) ArrayValue(com.google.firestore.v1.ArrayValue) Test(org.junit.Test)

Example 35 with Value

use of com.google.firestore.v1beta1.Value in project cel-java by projectnessie.

the class ConformanceServiceImpl method refValueToValue.

// TODO(jimlarson): The following conversion code should be moved to
// common/types/provider.go and consolidated/refactored as appropriate.
// In particular, make judicious use of types.NativeToValue().
/**
 * RefValueToValue converts between ref.Val and Value. The ref.Val must not be error or unknown.
 */
static Value refValueToValue(Val res) {
    switch(res.type().typeEnum()) {
        case Bool:
            return Value.newBuilder().setBoolValue(res.booleanValue()).build();
        case Bytes:
            return Value.newBuilder().setBytesValue(res.convertToNative(ByteString.class)).build();
        case Double:
            return Value.newBuilder().setDoubleValue(res.convertToNative(Double.class)).build();
        case Int:
            return Value.newBuilder().setInt64Value(res.intValue()).build();
        case Null:
            return Value.newBuilder().setNullValueValue(0).build();
        case String:
            return Value.newBuilder().setStringValue(res.value().toString()).build();
        case Type:
            return Value.newBuilder().setTypeValue(((TypeT) res).typeName()).build();
        case Uint:
            return Value.newBuilder().setUint64Value(res.intValue()).build();
        case Duration:
            Duration d = res.convertToNative(Duration.class);
            return Value.newBuilder().setObjectValue(Any.pack(d)).build();
        case Timestamp:
            Timestamp t = res.convertToNative(Timestamp.class);
            return Value.newBuilder().setObjectValue(Any.pack(t)).build();
        case List:
            Lister l = (Lister) res;
            ListValue.Builder elts = ListValue.newBuilder();
            for (IteratorT i = l.iterator(); i.hasNext() == True; ) {
                Val v = i.next();
                elts.addValues(refValueToValue(v));
            }
            return Value.newBuilder().setListValue(elts).build();
        case Map:
            Mapper m = (Mapper) res;
            MapValue.Builder elems = MapValue.newBuilder();
            for (IteratorT i = m.iterator(); i.hasNext() == True; ) {
                Val k = i.next();
                Val v = m.get(k);
                Value kv = refValueToValue(k);
                Value vv = refValueToValue(v);
                elems.addEntriesBuilder().setKey(kv).setValue(vv);
            }
            return Value.newBuilder().setMapValue(elems).build();
        case Object:
            // Object type
            Message pb = (Message) res.value();
            Value.Builder v = Value.newBuilder();
            // Somehow the conformance tests
            if (pb instanceof ListValue) {
                v.setListValue((ListValue) pb);
            } else if (pb instanceof MapValue) {
                v.setMapValue((MapValue) pb);
            } else {
                v.setObjectValue(Any.pack(pb));
            }
            return v.build();
        default:
            throw new IllegalStateException(String.format("Unknown %s", res.type().typeEnum()));
    }
}
Also used : Val(org.projectnessie.cel.common.types.ref.Val) TypeT(org.projectnessie.cel.common.types.TypeT) Message(com.google.protobuf.Message) Lister(org.projectnessie.cel.common.types.traits.Lister) ListValue(com.google.api.expr.v1alpha1.ListValue) Duration(com.google.protobuf.Duration) MapValue(com.google.api.expr.v1alpha1.MapValue) Timestamp(com.google.protobuf.Timestamp) IteratorT(org.projectnessie.cel.common.types.IteratorT) Mapper(org.projectnessie.cel.common.types.traits.Mapper) MapValue(com.google.api.expr.v1alpha1.MapValue) Value(com.google.api.expr.v1alpha1.Value) ExprValue(com.google.api.expr.v1alpha1.ExprValue) ListValue(com.google.api.expr.v1alpha1.ListValue) TypeT.newObjectTypeValue(org.projectnessie.cel.common.types.TypeT.newObjectTypeValue)

Aggregations

Test (org.junit.Test)126 Value (com.google.firestore.v1.Value)108 ArrayValue (com.google.firestore.v1.ArrayValue)73 LinkedHashSet (java.util.LinkedHashSet)71 ObjectValue (com.google.firebase.firestore.model.ObjectValue)53 NullValue (com.google.protobuf.NullValue)50 MapValue (com.google.firestore.v1.MapValue)47 ArrayList (java.util.ArrayList)30 HashMap (java.util.HashMap)25 Value (com.google.datastore.v1.Value)20 Map (java.util.Map)20 TableFieldSchema (com.google.api.services.bigquery.model.TableFieldSchema)17 List (java.util.List)17 Record (org.apache.avro.generic.GenericData.Record)16 SchemaAndRecord (org.apache.beam.sdk.io.gcp.bigquery.SchemaAndRecord)16 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)16 Set (java.util.Set)14 TestUtil.wrapObject (com.google.firebase.firestore.testutil.TestUtil.wrapObject)13 Nullable (androidx.annotation.Nullable)10 Value (com.google.privacy.dlp.v2.Value)9