-
Notifications
You must be signed in to change notification settings - Fork 16
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
Fix findOne
/find
wrt _id
column (actually all filterables)
#1359
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
633ed29
re-enable failing test as baseline
tatu-at-datastax b99412d
Merge branch 'main' into tatu/1357-filter-by-_id
tatu-at-datastax a9b0a40
mvn fmt:format
tatu-at-datastax 5cd72cd
Fix the IT by adding resolution for `_id` filter.
tatu-at-datastax bf87571
Merge branch 'main' into tatu/1357-filter-by-_id
tatu-at-datastax File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
import io.stargate.sgv2.jsonapi.service.operation.filters.table.NumberTableFilter; | ||
import io.stargate.sgv2.jsonapi.service.operation.filters.table.TextTableFilter; | ||
import io.stargate.sgv2.jsonapi.service.operation.query.DBFilterBase; | ||
import io.stargate.sgv2.jsonapi.service.shredding.collections.DocumentId; | ||
import java.math.BigDecimal; | ||
import java.util.ArrayList; | ||
import java.util.EnumSet; | ||
|
@@ -24,6 +25,7 @@ | |
public class TableFilterResolver<CmdT extends Command & Filterable> | ||
extends FilterResolver<CmdT, TableSchemaObject> { | ||
|
||
private static final Object DYNAMIC_DOCID_GROUP = new Object(); | ||
private static final Object DYNAMIC_TEXT_GROUP = new Object(); | ||
private static final Object DYNAMIC_NUMBER_GROUP = new Object(); | ||
|
||
|
@@ -61,7 +63,20 @@ protected FilterMatchRules<CmdT> buildMatchRules() { | |
ValueComparisonOperator.GTE, | ||
ValueComparisonOperator.LT, | ||
ValueComparisonOperator.LTE), | ||
JsonType.NUMBER); | ||
JsonType.NUMBER) | ||
// Although Tables does not have special handling for _id, our FilterClauseDeserializer | ||
// does, so we need to capture it here. | ||
.capture(DYNAMIC_DOCID_GROUP) | ||
.compareValues( | ||
"_id", | ||
EnumSet.of( | ||
ValueComparisonOperator.EQ, | ||
// ValueComparisonOperator.NE, // TODO: not sure this is supported | ||
ValueComparisonOperator.GT, | ||
ValueComparisonOperator.GTE, | ||
ValueComparisonOperator.LT, | ||
ValueComparisonOperator.LTE), | ||
JsonType.DOCUMENT_ID); | ||
|
||
return matchRules; | ||
} | ||
|
@@ -75,20 +90,44 @@ private static List<DBFilterBase> findDynamic(CaptureExpression captureExpressio | |
|
||
// TODO: How do we know what the CmdT of the JsonLiteral<CmdT> from .value() is ? | ||
for (FilterOperation<?> filterOperation : captureExpression.filterOperations()) { | ||
final Object rhsValue = filterOperation.operand().value(); | ||
if (captureExpression.marker() == DYNAMIC_TEXT_GROUP) { | ||
filters.add( | ||
new TextTableFilter( | ||
captureExpression.path(), | ||
NativeTypeTableFilter.Operator.from( | ||
(ValueComparisonOperator) filterOperation.operator()), | ||
(String) filterOperation.operand().value())); | ||
(String) rhsValue)); | ||
} else if (captureExpression.marker() == DYNAMIC_NUMBER_GROUP) { | ||
filters.add( | ||
new NumberTableFilter( | ||
captureExpression.path(), | ||
NativeTypeTableFilter.Operator.from( | ||
(ValueComparisonOperator) filterOperation.operator()), | ||
(BigDecimal) filterOperation.operand().value())); | ||
(BigDecimal) rhsValue)); | ||
} else if (captureExpression.marker() == DYNAMIC_DOCID_GROUP) { | ||
Object actualValue = ((DocumentId) rhsValue).value(); | ||
if (actualValue instanceof String) { | ||
filters.add( | ||
new TextTableFilter( | ||
captureExpression.path(), | ||
NativeTypeTableFilter.Operator.from( | ||
(ValueComparisonOperator) filterOperation.operator()), | ||
(String) actualValue)); | ||
} else if (actualValue instanceof BigDecimal) { | ||
filters.add( | ||
new NumberTableFilter( | ||
captureExpression.path(), | ||
NativeTypeTableFilter.Operator.from( | ||
(ValueComparisonOperator) filterOperation.operator()), | ||
(BigDecimal) actualValue)); | ||
} else { | ||
throw new UnsupportedOperationException( | ||
"Unsupported DocumentId type: " + rhsValue.getClass().getName()); | ||
} | ||
} else { | ||
throw new UnsupportedOperationException( | ||
"Unsupported dynamic filter type: " + filterOperation); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is just following the pattern. We can change these to Data API exception later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, sorry I missed this one before merging. |
||
} | ||
} | ||
|
||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should probably be refactored to avoid duplicating code to create Text/NumberTableFilter.