-
Notifications
You must be signed in to change notification settings - Fork 18
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
Support comparing to another fields #46
Conversation
Using our TypeAdapterFactory to add a third type and extending our class picking logic in there to look at the type of values also to pick the right class on deserialization seems like a slightly cleaner way to go. |
} | ||
|
||
@Override | ||
public String toString() { | ||
return "{" + super.toString() + ", " + "field: " + field + ", " + "values: " + values + "}"; | ||
} | ||
|
||
private static Pattern compile(String value) { | ||
/** | ||
* Pattern compiler Method. |
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.
"Common method to compile patterns"? Might become private based on another review comment
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.
Made it private.
@@ -0,0 +1,73 @@ | |||
/* | |||
* Copyright 2017, Yahoo Inc. |
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.
2018 and Oath
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.
CAST | ||
} | ||
@Expose | ||
Kind kind; |
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.
Make these private?
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.field = stringFilterClause.field; | ||
this.patterns = stringFilterClause.patterns; | ||
List<String> stringValues = stringFilterClause.getValues(); | ||
if (stringValues != null) { |
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 can't be null because it is a condition in your parser
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.
In our tests, we new a stringFilterClause and do not set values field.
@Override | ||
public void configure(BulletConfig configuration) { | ||
if (operation == REGEX_LIKE) { | ||
patterns = values.stream().map(v -> FilterClause.compile(v.getValue())).filter(Objects::nonNull).collect(Collectors.toList()); |
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 you abstract how to get a string from a filter clause, you can leave configure
defined in the FilterClause and not duplicate it.
Something like:
if (operation == REGEX_LIKE) {
patterns = values.stream().map(v -> FilterClause.compile(this.getValue(v)).filter(Objects::nonNull).collect(Collectors.toList());
}
StringFilterClause: getValue(String type) -> return type
ObjectFilterClause: getValue(Value type) -> return type.getValue()
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.
"'fields' : " + makeGroupFields(fields) + ", " + | ||
"'attributes' : {" + | ||
"'operations' : [" + | ||
operations.stream().map(QueryUtils::makeGroupOperation).reduce((a, b) -> a + " , " + b).orElse("") + |
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.
Redo the indentation please?
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.
"'fields' : " + makeGroupFields(fields) + ", " + | ||
"'size' : " + size + ", " + | ||
"'attributes' : " + makeMap(attributes) + | ||
"'type' : '" + getTypeFor(operation) + "', " + |
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.
These were being lined up with the second "
. Let's keep it that way for everything?
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.
@@ -0,0 +1,33 @@ | |||
/* | |||
* Copyright 2017, Yahoo Inc. |
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.
Ditto
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.
@@ -490,6 +491,47 @@ public void testBasicWindowMaximumEmittedWithNonMatchingRecords() { | |||
Assert.assertNull(querier.getData()); | |||
} | |||
|
|||
@Test | |||
public void testLogicFilterNot() { |
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.
Let's add a test for what happens when you mix and match ObjectFilterClause and StringFilterClause (both cases when first is String or Object). We parse by only looking at the first value. Are the other filters ignored? Are there RunTimeExceptions?
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.
They are RunTimeExceptions. Added 2 tests.
@@ -591,4 +595,14 @@ public void testNested() { | |||
Assert.assertFalse(FilterOperations.perform(recordF, clause)); | |||
Assert.assertTrue(FilterOperations.perform(recordG, clause)); | |||
} | |||
|
|||
@Test | |||
public void testCompareToFields() { |
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.
Can we add a test for what happens when an ObjectFilterClause is being tested and the cast cannot be done (the RunTimeException is thrown)?
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.
It will be ignored. Added a test.
Partially addresses #36.