Cosmetics: whitespaces

This commit is contained in:
Robert Schulze 2024-08-09 13:14:24 +00:00
parent 0f1765a273
commit fb26a9e6d4
No known key found for this signature in database
GPG Key ID: 26703B55FB13728A
3 changed files with 14 additions and 27 deletions

View File

@ -60,8 +60,8 @@ ApproximateNearestNeighborCondition::ApproximateNearestNeighborCondition(const S
bool ApproximateNearestNeighborCondition::alwaysUnknownOrTrue(String metric) const bool ApproximateNearestNeighborCondition::alwaysUnknownOrTrue(String metric) const
{ {
if (!index_is_useful) if (!index_is_useful)
return true; // Query isn't supported return true; /// query isn't supported
// If query is supported, check metrics for match /// If query is supported, check if distance function of index is the same as distance function in query
return !(stringToMetric(metric) == query_information->metric); return !(stringToMetric(metric) == query_information->metric);
} }
@ -138,11 +138,11 @@ bool ApproximateNearestNeighborCondition::checkQueryStructure(const SelectQueryI
void ApproximateNearestNeighborCondition::traverseAST(const ASTPtr & node, RPN & rpn) void ApproximateNearestNeighborCondition::traverseAST(const ASTPtr & node, RPN & rpn)
{ {
// If the node is ASTFunction, it may have children nodes /// If the node is ASTFunction, it may have children nodes
if (const auto * func = node->as<ASTFunction>()) if (const auto * func = node->as<ASTFunction>())
{ {
const ASTs & children = func->arguments->children; const ASTs & children = func->arguments->children;
// Traverse children nodes /// Traverse children nodes
for (const auto& child : children) for (const auto& child : children)
traverseAST(child, rpn); traverseAST(child, rpn);
} }
@ -253,7 +253,7 @@ void ApproximateNearestNeighborCondition::traverseOrderByAST(const ASTPtr & node
/// Returns true and stores ANNExpr if the query has valid ORDERBY clause /// Returns true and stores ANNExpr if the query has valid ORDERBY clause
bool ApproximateNearestNeighborCondition::matchRPNOrderBy(RPN & rpn, ApproximateNearestNeighborInformation & ann_info) bool ApproximateNearestNeighborCondition::matchRPNOrderBy(RPN & rpn, ApproximateNearestNeighborInformation & ann_info)
{ {
// ORDER BY clause must have at least 3 expressions /// ORDER BY clause must have at least 3 expressions
if (rpn.size() < 3) if (rpn.size() < 3)
return false; return false;

View File

@ -23,18 +23,17 @@ namespace DB
struct ApproximateNearestNeighborInformation struct ApproximateNearestNeighborInformation
{ {
using Embedding = std::vector<float>; using Embedding = std::vector<float>;
Embedding reference_vector;
enum class Metric : uint8_t enum class Metric : uint8_t
{ {
Unknown, Unknown,
L2 L2
}; };
Metric metric;
Embedding reference_vector;
Metric metric;
String column_name; String column_name;
UInt64 limit; UInt64 limit;
float distance = -1.0; float distance = -1.0;
}; };
@ -51,7 +50,7 @@ struct ApproximateNearestNeighborInformation
/// ///
/// Queries without LIMIT count are not supported /// Queries without LIMIT count are not supported
/// If the query is both of type 1. and 2., than we can't use the index and alwaysUnknownOrTrue returns true. /// If the query is both of type 1. and 2., than we can't use the index and alwaysUnknownOrTrue returns true.
/// reference_vector should have float coordinates, e.g. (0.2, 0.1, .., 0.5) /// reference_vector should have float coordinates, e.g. [0.2, 0.1, .., 0.5]
/// ///
/// If the query matches one of these two types, then this class extracts the main information needed for ANN indexes from the query. /// If the query matches one of these two types, then this class extracts the main information needed for ANN indexes from the query.
/// ///
@ -73,19 +72,11 @@ public:
/// Returns false if query can be speeded up by an ANN index, true otherwise. /// Returns false if query can be speeded up by an ANN index, true otherwise.
bool alwaysUnknownOrTrue(String metric) const; bool alwaysUnknownOrTrue(String metric) const;
/// Distance should be calculated regarding to referenceVector
std::vector<float> getReferenceVector() const; std::vector<float> getReferenceVector() const;
/// Reference vector's dimension count
size_t getDimensions() const; size_t getDimensions() const;
String getColumnName() const; String getColumnName() const;
ApproximateNearestNeighborInformation::Metric getMetricType() const; ApproximateNearestNeighborInformation::Metric getMetricType() const;
UInt64 getIndexGranularity() const { return index_granularity; } UInt64 getIndexGranularity() const { return index_granularity; }
/// Length's value from LIMIT clause
UInt64 getLimit() const; UInt64 getLimit() const;
private: private:
@ -126,18 +117,14 @@ private:
explicit RPNElement(Function function_ = FUNCTION_UNKNOWN) explicit RPNElement(Function function_ = FUNCTION_UNKNOWN)
: function(function_) : function(function_)
, func_name("Unknown")
, float_literal(std::nullopt)
, identifier(std::nullopt)
{} {}
Function function; Function function;
String func_name; String func_name = "Unknown";
std::optional<float> float_literal; std::optional<float> float_literal;
std::optional<String> identifier; std::optional<String> identifier;
std::optional<int64_t> int_literal; std::optional<int64_t> int_literal;
std::optional<Array> array_literal; std::optional<Array> array_literal;
UInt32 dim = 0; UInt32 dim = 0;
@ -165,7 +152,7 @@ private:
/// Returns true and stores Length if we have valid LIMIT clause in query /// Returns true and stores Length if we have valid LIMIT clause in query
static bool matchRPNLimit(RPNElement & rpn, UInt64 & limit); static bool matchRPNLimit(RPNElement & rpn, UInt64 & limit);
/* Matches dist function, reference vector, column name */ /// Matches dist function, reference vector, column name
static bool matchMainParts(RPN::iterator & iter, const RPN::iterator & end, ApproximateNearestNeighborInformation & ann_info); static bool matchMainParts(RPN::iterator & iter, const RPN::iterator & end, ApproximateNearestNeighborInformation & ann_info);
/// Gets float or int from AST node /// Gets float or int from AST node

View File

@ -232,11 +232,11 @@ MergeTreeIndexPtr hypothesisIndexCreator(const IndexDescription & index);
void hypothesisIndexValidator(const IndexDescription & index, bool attach); void hypothesisIndexValidator(const IndexDescription & index, bool attach);
#if USE_USEARCH #if USE_USEARCH
MergeTreeIndexPtr usearchIndexCreator(const IndexDescription& index); MergeTreeIndexPtr usearchIndexCreator(const IndexDescription & index);
void usearchIndexValidator(const IndexDescription& index, bool attach); void usearchIndexValidator(const IndexDescription & index, bool attach);
#endif #endif
MergeTreeIndexPtr fullTextIndexCreator(const IndexDescription& index); MergeTreeIndexPtr fullTextIndexCreator(const IndexDescription & index);
void fullTextIndexValidator(const IndexDescription& index, bool attach); void fullTextIndexValidator(const IndexDescription & index, bool attach);
} }