diff --git a/cpp-ch/local-engine/Common/CHUtil.cpp b/cpp-ch/local-engine/Common/CHUtil.cpp index 4a0f54e4bb588..015c53a466bb8 100644 --- a/cpp-ch/local-engine/Common/CHUtil.cpp +++ b/cpp-ch/local-engine/Common/CHUtil.cpp @@ -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) diff --git a/cpp-ch/local-engine/Shuffle/SelectorBuilder.cpp b/cpp-ch/local-engine/Shuffle/SelectorBuilder.cpp index f4fca6f6f3b9d..32ad51569f826 100644 --- a/cpp-ch/local-engine/Shuffle/SelectorBuilder.cpp +++ b/cpp-ch/local-engine/Shuffle/SelectorBuilder.cpp @@ -18,15 +18,14 @@ #include #include #include -#include #include #include #include #include #include -#include #include #include +#include #include #include #include @@ -37,13 +36,14 @@ #include #include #include +#include #include namespace DB { namespace ErrorCodes { - extern const int LOGICAL_ERROR; +extern const int LOGICAL_ERROR; } } namespace local_engine @@ -54,14 +54,10 @@ PartitionInfo PartitionInfo::fromSelector(DB::IColumn::Selector selector, size_t std::vector 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; @@ -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(); @@ -161,9 +155,7 @@ void RangeSelectorBuilder::initSortInformation(Poco::JSON::Array::Ptr orderings) auto sort_direction = ordering->get("direction").convert(); 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); @@ -180,9 +172,12 @@ void RangeSelectorBuilder::initSortInformation(Poco::JSON::Array::Ptr orderings) template void RangeSelectorBuilder::safeInsertFloatValue(const Poco::Dynamic::Var & field_value, DB::MutableColumnPtr & col) { - try { + try + { col->insert(field_value.convert()); - } catch (const std::exception &) { + } + catch (const std::exception &) + { String val = Poco::toLower(field_value.convert()); T res; if (val == "nan") @@ -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; @@ -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; } @@ -363,9 +352,7 @@ int RangeSelectorBuilder::binarySearchBound( const DB::Columns & bound_columns, Int64 l, Int64 r, const DB::Columns & columns, const std::vector & 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)