vkdb
A time series database engine in C++.
Loading...
Searching...
No Matches
vkdb::QueryBuilder< TValue > Class Template Reference

Query builder for querying a Table. More...

#include <builder.h>

Public Types

using keytype = TimeSeriesKey
 
using mapped_type = std::optional<TValue>
 
using valuetype = std::pair<const keytype, mapped_type>
 
using size_type = uint64_t
 
using result_type = std::vector<valuetype>
 

Public Member Functions

 QueryBuilder ()=delete
 Deleted default constructor.
 
 QueryBuilder (LSMTree< TValue > &lsm_tree, const TagColumns &tag_columns) noexcept
 Construct a new QueryBuilder object.
 
 QueryBuilder (QueryBuilder &&) noexcept=default
 Move-construct a QueryBuilder object.
 
QueryBuilderoperator= (QueryBuilder &&) noexcept=default
 Move-assign a QueryBuilder object.
 
 QueryBuilder (const QueryBuilder &) noexcept=default
 Copy-construct a QueryBuilder object.
 
QueryBuilderoperator= (const QueryBuilder &) noexcept=default
 Copy-assign a QueryBuilder object.
 
 ~QueryBuilder () noexcept=default
 Destroy the Query Builder object.
 
QueryBuilderpoint (const keytype &key)
 Configure builder for point query.
 
QueryBuilderrange (const keytype &start, const keytype &end)
 Configure builder for range query.
 
QueryBuilderfilterByTag (const TagKey &key, const TagValue &value)
 Filter the TimeSeriesKeys by a tag.
 
template<typename... Tags>
requires (AllConvertibleToNoCVRefQuals<Tag, Tags> && ...)
QueryBuilderfilterByAnyTags (const Tags &... tags)
 Filter the TimeSeriesKeys by multiple tags.
 
template<typename... Tags>
requires (AllConvertibleToNoCVRefQuals<Tag, Tags> && ...)
QueryBuilderfilterByAllTags (const Tags &... tags)
 Filter the TimeSeriesKeys by multiple tags.
 
QueryBuilderfilterByMetric (const Metric &metric)
 Filter the TimeSeriesKeys by a metric.
 
template<typename... Metrics>
requires (AllConvertibleToNoCVRefQuals<Metric, Metrics> && ...)
QueryBuilderfilterByAnyMetrics (const Metrics &... metrics)
 Filter the TimeSeriesKeys by multiple metrics.
 
QueryBuilderfilterByTimestamp (const Timestamp &timestamp)
 Filter the TimeSeriesKeys by a timestamp.
 
template<typename... Timestamps>
requires (AllConvertibleToNoCVRefQuals<Timestamp, Timestamps> && ...)
QueryBuilderfilterByAnyTimestamps (const Timestamps &... timestamps)
 Filter the TimeSeriesKeys by multiple timestamps.
 
QueryBuilderput (const keytype &key, const TValue &value)
 Put a key-value pair into the LSMTree.
 
QueryBuilderremove (const keytype &key)
 Remove a key from the LSMTree.
 
size_type count ()
 Count the number of entries in the range.
 
TValue sum ()
 Sum the values in the range.
 
double avg ()
 Calculate the average of the values in the range.
 
TValue min ()
 Calculate the minimum value in the range.
 
TValue max ()
 Calculate the maximum value in the range.
 
result_type execute ()
 Execute the query.
 

Detailed Description

template<ArithmeticNoCVRefQuals TValue>
class vkdb::QueryBuilder< TValue >

Query builder for querying a Table.

Template Parameters
TValueType of the value of the TimeSeriesKey.

Definition at line 26 of file builder.h.

Member Typedef Documentation

◆ keytype

template<ArithmeticNoCVRefQuals TValue>
using vkdb::QueryBuilder< TValue >::keytype = TimeSeriesKey

Definition at line 28 of file builder.h.

◆ mapped_type

template<ArithmeticNoCVRefQuals TValue>
using vkdb::QueryBuilder< TValue >::mapped_type = std::optional<TValue>

Definition at line 29 of file builder.h.

◆ result_type

template<ArithmeticNoCVRefQuals TValue>
using vkdb::QueryBuilder< TValue >::result_type = std::vector<valuetype>

Definition at line 32 of file builder.h.

◆ size_type

template<ArithmeticNoCVRefQuals TValue>
using vkdb::QueryBuilder< TValue >::size_type = uint64_t

Definition at line 31 of file builder.h.

◆ valuetype

template<ArithmeticNoCVRefQuals TValue>
using vkdb::QueryBuilder< TValue >::valuetype = std::pair<const keytype, mapped_type>

Definition at line 30 of file builder.h.

Constructor & Destructor Documentation

◆ QueryBuilder()

template<ArithmeticNoCVRefQuals TValue>
vkdb::QueryBuilder< TValue >::QueryBuilder ( LSMTree< TValue > & lsm_tree,
const TagColumns & tag_columns )
inlineexplicitnoexcept

Construct a new QueryBuilder object.

Query type is set to NONE and filters are initialised with a filter that always returns true.

Parameters
lsm_treeReference to the LSMTree to query.
tag_columnsReference to the tag columns of the Table.

Definition at line 48 of file builder.h.

Member Function Documentation

◆ avg()

template<ArithmeticNoCVRefQuals TValue>
double vkdb::QueryBuilder< TValue >::avg ( )
inlinenodiscard

Calculate the average of the values in the range.

Sets up the QueryBuilder for aggregation and returns the average of the values in the range.

Returns
double Average of the values in the range.
Exceptions
std::runtime_errorIf the aggregate setup fails or the range is empty.

Definition at line 342 of file builder.h.

◆ count()

template<ArithmeticNoCVRefQuals TValue>
size_type vkdb::QueryBuilder< TValue >::count ( )
inlinenodiscard

Count the number of entries in the range.

Sets up the QueryBuilder for aggregation and returns the number of entries in the range.

Returns
size_type Number of entries in the range.
Exceptions
std::runtime_errorIf the aggregate setup fails.

Definition at line 308 of file builder.h.

◆ execute()

template<ArithmeticNoCVRefQuals TValue>
result_type vkdb::QueryBuilder< TValue >::execute ( )
inline

Execute the query.

Executes the query based on the query type and query parameters.

Returns
result_type Result of the query.
Exceptions
std::runtime_errorIf the query type is unset and there are no filters, or if the query type is invalid, or if the execution fails.

Definition at line 398 of file builder.h.

◆ filterByAllTags()

template<ArithmeticNoCVRefQuals TValue>
template<typename... Tags>
requires (AllConvertibleToNoCVRefQuals<Tag, Tags> && ...)
QueryBuilder & vkdb::QueryBuilder< TValue >::filterByAllTags ( const Tags &... tags)
inlinenodiscard

Filter the TimeSeriesKeys by multiple tags.

Adds a filter that checks if the TimeSeriesKey has all of the specified tags.

Template Parameters
TagsVariadic template parameter for tags to filter by.
Parameters
tagsTags to filter by.
Returns
QueryBuilder& Reference to this QueryBuilder object.
Exceptions
std::runtime_errorIf a tag key is not in the tag columns.

Definition at line 181 of file builder.h.

◆ filterByAnyMetrics()

template<ArithmeticNoCVRefQuals TValue>
template<typename... Metrics>
requires (AllConvertibleToNoCVRefQuals<Metric, Metrics> && ...)
QueryBuilder & vkdb::QueryBuilder< TValue >::filterByAnyMetrics ( const Metrics &... metrics)
inlinenodiscard

Filter the TimeSeriesKeys by multiple metrics.

Adds a filter that checks if the TimeSeriesKey has any of the specified metrics.

Template Parameters
MetricsVariadic template parameter for metrics to filter by.
Parameters
metricsMetrics to filter by.
Returns
QueryBuilder& Reference to this QueryBuilder object.
Exceptions
std::runtime_errorIf adding the filter fails.

Definition at line 220 of file builder.h.

◆ filterByAnyTags()

template<ArithmeticNoCVRefQuals TValue>
template<typename... Tags>
requires (AllConvertibleToNoCVRefQuals<Tag, Tags> && ...)
QueryBuilder & vkdb::QueryBuilder< TValue >::filterByAnyTags ( const Tags &... tags)
inlinenodiscard

Filter the TimeSeriesKeys by multiple tags.

Adds a filter that checks if the TimeSeriesKey has any of the specified tags.

Template Parameters
TagsVariadic template parameter for tags to filter by.
Parameters
tagsTags to filter by.
Returns
QueryBuilder& Reference to this QueryBuilder object.
Exceptions
std::runtime_errorIf a tag key is not in the tag columns.

Definition at line 159 of file builder.h.

◆ filterByAnyTimestamps()

template<ArithmeticNoCVRefQuals TValue>
template<typename... Timestamps>
requires (AllConvertibleToNoCVRefQuals<Timestamp, Timestamps> && ...)
QueryBuilder & vkdb::QueryBuilder< TValue >::filterByAnyTimestamps ( const Timestamps &... timestamps)
inlinenodiscard

Filter the TimeSeriesKeys by multiple timestamps.

Adds a filter that checks if the TimeSeriesKey has any of the specified timestamps.

Template Parameters
TimestampsVariadic template parameter for timestamps to filter by.
Parameters
timestampsTimestamps to filter by.
Returns
QueryBuilder& Reference to this QueryBuilder object.
Exceptions
std::runtime_errorIf adding the filter fails.

Definition at line 257 of file builder.h.

◆ filterByMetric()

template<ArithmeticNoCVRefQuals TValue>
QueryBuilder & vkdb::QueryBuilder< TValue >::filterByMetric ( const Metric & metric)
inlinenodiscard

Filter the TimeSeriesKeys by a metric.

Adds a filter that checks if the TimeSeriesKey has the specified metric.

Parameters
metricMetric to filter by.
Returns
QueryBuilder& Reference to this QueryBuilder object.
Exceptions
std::runtime_errorIf adding the filter fails.

Definition at line 200 of file builder.h.

◆ filterByTag()

template<ArithmeticNoCVRefQuals TValue>
QueryBuilder & vkdb::QueryBuilder< TValue >::filterByTag ( const TagKey & key,
const TagValue & value )
inlinenodiscard

Filter the TimeSeriesKeys by a tag.

Adds a filter that checks if the TimeSeriesKey has the specified tag.

Parameters
keyTag key to filter by.
valueTag value to filter by.
Returns
QueryBuilder& Reference to this QueryBuilder object.
Exceptions
std::runtime_errorIf the tag key is not in the tag columns.

Definition at line 135 of file builder.h.

◆ filterByTimestamp()

template<ArithmeticNoCVRefQuals TValue>
QueryBuilder & vkdb::QueryBuilder< TValue >::filterByTimestamp ( const Timestamp & timestamp)
inlinenodiscard

Filter the TimeSeriesKeys by a timestamp.

Adds a filter that checks if the TimeSeriesKey has the specified timestamp.

Parameters
timestampTimestamp to filter by.
Returns
QueryBuilder& Reference to this QueryBuilder object.
Exceptions
std::runtime_errorIf adding the filter fails.

Definition at line 237 of file builder.h.

◆ max()

template<ArithmeticNoCVRefQuals TValue>
TValue vkdb::QueryBuilder< TValue >::max ( )
inlinenodiscard

Calculate the maximum value in the range.

Sets up the QueryBuilder for aggregation and returns the maximum value in the range.

Returns
TValue Maximum value in the range.
Exceptions
std::runtime_errorIf the aggregate setup fails or the range is empty.

Definition at line 380 of file builder.h.

◆ min()

template<ArithmeticNoCVRefQuals TValue>
TValue vkdb::QueryBuilder< TValue >::min ( )
inlinenodiscard

Calculate the minimum value in the range.

Sets up the QueryBuilder for aggregation and returns the minimum value in the range.

Returns
TValue Minimum value in the range.
Exceptions
std::runtime_errorIf the aggregate setup fails or the range is empty.

Definition at line 362 of file builder.h.

◆ point()

template<ArithmeticNoCVRefQuals TValue>
QueryBuilder & vkdb::QueryBuilder< TValue >::point ( const keytype & key)
inlinenodiscard

Configure builder for point query.

Query type is set to POINT and query parameters are set to the TimeSeriesKey to query.

Parameters
keyTimeSeriesKey to query.
Returns
QueryBuilder& Reference to this QueryBuilder object.
Exceptions
std::runtime_errorIf a tag in the key is not in the tag columns.

Definition at line 97 of file builder.h.

◆ put()

template<ArithmeticNoCVRefQuals TValue>
QueryBuilder & vkdb::QueryBuilder< TValue >::put ( const keytype & key,
const TValue & value )
inlinenodiscard

Put a key-value pair into the LSMTree.

Parameters
keyKey to put.
valueValue to put.
Returns
QueryBuilder& Reference to this QueryBuilder object.
Exceptions
std::runtime_errorIf any of the key's tags are not in the tag columns.

Definition at line 276 of file builder.h.

◆ range()

template<ArithmeticNoCVRefQuals TValue>
QueryBuilder & vkdb::QueryBuilder< TValue >::range ( const keytype & start,
const keytype & end )
inlinenodiscard

Configure builder for range query.

Query type is set to RANGE and query parameters are set to the start and end TimeSeriesKeys of the range.

Parameters
startStart TimeSeriesKey of the range.
endEnd TimeSeriesKey of the range.
Returns
QueryBuilder& Reference to this QueryBuilder object.
Exceptions
std::runtime_errorIf a tag in the start or end key is not in the tag columns.

Definition at line 116 of file builder.h.

◆ remove()

template<ArithmeticNoCVRefQuals TValue>
QueryBuilder & vkdb::QueryBuilder< TValue >::remove ( const keytype & key)
inlinenodiscard

Remove a key from the LSMTree.

Parameters
keyKey to remove.
Returns
QueryBuilder& Reference to this QueryBuilder object.
Exceptions
std::runtime_errorIf any of the key's tags are not in the tag columns.

Definition at line 292 of file builder.h.

◆ sum()

template<ArithmeticNoCVRefQuals TValue>
TValue vkdb::QueryBuilder< TValue >::sum ( )
inlinenodiscard

Sum the values in the range.

Sets up the QueryBuilder for aggregation and returns the sum of the values in the range.

Returns
TValue Sum of the values in the range.
Exceptions
std::runtime_errorIf the aggregate setup fails or the range is empty.

Definition at line 323 of file builder.h.


The documentation for this class was generated from the following file: