use of io.opentelemetry.proto.common.v1.ArrayValue in project firebase-android-sdk by firebase.
the class Values method arrayEquals.
private static boolean arrayEquals(Value left, Value right) {
ArrayValue leftArray = left.getArrayValue();
ArrayValue rightArray = right.getArrayValue();
if (leftArray.getValuesCount() != rightArray.getValuesCount()) {
return false;
}
for (int i = 0; i < leftArray.getValuesCount(); ++i) {
if (!equals(leftArray.getValues(i), rightArray.getValues(i))) {
return false;
}
}
return true;
}
use of io.opentelemetry.proto.common.v1.ArrayValue in project data-prepper by opensearch-project.
the class OTelProtoHelperTest method testArrayOfValueAsResourceAttributes.
/**
* Below object has a KeyValue with a key mapped to KeyValueList and is part of the span attributes
*
* @throws JsonProcessingException
*/
@Test
public void testArrayOfValueAsResourceAttributes() throws JsonProcessingException {
final KeyValue childAttr1 = KeyValue.newBuilder().setKey("ec2.instances").setValue(AnyValue.newBuilder().setIntValue(20).build()).build();
final KeyValue childAttr2 = KeyValue.newBuilder().setKey("ec2.instance.az").setValue(AnyValue.newBuilder().setStringValue("us-east-1").build()).build();
final AnyValue anyValue1 = AnyValue.newBuilder().setStringValue(UUID.randomUUID().toString()).build();
final AnyValue anyValue2 = AnyValue.newBuilder().setDoubleValue(2000.123).build();
final AnyValue anyValue3 = AnyValue.newBuilder().setKvlistValue(KeyValueList.newBuilder().addAllValues(Arrays.asList(childAttr1, childAttr2))).build();
final ArrayValue arrayValue = ArrayValue.newBuilder().addAllValues(Arrays.asList(anyValue1, anyValue2, anyValue3)).build();
final KeyValue spanAttribute1 = KeyValue.newBuilder().setKey("aws.details").setValue(AnyValue.newBuilder().setArrayValue(arrayValue)).build();
final Map<String, Object> actual = OTelProtoHelper.getResourceAttributes(Resource.newBuilder().addAllAttributes(Collections.singletonList(spanAttribute1)).build());
assertThat(actual.containsKey(OTelProtoHelper.RESOURCE_ATTRIBUTES_REPLACE_DOT_WITH_AT.apply(spanAttribute1.getKey()))).isTrue();
final List<Object> actualValue = returnList((String) actual.get(OTelProtoHelper.RESOURCE_ATTRIBUTES_REPLACE_DOT_WITH_AT.apply(spanAttribute1.getKey())));
assertThat((actualValue.get(0)).equals(anyValue1.getStringValue())).isTrue();
assertThat(((Double) actualValue.get(1)) == (anyValue2.getDoubleValue())).isTrue();
final Map<String, Object> map = returnMap((String) actualValue.get(2));
assertThat((Integer) map.get(OTelProtoHelper.REPLACE_DOT_WITH_AT.apply(childAttr1.getKey())) == childAttr1.getValue().getIntValue()).isTrue();
assertThat(map.get(OTelProtoHelper.REPLACE_DOT_WITH_AT.apply(childAttr2.getKey())).equals(childAttr2.getValue().getStringValue())).isTrue();
assertThat((Integer) map.get(OTelProtoHelper.REPLACE_DOT_WITH_AT.apply(childAttr1.getKey())) == (childAttr1.getValue().getIntValue())).isTrue();
}
use of io.opentelemetry.proto.common.v1.ArrayValue in project firebase-android-sdk by firebase.
the class Query method parseFieldFilter.
/**
* Takes a {@link Filter.UnaryFilter} object, parses the value object and returns a new {@link
* FieldFilter} for the field, operator, and parsed value.
*
* @param fieldFilterData The Filter.UnaryFilter object to parse.
* @return The created {@link FieldFilter}.
*/
private FieldFilter parseFieldFilter(Filter.UnaryFilter fieldFilterData) {
FieldPath fieldPath = fieldFilterData.getField();
Operator op = fieldFilterData.getOperator();
Object value = fieldFilterData.getValue();
checkNotNull(fieldPath, "Provided field path must not be null.");
checkNotNull(op, "Provided op must not be null.");
Value fieldValue;
com.google.firebase.firestore.model.FieldPath internalPath = fieldPath.getInternalPath();
if (internalPath.isKeyField()) {
if (op == Operator.ARRAY_CONTAINS || op == Operator.ARRAY_CONTAINS_ANY) {
throw new IllegalArgumentException("Invalid query. You can't perform '" + op.toString() + "' queries on FieldPath.documentId().");
} else if (op == Operator.IN || op == Operator.NOT_IN) {
validateDisjunctiveFilterElements(value, op);
ArrayValue.Builder referenceList = ArrayValue.newBuilder();
for (Object arrayValue : (List) value) {
referenceList.addValues(parseDocumentIdValue(arrayValue));
}
fieldValue = Value.newBuilder().setArrayValue(referenceList).build();
} else {
fieldValue = parseDocumentIdValue(value);
}
} else {
if (op == Operator.IN || op == Operator.NOT_IN || op == Operator.ARRAY_CONTAINS_ANY) {
validateDisjunctiveFilterElements(value, op);
}
fieldValue = firestore.getUserDataReader().parseQueryValue(value, op == Operator.IN || op == Operator.NOT_IN);
}
FieldFilter filter = FieldFilter.create(fieldPath.getInternalPath(), op, fieldValue);
return filter;
}
use of io.opentelemetry.proto.common.v1.ArrayValue in project firebase-android-sdk by firebase.
the class BundleSerializerTest method testDecodesNestedObjectValues.
@Test
public void testDecodesNestedObjectValues() throws JSONException {
String json = "{ mapValue: { fields: {\n" + "b: { booleanValue: true },\n" + "d: {\n" + " doubleValue:\n" + Double.MAX_VALUE + "},\n" + "i: { integerValue: 1 },\n" + "n: { nullValue: null },\n" + "s: { stringValue: 'foo' },\n" + "a: { arrayValue: {\n" + " values: [\n" + " { integerValue: 2 },\n" + " { stringValue: 'bar'},\n" + " { mapValue: { fields: { b: { booleanValue: false } } } }\n" + " ]\n" + " }\n" + "},\n" + "o: {\n" + " mapValue: {\n" + " fields: {\n" + " d: { integerValue: 100 },\n" + " nested: {\n" + " mapValue: {\n" + " fields: {\n" + " e: { integerValue:\n" + Long.MIN_VALUE + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + " }\n" + "} } } }\n";
MapValue.Builder inner = MapValue.newBuilder().putFields("b", Value.newBuilder().setBooleanValue(false).build());
ArrayValue.Builder array = ArrayValue.newBuilder().addValues(Value.newBuilder().setIntegerValue(2)).addValues(Value.newBuilder().setStringValue("bar")).addValues(Value.newBuilder().setMapValue(inner));
inner = MapValue.newBuilder().putFields("e", Value.newBuilder().setIntegerValue(Long.MIN_VALUE).build());
MapValue.Builder middle = MapValue.newBuilder().putFields("d", Value.newBuilder().setIntegerValue(100).build()).putFields("nested", Value.newBuilder().setMapValue(inner).build());
MapValue.Builder obj = MapValue.newBuilder().putFields("b", Value.newBuilder().setBooleanValue(true).build()).putFields("d", Value.newBuilder().setDoubleValue(Double.MAX_VALUE).build()).putFields("i", Value.newBuilder().setIntegerValue(1).build()).putFields("n", Value.newBuilder().setNullValueValue(0).build()).putFields("s", Value.newBuilder().setStringValue("foo").build()).putFields("a", Value.newBuilder().setArrayValue(array).build()).putFields("o", Value.newBuilder().setMapValue(middle).build());
Value proto = Value.newBuilder().setMapValue(obj).build();
assertDecodesValue(json, proto);
}
use of io.opentelemetry.proto.common.v1.ArrayValue in project opentelemetry-java-instrumentation by open-telemetry.
the class AgentTestingExporterAccess method fromProto.
private static Attributes fromProto(List<KeyValue> attributes) {
AttributesBuilder converted = Attributes.builder();
for (KeyValue attribute : attributes) {
String key = attribute.getKey();
AnyValue value = attribute.getValue();
switch(value.getValueCase()) {
case STRING_VALUE:
converted.put(key, value.getStringValue());
break;
case BOOL_VALUE:
converted.put(key, value.getBoolValue());
break;
case INT_VALUE:
converted.put(key, value.getIntValue());
break;
case DOUBLE_VALUE:
converted.put(key, value.getDoubleValue());
break;
case ARRAY_VALUE:
ArrayValue array = value.getArrayValue();
if (array.getValuesCount() != 0) {
switch(array.getValues(0).getValueCase()) {
case STRING_VALUE:
converted.put(stringArrayKey(key), array.getValuesList().stream().map(AnyValue::getStringValue).collect(toList()));
break;
case BOOL_VALUE:
converted.put(booleanArrayKey(key), array.getValuesList().stream().map(AnyValue::getBoolValue).collect(toList()));
break;
case INT_VALUE:
converted.put(longArrayKey(key), array.getValuesList().stream().map(AnyValue::getIntValue).collect(toList()));
break;
case DOUBLE_VALUE:
converted.put(doubleArrayKey(key), array.getValuesList().stream().map(AnyValue::getDoubleValue).collect(toList()));
break;
case VALUE_NOT_SET:
break;
default:
throw new IllegalStateException("Unexpected attribute: " + array.getValues(0).getValueCase());
}
}
break;
case VALUE_NOT_SET:
break;
default:
throw new IllegalStateException("Unexpected attribute: " + value.getValueCase());
}
}
return converted.build();
}
Aggregations