-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FMWK-124 Creating secondary index based on json path (#89)
- Loading branch information
Showing
13 changed files
with
540 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
src/main/java/com/aerospike/documentapi/data/DocFilterExp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.aerospike.documentapi.data; | ||
|
||
import com.aerospike.client.exp.Exp; | ||
import com.aerospike.documentapi.util.ExpConverter; | ||
|
||
public class DocFilterExp implements DocumentFilterExp { | ||
|
||
private final String binName; | ||
private final String jsonPath; | ||
private final Operator operator; | ||
private final Object value; | ||
private Integer regexFlags = null; | ||
|
||
public DocFilterExp(String binName, String jsonPath, Operator operator, Object value) { | ||
this.binName = binName; | ||
this.jsonPath = jsonPath; | ||
this.operator = operator; | ||
this.value = value; | ||
} | ||
|
||
public Exp toFilterExp() { | ||
switch (operator) { | ||
case LT: | ||
return ExpConverter.lt(binName, jsonPath, value); | ||
case GT: | ||
return ExpConverter.gt(binName, jsonPath, value); | ||
case LE: | ||
return ExpConverter.le(binName, jsonPath, value); | ||
case GE: | ||
return ExpConverter.ge(binName, jsonPath, value); | ||
case EQ: | ||
return ExpConverter.eq(binName, jsonPath, value); | ||
case NE: | ||
return ExpConverter.ne(binName, jsonPath, value); | ||
case REGEX: | ||
return ExpConverter.regex(binName, jsonPath, value.toString(), regexFlags); | ||
default: | ||
return null; | ||
} | ||
} | ||
|
||
@Override | ||
public void setRegexFlags(int regexFlags) { | ||
this.regexFlags = regexFlags; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/aerospike/documentapi/data/DocFilterSecIndex.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.aerospike.documentapi.data; | ||
|
||
import com.aerospike.client.query.Filter; | ||
import com.aerospike.client.query.IndexCollectionType; | ||
import com.aerospike.documentapi.util.FilterConverter; | ||
|
||
import static com.aerospike.client.query.IndexCollectionType.DEFAULT; | ||
|
||
public class DocFilterSecIndex implements DocumentFilterSecIndex { | ||
|
||
private final String binName; | ||
private final String jsonPath; | ||
private final Operator operator; | ||
private final Object value; | ||
private IndexCollectionType idxCollectionType = DEFAULT; | ||
|
||
public DocFilterSecIndex(String binName, String jsonPath, Operator operator, Object value) { | ||
this.binName = binName; | ||
this.jsonPath = jsonPath; | ||
this.operator = operator; | ||
this.value = value; | ||
} | ||
|
||
public Filter toSecIndexFilter() { | ||
switch (operator) { | ||
case LT: | ||
return FilterConverter.lt(binName, jsonPath, value, idxCollectionType); | ||
case GT: | ||
return FilterConverter.gt(binName, jsonPath, value, idxCollectionType); | ||
case LE: | ||
return FilterConverter.le(binName, jsonPath, value, idxCollectionType); | ||
case GE: | ||
return FilterConverter.ge(binName, jsonPath, value, idxCollectionType); | ||
case EQ: | ||
return FilterConverter.eq(binName, jsonPath, value); | ||
default: | ||
throw new UnsupportedOperationException(String.format("'%s' secondary filter is not supported", operator)); | ||
} | ||
} | ||
|
||
@Override | ||
public void setIdxCollectionType(IndexCollectionType idxCollectionType) { | ||
this.idxCollectionType = idxCollectionType; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/aerospike/documentapi/data/DocumentFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.aerospike.documentapi.data; | ||
|
||
/** | ||
* Document filter interface extended by {@link DocumentFilterExp} and {@link DocumentFilterSecIndex}. | ||
*/ | ||
public interface DocumentFilter { | ||
} |
48 changes: 18 additions & 30 deletions
48
src/main/java/com/aerospike/documentapi/data/DocumentFilterExp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,24 @@ | ||
package com.aerospike.documentapi.data; | ||
|
||
import com.aerospike.client.exp.Exp; | ||
import com.aerospike.documentapi.util.DocumentExp; | ||
|
||
public class DocumentFilterExp { | ||
/** | ||
* Base interface for creating filter expression. | ||
* | ||
* <p>For the supported json paths see {@link com.aerospike.documentapi.util.ExpConverter}.</p> | ||
* <p>Supported operators: </p> | ||
* <ul> | ||
* <li>EQ</li> | ||
* <li>NE</li> | ||
* <li>GT</li> | ||
* <li>GE</li> | ||
* <li>LT</li> | ||
* <li>LE</li> | ||
* <li>REGEX</li> | ||
* </ul> | ||
*/ | ||
public interface DocumentFilterExp extends DocumentFilter { | ||
Exp toFilterExp(); | ||
|
||
private Exp exp; | ||
|
||
public DocumentFilterExp(String binName, String jsonPath, Operator.Simple operator, Object value) { | ||
switch (operator) { | ||
case LT: | ||
exp = DocumentExp.lt(binName, jsonPath, value); | ||
break; | ||
case GT: | ||
exp = DocumentExp.gt(binName, jsonPath, value); | ||
break; | ||
case LTE: | ||
exp = DocumentExp.le(binName, jsonPath, value); | ||
break; | ||
case GTE: | ||
exp = DocumentExp.ge(binName, jsonPath, value); | ||
break; | ||
case EQ: | ||
exp = DocumentExp.eq(binName, jsonPath, value); | ||
break; | ||
case NE: | ||
exp = DocumentExp.ne(binName, jsonPath, value); | ||
break; | ||
} | ||
} | ||
|
||
public Exp toFilterExpression() { | ||
return exp; | ||
} | ||
void setRegexFlags(int regexFlags); | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/aerospike/documentapi/data/DocumentFilterSecIndex.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.aerospike.documentapi.data; | ||
|
||
import com.aerospike.client.query.Filter; | ||
import com.aerospike.client.query.IndexCollectionType; | ||
|
||
/** | ||
* Base interface for creating secondary index filter. | ||
* | ||
* <p>For the supported json paths see {@link com.aerospike.documentapi.util.FilterConverter}.</p> | ||
* <p>Supported operators: </p> | ||
* <ul> | ||
* <li>EQ</li> | ||
* <li>GT</li> | ||
* <li>GE</li> | ||
* <li>LT</li> | ||
* <li>LE</li> | ||
* </ul> | ||
*/ | ||
public interface DocumentFilterSecIndex extends DocumentFilter { | ||
Filter toSecIndexFilter(); | ||
|
||
void setIdxCollectionType(IndexCollectionType idxCollectionType); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.