Skip to content
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

Merged
merged 8 commits into from
Aug 8, 2018

Conversation

hbxie
Copy link
Contributor

@hbxie hbxie commented Aug 3, 2018

Partially addresses #36.

@coveralls
Copy link

coveralls commented Aug 3, 2018

Coverage Status

Coverage decreased (-0.08%) to 99.628% when pulling 27be347 on hbxie:compare-to-fields into 4229e56 on bullet-db:master.

@akshaisarma
Copy link
Member

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.
Copy link
Member

@akshaisarma akshaisarma Aug 7, 2018

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

Copy link
Contributor Author

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.
Copy link
Member

Choose a reason for hiding this comment

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

2018 and Oath

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.

CAST
}
@Expose
Kind kind;
Copy link
Member

Choose a reason for hiding this comment

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

Make these private?

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.field = stringFilterClause.field;
this.patterns = stringFilterClause.patterns;
List<String> stringValues = stringFilterClause.getValues();
if (stringValues != null) {
Copy link
Member

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

Copy link
Contributor Author

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

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

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.

"'fields' : " + makeGroupFields(fields) + ", " +
"'attributes' : {" +
"'operations' : [" +
operations.stream().map(QueryUtils::makeGroupOperation).reduce((a, b) -> a + " , " + b).orElse("") +
Copy link
Member

Choose a reason for hiding this comment

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

Redo the indentation please?

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.

"'fields' : " + makeGroupFields(fields) + ", " +
"'size' : " + size + ", " +
"'attributes' : " + makeMap(attributes) +
"'type' : '" + getTypeFor(operation) + "', " +
Copy link
Member

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?

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.

@@ -0,0 +1,33 @@
/*
* Copyright 2017, Yahoo Inc.
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

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.

@@ -490,6 +491,47 @@ public void testBasicWindowMaximumEmittedWithNonMatchingRecords() {
Assert.assertNull(querier.getData());
}

@Test
public void testLogicFilterNot() {
Copy link
Member

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?

Copy link
Contributor Author

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

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

Copy link
Contributor Author

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.

@hbxie hbxie merged commit 15c7a90 into bullet-db:master Aug 8, 2018
@hbxie hbxie deleted the compare-to-fields branch August 8, 2018 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants