This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-4.0
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-4.0 by this push:
new 3ef061894f1 branch-4.0: [chore](type) remove to_string from DataType
part II #56402 (#56555)
3ef061894f1 is described below
commit 3ef061894f16aecff3135ab1f12d0a3df8e8b8b5
Author: github-actions[bot]
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Sun Sep 28 20:01:09 2025 +0800
branch-4.0: [chore](type) remove to_string from DataType part II #56402
(#56555)
Cherry-picked from #56402
Co-authored-by: Mryange <[email protected]>
---
be/src/runtime/fold_constant_executor.cpp | 30 +++++-----------------
be/src/vec/data_types/data_type_date.h | 4 ++-
.../data_types/data_type_date_or_datetime_v2.cpp | 14 ----------
.../vec/data_types/data_type_date_or_datetime_v2.h | 22 ++++++++++++++--
be/src/vec/data_types/data_type_date_time.cpp | 8 ------
be/src/vec/data_types/data_type_date_time.h | 10 +++++++-
be/src/vec/data_types/data_type_number_base.cpp | 2 ++
be/src/vec/data_types/data_type_number_base.h | 3 ++-
be/src/vec/sink/writer/vmysql_table_writer.cpp | 21 ++++-----------
9 files changed, 48 insertions(+), 66 deletions(-)
diff --git a/be/src/runtime/fold_constant_executor.cpp
b/be/src/runtime/fold_constant_executor.cpp
index 6449b0218ab..2887d39f45b 100644
--- a/be/src/runtime/fold_constant_executor.cpp
+++ b/be/src/runtime/fold_constant_executor.cpp
@@ -60,6 +60,7 @@
#include "vec/data_types/data_type_number.h"
#include "vec/exprs/vexpr.h"
#include "vec/exprs/vexpr_context.h"
+#include "vec/functions/cast/cast_to_string.h"
#include "vec/runtime/vdatetime_value.h"
namespace doris {
@@ -250,27 +251,19 @@ Status FoldConstantExecutor::_get_result(void* src,
size_t size,
case TYPE_DATE:
case TYPE_DATETIME: {
auto* date_value = reinterpret_cast<VecDateTimeValue*>(src);
- char str[MAX_DTVALUE_STR_LEN];
- date_value->to_string(str);
- result = std::string(str);
+ result = vectorized::CastToString::from_date_or_datetime(*date_value);
break;
}
case TYPE_DATEV2: {
DateV2Value<DateV2ValueType> value =
binary_cast<uint32_t,
DateV2Value<DateV2ValueType>>(*(int32_t*)src);
-
- char buf[64];
- char* pos = value.to_string(buf);
- result = std::string(buf, pos - buf - 1);
+ result = vectorized::CastToString::from_datev2(value);
break;
}
case TYPE_DATETIMEV2: {
DateV2Value<DateTimeV2ValueType> value =
binary_cast<uint64_t,
DateV2Value<DateTimeV2ValueType>>(*(int64_t*)src);
-
- char buf[64];
- char* pos = value.to_string(buf, type->get_scale());
- result = std::string(buf, pos - buf - 1);
+ result = vectorized::CastToString::from_datetimev2(value,
type->get_scale());
break;
}
case TYPE_DECIMALV2: {
@@ -280,22 +273,13 @@ Status FoldConstantExecutor::_get_result(void* src,
size_t size,
case TYPE_DECIMAL32:
case TYPE_DECIMAL64:
case TYPE_DECIMAL128I:
- case TYPE_DECIMAL256: {
- result = column_type->to_string(*column_ptr, 0);
- break;
- }
+ case TYPE_DECIMAL256:
case TYPE_ARRAY:
case TYPE_JSONB:
case TYPE_MAP:
- case TYPE_STRUCT: {
- result = column_type->to_string(*column_ptr, 0);
- break;
- }
+ case TYPE_STRUCT:
case TYPE_VARIANT:
- case TYPE_QUANTILE_STATE: {
- result = column_type->to_string(*column_ptr, 0);
- break;
- }
+ case TYPE_QUANTILE_STATE:
case TYPE_IPV4:
case TYPE_IPV6: {
result = column_type->to_string(*column_ptr, 0);
diff --git a/be/src/vec/data_types/data_type_date.h
b/be/src/vec/data_types/data_type_date.h
index c6c53194805..8e57f8a0485 100644
--- a/be/src/vec/data_types/data_type_date.h
+++ b/be/src/vec/data_types/data_type_date.h
@@ -49,7 +49,8 @@ public:
std::string do_get_name() const override { return "Date"; }
bool equals(const IDataType& rhs) const override;
- /// TODO: remove this in the future
+/// TODO: remove this in the future
+#ifdef BE_TEST
using IDataType::to_string;
std::string to_string(Int64 int_val) const {
doris::VecDateTimeValue value = binary_cast<Int64,
doris::VecDateTimeValue>(int_val);
@@ -57,6 +58,7 @@ public:
value.to_string(buf);
return buf;
}
+#endif
static void cast_to_date(Int64& x);
Field get_field(const TExprNode& node) const override {
VecDateTimeValue value;
diff --git a/be/src/vec/data_types/data_type_date_or_datetime_v2.cpp
b/be/src/vec/data_types/data_type_date_or_datetime_v2.cpp
index 2486b5e87d8..23afde77a07 100644
--- a/be/src/vec/data_types/data_type_date_or_datetime_v2.cpp
+++ b/be/src/vec/data_types/data_type_date_or_datetime_v2.cpp
@@ -55,13 +55,6 @@ namespace doris::vectorized {
bool DataTypeDateV2::equals(const IDataType& rhs) const {
return typeid(rhs) == typeid(*this);
}
-std::string DataTypeDateV2::to_string(UInt32 int_val) const {
- DateV2Value<DateV2ValueType> val = binary_cast<UInt32,
DateV2Value<DateV2ValueType>>(int_val);
-
- char buf[64];
- val.to_string(buf); // DateTime to_string the end is /0
- return std::string {buf};
-}
MutableColumnPtr DataTypeDateV2::create_column() const {
return DataTypeNumberBase<PrimitiveType::TYPE_DATEV2>::create_column();
@@ -101,14 +94,7 @@ bool DataTypeDateTimeV2::equals(const IDataType& rhs) const
{
return typeid(rhs) == typeid(*this) &&
_scale == static_cast<const DataTypeDateTimeV2&>(rhs)._scale;
}
-std::string DataTypeDateTimeV2::to_string(UInt64 int_val) const {
- DateV2Value<DateTimeV2ValueType> val =
- binary_cast<UInt64, DateV2Value<DateTimeV2ValueType>>(int_val);
- char buf[64];
- val.to_string(buf, _scale);
- return buf; // DateTime to_string the end is /0
-}
void DataTypeDateTimeV2::to_pb_column_meta(PColumnMeta* col_meta) const {
IDataType::to_pb_column_meta(col_meta);
col_meta->mutable_decimal_param()->set_scale(_scale);
diff --git a/be/src/vec/data_types/data_type_date_or_datetime_v2.h
b/be/src/vec/data_types/data_type_date_or_datetime_v2.h
index 929cf183e51..82247777696 100644
--- a/be/src/vec/data_types/data_type_date_or_datetime_v2.h
+++ b/be/src/vec/data_types/data_type_date_or_datetime_v2.h
@@ -79,9 +79,18 @@ public:
}
bool equals(const IDataType& rhs) const override;
+#ifdef BE_TEST
/// TODO: remove this in the future
using IDataType::to_string;
- std::string to_string(UInt32 int_val) const;
+ std::string to_string(UInt32 int_val) const {
+ DateV2Value<DateV2ValueType> val =
+ binary_cast<UInt32, DateV2Value<DateV2ValueType>>(int_val);
+
+ char buf[64];
+ val.to_string(buf); // DateTime to_string the end is /0
+ return std::string {buf};
+ }
+#endif
MutableColumnPtr create_column() const override;
@@ -126,9 +135,18 @@ public:
bool equals_ignore_precision(const IDataType& rhs) const override {
return rhs.get_primitive_type() == PrimitiveType::TYPE_DATETIMEV2;
}
+#ifdef BE_TEST
/// TODO: remove this in the future
using IDataType::to_string;
- std::string to_string(UInt64 int_val) const;
+ std::string to_string(UInt64 int_val) const {
+ DateV2Value<DateTimeV2ValueType> val =
+ binary_cast<UInt64, DateV2Value<DateTimeV2ValueType>>(int_val);
+
+ char buf[64];
+ val.to_string(buf, _scale);
+ return buf; // DateTime to_string the end is /0
+ }
+#endif
using SerDeType = DataTypeDateTimeV2SerDe;
DataTypeSerDeSPtr get_serde(int nesting_level = 1) const override {
return std::make_shared<SerDeType>(_scale, nesting_level);
diff --git a/be/src/vec/data_types/data_type_date_time.cpp
b/be/src/vec/data_types/data_type_date_time.cpp
index d8b89b06de3..933400d68f9 100644
--- a/be/src/vec/data_types/data_type_date_time.cpp
+++ b/be/src/vec/data_types/data_type_date_time.cpp
@@ -40,14 +40,6 @@ namespace doris::vectorized {
bool DataTypeDateTime::equals(const IDataType& rhs) const {
return typeid(rhs) == typeid(*this);
}
-std::string DataTypeDateTime::to_string(Int64 int_val) const {
- doris::VecDateTimeValue value = binary_cast<Int64,
doris::VecDateTimeValue>(int_val);
-
- char buf[64];
- value.to_string(buf);
- // DateTime to_string the end is /0
- return buf;
-}
void DataTypeDateTime::cast_to_date_time(Int64& x) {
auto value = binary_cast<Int64, doris::VecDateTimeValue>(x);
diff --git a/be/src/vec/data_types/data_type_date_time.h
b/be/src/vec/data_types/data_type_date_time.h
index b5285ee54c6..8a49e3805c3 100644
--- a/be/src/vec/data_types/data_type_date_time.h
+++ b/be/src/vec/data_types/data_type_date_time.h
@@ -75,10 +75,18 @@ public:
}
bool equals(const IDataType& rhs) const override;
+#ifdef BE_TEST
/// TODO: remove this in the future
using IDataType::to_string;
- std::string to_string(Int64 value) const;
+ std::string to_string(Int64 int_val) const {
+ doris::VecDateTimeValue value = binary_cast<Int64,
doris::VecDateTimeValue>(int_val);
+ char buf[64];
+ value.to_string(buf);
+ // DateTime to_string the end is /0
+ return buf;
+ }
+#endif
using SerDeType = DataTypeDateTimeSerDe;
DataTypeSerDeSPtr get_serde(int nesting_level = 1) const override {
return std::make_shared<SerDeType>(nesting_level);
diff --git a/be/src/vec/data_types/data_type_number_base.cpp
b/be/src/vec/data_types/data_type_number_base.cpp
index 087686f6b63..5426b59e632 100644
--- a/be/src/vec/data_types/data_type_number_base.cpp
+++ b/be/src/vec/data_types/data_type_number_base.cpp
@@ -48,6 +48,7 @@
namespace doris::vectorized {
#include "common/compile_check_begin.h"
+#ifdef BE_TEST
template <PrimitiveType T>
std::string DataTypeNumberBase<T>::to_string(
const typename PrimitiveTypeTraits<T>::ColumnItemType& value) {
@@ -62,6 +63,7 @@ std::string DataTypeNumberBase<T>::to_string(
return CastToString::from_number(value);
}
}
+#endif
template <PrimitiveType T>
Field DataTypeNumberBase<T>::get_default() const {
diff --git a/be/src/vec/data_types/data_type_number_base.h
b/be/src/vec/data_types/data_type_number_base.h
index 67a2a535767..475f8f2105e 100644
--- a/be/src/vec/data_types/data_type_number_base.h
+++ b/be/src/vec/data_types/data_type_number_base.h
@@ -56,10 +56,11 @@ public:
static constexpr PrimitiveType PType = T;
using ColumnType = typename PrimitiveTypeTraits<T>::ColumnType;
using FieldType = typename PrimitiveTypeTraits<T>::ColumnItemType;
+#ifdef BE_TEST
/// TODO: remove this in the future
using IDataType::to_string;
static std::string to_string(const typename
PrimitiveTypeTraits<T>::ColumnItemType& value);
-
+#endif
const std::string get_family_name() const override { return
type_to_string(T); }
PrimitiveType get_primitive_type() const override {
// Doris does not support uint8 at present, use uint8 as boolean type
diff --git a/be/src/vec/sink/writer/vmysql_table_writer.cpp
b/be/src/vec/sink/writer/vmysql_table_writer.cpp
index 23da5957630..93e37c78a38 100644
--- a/be/src/vec/sink/writer/vmysql_table_writer.cpp
+++ b/be/src/vec/sink/writer/vmysql_table_writer.cpp
@@ -215,9 +215,7 @@ Status VMysqlTableWriter::_insert_row(vectorized::Block&
block, size_t row) {
int64_t int_val = assert_cast<const
vectorized::ColumnDate&>(*column).get_data()[row];
VecDateTimeValue value = binary_cast<int64_t,
doris::VecDateTimeValue>(int_val);
- char buf[64];
- char* pos = value.to_string(buf);
- std::string str(buf, pos - buf - 1);
+ std::string str =
vectorized::CastToString::from_date_or_datetime(value);
fmt::format_to(_insert_stmt_buffer, "'{}'", str);
break;
}
@@ -226,9 +224,7 @@ Status VMysqlTableWriter::_insert_row(vectorized::Block&
block, size_t row) {
assert_cast<const
vectorized::ColumnDateTime&>(*column).get_data()[row];
VecDateTimeValue value = binary_cast<int64_t,
doris::VecDateTimeValue>(int_val);
- char buf[64];
- char* pos = value.to_string(buf);
- std::string str(buf, pos - buf - 1);
+ std::string str =
vectorized::CastToString::from_date_or_datetime(value);
fmt::format_to(_insert_stmt_buffer, "'{}'", str);
break;
}
@@ -238,9 +234,7 @@ Status VMysqlTableWriter::_insert_row(vectorized::Block&
block, size_t row) {
DateV2Value<DateV2ValueType> value =
binary_cast<uint32_t,
DateV2Value<DateV2ValueType>>(int_val);
- char buf[64];
- char* pos = value.to_string(buf);
- std::string str(buf, pos - buf - 1);
+ std::string str = vectorized::CastToString::from_datev2(value);
fmt::format_to(_insert_stmt_buffer, "'{}'", str);
break;
}
@@ -250,13 +244,8 @@ Status VMysqlTableWriter::_insert_row(vectorized::Block&
block, size_t row) {
DateV2Value<DateTimeV2ValueType> value =
binary_cast<uint64_t,
DateV2Value<DateTimeV2ValueType>>(int_val);
- char buf[64];
- char* pos = value.to_string(
- buf,
- assert_cast<const DataTypeDateTimeV2*>(
-
remove_nullable(_vec_output_expr_ctxs[i]->root()->data_type()).get())
- ->get_scale());
- std::string str(buf, pos - buf - 1);
+ std::string str =
+ vectorized::CastToString::from_datetimev2(value,
type_ptr->get_scale());
fmt::format_to(_insert_stmt_buffer, "'{}'", str);
break;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]