-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
feat(core): Add support for boolean
metadata attributes in FunctionalTranslator
#7407
base: main
Are you sure you want to change the base?
feat(core): Add support for boolean
metadata attributes in FunctionalTranslator
#7407
Conversation
…provided value type
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Skipped Deployment
|
const sq6 = new StructuredQuery( | ||
"", | ||
new Comparison(Comparators.eq, "isReleased", true) | ||
); |
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 isn't technically a required test addition since I didn't modify the actual Comparison
logic, but since I added support for boolean
types in Comparison
, I thought it was worthwhile to include it here just for posterity.
@@ -17,6 +17,7 @@ const correctQuery = new StructuredQuery( | |||
]), | |||
new Comparison(Comparators.lt, "length", 180), | |||
new Comparison(Comparators.eq, "genre", "pop"), | |||
new Comparison(Comparators.eq, "hasLyrics", true), |
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.
Same as this comment
describe("FunctionalTranslator", () => { | ||
const translator = new FunctionalTranslator(); | ||
|
||
describe("getAllowedComparatorsForType", () => { |
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.
As mentioned in the PR description, I only added the bare minimum tests needed to ensure the modification to the existing functionality did not break the visitComparison
logic.
const value = inputValuesByAttribute[attribute]; | ||
const validDocuments = validDocumentsByComparator[comparator]; | ||
for (const validDocument of validDocuments) { | ||
test(`${value} -> ${comparator} -> ${validDocument.metadata[attribute]}`, () => { |
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.
boolean
metadata attributes in FunctionalTranslator
boolean
metadata attributes in FunctionalTranslator
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.
Looks reasonable to me!
@nick-w-nick seems like it's breaking some types in
Any way we can make this backwards compatible? |
@jacoblee93 The type issues have been resolved, could you re-run the CI? Thanks! |
While adding support for
boolean
as a type in thecastValue
function to allow them to be used in metadata filters that are created within aStructuredQuery
, I noticed that this would cause theFunctionalTranslator
implementation to have a gap in functionality, where booleans were technically supported as filter inputs, but would not be handled correctly during the query translation without modifications.To remedy this, I've added a new utility method called
getAllowedComparatorsForType
which returns the allowed comparators that can be used with a given type. This enables guards around using incorrect combinations of values and comparators.Another added benefit of this utility is that we can easily get the list of comparators for each expected type, making it possible to generate tests for every comparator for each data type automatically. I've gone ahead and added an MVP set of tests for the
FunctionalTranslator
, limited to thegetAllowedComparatorsForType
andvisitComparison
methods, to not overcrowd the PR with unrelated changes.