Search in sources :

Example 76 with Value

use of com.google.api.ads.admanager.jaxws.v202205.Value in project firebase-android-sdk by firebase.

the class Target method getDescendingBound.

/**
 * Returns the value for a descending bound of `segment`.
 *
 * @param segment The segment to get the value for.
 * @param bound A bound to restrict the index range.
 * @return a Pair with a nullable Value and a boolean indicating whether the bound is inclusive
 */
private Pair<Value, Boolean> getDescendingBound(FieldIndex.Segment segment, @Nullable Bound bound) {
    Value segmentValue = MAX_VALUE;
    boolean segmentInclusive = true;
    // Process all filters to find a value for the current field segment
    for (FieldFilter fieldFilter : getFieldFiltersForPath(segment.getFieldPath())) {
        Value filterValue = MAX_VALUE;
        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 (upperBoundCompare(segmentValue, segmentInclusive, filterValue, filterInclusive) > 0) {
            segmentValue = filterValue;
            segmentInclusive = filterInclusive;
        }
    }
    // can narrow the scope.
    if (bound != null) {
        for (int i = 0; i < orderBys.size(); ++i) {
            OrderBy orderBy = this.orderBys.get(i);
            if (orderBy.getField().equals(segment.getFieldPath())) {
                Value cursorValue = bound.getPosition().get(i);
                if (upperBoundCompare(segmentValue, segmentInclusive, cursorValue, bound.isInclusive()) > 0) {
                    segmentValue = cursorValue;
                    segmentInclusive = bound.isInclusive();
                }
                break;
            }
        }
    }
    return new Pair<>(segmentValue, segmentInclusive);
}
Also used : Value(com.google.firestore.v1.Value) Pair(android.util.Pair)

Example 77 with Value

use of com.google.api.ads.admanager.jaxws.v202205.Value in project firebase-android-sdk by firebase.

the class OrderBy method compare.

int compare(Document d1, Document d2) {
    if (field.equals(FieldPath.KEY_PATH)) {
        return direction.getComparisonModifier() * d1.getKey().compareTo(d2.getKey());
    } else {
        Value v1 = d1.getField(field);
        Value v2 = d2.getField(field);
        Assert.hardAssert(v1 != null && v2 != null, "Trying to compare documents on fields that don't exist.");
        return direction.getComparisonModifier() * Values.compare(v1, v2);
    }
}
Also used : Value(com.google.firestore.v1.Value)

Example 78 with Value

use of com.google.api.ads.admanager.jaxws.v202205.Value in project firebase-android-sdk by firebase.

the class Bound method compareToDocument.

private int compareToDocument(List<OrderBy> orderBy, Document document) {
    hardAssert(position.size() <= orderBy.size(), "Bound has more components than query's orderBy");
    int comparison = 0;
    for (int i = 0; i < position.size(); i++) {
        OrderBy orderByComponent = orderBy.get(i);
        Value component = position.get(i);
        if (orderByComponent.field.equals(FieldPath.KEY_PATH)) {
            hardAssert(Values.isReferenceValue(component), "Bound has a non-key value where the key path is being used %s", component);
            comparison = DocumentKey.fromName(component.getReferenceValue()).compareTo(document.getKey());
        } else {
            Value docValue = document.getField(orderByComponent.getField());
            hardAssert(docValue != null, "Field should exist since document matched the orderBy already.");
            comparison = Values.compare(component, docValue);
        }
        if (orderByComponent.getDirection().equals(Direction.DESCENDING)) {
            comparison = comparison * -1;
        }
        if (comparison != 0) {
            break;
        }
    }
    return comparison;
}
Also used : Value(com.google.firestore.v1.Value)

Example 79 with Value

use of com.google.api.ads.admanager.jaxws.v202205.Value in project firebase-android-sdk by firebase.

the class ConformanceTest method executeTestCases.

