-
Notifications
You must be signed in to change notification settings - Fork 6
fix:addresses not_in filter query for array type field - attributes.lables #83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
aec7797
d209ee0
ed15403
ea6bdb7
583fb9e
4a0d161
3fc02c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -130,6 +130,8 @@ private static Filter transform(AttributeFilter filter) { | |
| return transformToEqFilterWithValueListRhs(filter); | ||
| } else if (ATTRIBUTES_LABELS_FIELD_NAME.equals(filter.getName()) && filter.getOperator() == Operator.IN) { | ||
| return transformToOrFilterChainForStrArray(filter); | ||
| } else if (ATTRIBUTES_LABELS_FIELD_NAME.equals(filter.getName()) && filter.getOperator() == Operator.NOT_IN) { | ||
| return transformToAndFilterChainForStrArray(filter); | ||
| } else { | ||
| return transformNonListRhsFilterTypes(filter); | ||
| } | ||
|
|
@@ -183,6 +185,28 @@ private static Filter transformToOrFilterChainForStrArray(AttributeFilter attrib | |
| return f; | ||
| } | ||
|
|
||
| private static Filter transformToAndFilterChainForStrArray(AttributeFilter attributeFilter) { | ||
skjindal93 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| String fieldName = attributeFilter.getName() + VALUE_LIST_VALUES_CONST; | ||
|
|
||
| Filter f = new Filter(); | ||
| f.setFieldName(""); | ||
| f.setOp(Op.AND); | ||
|
|
||
| Filter exists = new Filter(); | ||
| exists.setFieldName(fieldName); | ||
| exists.setOp(Op.EXISTS); | ||
|
||
| exists.setValue(true); | ||
|
|
||
| List<Filter> filters = attributeFilter.getAttributeValue().getValueList().getValuesList().stream() | ||
| .map(rhsAttributeValue -> createNeqFilterForAttributeValue(fieldName, rhsAttributeValue)) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| filters.add(exists); | ||
| f.setChildFilters(filters.toArray(new Filter[]{})); | ||
|
|
||
| return f; | ||
| } | ||
|
|
||
| private static Filter transformToEqFilterWithValueListRhs(AttributeFilter attributeFilter) { | ||
| String fieldName = attributeFilter.getName() + VALUE_LIST_VALUES_CONST; | ||
| return createEqFilterForAttributeValue(fieldName, attributeFilter.getAttributeValue()); | ||
|
|
@@ -192,24 +216,36 @@ private static Filter createEqFilterForAttributeValue(String fieldName, Attribut | |
| Filter f = new Filter(); | ||
| f.setFieldName(fieldName); | ||
| f.setOp(Op.EQ); | ||
| f.setValue(prepareRhsValueForSpecialValueListCase(attributeValue)); | ||
| // Set child filters to empty array | ||
| f.setChildFilters(new Filter[]{}); | ||
| return f; | ||
| } | ||
|
|
||
| private static Filter createNeqFilterForAttributeValue(String fieldName, AttributeValue attributeValue) { | ||
| Filter f = new Filter(); | ||
| f.setFieldName(fieldName); | ||
| f.setOp(Op.NEQ); | ||
skjindal93 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| f.setValue(prepareRhsValueForSpecialValueListCase(attributeValue)); | ||
| // Set child filters to empty array | ||
| f.setChildFilters(new Filter[]{}); | ||
| return f; | ||
| } | ||
|
|
||
| private static Object prepareRhsValueForSpecialValueListCase(AttributeValue attributeValue) { | ||
| org.hypertrace.entity.data.service.v1.AttributeValue.TypeCase typeCase = attributeValue.getTypeCase(); | ||
| if (typeCase == TypeCase.VALUE) { | ||
| try { | ||
| JsonNode mapNode = OBJECT_MAPPER.readTree(JSONFORMAT_PRINTER.print(attributeValue)); | ||
| Map map = OBJECT_MAPPER.convertValue(mapNode, Map.class); | ||
| f.setValue(map); | ||
| return map; | ||
| } catch (JsonProcessingException | InvalidProtocolBufferException e) { | ||
| throw new RuntimeException(e); | ||
| } | ||
| } else { // For now, just expecting VALUE type on the RHS | ||
| throw new UnsupportedOperationException( | ||
| String.format("The RHS of filter for string array types can only be VALUE: %s", attributeValue)); | ||
| } | ||
|
|
||
| // Set child filters to empty array | ||
| f.setChildFilters(new Filter[]{}); | ||
| return f; | ||
| } | ||
|
|
||
| private static void transform(AttributeValue attributeValue, Filter filter, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.