Search in sources :

Example 6 with Value

use of com.google.api.ads.admanager.jaxws.v202205.Value in project entity-service by hypertrace.

the class PrimitiveFilteringExpressionConverter method convert.

@Override
public FilterTypeExpression convert(final ColumnIdentifier columnIdentifier, final Operator operator, final LiteralConstant constant, final RequestContext requestContext) throws ConversionException {
    final String id = columnIdentifier.getColumnName();
    final String subDocPath = getSubDocPathById(entityAttributeMapping, id, requestContext);
    final Value value = constant.getValue();
    final ValueType valueType = value.getValueType();
    final IdentifierConverter identifierConverter = identifierConverterFactory.getIdentifierConverter(id, subDocPath, valueType, requestContext);
    final IdentifierConversionMetadata metadata = IdentifierConversionMetadata.builder().subDocPath(subDocPath).operator(operator).valueType(valueType).build();
    final String suffixedSubDocPath = identifierConverter.convert(metadata, requestContext);
    final IdentifierExpression identifierExpression = IdentifierExpression.of(suffixedSubDocPath);
    final RelationalOperator relationalOperator = convertOperator(operator);
    final ConstantExpression constantExpression = constantExpressionConverter.convert(constant, requestContext);
    return RelationalExpression.of(identifierExpression, relationalOperator, constantExpression);
}
Also used : RelationalOperator(org.hypertrace.core.documentstore.expression.operators.RelationalOperator) ValueType(org.hypertrace.entity.query.service.v1.ValueType) IdentifierConverter(org.hypertrace.entity.query.service.converter.identifier.IdentifierConverter) ConstantExpression(org.hypertrace.core.documentstore.expression.impl.ConstantExpression) Value(org.hypertrace.entity.query.service.v1.Value) IdentifierConversionMetadata(org.hypertrace.entity.query.service.converter.identifier.IdentifierConversionMetadata) IdentifierExpression(org.hypertrace.core.documentstore.expression.impl.IdentifierExpression)

Example 7 with Value

use of com.google.api.ads.admanager.jaxws.v202205.Value in project entity-service by hypertrace.

the class DocumentConverterImpl method buildRow.

private Row buildRow(final ResultSetMetadata resultSetMetadata, final Map<String, Value> valueMap) {
    final Row.Builder builder = Row.newBuilder();
    final Value defaultValue = getNullPlaceholderValue();
    for (final ColumnMetadata columnMetadata : resultSetMetadata.getColumnMetadataList()) {
        final Value value = valueMap.getOrDefault(columnMetadata.getColumnName(), defaultValue);
        builder.addColumn(value);
    }
    return builder.build();
}
Also used : ColumnMetadata(org.hypertrace.entity.query.service.v1.ColumnMetadata) Value(org.hypertrace.entity.query.service.v1.Value) Row(org.hypertrace.entity.query.service.v1.Row)

Example 8 with Value

use of com.google.api.ads.admanager.jaxws.v202205.Value in project entity-service by hypertrace.

the class ArrayGetter method getValue.

