add settings && add test case

This commit is contained in:
zxc111 2021-07-13 00:46:22 +08:00
parent cd97478c06
commit e0261866a4
4 changed files with 24 additions and 3 deletions

View File

@ -129,12 +129,15 @@ namespace ErrorCodes
} }
using RelativeSize = boost::rational<ASTSampleRatio::BigNum>; using RelativeSize = boost::rational<ASTSampleRatio::BigNum>;
static void checkSampleExpression(const StorageInMemoryMetadata & metadata, bool allow_sampling_expression_not_in_primary_key) static void checkSampleExpression(const StorageInMemoryMetadata & metadata, bool allow_sampling_expression_not_in_primary_key, bool check_sample_column_is_correct)
{ {
const auto & pk_sample_block = metadata.getPrimaryKey().sample_block; const auto & pk_sample_block = metadata.getPrimaryKey().sample_block;
if (!pk_sample_block.has(metadata.sampling_key.column_names[0]) && !allow_sampling_expression_not_in_primary_key) if (!pk_sample_block.has(metadata.sampling_key.column_names[0]) && !allow_sampling_expression_not_in_primary_key)
throw Exception("Sampling expression must be present in the primary key", ErrorCodes::BAD_ARGUMENTS); throw Exception("Sampling expression must be present in the primary key", ErrorCodes::BAD_ARGUMENTS);
if (!check_sample_column_is_correct)
return;
const auto & sampling_key = metadata.getSamplingKey(); const auto & sampling_key = metadata.getSamplingKey();
DataTypePtr sampling_column_type = sampling_key.data_types[0]; DataTypePtr sampling_column_type = sampling_key.data_types[0];
@ -225,7 +228,8 @@ MergeTreeData::MergeTreeData(
if (metadata_.sampling_key.definition_ast != nullptr) if (metadata_.sampling_key.definition_ast != nullptr)
{ {
/// This is for backward compatibility. /// This is for backward compatibility.
checkSampleExpression(metadata_, attach || settings->compatibility_allow_sampling_expression_not_in_primary_key); checkSampleExpression(metadata_, attach || settings->compatibility_allow_sampling_expression_not_in_primary_key,
settings->check_sample_column_is_correct);
} }
checkTTLExpressions(metadata_, metadata_); checkTTLExpressions(metadata_, metadata_);
@ -1700,7 +1704,8 @@ void MergeTreeData::checkAlterIsPossible(const AlterCommands & commands, Context
"ALTER MODIFY SAMPLE BY is not supported for default-partitioned tables created with the old syntax", "ALTER MODIFY SAMPLE BY is not supported for default-partitioned tables created with the old syntax",
ErrorCodes::BAD_ARGUMENTS); ErrorCodes::BAD_ARGUMENTS);
checkSampleExpression(new_metadata, getSettings()->compatibility_allow_sampling_expression_not_in_primary_key); checkSampleExpression(new_metadata, getSettings()->compatibility_allow_sampling_expression_not_in_primary_key,
getSettings()->check_sample_column_is_correct);
} }
if (command.type == AlterCommand::ADD_INDEX && !is_custom_partitioned) if (command.type == AlterCommand::ADD_INDEX && !is_custom_partitioned)
{ {

View File

@ -130,6 +130,7 @@ struct Settings;
M(UInt64, max_concurrent_queries, 0, "Max number of concurrently executed queries related to the MergeTree table (0 - disabled). Queries will still be limited by other max_concurrent_queries settings.", 0) \ M(UInt64, max_concurrent_queries, 0, "Max number of concurrently executed queries related to the MergeTree table (0 - disabled). Queries will still be limited by other max_concurrent_queries settings.", 0) \
M(UInt64, min_marks_to_honor_max_concurrent_queries, 0, "Minimal number of marks to honor the MergeTree-level's max_concurrent_queries (0 - disabled). Queries will still be limited by other max_concurrent_queries settings.", 0) \ M(UInt64, min_marks_to_honor_max_concurrent_queries, 0, "Minimal number of marks to honor the MergeTree-level's max_concurrent_queries (0 - disabled). Queries will still be limited by other max_concurrent_queries settings.", 0) \
M(UInt64, min_bytes_to_rebalance_partition_over_jbod, 0, "Minimal amount of bytes to enable part rebalance over JBOD array (0 - disabled).", 0) \ M(UInt64, min_bytes_to_rebalance_partition_over_jbod, 0, "Minimal amount of bytes to enable part rebalance over JBOD array (0 - disabled).", 0) \
M(Bool, check_sample_column_is_correct, true, "Check columns or columns by hash for sampling are unsigned integer.", 0) \
\ \
/** Experimental/work in progress feature. Unsafe for production. */ \ /** Experimental/work in progress feature. Unsafe for production. */ \
M(UInt64, part_moves_between_shards_enable, 0, "Experimental/Incomplete feature to move parts between shards. Does not take into account sharding expressions.", 0) \ M(UInt64, part_moves_between_shards_enable, 0, "Experimental/Incomplete feature to move parts between shards. Does not take into account sharding expressions.", 0) \

View File

@ -0,0 +1,15 @@
CREATE DATABASE IF NOT EXISTS test_sample;
CREATE TABLE IF NOT EXISTS test_sample.sample_incorrect
(`x` UUID)
ENGINE = MergeTree
ORDER BY tuple(x)
SAMPLE BY x; -- { serverError 59 }
CREATE TABLE IF NOT EXISTS test_sample.sample_correct
(`x` String)
ENGINE = MergeTree
ORDER BY tuple(sipHash64(x))
SAMPLE BY sipHash64(x);
DROP DATABASE test_sample;