Skip to content

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

Merged
merged 18 commits into from
Feb 6, 2020

Conversation

schmidt-sebastian
Copy link
Contributor

No description provided.

@schmidt-sebastian schmidt-sebastian changed the base branch from master to mrschmidt/migratevalues February 5, 2020 23:08
@googlebot googlebot added the cla: yes Override cla label Feb 5, 2020
@schmidt-sebastian schmidt-sebastian changed the title Mrschmidt/droparray Drop Array, Reference, Number, Integer and DoubleValue Feb 5, 2020
@codecov
Copy link

codecov bot commented Feb 5, 2020

Codecov Report

Merging #1206 into mrschmidt/rewritefieldvalue will not change coverage.
The diff coverage is n/a.

Flag Coverage Δ Complexity Δ
#FirebaseFirestore 62.07% <0%> (ø) 2254% <0%> (ø) ⬇️
#FirebaseFirestore_Ktx 41.17% <0%> (ø) 0% <0%> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0abdfb1...6ef7289. Read the comment docs.

@schmidt-sebastian
Copy link
Contributor Author

/test smoke-tests

Copy link
Contributor

@wilhuff wilhuff left a 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));
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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);
}

Copy link
Contributor Author

@schmidt-sebastian schmidt-sebastian Feb 6, 2020

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));
Copy link
Contributor

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.)

Copy link
Contributor Author

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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doc.getFieldProto(getField())?

Copy link
Contributor Author

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());
Copy link
Contributor

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.

Copy link
Contributor Author

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());
Copy link
Contributor

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.

Copy link
Contributor Author

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()) {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used haystackElement

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff Feb 6, 2020
@schmidt-sebastian schmidt-sebastian changed the base branch from mrschmidt/migratevalues to mrschmidt/rewritefieldvalue February 6, 2020 05:12
@schmidt-sebastian schmidt-sebastian changed the base branch from mrschmidt/rewritefieldvalue to mrschmidt/migratevalues February 6, 2020 05:13
@schmidt-sebastian schmidt-sebastian changed the base branch from mrschmidt/migratevalues to mrschmidt/rewritefieldvalue February 6, 2020 05:18
@google-oss-bot
Copy link
Contributor

@schmidt-sebastian: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
smoke-tests 6ef7289 link /test smoke-tests

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.

Copy link
Contributor

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@wilhuff wilhuff assigned schmidt-sebastian and unassigned wilhuff Feb 6, 2020
@schmidt-sebastian schmidt-sebastian merged commit 32e1e92 into mrschmidt/rewritefieldvalue Feb 6, 2020
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/droparray branch February 7, 2020 00:22
@firebase firebase locked and limited conversation to collaborators Mar 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants