Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
SeaRise committed Mar 21, 2022
1 parent d7cf5a4 commit 057858d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 8 additions & 5 deletions dbms/src/Flash/Coprocessor/DAGExpressionAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ void DAGExpressionAnalyzer::appendCastForRootFinalProjection(
tipb::Expr tz_expr = constructTZExpr(context.getTimezoneInfo());
String tz_col;
String tz_cast_func_name = context.getTimezoneInfo().is_name_based ? "ConvertTimeZoneToUTC" : "ConvertTimeZoneByOffsetToUTC";
// <origin_column_name, offset>
std::unordered_map<String, size_t> had_casted_map;

const auto & current_columns = getCurrentInputColumns();
Expand All @@ -871,25 +872,26 @@ void DAGExpressionAnalyzer::appendCastForRootFinalProjection(
/// the timestamp column to UTC based, refer to appendTimeZoneCastsAfterTS for more details
if ((need_append_timezone_cast && require_schema[offset].tp() == TiDB::TypeTimestamp) || need_append_type_cast_vec[index])
{
auto it = had_casted_map.find(current_columns[offset].name);
const String & origin_column_name = current_columns[offset].name;
auto it = had_casted_map.find(origin_column_name);
if (it == had_casted_map.end())
{
/// first add timestamp cast
String updated_name = current_columns[offset].name;
String updated_name = origin_column_name;
auto updated_type = current_columns[offset].type;
/// first add timestamp cast
if (need_append_timezone_cast && require_schema[offset].tp() == TiDB::TypeTimestamp)
{
if (tz_col.empty())
tz_col = getActions(tz_expr, actions);
updated_name = appendTimeZoneCast(tz_col, current_columns[offset].name, tz_cast_func_name, actions);
updated_name = appendTimeZoneCast(tz_col, updated_name, tz_cast_func_name, actions);
}
/// then add type cast
if (need_append_type_cast_vec[index])
{
updated_type = getDataTypeByFieldTypeForComputingLayer(require_schema[offset]);
updated_name = appendCast(updated_type, actions, updated_name);
}
had_casted_map[current_columns[offset].name] = index;
had_casted_map[origin_column_name] = offset;

after_cast_columns[offset].name = updated_name;
after_cast_columns[offset].type = updated_type;
Expand Down Expand Up @@ -945,6 +947,7 @@ NamesWithAliases DAGExpressionAnalyzer::appendFinalProjectForRootQueryBlock(

bool need_append_timezone_cast = !keep_session_timezone_info && !context.getTimezoneInfo().is_utc_timezone;
auto [need_append_type_cast, need_append_type_cast_vec] = isCastRequiredForRootFinalProjection(schema, output_offsets);
assert(need_append_type_cast_vec.size() == output_offsets.size());

auto & step = initAndGetLastStep(chain);

Expand Down
4 changes: 3 additions & 1 deletion dbms/src/Flash/Coprocessor/DAGExpressionAnalyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,9 @@ class DAGExpressionAnalyzer : private boost::noncopyable
bool need_append_timezone_cast,
const BoolVec & need_append_type_cast_vec);

// return {need_append_type_cast, BoolVec of which one should append type cast}
// return {need_append_type_cast, need_append_type_cast_vec}
// need_append_type_cast_vec: BoolVec of which one should append type cast.
// And need_append_type_cast_vec.size() == output_offsets.size().
std::pair<bool, BoolVec> isCastRequiredForRootFinalProjection(
const std::vector<tipb::FieldType> & require_schema,
const std::vector<Int32> & output_offsets) const;
Expand Down

0 comments on commit 057858d

Please sign in to comment.