2021-04-26 09:40:54 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeIndexHypothesis.h>
|
2021-11-21 19:14:20 +00:00
|
|
|
#include <Storages/MergeTree/MergeTreeIndexHypothesisMergedCondition.h>
|
2021-04-26 09:40:54 +00:00
|
|
|
|
|
|
|
#include <Interpreters/ExpressionActions.h>
|
|
|
|
#include <Interpreters/ExpressionAnalyzer.h>
|
|
|
|
#include <Interpreters/TreeRewriter.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int LOGICAL_ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MergeTreeIndexGranuleHypothesis::MergeTreeIndexGranuleHypothesis(const String & index_name_)
|
|
|
|
: index_name(index_name_), is_empty(true), met(false)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-03-13 12:23:51 +00:00
|
|
|
MergeTreeIndexGranuleHypothesis::MergeTreeIndexGranuleHypothesis(const String & index_name_, bool met_)
|
2021-04-26 09:40:54 +00:00
|
|
|
: index_name(index_name_), is_empty(false), met(met_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MergeTreeIndexGranuleHypothesis::serializeBinary(WriteBuffer & ostr) const
|
|
|
|
{
|
|
|
|
const auto & size_type = DataTypePtr(std::make_shared<DataTypeUInt8>());
|
2022-12-02 12:57:11 +00:00
|
|
|
size_type->getDefaultSerialization()->serializeBinary(static_cast<UInt8>(met), ostr, {});
|
2021-04-26 09:40:54 +00:00
|
|
|
}
|
|
|
|
|
2021-11-10 16:35:28 +00:00
|
|
|
void MergeTreeIndexGranuleHypothesis::deserializeBinary(ReadBuffer & istr, MergeTreeIndexVersion version)
|
2021-04-26 09:40:54 +00:00
|
|
|
{
|
2021-11-10 16:35:28 +00:00
|
|
|
if (version != 1)
|
|
|
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Unknown index version {}.", version);
|
|
|
|
|
2021-04-26 09:40:54 +00:00
|
|
|
Field field_met;
|
|
|
|
const auto & size_type = DataTypePtr(std::make_shared<DataTypeUInt8>());
|
2022-12-02 12:57:11 +00:00
|
|
|
size_type->getDefaultSerialization()->deserializeBinary(field_met, istr, {});
|
2021-04-26 09:40:54 +00:00
|
|
|
met = field_met.get<UInt8>();
|
|
|
|
is_empty = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
MergeTreeIndexAggregatorHypothesis::MergeTreeIndexAggregatorHypothesis(const String & index_name_, const String & column_name_)
|
|
|
|
: index_name(index_name_), column_name(column_name_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MergeTreeIndexGranulePtr MergeTreeIndexAggregatorHypothesis::getGranuleAndReset()
|
|
|
|
{
|
|
|
|
const auto granule = std::make_shared<MergeTreeIndexGranuleHypothesis>(index_name, met);
|
|
|
|
met = true;
|
|
|
|
is_empty = true;
|
|
|
|
return granule;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MergeTreeIndexAggregatorHypothesis::update(const Block & block, size_t * pos, size_t limit)
|
|
|
|
{
|
|
|
|
size_t rows_read = std::min(limit, block.rows() - *pos);
|
|
|
|
if (rows_read == 0)
|
|
|
|
return;
|
|
|
|
const auto & column = block.getByName(column_name).column->cut(*pos, rows_read);
|
|
|
|
|
|
|
|
if (!column->hasEqualValues() || column->get64(0) == 0)
|
|
|
|
met = false;
|
|
|
|
|
|
|
|
is_empty = false;
|
|
|
|
*pos += rows_read;
|
|
|
|
}
|
|
|
|
|
|
|
|
MergeTreeIndexGranulePtr MergeTreeIndexHypothesis::createIndexGranule() const
|
|
|
|
{
|
|
|
|
return std::make_shared<MergeTreeIndexGranuleHypothesis>(index.name);
|
|
|
|
}
|
|
|
|
|
2023-08-29 19:53:40 +00:00
|
|
|
MergeTreeIndexAggregatorPtr MergeTreeIndexHypothesis::createIndexAggregator(const MergeTreeWriterSettings & /*settings*/) const
|
2021-04-26 09:40:54 +00:00
|
|
|
{
|
|
|
|
return std::make_shared<MergeTreeIndexAggregatorHypothesis>(index.name, index.sample_block.getNames().front());
|
|
|
|
}
|
|
|
|
|
|
|
|
MergeTreeIndexConditionPtr MergeTreeIndexHypothesis::createIndexCondition(
|
2024-01-03 17:50:46 +00:00
|
|
|
const ActionsDAGPtr &, ContextPtr) const
|
2021-04-26 09:40:54 +00:00
|
|
|
{
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Not supported");
|
2021-04-26 09:40:54 +00:00
|
|
|
}
|
|
|
|
|
2022-03-01 21:42:27 +00:00
|
|
|
MergeTreeIndexMergedConditionPtr MergeTreeIndexHypothesis::createIndexMergedCondition(
|
2021-11-21 19:14:20 +00:00
|
|
|
const SelectQueryInfo & query_info, StorageMetadataPtr storage_metadata) const
|
|
|
|
{
|
|
|
|
return std::make_shared<MergeTreeIndexhypothesisMergedCondition>(
|
|
|
|
query_info, storage_metadata->getConstraints(), index.granularity);
|
|
|
|
}
|
|
|
|
|
2021-04-26 09:40:54 +00:00
|
|
|
MergeTreeIndexPtr hypothesisIndexCreator(const IndexDescription & index)
|
|
|
|
{
|
|
|
|
return std::make_shared<MergeTreeIndexHypothesis>(index);
|
|
|
|
}
|
|
|
|
|
2021-05-02 19:16:40 +00:00
|
|
|
void hypothesisIndexValidator(const IndexDescription & index, bool /*attach*/)
|
2021-04-26 09:40:54 +00:00
|
|
|
{
|
2021-05-02 19:16:40 +00:00
|
|
|
if (index.expression_list_ast->children.size() != 1)
|
2023-01-23 21:13:58 +00:00
|
|
|
throw Exception(ErrorCodes::LOGICAL_ERROR, "Hypothesis index needs exactly one expression");
|
2021-04-26 09:40:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|