You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When selecting data from a query (e.g. SELECT id,comment,language,similarity_cosine(embedding,:embedding) AS score FROM comments) that returns an entity and auxiliary information (such as a score), it makes sense to capture materialize the entity independently from the score.
While it would be possible to create a dedicated data structure for this projection result, it is much leaner to reuse existing data models and customize the result mapping at the stage where CassandraTemplate already has access to the Row.
Something along the lines of:
/** * Trigger {@code SELECT} query execution by calling one of the terminating methods and return mapped results. */interfaceTerminatingResults<T> {
<R> TerminatingResults<R> map(QueryResultConverter<? superT, ? extendsR> converter);
defaultOptional<T> first() {
returnOptional.ofNullable(firstValue());
}
@NullableTfirstValue();
// …
The actual converter needs to be tied to the Row and upstream result produced by a converter:
interfaceQueryResultConverter<T, R> {
/** * Returns a function that returns the materialized entity.. */@SuppressWarnings("unchecked")
static <T> QueryResultConverter<T, T> entity() {
return (row, result) -> result.get();
}
RmapRow(Rowrow, ConversionResultSupplier<T> reader);
/** * A supplier that converts a {@link Row} into {@code T}. Allows for lazy reading of query results. */interfaceConversionResultSupplier<T> {
/** * Obtain the upstream conversion result. * * @return the upstream conversion result. */Tget();
}
}
Open issues:
Find a better name for ConversionResultSupplier.
Supplier pattern allows Lazy caching to buffer multiple calls to get, however, a UpstreamConverter.convert(Row) might be more explicit
The text was updated successfully, but these errors were encountered:
When selecting data from a query (e.g.
SELECT id,comment,language,similarity_cosine(embedding,:embedding) AS score FROM comments
) that returns an entity and auxiliary information (such as a score), it makes sense to capture materialize the entity independently from thescore
.While it would be possible to create a dedicated data structure for this projection result, it is much leaner to reuse existing data models and customize the result mapping at the stage where
CassandraTemplate
already has access to theRow
.Something along the lines of:
The actual converter needs to be tied to the
Row
and upstream result produced by a converter:Open issues:
ConversionResultSupplier
.Supplier
pattern allowsLazy
caching to buffer multiple calls toget
, however, aUpstreamConverter.convert(Row)
might be more explicitThe text was updated successfully, but these errors were encountered: