The similarity function syntax is: `similarity_<metric_name>(<vector>, <vector>)` Where `<metric_name>` is one of `cosine`, `euclidean` and `dot_product` matching the intended similarity metric to be used within calculations. Where `<vector>` is either a vector column name or vector literal. Add `vectorSimilarityArgs` symbol that is an extension of `selectionFunctionArgs`, but allowing to use the `value` as an argument as well as the `unaliasedSelector`. This is needed as the similarity function syntax allows both the arguments to be a vector value, so the grammar needs to recognize the vector literal there as well. Since we actually support `SELECT`s with constants since this patch, return true instead of throwing an error while trying to convert the function call to constant.
90 lines
3.0 KiB
C++
90 lines
3.0 KiB
C++
/*
|
|
* Copyright (C) 2015-present ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0
|
|
*/
|
|
|
|
#include "cql3/query_options.hh"
|
|
#include "cql3/functions/functions.hh"
|
|
#include "cql3/functions/castas_fcts.hh"
|
|
#include "cql3/functions/aggregate_fcts.hh"
|
|
#include "cql3/expr/expression.hh"
|
|
#include "cql3/expr/expr-utils.hh"
|
|
|
|
namespace cql3 {
|
|
|
|
namespace selection {
|
|
|
|
seastar::logger slogger("cql3_selection");
|
|
|
|
|
|
expr::expression
|
|
make_count_rows_function_expression() {
|
|
return expr::function_call{
|
|
cql3::functions::function_name::native_function(cql3::functions::aggregate_fcts::COUNT_ROWS_FUNCTION_NAME),
|
|
std::vector<cql3::expr::expression>()};
|
|
}
|
|
|
|
|
|
bool
|
|
selectable_processes_selection(const expr::expression& selectable) {
|
|
return expr::visit(overloaded_functor{
|
|
[&] (const expr::constant&) -> bool {
|
|
return true;
|
|
},
|
|
[&] (const expr::conjunction& conj) -> bool {
|
|
on_internal_error(slogger, "no way to express 'SELECT a AND b' in the grammar yet");
|
|
},
|
|
[&] (const expr::binary_operator& conj) -> bool {
|
|
on_internal_error(slogger, "no way to express 'SELECT a binop b' in the grammar yet");
|
|
},
|
|
[] (const expr::subscript&) -> bool {
|
|
return true;
|
|
},
|
|
[&] (const expr::column_value& column) -> bool {
|
|
return false;
|
|
},
|
|
[&] (const expr::unresolved_identifier& ui) -> bool {
|
|
on_internal_error(slogger, "selectable_processes_selection saw an unprepared column_identifier");
|
|
},
|
|
[&] (const expr::column_mutation_attribute& cma) -> bool {
|
|
return true;
|
|
},
|
|
[&] (const expr::function_call& fc) -> bool {
|
|
return true;
|
|
},
|
|
[&] (const expr::cast& c) -> bool {
|
|
return true;
|
|
},
|
|
[&] (const expr::field_selection& fs) -> bool {
|
|
return true;
|
|
},
|
|
[&] (const expr::bind_variable&) -> bool {
|
|
on_internal_error(slogger, "bind_variable found its way to selector context");
|
|
},
|
|
[&] (const expr::untyped_constant&) -> bool {
|
|
on_internal_error(slogger, "untyped_constant found its way to selector context");
|
|
},
|
|
[&] (const expr::tuple_constructor&) -> bool {
|
|
on_internal_error(slogger, "tuple_constructor found its way to selector context");
|
|
},
|
|
[&] (const expr::collection_constructor&) -> bool {
|
|
on_internal_error(slogger, "collection_constructor found its way to selector context");
|
|
},
|
|
[&] (const expr::usertype_constructor&) -> bool {
|
|
on_internal_error(slogger, "collection_constructor found its way to selector context");
|
|
},
|
|
[&] (const expr::temporary& t) -> bool {
|
|
// Well it doesn't process the selection, but it's not bypasses the selection completely
|
|
// so we can't use the fast path. In any case it won't be seen.
|
|
return true;
|
|
},
|
|
}, selectable);
|
|
};
|
|
|
|
}
|
|
|
|
}
|