Skip to content

Commit

Permalink
FFix cast or null
Browse files Browse the repository at this point in the history
  • Loading branch information
loneylee committed Dec 6, 2023
1 parent 84683be commit 51047fd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 24 deletions.
8 changes: 5 additions & 3 deletions cpp-ch/local-engine/Common/CHUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,13 @@ const DB::ActionsDAG::Node * ActionsDAGUtil::convertNodeType(
const auto * right_arg = &actions_dag->addColumn(std::move(type_name_col));
const auto * left_arg = node;
DB::CastDiagnostic diagnostic = {node->result_name, node->result_name};
DB::FunctionOverloadResolverPtr func_builder_cast
= DB::createInternalCastOverloadResolver(DB::CastType::accurateOrNull, std::move(diagnostic));
auto type = CastType::nonAccurate;

if (startsWith(type_name, "Nullable"))
type = CastType::accurateOrNull;

DB::ActionsDAG::NodeRawConstPtrs children = {left_arg, right_arg};
return &actions_dag->addFunction(func_builder_cast, std::move(children), result_name);
return &actions_dag->addFunction(DB::createInternalCastOverloadResolver(type, std::move(diagnostic)), std::move(children), result_name);
}

String QueryPipelineUtil::explainPipeline(DB::QueryPipeline & pipeline)
Expand Down
29 changes: 8 additions & 21 deletions cpp-ch/local-engine/Shuffle/SelectorBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@
#include <limits>
#include <memory>
#include <mutex>
#include <Common/CHUtil.h>
#include <Columns/ColumnArray.h>
#include <Columns/ColumnMap.h>
#include <Columns/ColumnNullable.h>
#include <Columns/ColumnTuple.h>
#include <DataTypes/DataTypeArray.h>
#include <DataTypes/DataTypesDecimal.h>
#include <DataTypes/DataTypeMap.h>
#include <DataTypes/DataTypeTuple.h>
#include <DataTypes/DataTypesDecimal.h>
#include <Functions/FunctionFactory.h>
#include <Parser/SerializedPlanParser.h>
#include <Parser/TypeParser.h>
Expand All @@ -37,13 +36,14 @@
#include <Poco/JSON/Parser.h>
#include <Poco/MemoryStream.h>
#include <Poco/StreamCopier.h>
#include <Common/CHUtil.h>
#include <Common/Exception.h>

namespace DB
{
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
extern const int LOGICAL_ERROR;
}
}
namespace local_engine
Expand All @@ -54,14 +54,10 @@ PartitionInfo PartitionInfo::fromSelector(DB::IColumn::Selector selector, size_t
std::vector<size_t> partition_row_idx_start_points(partition_num + 1, 0);
IColumn::Selector partition_selector(rows, 0);
for (size_t i = 0; i < rows; ++i)
{
partition_row_idx_start_points[selector[i]]++;
}

for (size_t i = 1; i <= partition_num; ++i)
{
partition_row_idx_start_points[i] += partition_row_idx_start_points[i - 1];
}
for (size_t i = rows; i-- > 0;)
{
partition_selector[partition_row_idx_start_points[selector[i]] - 1] = i;
Expand Down Expand Up @@ -95,9 +91,7 @@ PartitionInfo HashSelectorBuilder::build(DB::Block & block)
{
ColumnsWithTypeAndName args;
for (size_t i = 0; i < exprs_index.size(); i++)
{
args.emplace_back(block.safeGetByPosition(exprs_index.at(i)));
}
auto flatten_block = BlockUtil::flattenBlock(DB::Block(args), BlockUtil::FLAT_STRUCT_FORCE | BlockUtil::FLAT_NESTED_TABLE, true);
args = flatten_block.getColumnsWithTypeAndName();

Expand Down Expand Up @@ -161,9 +155,7 @@ void RangeSelectorBuilder::initSortInformation(Poco::JSON::Array::Ptr orderings)
auto sort_direction = ordering->get("direction").convert<int>();
auto d_iter = direction_map.find(sort_direction);
if (d_iter == direction_map.end())
{
throw DB::Exception(DB::ErrorCodes::LOGICAL_ERROR, "Unsupported sorting direction:{}", sort_direction);
}
DB::SortColumnDescription ch_col_sort_descr(col_name, d_iter->second.first, d_iter->second.second);
sort_descriptions.emplace_back(ch_col_sort_descr);

Expand All @@ -180,9 +172,12 @@ void RangeSelectorBuilder::initSortInformation(Poco::JSON::Array::Ptr orderings)
template <typename T>
void RangeSelectorBuilder::safeInsertFloatValue(const Poco::Dynamic::Var & field_value, DB::MutableColumnPtr & col)
{
try {
try
{
col->insert(field_value.convert<T>());
} catch (const std::exception &) {
}
catch (const std::exception &)
{
String val = Poco::toLower(field_value.convert<std::string>());
T res;
if (val == "nan")
Expand Down Expand Up @@ -318,12 +313,8 @@ void RangeSelectorBuilder::computePartitionIdByBinarySearch(DB::Block & block, D
const auto & bounds_columns = range_bounds_block.getColumns();
auto max_part = bounds_columns[0]->size();
for (size_t i = 0; i < bounds_columns.size(); i++)
{
if (bounds_columns[i]->isNullable() && !input_columns[sorting_key_columns[i]]->isNullable())
{
input_columns[sorting_key_columns[i]] = makeNullable(input_columns[sorting_key_columns[i]]);
}
}
for (size_t r = 0; r < total_rows; ++r)
{
size_t selected_partition = 0;
Expand All @@ -350,9 +341,7 @@ int RangeSelectorBuilder::compareRow(
auto res = columns[lpos]->compareAt(row, bound_row, *bound_columns[rpos], sort_descriptions[i].nulls_direction)
* sort_descriptions[i].direction;
if (res != 0)
{
return res;
}
}
return 0;
}
Expand All @@ -363,9 +352,7 @@ int RangeSelectorBuilder::binarySearchBound(
const DB::Columns & bound_columns, Int64 l, Int64 r, const DB::Columns & columns, const std::vector<size_t> & used_cols, size_t row)
{
if (l > r)
{
return -1;
}
auto m = (l + r) >> 1;
auto cmp_ret = compareRow(columns, used_cols, row, bound_columns, m);
if (l == r)
Expand Down

0 comments on commit 51047fd

Please sign in to comment.