Repository navigation
Let a query column name the function that computed it - #746
Merged
Merged
Conversation
A query column that stores a function's result, such as a generated column holding fold_accents(title), is compared with a value the same function must have folded. The docs had the application fold the input in a query of its own, one round trip per search that every call site had to remember, and a SqlFunction on the column folds the stored side again. @QueryColumn names the function, and a value compared with the column passes through it on the value side only: LOWER(m.title_folded) LIKE LOWER(fold_accents(?)). The column is read as stored, which is what its index holds, and the database computes the value in the same statement. It applies to the comparison operators, IN, BETWEEN, the text operators, search, suggest and orderFirst; an IN list keeps its placeholders rather than binding one array, as for a SqlFunction. A keyset position holds a value read from a row, so it is compared as it is: the expression carries a fromRow flag, part of the compiled-SQL cache key. Column.function() reports the function in core, Java 21 and Kotlin. Fixes #745
3 tasks done
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
A query column that stores a function's result, such as a generated column holding
fold_accents(title), is compared with a value the same function must have folded. Until now the docs had the application fold the input in a query of its own first, one round trip per search that every call site had to remember, and a comparison passing the raw input compiled and ran while silently missing accented matches. Wrapping the column in aSqlFunctionfolds the stored side again and brings back the per-row recheck the stored column exists to avoid.@QueryColumnnow names the function, and a value compared with the column passes through it on the value side only:renders
QueryModelImpl, so the wrap covers the comparison operators,IN,BETWEEN, the text operators,search,suggestandorderFirst. AnINlist with a function keeps its placeholders rather than binding one array, as it does for aSqlFunction. ASqlFunctioncall on such a column wraps outside it:lower(o.last_name_upper) = lower(upper(?)).ObjectExpressioncarries afromRowflag for that, set by the keyset predicate builder and part of the compiled-SQL cache key. The flag states where the value came from and nothing else; for a column without a function it changes nothing.SqlFunctionvalidates one, and a bad name is refused when the model is built.Column.function()reports it in core and the Java 21 wrapper,function: String?in Kotlin;Model.queryColumns()carries it. The attribute defaults to none, so a query column compared as it is, such as atsvectoror a sort key, is unchanged.Docs: the search page's "Storing the Folded Text" loses the folding query and shows the declaration with the function; the entities page, the annotation Javadoc and the changelog describe the attribute; the entity, entity-from-schema and query skills (Java and Kotlin) follow. The branch also carries a small factory test for the inline branch of the nullability check, left over from the coverage review of #744.
Test plan
lastNameUpperoverupper(last_name)with SQL-shape assertions for an equality, a search, anINlist,orderFirst, aSqlFunctionaround the column, the second scroll window (last_name_upper > ?, no function) and the refusal of a non-identifier function namefunction = "lower"on the folded column and match an upper-cased input; the wrappers report the functionFixes #745