@Override
public Value getValue(final JsonNode jsonNode) throws ConversionException {
    final Iterator<JsonNode> elements = jsonNode.elements();
    final List<Value> values = new ArrayList<>();
    while (elements.hasNext()) {
        final JsonNode node = elements.next();
        final Value value;
        if (nestedValueGetter.matches(node)) {
            value = nestedValueGetter.getValue(node);
        } else if (directValueGetter.matches(node)) {
            value = directValueGetter.getValue(node);
        } else {
            throw new ConversionException(String.format("Unexpected node (%s) found", node));
        }
        values.add(value);
    }
    final ValueType primitiveType = values.stream().map(Value::getValueType).findFirst().orElse(STRING);
    final ValueType type = valueHelper.getArrayValueType(primitiveType);
    final Value.Builder valueBuilder = Value.newBuilder().setValueType(type);
    switch(type) {
        case STRING_ARRAY:
            values.stream().map(Value::getString).forEach(valueBuilder::addStringArray);
            break;
        case INT_ARRAY:
            values.stream().map(Value::getInt).forEach(valueBuilder::addIntArray);
            break;
        case LONG_ARRAY:
            values.stream().map(Value::getLong).forEach(valueBuilder::addLongArray);
            break;
        case FLOAT_ARRAY:
            values.stream().map(Value::getFloat).forEach(valueBuilder::addFloatArray);
            break;
        case DOUBLE_ARRAY:
            values.stream().map(Value::getDouble).forEach(valueBuilder::addDoubleArray);
            break;
        case BYTES_ARRAY:
            values.stream().map(Value::getBytes).forEach(valueBuilder::addBytesArray);
            break;
        case BOOLEAN_ARRAY:
            values.stream().map(Value::getBoolean).forEach(valueBuilder::addBooleanArray);
            break;
        default:
            throw new ConversionException(String.format("Unknown array type: %s", type));
    }
    return valueBuilder.build();
}
Also used : ConversionException(org.hypertrace.entity.query.service.converter.ConversionException) ValueType(org.hypertrace.entity.query.service.v1.ValueType) Value(org.hypertrace.entity.query.service.v1.Value) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 9 with Value

use of com.google.api.ads.admanager.jaxws.v202205.Value in project entity-service by hypertrace.

the class MapValueGetter method getValue.

@Override
public Value getValue(final JsonNode jsonNode) throws ConversionException {
    final JsonNode valuesNode = jsonNode.get(VALUE_MAP_KEY);
    if (valuesNode == null || !valuesNode.isObject()) {
        throw new ConversionException(String.format("Unexpected node (%s) found under %s", valuesNode, VALUE_MAP_KEY));
    }
    final JsonNode mapNode = valuesNode.get(VALUES_KEY);
    final Iterator<Entry<String, JsonNode>> fields = mapNode == null ? emptyIterator() : mapNode.fields();
    final Value.Builder valueBuilder = Value.newBuilder().setValueType(STRING_MAP);
    while (fields.hasNext()) {
        final Entry<String, JsonNode> entry = fields.next();
        final String key = entry.getKey();
        final JsonNode node = entry.getValue();
        if (!nestedValueGetter.matches(node)) {
            throw new ConversionException(String.format("Unexpected node (%s) found for key (%s)", node, key));
        }
        final Value value = nestedValueGetter.getValue(node);
        final Object objValue = valueOneOfAccessor.access(value, value.getValueType());
        valueBuilder.putStringMap(key, objValue.toString());
    }
    return valueBuilder.build();
}
Also used : ConversionException(org.hypertrace.entity.query.service.converter.ConversionException) Entry(java.util.Map.Entry) Value(org.hypertrace.entity.query.service.v1.Value) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 10 with Value

use of com.google.api.ads.admanager.jaxws.v202205.Value in project grpc-gcp-java by GoogleCloudPlatform.

the class DataStoreChecksumClient method simpleLookup.

private static void simpleLookup(DatastoreBlockingStub stub, String projectId) {
    PathElement pathElement = PathElement.newBuilder().setKind("Person").setName("weiranf").build();
    Key key = Key.newBuilder().addPath(pathElement).build();
    LookupRequest lookupRequest = LookupRequest.newBuilder().setProjectId(projectId).addKeys(key).build();
    LookupResponse lookupResponse = stub.lookup(lookupRequest);
    if (lookupResponse.getFoundCount() > 0) {
        System.out.println("ENTITY FOUND:");
        Entity entity = lookupResponse.getFound(0).getEntity();
        Map<String, Value> map = entity.getPropertiesMap();
        for (Map.Entry<String, Value> entry : map.entrySet()) {
            System.out.printf("%s => %s\n", entry.getKey(), entry.getValue().getStringValue());
        }
    } else {
        System.out.println("NO ENTITY FOUND!");
    }
}
Also used : Entity(com.google.datastore.v1.Entity) PathElement(com.google.datastore.v1.Key.PathElement) Value(com.google.datastore.v1.Value) LookupResponse(com.google.datastore.v1.LookupResponse) Map(java.util.Map) Key(com.google.datastore.v1.Key) LookupRequest(com.google.datastore.v1.LookupRequest)

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