mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-06 07:32:27 +00:00
Fix comparisons with modulo key (version 2)
This commit is contained in:
parent
94b5763dbd
commit
fcfec83875
@ -2,6 +2,7 @@
|
||||
|
||||
#include <Functions/IFunction.h>
|
||||
#include <Parsers/ASTIdentifier.h>
|
||||
#include <Parsers/ASTFunction.h>
|
||||
#include <Interpreters/ExpressionActions.h>
|
||||
#include <Interpreters/ExpressionAnalyzer.h>
|
||||
#include <Interpreters/TreeRewriter.h>
|
||||
@ -89,7 +90,7 @@ KeyDescription KeyDescription::getKeyFromAST(
|
||||
bool KeyDescription::moduloToModuloLegacyRecursive(ASTPtr node_expr)
|
||||
{
|
||||
if (!node_expr)
|
||||
return;
|
||||
return false;
|
||||
|
||||
auto * function_expr = node_expr->as<ASTFunction>();
|
||||
bool modulo_in_ast = false;
|
||||
|
@ -71,7 +71,7 @@ struct KeyDescription
|
||||
KeyDescription & operator=(const KeyDescription & other);
|
||||
|
||||
/// Substitute modulo with moduloLegacy. Used in KeyCondition to allow proper comparison with keys.
|
||||
static void moduloToModuloLegacyRecursive(ASTPtr node_expr);
|
||||
static bool moduloToModuloLegacyRecursive(ASTPtr node_expr);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -602,10 +602,17 @@ bool KeyCondition::canConstantBeWrappedByMonotonicFunctions(
|
||||
auto adjusted_node = node->clone();
|
||||
KeyDescription::moduloToModuloLegacyRecursive(adjusted_node);
|
||||
|
||||
String adjusted_expr_name = adjusted_node->getColumnName();
|
||||
// Constant expr should use alias names if any
|
||||
String expr_name = adjusted_node->getColumnName();
|
||||
String passed_expr_name = node->getColumnName();
|
||||
String expr_name;
|
||||
|
||||
const auto & sample_block = key_expr->getSampleBlock();
|
||||
if (!sample_block.has(expr_name))
|
||||
if (sample_block.has(passed_expr_name))
|
||||
expr_name = passed_expr_name;
|
||||
else if (sample_block.has(adjusted_expr_name))
|
||||
expr_name = adjusted_expr_name;
|
||||
else
|
||||
return false;
|
||||
|
||||
/// TODO Nullable index is not yet landed.
|
||||
@ -673,10 +680,17 @@ bool KeyCondition::canConstantBeWrappedByFunctions(
|
||||
auto adjusted_ast = ast->clone();
|
||||
KeyDescription::moduloToModuloLegacyRecursive(adjusted_ast);
|
||||
|
||||
String adjusted_expr_name = adjusted_ast->getColumnName();
|
||||
// Constant expr should use alias names if any
|
||||
String expr_name = adjusted_ast->getColumnName();
|
||||
String passed_expr_name = ast->getColumnName();
|
||||
String expr_name;
|
||||
|
||||
const auto & sample_block = key_expr->getSampleBlock();
|
||||
if (!sample_block.has(expr_name))
|
||||
if (sample_block.has(passed_expr_name))
|
||||
expr_name = passed_expr_name;
|
||||
else if (sample_block.has(adjusted_expr_name))
|
||||
expr_name = adjusted_expr_name;
|
||||
else
|
||||
return false;
|
||||
|
||||
/// TODO Nullable index is not yet landed.
|
||||
|
Loading…
Reference in New Issue
Block a user