-
Notifications
You must be signed in to change notification settings - Fork 625
Drop Array, Reference, Number, Integer and DoubleValue #1206
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
Drop Array, Reference, Number, Integer and DoubleValue #1206
Conversation
8e0ec91
to
637838b
Compare
Codecov Report
Continue to review full report at Codecov.
|
/test smoke-tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
@@ -36,12 +36,12 @@ public static FieldValue wrap(Object value) { | |||
UserDataReader dataReader = new UserDataReader(databaseId); | |||
// HACK: We use parseQueryValue() since it accepts scalars as well as arrays / objects, and | |||
// our tests currently use wrap() pretty generically so we don't know the intent. | |||
return dataReader.parseQueryValue(value); | |||
return new FieldValue(dataReader.parseQueryValue(value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a caller other than wrapObject
calls wrap
on a Map<String, Object>
this will return the wrong type.
It seems like this should parse the query value then check the type and wrap appropriately (or call FieldValue.valueOf). That would also mean that wrapObject
wouldn't have change below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. This conversion should go away entirely in a follow-up PR too.
@@ -157,8 +164,8 @@ private static boolean objectEquals(Value left, Value right) { | |||
} | |||
|
|||
/** Returns true if the Value list contains the specified element. */ | |||
public static boolean contains(List<Value> haystack, Value needle) { | |||
for (Value haystackEl : haystack) { | |||
public static boolean contains(ArrayValueOrBuilder haystack, Value needle) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nearly all callers check the array type before calling this. It seems like it would be worth adding an alternative like this:
public static boolean arrayContains(Value haystack, Value needle) {
return isArray(haystack) && contains(haystack.getArrayValue(), needle);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only ArrayContainsFilter does the check right at the callsite. All other filters verify the value in the constructor, which is IMHO the better thing to do since the assert will include a stacktrace that should indicate where the incorrect value was created.
Furthermore, ArrayTransformOperation doesn't have a Value, it only operates on ArrayValue.Builder. For that reason, I left this as is for now.
for (FieldValue indexComponent : position) { | ||
builder.append(indexComponent.toString()); | ||
for (Value indexComponent : position) { | ||
builder.append(ProtoValues.canonicalId(indexComponent)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we're fixing the format here, should we separate these values with something?
(Optional; may not be worth it. Just a thought because it may make these more readable.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comma separation.
super(field, Operator.IN, value); | ||
hardAssert(ProtoValues.isArray(value), "InFilter expects an ArrayValue"); | ||
} | ||
|
||
@Override | ||
public boolean matches(Document doc) { | ||
FieldValue other = doc.getField(getField()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc.getFieldProto(getField())
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup! Done.
} | ||
|
||
@Override | ||
public boolean matches(Document doc) { | ||
ReferenceValue referenceValue = (ReferenceValue) getValue(); | ||
int comparator = doc.getKey().compareTo(referenceValue.getKey()); | ||
DocumentKey referencedKey = DocumentKey.fromName(getValue().getReferenceValue()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like something we could store as a field. It doesn't change for every document we match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
for (FieldValue refValue : arrayValue.getValues()) { | ||
if (doc.getKey().equals(((ReferenceValue) refValue).getKey())) { | ||
for (Value refValue : getValue().getArrayValue().getValuesList()) { | ||
DocumentKey referencedKey = DocumentKey.fromName(refValue.getReferenceValue()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly we could do this conversion once in the constructor and keep a list of document keys as a field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. This simplifies the code a bit since I can now use List.contains().
public static boolean contains(List<Value> haystack, Value needle) { | ||
for (Value haystackEl : haystack) { | ||
public static boolean contains(ArrayValueOrBuilder haystack, Value needle) { | ||
for (Value haystackEl : haystack.getValuesList()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Java doesn't tend to abbreviate like this. Consider naming this just element
, or haystackElement
if you want to preserve the binding to the haystack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Used haystackElement
@schmidt-sebastian: The following test failed, say
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
No description provided.