private void executeTestCases(TestCase testCase, ConformanceRuntime runtime) throws Exception {
    // Note: This method is copied from Google3 and modified to match the Android API.
    TestCollection testCollection;
    TestDocument testDocument;
    for (Collection collection : testCase.getCollections()) {
        testCollection = runtime.addInitialCollectionWithPath(collection.getName());
        for (Document document : collection.getDocuments()) {
            testDocument = testCollection.addDocumentWithId(getId(document));
            for (Map.Entry<String, Value> field : document.getFieldsMap().entrySet()) {
                testDocument.putField(field.getKey(), decodeValue(firestore, field.getValue()));
            }
        }
        if (testCase.getException()) {
            runtime.expectException();
        } else {
            Result result = testCase.getResult();
            for (Document document : result.getDocuments()) {
                testDocument = runtime.addExpectedDocumentWithId(getId(document));
                for (Map.Entry<String, Value> field : document.getFieldsMap().entrySet()) {
                    testDocument.putField(field.getKey(), decodeValue(firestore, field.getValue()));
                }
            }
        }
        try {
            runtime.setup();
            try {
                Query query = runtime.createQueryAtPath(testCase.getQuery().getCollection());
                for (QueryFilter filter : testCase.getQuery().getFilters()) {
                    Where where = filter.getWhere();
                    if (where != null) {
                        switch(where.getOp()) {
                            case LESS_THAN:
                                query = query.whereLessThan(formatFieldPath(where.getField()), decodeValue(firestore, where.getValue()));
                                break;
                            case LESS_THAN_OR_EQUAL:
                                query = query.whereLessThanOrEqualTo(formatFieldPath(where.getField()), decodeValue(firestore, where.getValue()));
                                break;
                            case GREATER_THAN:
                                query = query.whereGreaterThan(formatFieldPath(where.getField()), decodeValue(firestore, where.getValue()));
                                break;
                            case GREATER_THAN_OR_EQUAL:
                                query = query.whereGreaterThanOrEqualTo(formatFieldPath(where.getField()), decodeValue(firestore, where.getValue()));
                                break;
                            case EQUAL:
                                query = query.whereEqualTo(formatFieldPath(where.getField()), decodeValue(firestore, where.getValue()));
                                break;
                            case NOT_EQUAL:
                                query = query.whereNotEqualTo(formatFieldPath(where.getField()), decodeValue(firestore, where.getValue()));
                                break;
                            case ARRAY_CONTAINS:
                                query = query.whereArrayContains(formatFieldPath(where.getField()), decodeValue(firestore, where.getValue()));
                                break;
                            case IN:
                                query = query.whereIn(formatFieldPath(where.getField()), Collections.singletonList(decodeValue(firestore, where.getValue())));
                                break;
                            case ARRAY_CONTAINS_ANY:
                                query = query.whereArrayContainsAny(formatFieldPath(where.getField()), Collections.singletonList(decodeValue(firestore, where.getValue())));
                                break;
                            case NOT_IN:
                                query = query.whereNotIn(formatFieldPath(where.getField()), Collections.singletonList(decodeValue(firestore, where.getValue())));
                                break;
                            default:
                                throw new Exception("Unexpected operation: " + where.getOp());
                        }
                    }
                    Order order = filter.getOrder();
                    if (order != null) {
                        query = query.orderBy(formatFieldPath(order.getField()), order.getDirection().equals(StructuredQuery.Direction.ASCENDING) ? Query.Direction.ASCENDING : Query.Direction.DESCENDING);
                    }
                    Value startAt = filter.getStartAt();
                    if (startAt != null) {
                        query = query.startAt(decodeValue(firestore, startAt));
                    }
                    Value startAfter = filter.getStartAfter();
                    if (startAfter != null) {
                        query = query.startAfter(decodeValue(firestore, startAfter));
                    }
                    Value endBefore = filter.getEndBefore();
                    if (endBefore != null) {
                        query = query.endBefore(decodeValue(firestore, endBefore));
                    }
                    Value endAt = filter.getEndAt();
                    if (endAt != null) {
                        query = query.endAt(decodeValue(firestore, endAt));
                    }
                    Long limit = filter.getLimit();
                    if (limit != null && limit > 0) {
                        query = query.limit(limit);
                    }
                }
                runtime.runQuery(query);
            } catch (RuntimeException | AssertionError x) {
                runtime.checkQueryError(x);
            }
        } finally {
            runtime.teardown();
        }
    }
}
Also used : Order(com.google.firebase.firestore.conformance.model.Order) StructuredQuery(com.google.firestore.v1.StructuredQuery) TestDocument(com.google.firebase.firestore.conformance.TestDocument) Document(com.google.firestore.v1.Document) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Result(com.google.firebase.firestore.conformance.model.Result) TestDocument(com.google.firebase.firestore.conformance.TestDocument) QueryFilter(com.google.firebase.firestore.conformance.model.QueryFilter) TestUtil.decodeValue(com.google.firebase.firestore.testutil.TestUtil.decodeValue) Value(com.google.firestore.v1.Value) TestCollection(com.google.firebase.firestore.conformance.TestCollection) Collection(com.google.firebase.firestore.conformance.model.Collection) TestCollection(com.google.firebase.firestore.conformance.TestCollection) Map(java.util.Map) Where(com.google.firebase.firestore.conformance.model.Where)

Example 80 with Value

use of com.google.api.ads.admanager.jaxws.v202205.Value in project firebase-android-sdk by firebase.

the class UserDataReader method parseMap.

private <K, V> Value parseMap(Map<K, V> map, ParseContext context) {
    if (map.isEmpty()) {
        if (context.getPath() != null && !context.getPath().isEmpty()) {
            context.addToFieldMask(context.getPath());
        }
        return Value.newBuilder().setMapValue(MapValue.getDefaultInstance()).build();
    } else {
        MapValue.Builder mapBuilder = MapValue.newBuilder();
        for (Entry<K, V> entry : map.entrySet()) {
            if (!(entry.getKey() instanceof String)) {
                throw context.createError(String.format("Non-String Map key (%s) is not allowed", entry.getValue()));
            }
            String key = (String) entry.getKey();
            @Nullable Value parsedValue = parseData(entry.getValue(), context.childContext(key));
            if (parsedValue != null) {
                mapBuilder.putFields(key, parsedValue);
            }
        }
        return Value.newBuilder().setMapValue(mapBuilder).build();
    }
}
Also used : ObjectValue(com.google.firebase.firestore.model.ObjectValue) Value(com.google.firestore.v1.Value) NullValue(com.google.protobuf.NullValue) DeleteFieldValue(com.google.firebase.firestore.FieldValue.DeleteFieldValue) MapValue(com.google.firestore.v1.MapValue) ServerTimestampFieldValue(com.google.firebase.firestore.FieldValue.ServerTimestampFieldValue) ArrayUnionFieldValue(com.google.firebase.firestore.FieldValue.ArrayUnionFieldValue) ArrayRemoveFieldValue(com.google.firebase.firestore.FieldValue.ArrayRemoveFieldValue) ArrayValue(com.google.firestore.v1.ArrayValue) MapValue(com.google.firestore.v1.MapValue) Nullable(androidx.annotation.Nullable)

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)24 Value (com.google.datastore.v1.Value)20 Map (java.util.Map)19 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