提交 f253719e 编写于 作者: V VadimPE

CLICKHOUSE-3934 add SettingsJoinStrictness

上级 d626ae11
......@@ -391,7 +391,8 @@ namespace ErrorCodes
extern const int CANNOT_READLINE = 414;
extern const int ALL_REPLICAS_LOST = 415;
extern const int REPLICA_STATUS_CHANGED = 416;
extern const int EXPECT_ALL_OR_ANY = 417;
extern const int EXPECTED_ALL_OR_ANY = 417;
extern const int UNKNOWN_JOIN_STRICTNESS = 418;
extern const int KEEPER_EXCEPTION = 999;
extern const int POCO_EXCEPTION = 1000;
......
......@@ -96,7 +96,7 @@ namespace ErrorCodes
extern const int CONDITIONAL_TREE_PARENT_NOT_FOUND;
extern const int TYPE_MISMATCH;
extern const int INVALID_JOIN_ON_EXPRESSION;
extern const int EXPECT_ALL_OR_ANY;
extern const int EXPECTED_ALL_OR_ANY;
}
......@@ -2492,10 +2492,8 @@ bool ExpressionAnalyzer::appendJoin(ExpressionActionsChain & chain, bool only_ty
join_params.strictness = ASTTableJoin::Strictness::Any;
else if (settings.join_default_strictness.toString() == "ALL")
join_params.strictness = ASTTableJoin::Strictness::All;
else if (settings.join_default_strictness.toString() != "")
throw Exception("Unexcepted join_default_strictness = " + settings.join_default_strictness.toString() + ". It can be an empty string, ANY or ALL");
else
throw Exception("Expected ANY or ALL in JOIN section, because setting (join_default_strictness) is empty", DB::ErrorCodes::EXPECT_ALL_OR_ANY);
throw Exception("Expected ANY or ALL in JOIN section, because setting (join_default_strictness) is empty", DB::ErrorCodes::EXPECTED_ALL_OR_ANY);
}
const auto & table_to_join = static_cast<const ASTTableExpression &>(*join_element.table_expression);
......
......@@ -173,7 +173,7 @@ struct Settings
\
M(SettingBool, join_use_nulls, 0, "Use NULLs for non-joined rows of outer JOINs. If false, use default value of corresponding columns data type.") \
\
M(SettingString, join_default_strictness, "", "Set default strictness in JOIN query. If empty, query without strictness will throw exception") \
M(SettingJoinStrictness, join_default_strictness, JoinStrictness::Unspecified, "Set default strictness in JOIN query. If empty, query without strictness will throw exception") \
\
M(SettingUInt64, preferred_block_size_bytes, 1000000, "") \
\
......
......@@ -22,6 +22,7 @@ namespace ErrorCodes
extern const int UNKNOWN_COMPRESSION_METHOD;
extern const int UNKNOWN_DISTRIBUTED_PRODUCT_MODE;
extern const int UNKNOWN_GLOBAL_SUBQUERIES_METHOD;
extern const int UNKNOWN_JOIN_STRICTNESS;
extern const int SIZE_OF_FIXED_STRING_DOESNT_MATCH;
extern const int BAD_ARGUMENTS;
}
......@@ -288,6 +289,53 @@ void SettingLoadBalancing::write(WriteBuffer & buf) const
}
JoinStrictness SettingJoinStrictness::getJoinStrictness(const String & s)
{
if (s == "") return JoinStrictness::Unspecified;
if (s == "ALL") return JoinStrictness::ALL;
if (s == "ANY") return JoinStrictness::ANY;
throw Exception("Unknown join strictness mode: '" + s + "', must be one of '', 'ALL', 'ANY'",
ErrorCodes::UNKNOWN_JOIN_STRICTNESS);
}
String SettingJoinStrictness::toString() const
{
const char * strings[] = {"", "ALL", "ANY"};
if (value < JoinStrictness::Unspecified || value > JoinStrictness::ANY)
throw Exception("Unknown join strictness mode", ErrorCodes::UNKNOWN_JOIN_STRICTNESS);
return strings[static_cast<size_t>(value)];
}
void SettingJoinStrictness::set(JoinStrictness x)
{
value = x;
changed = true;
}
void SettingJoinStrictness::set(const Field & x)
{
set(safeGet<const String &>(x));
}
void SettingJoinStrictness::set(const String & x)
{
set(getJoinStrictness(x));
}
void SettingJoinStrictness::set(ReadBuffer & buf)
{
String x;
readBinary(x, buf);
set(x);
}
void SettingJoinStrictness::write(WriteBuffer & buf) const
{
writeBinary(toString(), buf);
}
TotalsMode SettingTotalsMode::getTotalsMode(const String & s)
{
if (s == "before_having") return TotalsMode::BEFORE_HAVING;
......
......@@ -191,6 +191,37 @@ struct SettingLoadBalancing
};
enum class JoinStrictness
{
Unspecified = 0, /// Query JOIN without strictness will throw Exception.
ALL, /// Query JOIN without strictness -> ALL JOIN ...
ANY, /// Query JOIN without strictness -> ANY JOIN ...
};
struct SettingJoinStrictness
{
JoinStrictness value;
bool changed = false;
SettingJoinStrictness(JoinStrictness x) : value(x) {}
operator JoinStrictness() const { return value; }
SettingJoinStrictness & operator= (JoinStrictness x) { set(x); return *this; }
static JoinStrictness getJoinStrictness(const String & s);
String toString() const;
void set(JoinStrictness x);
void set(const Field & x);
void set(const String & x);
void set(ReadBuffer & buf);
void write(WriteBuffer & buf) const;
};
/// Which rows should be included in TOTALS.
enum class TotalsMode
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册