Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into ps-v3-combine-split
Browse files Browse the repository at this point in the history
  • Loading branch information
JaySon-Huang committed Jan 28, 2022
2 parents 4222789 + 30cc13c commit 5fd7c35
Show file tree
Hide file tree
Showing 6 changed files with 595 additions and 115 deletions.
6 changes: 5 additions & 1 deletion dbms/src/Flash/Coprocessor/DAGContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ class DAGContext
warnings_.push_back(error);
}
}
void clearWarnings() { warnings.clear(); }
void clearWarnings()
{
warnings.clear();
warning_count = 0;
}
UInt64 getWarningCount() { return warning_count; }
const mpp::TaskMeta & getMPPTaskMeta() const { return mpp_task_meta; }
bool isBatchCop() const { return is_batch_cop; }
Expand Down
45 changes: 31 additions & 14 deletions dbms/src/Functions/FunctionsTiDBConversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -940,9 +940,9 @@ struct TiDBConvertToDecimal
if (need_to_round)
{
if (value < 0)
value--;
--value;
else
value++;
++value;
}
}

Expand Down Expand Up @@ -1217,6 +1217,7 @@ struct TiDBConvertToDecimal
template <typename FromDataType, typename ToDataType, bool return_nullable>
struct TiDBConvertToTime
{
public:
static_assert(std::is_same_v<ToDataType, DataTypeMyDate> || std::is_same_v<ToDataType, DataTypeMyDateTime>);

using FromFieldType = typename FromDataType::FieldType;
Expand Down Expand Up @@ -1252,7 +1253,6 @@ struct TiDBConvertToTime
col_null_map_to = ColumnUInt8::create(size, 0);
vec_null_map_to = &col_null_map_to->getData();
}

if constexpr (std::is_same_v<FromDataType, DataTypeString>)
{
// cast string as time
Expand All @@ -1262,7 +1262,7 @@ struct TiDBConvertToTime
const ColumnString::Offsets * offsets = &col_from->getOffsets();

size_t current_offset = 0;
for (size_t i = 0; i < size; i++)
for (size_t i = 0; i < size; ++i)
{
size_t next_offset = (*offsets)[i];
size_t string_size = next_offset - current_offset - 1;
Expand All @@ -1287,7 +1287,8 @@ struct TiDBConvertToTime
{
// Fill NULL if cannot parse
(*vec_null_map_to)[i] = 1;
context.getDAGContext()->handleInvalidTime("Invalid time value: '" + string_value + "'", Errors::Types::WrongValue);
vec_to[i] = 0;
handleInvalidTime(context, string_value);
}
current_offset = next_offset;
}
Expand All @@ -1298,7 +1299,7 @@ struct TiDBConvertToTime
const auto * col_from = checkAndGetColumn<ColumnUInt64>(block.getByPosition(arguments[0]).column.get());
const ColumnUInt64::Container & vec_from = col_from->getData();

for (size_t i = 0; i < size; i++)
for (size_t i = 0; i < size; ++i)
{
MyDateTime datetime(vec_from[i]);

Expand Down Expand Up @@ -1347,7 +1348,7 @@ struct TiDBConvertToTime

const typename ColumnVector<FromFieldType>::Container & vec_from = col_from->getData();

for (size_t i = 0; i < size; i++)
for (size_t i = 0; i < size; ++i)
{
try
{
Expand All @@ -1368,9 +1369,8 @@ struct TiDBConvertToTime
{
// Cannot cast, fill with NULL
(*vec_null_map_to)[i] = 1;
context.getDAGContext()->handleInvalidTime(
"Invalid time value: '" + toString(vec_from[i]) + "'",
Errors::Types::WrongValue);
vec_to[i] = 0;
handleInvalidTime(context, vec_from[i]);
}
}
}
Expand All @@ -1384,7 +1384,7 @@ struct TiDBConvertToTime

const typename ColumnVector<FromFieldType>::Container & vec_from = col_from->getData();

for (size_t i = 0; i < size; i++)
for (size_t i = 0; i < size; ++i)
{
Float64 value = vec_from[i];
// Convert to string and then parse to time
Expand All @@ -1393,6 +1393,7 @@ struct TiDBConvertToTime
if (value_str == "0")
{
(*vec_null_map_to)[i] = 1;
vec_to[i] = 0;
}
else
{
Expand All @@ -1415,7 +1416,15 @@ struct TiDBConvertToTime
{
// Fill NULL if cannot parse
(*vec_null_map_to)[i] = 1;
context.getDAGContext()->handleInvalidTime("Invalid time value: '" + value_str + "'", Errors::Types::WrongValue);
vec_to[i] = 0;
handleInvalidTime(context, value_str);
}
catch (const std::exception &)
{
// Fill NULL if cannot parse
(*vec_null_map_to)[i] = 1;
vec_to[i] = 0;
handleInvalidTime(context, value_str);
}
}
}
Expand Down Expand Up @@ -1446,14 +1455,15 @@ struct TiDBConvertToTime
catch (const Exception &)
{
(*vec_null_map_to)[i] = 1;
context.getDAGContext()->handleInvalidTime("Invalid time value: '" + value_str + "'", Errors::Types::WrongValue);
vec_to[i] = 0;
handleInvalidTime(context, value_str);
}
}
}
else
{
throw Exception(
"Illegal column " + block.getByPosition(arguments[0]).column->getName() + " of first argument of function tidb_cast",
fmt::format("Illegal column {} of first argument of function tidb_cast", block.getByPosition(arguments[0]).column->getName()),
ErrorCodes::ILLEGAL_COLUMN);
}

Expand All @@ -1462,6 +1472,13 @@ struct TiDBConvertToTime
else
block.getByPosition(result).column = std::move(col_to);
}

private:
template <typename T>
static void handleInvalidTime(const Context & context, const T & value)
{
context.getDAGContext()->handleInvalidTime(fmt::format("Invalid time value: '{}'", value), Errors::Types::WrongValue);
}
};

/// cast duration as duration
Expand Down
Loading

0 comments on commit 5fd7c35

Please sign in to comment.