temp-commit

This commit is contained in:
Konstantin Bogdanov 2024-07-02 18:46:44 +02:00
parent 31cf3a45b5
commit c70a92ace0
Signed by: thevar1able
GPG Key ID: DB399448D9FE52F1

View File

@ -3,6 +3,10 @@
#include <Columns/ColumnConst.h>
#include <Columns/ColumnSet.h>
#include <Common/typeid_cast.h>
#include "Analyzer/Passes/QueryAnalysisPass.h"
#include "Analyzer/QueryTreeBuilder.h"
#include "Interpreters/SelectQueryOptions.h"
#include "Planner/PlannerActionsVisitor.h"
#include <Core/Block.h>
#include <DataTypes/DataTypesNumber.h>
#include <DataTypes/FieldToDataType.h>
@ -82,17 +86,64 @@ std::optional<EvaluateConstantExpressionResult> evaluateConstantExpressionImpl(c
auto *ast_as_select = new_ast->as<ASTSelectQuery>();
ast_as_select->setExpression(ASTSelectQuery::Expression::SELECT, expr_list);
InterpreterSelectQueryAnalyzer interpreter(new_ast, context, SelectQueryOptions());
auto io = interpreter.execute();
// InterpreterSelectQueryAnalyzer interpreter(new_ast, context, SelectQueryOptions());
// auto & io = interpreter.getPlanner();
Block block;
PullingPipelineExecutor executor(io.pipeline);
executor.pull(block);
// Block block;
// PullingPipelineExecutor executor(io.pipeline);
// executor.pull(block);
auto & column = block.safeGetByPosition(0);
auto type = column.type;
return std::make_pair((*column.column)[0], type);
auto test = buildQueryTree(ast, context);
SelectQueryOptions options = {};
options.only_analyze = true;
Planner p = Planner(test, options);
QueryAnalysisPass query_analysis_pass;
query_analysis_pass.run(test, context);
auto actions_dag = std::make_shared<ActionsDAG>();
PlannerActionsVisitor actions_visitor(p.getPlannerContext(), false);
auto expr_nodes = actions_visitor.visit(*actions_dag, test);
// auto & column = block.safeGetByPosition(0);
// auto type = column.type;
//
// return std::make_pair((*column.column)[0], type);
ColumnPtr result_column;
DataTypePtr result_type;
String result_name = ast->getColumnName();
for (const auto & action_node : actions_dag->getOutputs())
{
if ((action_node->result_name == result_name) && action_node->column)
{
result_column = action_node->column;
result_type = action_node->result_type;
break;
}
}
if (!result_column)
throw Exception(ErrorCodes::BAD_ARGUMENTS,
"Element of set in IN, VALUES, or LIMIT, or aggregate function parameter, or a table function argument "
"is not a constant expression (result column not found): {}", result_name);
if (result_column->empty())
throw Exception(ErrorCodes::LOGICAL_ERROR,
"Empty result column after evaluation "
"of constant expression for IN, VALUES, or LIMIT, or aggregate function parameter, or a table function argument");
/// Expressions like rand() or now() are not constant
if (!isColumnConst(*result_column))
throw Exception(ErrorCodes::BAD_ARGUMENTS,
"Element of set in IN, VALUES, or LIMIT, or aggregate function parameter, or a table function argument "
"is not a constant expression (result column is not const): {}", result_name);
return std::make_pair((*result_column)[0], result_type);
}
else
{