diff --git a/be/src/common/daemon.cpp b/be/src/common/daemon.cpp index d70ee07487..cabaedb2f2 100644 --- a/be/src/common/daemon.cpp +++ b/be/src/common/daemon.cpp @@ -25,7 +25,6 @@ #include "exprs/bitmap_function.h" #include "exprs/cast_functions.h" #include "exprs/compound_predicate.h" -#include "exprs/decimal_operators.h" #include "exprs/decimalv2_operators.h" #include "exprs/encryption_functions.h" #include "exprs/es_functions.h" @@ -250,7 +249,6 @@ void Daemon::init(int argc, char** argv, const std::vector& paths) { MathFunctions::init(); EncryptionFunctions::init(); TimestampFunctions::init(); - DecimalOperators::init(); DecimalV2Operators::init(); TimeOperators::init(); UtilityFunctions::init(); diff --git a/be/src/exec/es/es_predicate.cpp b/be/src/exec/es/es_predicate.cpp index b4558149f8..3a73f15fc9 100644 --- a/be/src/exec/es/es_predicate.cpp +++ b/be/src/exec/es/es_predicate.cpp @@ -88,9 +88,6 @@ std::string ExtLiteral::value_to_string() { case TYPE_BOOLEAN: ss << std::to_string(get_bool()); break; - case TYPE_DECIMAL: - ss << get_decimal_string(); - break; case TYPE_DECIMALV2: ss << get_decimalv2_string(); break; @@ -158,11 +155,6 @@ bool ExtLiteral::get_bool() { return *(reinterpret_cast(_value)); } -std::string ExtLiteral::get_decimal_string() { - DCHECK(_type == TYPE_DECIMAL); - return reinterpret_cast(_value)->to_string(); -} - std::string ExtLiteral::get_decimalv2_string() { DCHECK(_type == TYPE_DECIMALV2); return reinterpret_cast(_value)->to_string(); diff --git a/be/src/exec/es_scan_node.cpp b/be/src/exec/es_scan_node.cpp index 78172bcf4d..43d1be129c 100644 --- a/be/src/exec/es_scan_node.cpp +++ b/be/src/exec/es_scan_node.cpp @@ -635,14 +635,6 @@ bool EsScanNode::to_ext_literal(PrimitiveType slot_type, void* value, TExtLitera break; } - case TYPE_DECIMAL: { - node_type = (TExprNodeType::DECIMAL_LITERAL); - TDecimalLiteral decimal_literal; - decimal_literal.__set_value(reinterpret_cast(value)->to_string()); - literal->__set_decimal_literal(decimal_literal); - break; - } - case TYPE_DATE: case TYPE_DATETIME: { node_type = (TExprNodeType::DATE_LITERAL); @@ -861,15 +853,6 @@ Status EsScanNode::materialize_row(MemPool* tuple_pool, Tuple* tuple, reinterpret_cast(slot)->set_type(TIME_DATETIME); break; } - case TYPE_DECIMAL: { - if (val_idx >= col.binary_vals.size()) { - return Status::InternalError( - strings::Substitute(ERROR_INVALID_COL_DATA, "DECIMAL")); - } - const string& val = col.binary_vals[val_idx]; - *reinterpret_cast(slot) = *reinterpret_cast(&val); - break; - } default: DCHECK(false); } diff --git a/be/src/exec/hash_table.cpp b/be/src/exec/hash_table.cpp index 8b2b1dfa72..a78607ae36 100644 --- a/be/src/exec/hash_table.cpp +++ b/be/src/exec/hash_table.cpp @@ -146,15 +146,6 @@ uint32_t HashTable::hash_variable_len_row() { StringValue* str = reinterpret_cast(loc); hash = HashUtil::hash(str->ptr, str->len, hash); } - } else if (_build_expr_ctxs[i]->root()->type().type == TYPE_DECIMAL) { - void* loc = _expr_values_buffer + _expr_values_buffer_offsets[i]; - if (_expr_value_null_bits[i]) { - // Hash the null random seed values at 'loc' - hash = HashUtil::hash(loc, sizeof(StringValue), hash); - } else { - DecimalValue* decimal = reinterpret_cast(loc); - hash = decimal->hash(hash); - } } } diff --git a/be/src/exec/odbc_connector.cpp b/be/src/exec/odbc_connector.cpp index 6895cfff50..cb734a7b2e 100644 --- a/be/src/exec/odbc_connector.cpp +++ b/be/src/exec/odbc_connector.cpp @@ -190,17 +190,19 @@ void ODBCConnector::_init_profile(doris::RuntimeProfile* profile) { Status ODBCConnector::init_to_write(doris::RuntimeProfile* profile) { if (!_is_open) { - return Status::InternalError( "Init before open."); + return Status::InternalError("Init before open."); } _init_profile(profile); // Allocate a statement handle - ODBC_DISPOSE(_dbc, SQL_HANDLE_DBC, SQLAllocHandle(SQL_HANDLE_STMT, _dbc, &_stmt), "alloc statement"); + ODBC_DISPOSE(_dbc, SQL_HANDLE_DBC, SQLAllocHandle(SQL_HANDLE_STMT, _dbc, &_stmt), + "alloc statement"); return Status::OK(); } -Status ODBCConnector::append(const std::string& table_name, RowBatch *batch, uint32_t start_send_row, uint32* num_rows_sent) { +Status ODBCConnector::append(const std::string& table_name, RowBatch* batch, + uint32_t start_send_row, uint32* num_rows_sent) { _insert_stmt_buffer.clear(); std::u16string insert_stmt; { @@ -218,99 +220,86 @@ Status ODBCConnector::append(const std::string& table_name, RowBatch *batch, uin if (j != 0) { fmt::format_to(_insert_stmt_buffer, "{}", ", "); } - void *item = _output_expr_ctxs[j]->get_value(row); + void* item = _output_expr_ctxs[j]->get_value(row); if (item == nullptr) { fmt::format_to(_insert_stmt_buffer, "{}", "NULL"); continue; } switch (_output_expr_ctxs[j]->root()->type().type) { - case TYPE_BOOLEAN: - case TYPE_TINYINT: - fmt::format_to(_insert_stmt_buffer, "{}", *static_cast(item)); - break; - case TYPE_SMALLINT: - fmt::format_to(_insert_stmt_buffer, "{}", *static_cast(item)); - break; - case TYPE_INT: - fmt::format_to(_insert_stmt_buffer, "{}", *static_cast(item)); - break; - case TYPE_BIGINT: - fmt::format_to(_insert_stmt_buffer, "{}", *static_cast(item)); - break; - case TYPE_FLOAT: - fmt::format_to(_insert_stmt_buffer, "{}", *static_cast(item)); - break; - case TYPE_DOUBLE: - fmt::format_to(_insert_stmt_buffer, "{}", *static_cast(item)); - break; - case TYPE_DATE: - case TYPE_DATETIME: { - char buf[64]; - const auto *time_val = (const DateTimeValue *) (item); - time_val->to_string(buf); - fmt::format_to(_insert_stmt_buffer, "'{}'", buf); - break; - } - case TYPE_VARCHAR: - case TYPE_CHAR: { - const auto *string_val = (const StringValue *) (item); + case TYPE_BOOLEAN: + case TYPE_TINYINT: + fmt::format_to(_insert_stmt_buffer, "{}", *static_cast(item)); + break; + case TYPE_SMALLINT: + fmt::format_to(_insert_stmt_buffer, "{}", *static_cast(item)); + break; + case TYPE_INT: + fmt::format_to(_insert_stmt_buffer, "{}", *static_cast(item)); + break; + case TYPE_BIGINT: + fmt::format_to(_insert_stmt_buffer, "{}", *static_cast(item)); + break; + case TYPE_FLOAT: + fmt::format_to(_insert_stmt_buffer, "{}", *static_cast(item)); + break; + case TYPE_DOUBLE: + fmt::format_to(_insert_stmt_buffer, "{}", *static_cast(item)); + break; + case TYPE_DATE: + case TYPE_DATETIME: { + char buf[64]; + const auto* time_val = (const DateTimeValue*)(item); + time_val->to_string(buf); + fmt::format_to(_insert_stmt_buffer, "'{}'", buf); + break; + } + case TYPE_VARCHAR: + case TYPE_CHAR: { + const auto* string_val = (const StringValue*)(item); - if (string_val->ptr == NULL) { - if (string_val->len == 0) { - fmt::format_to(_insert_stmt_buffer, "{}", "''"); - } else { - fmt::format_to(_insert_stmt_buffer, "{}", "NULL"); - } + if (string_val->ptr == NULL) { + if (string_val->len == 0) { + fmt::format_to(_insert_stmt_buffer, "{}", "''"); } else { - fmt::format_to(_insert_stmt_buffer, "'{}'", - fmt::basic_string_view(string_val->ptr, string_val->len)); + fmt::format_to(_insert_stmt_buffer, "{}", "NULL"); } - break; + } else { + fmt::format_to(_insert_stmt_buffer, "'{}'", + fmt::basic_string_view(string_val->ptr, string_val->len)); } - case TYPE_DECIMAL: { - const auto *decimal_val = reinterpret_cast(item); - std::string decimal_str; - int output_scale = _output_expr_ctxs[j]->root()->output_scale(); + break; + } + case TYPE_DECIMALV2: { + const DecimalV2Value decimal_val( + reinterpret_cast(item)->value); + std::string decimal_str; + int output_scale = _output_expr_ctxs[j]->root()->output_scale(); - if (output_scale > 0 && output_scale <= 30) { - decimal_str = decimal_val->to_string(output_scale); - } else { - decimal_str = decimal_val->to_string(); - } - fmt::format_to(_insert_stmt_buffer, "{}", decimal_str); - break; - } - case TYPE_DECIMALV2: { - const DecimalV2Value decimal_val(reinterpret_cast(item)->value); - std::string decimal_str; - int output_scale = _output_expr_ctxs[j]->root()->output_scale(); - - if (output_scale > 0 && output_scale <= 30) { - decimal_str = decimal_val.to_string(output_scale); - } else { - decimal_str = decimal_val.to_string(); - } - fmt::format_to(_insert_stmt_buffer, "{}", decimal_str); - break; - } - case TYPE_LARGEINT: { - char buf[48]; - int len = 48; - char *v = LargeIntValue::to_string(reinterpret_cast(item)->value, - buf, &len); - fmt::format_to(_insert_stmt_buffer, "{}", std::string(v, len)); - break; - } - default: { - fmt::memory_buffer err_out; - fmt::format_to(err_out, "can't convert this type to mysql type. type = {}", - _output_expr_ctxs[j]->root()->type().type); - return Status::InternalError(err_out.data()); + if (output_scale > 0 && output_scale <= 30) { + decimal_str = decimal_val.to_string(output_scale); + } else { + decimal_str = decimal_val.to_string(); } + fmt::format_to(_insert_stmt_buffer, "{}", decimal_str); + break; + } + case TYPE_LARGEINT: { + char buf[48]; + int len = 48; + char* v = LargeIntValue::to_string( + reinterpret_cast(item)->value, buf, &len); + fmt::format_to(_insert_stmt_buffer, "{}", std::string(v, len)); + break; + } + default: { + fmt::memory_buffer err_out; + fmt::format_to(err_out, "can't convert this type to mysql type. type = {}", + _output_expr_ctxs[j]->root()->type().type); + return Status::InternalError(err_out.data()); + } } } - if (i < num_rows - 1 && _insert_stmt_buffer.size() < INSERT_BUFFER_SIZE) { fmt::format_to(_insert_stmt_buffer, "{}", "),("); } else { @@ -320,13 +309,15 @@ Status ODBCConnector::append(const std::string& table_name, RowBatch *batch, uin } } // Translate utf8 string to utf16 to use unicode encodeing - insert_stmt = utf8_to_wstring(std::string(_insert_stmt_buffer.data(), - _insert_stmt_buffer.data() + _insert_stmt_buffer.size())); + insert_stmt = utf8_to_wstring( + std::string(_insert_stmt_buffer.data(), + _insert_stmt_buffer.data() + _insert_stmt_buffer.size())); } { SCOPED_TIMER(_result_send_timer); - ODBC_DISPOSE(_stmt, SQL_HANDLE_STMT, SQLExecDirectW(_stmt, (SQLWCHAR *) (insert_stmt.c_str()), SQL_NTS), + ODBC_DISPOSE(_stmt, SQL_HANDLE_STMT, + SQLExecDirectW(_stmt, (SQLWCHAR*)(insert_stmt.c_str()), SQL_NTS), _insert_stmt_buffer.data()); } COUNTER_UPDATE(_sent_rows_counter, *num_rows_sent); @@ -339,7 +330,8 @@ Status ODBCConnector::begin_trans() { } ODBC_DISPOSE(_dbc, SQL_HANDLE_DBC, - SQLSetConnectAttr(_dbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_OFF, SQL_IS_UINTEGER), + SQLSetConnectAttr(_dbc, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER)SQL_AUTOCOMMIT_OFF, + SQL_IS_UINTEGER), "Begin transcation"); _is_in_transaction = true; @@ -351,8 +343,7 @@ Status ODBCConnector::abort_trans() { return Status::InternalError("Abort transaction before begin trans."); } - ODBC_DISPOSE(_dbc, SQL_HANDLE_DBC, - SQLEndTran(SQL_HANDLE_DBC, _dbc, SQL_ROLLBACK), + ODBC_DISPOSE(_dbc, SQL_HANDLE_DBC, SQLEndTran(SQL_HANDLE_DBC, _dbc, SQL_ROLLBACK), "Abort transcation"); return Status::OK(); @@ -363,8 +354,7 @@ Status ODBCConnector::finish_trans() { return Status::InternalError("Abort transaction before begin trans."); } - ODBC_DISPOSE(_dbc, SQL_HANDLE_DBC, - SQLEndTran(SQL_HANDLE_DBC, _dbc, SQL_COMMIT), + ODBC_DISPOSE(_dbc, SQL_HANDLE_DBC, SQLEndTran(SQL_HANDLE_DBC, _dbc, SQL_COMMIT), "commit transcation"); _is_in_transaction = false; @@ -385,7 +375,7 @@ Status ODBCConnector::error_status(const std::string& prefix, const std::string& // hType Type of handle (HANDLE_STMT, HANDLE_ENV, HANDLE_DBC) // RetCode Return code of failing command std::string ODBCConnector::handle_diagnostic_record(SQLHANDLE hHandle, SQLSMALLINT hType, - RETCODE RetCode) { + RETCODE RetCode) { SQLSMALLINT rec = 0; SQLINTEGER error; CHAR message[1000]; diff --git a/be/src/exec/olap_common.cpp b/be/src/exec/olap_common.cpp index 54c584eef8..aa15d7d12c 100644 --- a/be/src/exec/olap_common.cpp +++ b/be/src/exec/olap_common.cpp @@ -45,11 +45,6 @@ void ColumnValueRange::convert_to_fixed_value() { return; } -template <> -void ColumnValueRange::convert_to_fixed_value() { - return; -} - template <> void ColumnValueRange::convert_to_fixed_value() { return; diff --git a/be/src/exec/olap_common.h b/be/src/exec/olap_common.h index e5fa57eaab..94ecd1d063 100644 --- a/be/src/exec/olap_common.h +++ b/be/src/exec/olap_common.h @@ -31,9 +31,9 @@ #include "exec/scan_node.h" #include "gen_cpp/PlanNodes_types.h" #include "olap/tuple.h" -#include "runtime/type_limit.h" #include "runtime/descriptors.h" #include "runtime/string_value.hpp" +#include "runtime/type_limit.h" namespace doris { @@ -59,7 +59,8 @@ public: ColumnValueRange(std::string col_name, PrimitiveType type); - ColumnValueRange(std::string col_name, PrimitiveType type, const T& min, const T& max, bool contain_null); + ColumnValueRange(std::string col_name, PrimitiveType type, const T& min, const T& max, + bool contain_null); // should add fixed value before add range Status add_fixed_value(const T& value); @@ -126,7 +127,7 @@ public: // 2. convert to min max filter condition TCondition null_pred; if (TYPE_MAX == _high_value && _high_op == FILTER_LESS_OR_EQUAL && - TYPE_MIN == _low_value && _low_op == FILTER_LARGER_OR_EQUAL && !contain_null()) { + TYPE_MIN == _low_value && _low_op == FILTER_LARGER_OR_EQUAL && !contain_null()) { null_pred.__set_column_name(_column_name); null_pred.__set_condition_op("is"); null_pred.condition_values.emplace_back("not null"); @@ -198,7 +199,8 @@ public: bool is_whole_value_range() const { return _fixed_values.empty() && _low_value == TYPE_MIN && _high_value == TYPE_MAX && - _low_op == FILTER_LARGER_OR_EQUAL && _high_op == FILTER_LESS_OR_EQUAL && contain_null(); + _low_op == FILTER_LARGER_OR_EQUAL && _high_op == FILTER_LESS_OR_EQUAL && + contain_null(); } // only two case will set range contain null, call by temp_range in olap scan node @@ -228,7 +230,8 @@ public: return ColumnValueRange::create_empty_column_value_range("", type); } - static ColumnValueRange create_empty_column_value_range(const std::string& col_name, PrimitiveType type) { + static ColumnValueRange create_empty_column_value_range(const std::string& col_name, + PrimitiveType type) { return ColumnValueRange(col_name, type, TYPE_MAX, TYPE_MIN, false); } @@ -236,8 +239,8 @@ protected: bool is_in_range(const T& value); private: - const static T TYPE_MIN; // Column type's min value - const static T TYPE_MAX; // Column type's max value + const static T TYPE_MIN; // Column type's min value + const static T TYPE_MAX; // Column type's max value std::string _column_name; PrimitiveType _column_type; // Column type (eg: TINYINT,SMALLINT,INT,BIGINT) @@ -314,11 +317,10 @@ private: bool _is_convertible; }; -typedef boost::variant, ColumnValueRange, - ColumnValueRange, ColumnValueRange, - ColumnValueRange<__int128>, ColumnValueRange, - ColumnValueRange, ColumnValueRange, - ColumnValueRange, ColumnValueRange> +typedef boost::variant< + ColumnValueRange, ColumnValueRange, ColumnValueRange, + ColumnValueRange, ColumnValueRange<__int128>, ColumnValueRange, + ColumnValueRange, ColumnValueRange, ColumnValueRange> ColumnValueRangeType; template @@ -331,17 +333,18 @@ ColumnValueRange::ColumnValueRange() : _column_type(INVALID_TYPE) {} template ColumnValueRange::ColumnValueRange(std::string col_name, PrimitiveType type) - : ColumnValueRange(std::move(col_name), type, TYPE_MIN, TYPE_MAX, true){} + : ColumnValueRange(std::move(col_name), type, TYPE_MIN, TYPE_MAX, true) {} template -ColumnValueRange::ColumnValueRange(std::string col_name, PrimitiveType type, const T& min, const T& max, bool contain_null) +ColumnValueRange::ColumnValueRange(std::string col_name, PrimitiveType type, const T& min, + const T& max, bool contain_null) : _column_name(std::move(col_name)), _column_type(type), _low_value(min), _high_value(max), _low_op(FILTER_LARGER_OR_EQUAL), _high_op(FILTER_LESS_OR_EQUAL), - _contain_null(contain_null){} + _contain_null(contain_null) {} template Status ColumnValueRange::add_fixed_value(const T& value) { @@ -420,9 +423,6 @@ size_t ColumnValueRange::get_convertible_fixed_value_size() const { template <> void ColumnValueRange::convert_to_fixed_value(); -template <> -void ColumnValueRange::convert_to_fixed_value(); - template <> void ColumnValueRange::convert_to_fixed_value(); @@ -630,8 +630,8 @@ void ColumnValueRange::intersection(ColumnValueRange& range) { // 3. fixed_value intersection, fixed value range do not contain null if (is_fixed_value_range() || range.is_fixed_value_range()) { if (is_fixed_value_range() && range.is_fixed_value_range()) { - set_intersection(_fixed_values.begin(), _fixed_values.end(), range._fixed_values.begin(), - range._fixed_values.end(), + set_intersection(_fixed_values.begin(), _fixed_values.end(), + range._fixed_values.begin(), range._fixed_values.end(), std::inserter(result_values, result_values.begin())); } else if (is_fixed_value_range() && !range.is_fixed_value_range()) { iterator_type iter = _fixed_values.begin(); @@ -661,7 +661,6 @@ void ColumnValueRange::intersection(ColumnValueRange& range) { set_empty_value_range(); } } else { - if (contain_null() && range.contain_null()) { // if both is_whole_range to keep the same, else set_contain_null if (!is_whole_value_range() || !range.is_whole_value_range()) { diff --git a/be/src/exec/olap_rewrite_node.cpp b/be/src/exec/olap_rewrite_node.cpp index da8aef7915..dedea4b566 100644 --- a/be/src/exec/olap_rewrite_node.cpp +++ b/be/src/exec/olap_rewrite_node.cpp @@ -54,12 +54,9 @@ Status OlapRewriteNode::prepare(RuntimeState* state) { _child_row_batch.reset(new RowBatch(child(0)->row_desc(), state->batch_size(), state->fragment_mem_tracker().get())); - _max_decimal_val.resize(_column_types.size()); _max_decimalv2_val.resize(_column_types.size()); for (int i = 0; i < _column_types.size(); ++i) { - if (_column_types[i].type == TPrimitiveType::DECIMAL) { - _max_decimal_val[i].to_max_decimal(_column_types[i].precision, _column_types[i].scale); - } else if (_column_types[i].type == TPrimitiveType::DECIMALV2) { + if (_column_types[i].type == TPrimitiveType::DECIMALV2) { _max_decimalv2_val[i].to_max_decimal(_column_types[i].precision, _column_types[i].scale); } @@ -162,23 +159,6 @@ bool OlapRewriteNode::copy_one_row(TupleRow* src_row, Tuple* tuple, MemPool* poo } break; } - case TPrimitiveType::DECIMAL: { - DecimalValue* dec_val = (DecimalValue*)src_value; - DecimalValue* dst_val = (DecimalValue*)tuple->get_slot(slot_desc->tuple_offset()); - if (dec_val->scale() > column_type.scale) { - int code = dec_val->round(dst_val, column_type.scale, HALF_UP); - if (code != E_DEC_OK) { - (*ss) << "round one decimal failed.value=" << dec_val->to_string(); - return false; - } - } else { - *dst_val = *dec_val; - } - if (*dst_val > _max_decimal_val[i]) { - dst_val->to_max_decimal(column_type.precision, column_type.scale); - } - break; - } case TPrimitiveType::DECIMALV2: { DecimalV2Value* dec_val = (DecimalV2Value*)src_value; DecimalV2Value* dst_val = (DecimalV2Value*)tuple->get_slot(slot_desc->tuple_offset()); diff --git a/be/src/exec/olap_rewrite_node.h b/be/src/exec/olap_rewrite_node.h index 0b35ab295d..3f9ac745f7 100644 --- a/be/src/exec/olap_rewrite_node.h +++ b/be/src/exec/olap_rewrite_node.h @@ -62,7 +62,6 @@ private: TupleId _output_tuple_id; TupleDescriptor* _output_tuple_desc; - std::vector _max_decimal_val; std::vector _max_decimalv2_val; }; diff --git a/be/src/exec/olap_scan_node.cpp b/be/src/exec/olap_scan_node.cpp index 409e27f63c..92b31b85d5 100644 --- a/be/src/exec/olap_scan_node.cpp +++ b/be/src/exec/olap_scan_node.cpp @@ -583,13 +583,6 @@ Status OlapScanNode::normalize_conjuncts() { break; } - case TYPE_DECIMAL: { - ColumnValueRange range(slots[slot_idx]->col_name(), - slots[slot_idx]->type().type); - normalize_predicate(range, slots[slot_idx]); - break; - } - case TYPE_DECIMALV2: { ColumnValueRange range(slots[slot_idx]->col_name(), slots[slot_idx]->type().type); @@ -940,7 +933,6 @@ Status OlapScanNode::change_fixed_value_range(ColumnValueRange& temp_range, P } break; } - case TYPE_DECIMAL: case TYPE_DECIMALV2: case TYPE_CHAR: case TYPE_VARCHAR: @@ -1239,7 +1231,6 @@ Status OlapScanNode::normalize_noneq_binary_predicate(SlotDescriptor* slot, break; } case TYPE_TINYINT: - case TYPE_DECIMAL: case TYPE_DECIMALV2: case TYPE_CHAR: case TYPE_VARCHAR: diff --git a/be/src/exec/olap_scanner.cpp b/be/src/exec/olap_scanner.cpp index 9b2b9fb195..44611707b8 100644 --- a/be/src/exec/olap_scanner.cpp +++ b/be/src/exec/olap_scanner.cpp @@ -409,15 +409,6 @@ void OlapScanner::_convert_row_to_tuple(Tuple* tuple) { slot->len = slice->size; break; } - case TYPE_DECIMAL: { - DecimalValue* slot = tuple->get_decimal_slot(slot_desc->tuple_offset()); - - // TODO(lingbin): should remove this assign, use set member function - int64_t int_value = *(int64_t*)(ptr); - int32_t frac_value = *(int32_t*)(ptr + sizeof(int64_t)); - *slot = DecimalValue(int_value, frac_value); - break; - } case TYPE_DECIMALV2: { DecimalV2Value* slot = tuple->get_decimalv2_slot(slot_desc->tuple_offset()); diff --git a/be/src/exec/olap_utils.h b/be/src/exec/olap_utils.h index d4a97eadd1..b3929f3b7d 100644 --- a/be/src/exec/olap_utils.h +++ b/be/src/exec/olap_utils.h @@ -65,9 +65,6 @@ inline CompareLargeFunc get_compare_func(PrimitiveType type) { case TYPE_DATETIME: return compare_large; - case TYPE_DECIMAL: - return compare_large; - case TYPE_DECIMALV2: return compare_large; @@ -174,8 +171,7 @@ inline int get_olap_size(PrimitiveType type) { return 8; } - case TYPE_DECIMALV2: - case TYPE_DECIMAL: { + case TYPE_DECIMALV2: { return 12; } diff --git a/be/src/exec/parquet_writer.cpp b/be/src/exec/parquet_writer.cpp index 013c88b941..319f65d90a 100644 --- a/be/src/exec/parquet_writer.cpp +++ b/be/src/exec/parquet_writer.cpp @@ -36,10 +36,8 @@ namespace doris { /// ParquetOutputStream -ParquetOutputStream::ParquetOutputStream(FileWriter* file_writer) : - _file_writer(file_writer), - _cur_pos(0), - _written_len(0){ +ParquetOutputStream::ParquetOutputStream(FileWriter* file_writer) + : _file_writer(file_writer), _cur_pos(0), _written_len(0) { set_mode(arrow::io::FileMode::WRITE); } @@ -92,7 +90,7 @@ ParquetWriterWrapper::ParquetWriterWrapper(FileWriter* file_writer, const std::vector& output_expr_ctxs, const std::map& properties, const std::vector>& schema) - :_output_expr_ctxs(output_expr_ctxs), + : _output_expr_ctxs(output_expr_ctxs), _str_schema(schema), _cur_writed_rows(0), _rg_writer(nullptr) { @@ -102,7 +100,8 @@ ParquetWriterWrapper::ParquetWriterWrapper(FileWriter* file_writer, init_parquet_writer(); } -void ParquetWriterWrapper::parse_properties(const std::map& propertie_map) { +void ParquetWriterWrapper::parse_properties( + const std::map& propertie_map) { parquet::WriterProperties::Builder builder; for (auto it = propertie_map.begin(); it != propertie_map.end(); it++) { std::string property_name = it->first; @@ -160,7 +159,7 @@ Status ParquetWriterWrapper::parse_schema(const std::vector( parquet::schema::GroupNode::Make("schema", parquet::Repetition::REQUIRED, fields)); } @@ -226,209 +226,195 @@ Status ParquetWriterWrapper::_write_one_row(TupleRow* row) { } try { for (int index = 0; index < num_columns; ++index) { - void *item = _output_expr_ctxs[index]->get_value(row); + void* item = _output_expr_ctxs[index]->get_value(row); switch (_output_expr_ctxs[index]->root()->type().type) { - case TYPE_BOOLEAN: { - if (_str_schema[index][1] != "boolean") { - std::stringstream ss; - ss << "project field type is boolean, but the definition type of column " - << _str_schema[index][2] << " is " << _str_schema[index][1]; - return Status::InvalidArgument(ss.str()); - } - parquet::RowGroupWriter* rgWriter = get_rg_writer(); - parquet::BoolWriter *col_writer = static_cast(rgWriter->column(index)); - if (item != nullptr) { - col_writer->WriteBatch(1, nullptr, nullptr, static_cast (item)); - } else { - bool default_bool = false; - col_writer->WriteBatch(1, nullptr, nullptr, &default_bool); - } - break; - } - case TYPE_TINYINT: - case TYPE_SMALLINT: - case TYPE_INT: { - if (_str_schema[index][1] != "int32") { - std::stringstream ss; - ss << "project field type is tiny int/small int/int, should use int32, but the definition type of column " - << _str_schema[index][2] << " is " << _str_schema[index][1]; - return Status::InvalidArgument(ss.str()); - } - - parquet::RowGroupWriter* rgWriter = get_rg_writer(); - parquet::Int32Writer *col_writer = static_cast(rgWriter->column(index)); - if (item != nullptr) { - col_writer->WriteBatch(1, nullptr, nullptr, static_cast(item)); - } else { - int32_t default_int32 = 0; - col_writer->WriteBatch(1, nullptr, nullptr, &default_int32); - } - break; - } - case TYPE_BIGINT: { - if (_str_schema[index][1] != "int64") { - std::stringstream ss; - ss << "project field type is big int, should use int64, but the definition type of column " - << _str_schema[index][2] << " is " << _str_schema[index][1]; - return Status::InvalidArgument(ss.str()); - } - parquet::RowGroupWriter* rgWriter = get_rg_writer(); - parquet::Int64Writer *col_writer = static_cast(rgWriter->column(index)); - if (item != nullptr) { - col_writer->WriteBatch(1, nullptr, nullptr, (int64_t * )(item)); - } else { - int64_t default_int644 = 0; - col_writer->WriteBatch(1, nullptr, nullptr, &default_int644); - } - break; - } - case TYPE_LARGEINT: { - // TODO: not support int_128 - // It is better write a default value, because rg_writer need all columns has value before flush to disk. - parquet::RowGroupWriter* rgWriter = get_rg_writer(); - parquet::Int64Writer *col_writer = static_cast(rgWriter->column(index)); - int64_t default_int64 = 0; - col_writer->WriteBatch(1, nullptr, nullptr, &default_int64); - return Status::InvalidArgument("do not support large int type."); - } - case TYPE_FLOAT: { - if (_str_schema[index][1] != "float") { - std::stringstream ss; - ss << "project field type is float, but the definition type of column " - << _str_schema[index][2] << " is " << _str_schema[index][1]; - return Status::InvalidArgument(ss.str()); - } - parquet::RowGroupWriter* rgWriter = get_rg_writer(); - parquet::FloatWriter *col_writer = static_cast(rgWriter->column(index)); - if (item != nullptr) { - col_writer->WriteBatch(1, nullptr, nullptr, (float_t *) (item)); - } else { - float_t default_float = 0.0; - col_writer->WriteBatch(1, nullptr, nullptr, &default_float); - } - break; - } - case TYPE_DOUBLE: { - if (_str_schema[index][1] != "double") { - std::stringstream ss; - ss << "project field type is double, but the definition type of column " - << _str_schema[index][2] << " is " << _str_schema[index][1]; - return Status::InvalidArgument(ss.str()); - } - parquet::RowGroupWriter* rgWriter = get_rg_writer(); - parquet::DoubleWriter *col_writer = static_cast(rgWriter->column(index)); - if (item != nullptr) { - col_writer->WriteBatch(1, nullptr, nullptr, (double_t *) (item)); - } else { - double_t default_double = 0.0; - col_writer->WriteBatch(1, nullptr, nullptr, &default_double); - } - break; - } - case TYPE_DATETIME: - case TYPE_DATE: { - if (_str_schema[index][1] != "int64") { - std::stringstream ss; - ss << "project field type is date/datetime, should use int64, but the definition type of column " - << _str_schema[index][2] << " is " << _str_schema[index][1]; - return Status::InvalidArgument(ss.str()); - } - parquet::RowGroupWriter* rgWriter = get_rg_writer(); - parquet::Int64Writer *col_writer = static_cast(rgWriter->column(index)); - if (item != nullptr) { - const DateTimeValue *time_val = (const DateTimeValue *) (item); - int64_t timestamp = time_val->to_olap_datetime(); - col_writer->WriteBatch(1, nullptr, nullptr, ×tamp); - } else { - int64_t default_int64 = 0; - col_writer->WriteBatch(1, nullptr, nullptr, &default_int64); - } - break; - } - case TYPE_CHAR: - case TYPE_VARCHAR: { - if (_str_schema[index][1] != "byte_array") { - std::stringstream ss; - ss << "project field type is char/varchar, should use byte_array, but the definition type of column " - << _str_schema[index][2] << " is " << _str_schema[index][1]; - return Status::InvalidArgument(ss.str()); - } - parquet::RowGroupWriter* rgWriter = get_rg_writer(); - parquet::ByteArrayWriter *col_writer = static_cast(rgWriter->column(index)); - if (item != nullptr) { - const StringValue *string_val = (const StringValue *) (item); - parquet::ByteArray value; - value.ptr = reinterpret_cast(string_val->ptr); - value.len = string_val->len; - col_writer->WriteBatch(1, nullptr, nullptr, &value); - } else { - parquet::ByteArray value; - col_writer->WriteBatch(1, nullptr, nullptr, &value); - } - break; - } - case TYPE_DECIMAL: { - if (_str_schema[index][1] != "byte_array") { - std::stringstream ss; - ss << "project field type is decimal, should use byte_array, but the definition type of column " - << _str_schema[index][2] << " is " << _str_schema[index][1]; - return Status::InvalidArgument(ss.str()); - } - parquet::RowGroupWriter* rgWriter = get_rg_writer(); - parquet::ByteArrayWriter *col_writer = static_cast(rgWriter->column(index)); - if (item != nullptr) { - const DecimalValue *decimal_val = reinterpret_cast(item); - std::string decimal_str; - int output_scale = _output_expr_ctxs[index]->root()->output_scale(); - if (output_scale > 0 && output_scale <= 30) { - decimal_str = decimal_val->to_string(output_scale); - } else { - decimal_str = decimal_val->to_string(); - } - parquet::ByteArray value; - value.ptr = reinterpret_cast(&decimal_str); - value.len = decimal_str.length(); - col_writer->WriteBatch(1, nullptr, nullptr, &value); - } else { - parquet::ByteArray value; - col_writer->WriteBatch(1, nullptr, nullptr, &value); - } - break; - } - case TYPE_DECIMALV2: { - if (_str_schema[index][1] != "byte_array") { - std::stringstream ss; - ss << "project field type is decimal v2, should use byte_array, but the definition type of column " - << _str_schema[index][2] << " is " << _str_schema[index][1]; - return Status::InvalidArgument(ss.str()); - } - parquet::RowGroupWriter* rgWriter = get_rg_writer(); - parquet::ByteArrayWriter *col_writer = static_cast(rgWriter->column(index)); - if (item != nullptr) { - const DecimalV2Value decimal_val( - reinterpret_cast(item)->value); - std::string decimal_str; - int output_scale = _output_expr_ctxs[index]->root()->output_scale(); - if (output_scale > 0 && output_scale <= 30) { - decimal_str = decimal_val.to_string(output_scale); - } else { - decimal_str = decimal_val.to_string(); - } - parquet::ByteArray value; - value.ptr = reinterpret_cast(&decimal_str); - value.len = decimal_str.length(); - col_writer->WriteBatch(1, nullptr, nullptr, &value); - } else { - parquet::ByteArray value; - col_writer->WriteBatch(1, nullptr, nullptr, &value); - } - break; - } - default: { + case TYPE_BOOLEAN: { + if (_str_schema[index][1] != "boolean") { std::stringstream ss; - ss << "unsupported file format: " << _output_expr_ctxs[index]->root()->type().type; + ss << "project field type is boolean, but the definition type of column " + << _str_schema[index][2] << " is " << _str_schema[index][1]; return Status::InvalidArgument(ss.str()); } + parquet::RowGroupWriter* rgWriter = get_rg_writer(); + parquet::BoolWriter* col_writer = + static_cast(rgWriter->column(index)); + if (item != nullptr) { + col_writer->WriteBatch(1, nullptr, nullptr, static_cast(item)); + } else { + bool default_bool = false; + col_writer->WriteBatch(1, nullptr, nullptr, &default_bool); + } + break; + } + case TYPE_TINYINT: + case TYPE_SMALLINT: + case TYPE_INT: { + if (_str_schema[index][1] != "int32") { + std::stringstream ss; + ss << "project field type is tiny int/small int/int, should use int32, but the " + "definition type of column " + << _str_schema[index][2] << " is " << _str_schema[index][1]; + return Status::InvalidArgument(ss.str()); + } + + parquet::RowGroupWriter* rgWriter = get_rg_writer(); + parquet::Int32Writer* col_writer = + static_cast(rgWriter->column(index)); + if (item != nullptr) { + col_writer->WriteBatch(1, nullptr, nullptr, static_cast(item)); + } else { + int32_t default_int32 = 0; + col_writer->WriteBatch(1, nullptr, nullptr, &default_int32); + } + break; + } + case TYPE_BIGINT: { + if (_str_schema[index][1] != "int64") { + std::stringstream ss; + ss << "project field type is big int, should use int64, but the definition " + "type of column " + << _str_schema[index][2] << " is " << _str_schema[index][1]; + return Status::InvalidArgument(ss.str()); + } + parquet::RowGroupWriter* rgWriter = get_rg_writer(); + parquet::Int64Writer* col_writer = + static_cast(rgWriter->column(index)); + if (item != nullptr) { + col_writer->WriteBatch(1, nullptr, nullptr, (int64_t*)(item)); + } else { + int64_t default_int644 = 0; + col_writer->WriteBatch(1, nullptr, nullptr, &default_int644); + } + break; + } + case TYPE_LARGEINT: { + // TODO: not support int_128 + // It is better write a default value, because rg_writer need all columns has value before flush to disk. + parquet::RowGroupWriter* rgWriter = get_rg_writer(); + parquet::Int64Writer* col_writer = + static_cast(rgWriter->column(index)); + int64_t default_int64 = 0; + col_writer->WriteBatch(1, nullptr, nullptr, &default_int64); + return Status::InvalidArgument("do not support large int type."); + } + case TYPE_FLOAT: { + if (_str_schema[index][1] != "float") { + std::stringstream ss; + ss << "project field type is float, but the definition type of column " + << _str_schema[index][2] << " is " << _str_schema[index][1]; + return Status::InvalidArgument(ss.str()); + } + parquet::RowGroupWriter* rgWriter = get_rg_writer(); + parquet::FloatWriter* col_writer = + static_cast(rgWriter->column(index)); + if (item != nullptr) { + col_writer->WriteBatch(1, nullptr, nullptr, (float_t*)(item)); + } else { + float_t default_float = 0.0; + col_writer->WriteBatch(1, nullptr, nullptr, &default_float); + } + break; + } + case TYPE_DOUBLE: { + if (_str_schema[index][1] != "double") { + std::stringstream ss; + ss << "project field type is double, but the definition type of column " + << _str_schema[index][2] << " is " << _str_schema[index][1]; + return Status::InvalidArgument(ss.str()); + } + parquet::RowGroupWriter* rgWriter = get_rg_writer(); + parquet::DoubleWriter* col_writer = + static_cast(rgWriter->column(index)); + if (item != nullptr) { + col_writer->WriteBatch(1, nullptr, nullptr, (double_t*)(item)); + } else { + double_t default_double = 0.0; + col_writer->WriteBatch(1, nullptr, nullptr, &default_double); + } + break; + } + case TYPE_DATETIME: + case TYPE_DATE: { + if (_str_schema[index][1] != "int64") { + std::stringstream ss; + ss << "project field type is date/datetime, should use int64, but the " + "definition type of column " + << _str_schema[index][2] << " is " << _str_schema[index][1]; + return Status::InvalidArgument(ss.str()); + } + parquet::RowGroupWriter* rgWriter = get_rg_writer(); + parquet::Int64Writer* col_writer = + static_cast(rgWriter->column(index)); + if (item != nullptr) { + const DateTimeValue* time_val = (const DateTimeValue*)(item); + int64_t timestamp = time_val->to_olap_datetime(); + col_writer->WriteBatch(1, nullptr, nullptr, ×tamp); + } else { + int64_t default_int64 = 0; + col_writer->WriteBatch(1, nullptr, nullptr, &default_int64); + } + break; + } + case TYPE_CHAR: + case TYPE_VARCHAR: { + if (_str_schema[index][1] != "byte_array") { + std::stringstream ss; + ss << "project field type is char/varchar, should use byte_array, but the " + "definition type of column " + << _str_schema[index][2] << " is " << _str_schema[index][1]; + return Status::InvalidArgument(ss.str()); + } + parquet::RowGroupWriter* rgWriter = get_rg_writer(); + parquet::ByteArrayWriter* col_writer = + static_cast(rgWriter->column(index)); + if (item != nullptr) { + const StringValue* string_val = (const StringValue*)(item); + parquet::ByteArray value; + value.ptr = reinterpret_cast(string_val->ptr); + value.len = string_val->len; + col_writer->WriteBatch(1, nullptr, nullptr, &value); + } else { + parquet::ByteArray value; + col_writer->WriteBatch(1, nullptr, nullptr, &value); + } + break; + } + case TYPE_DECIMALV2: { + if (_str_schema[index][1] != "byte_array") { + std::stringstream ss; + ss << "project field type is decimal v2, should use byte_array, but the " + "definition type of column " + << _str_schema[index][2] << " is " << _str_schema[index][1]; + return Status::InvalidArgument(ss.str()); + } + parquet::RowGroupWriter* rgWriter = get_rg_writer(); + parquet::ByteArrayWriter* col_writer = + static_cast(rgWriter->column(index)); + if (item != nullptr) { + const DecimalV2Value decimal_val( + reinterpret_cast(item)->value); + std::string decimal_str; + int output_scale = _output_expr_ctxs[index]->root()->output_scale(); + if (output_scale > 0 && output_scale <= 30) { + decimal_str = decimal_val.to_string(output_scale); + } else { + decimal_str = decimal_val.to_string(); + } + parquet::ByteArray value; + value.ptr = reinterpret_cast(&decimal_str); + value.len = decimal_str.length(); + col_writer->WriteBatch(1, nullptr, nullptr, &value); + } else { + parquet::ByteArray value; + col_writer->WriteBatch(1, nullptr, nullptr, &value); + } + break; + } + default: { + std::stringstream ss; + ss << "unsupported file format: " << _output_expr_ctxs[index]->root()->type().type; + return Status::InvalidArgument(ss.str()); + } } } } catch (const std::exception& e) { @@ -451,11 +437,10 @@ void ParquetWriterWrapper::close() { _outstream->Close(); } catch (const std::exception& e) { _rg_writer = nullptr; - LOG(WARNING) <<"Parquet writer close error: " << e.what(); + LOG(WARNING) << "Parquet writer close error: " << e.what(); } } -ParquetWriterWrapper::~ParquetWriterWrapper() { -} +ParquetWriterWrapper::~ParquetWriterWrapper() {} } // namespace doris diff --git a/be/src/exec/schema_scanner/schema_columns_scanner.cpp b/be/src/exec/schema_scanner/schema_columns_scanner.cpp index b248c4b491..365d3b0f45 100644 --- a/be/src/exec/schema_scanner/schema_columns_scanner.cpp +++ b/be/src/exec/schema_scanner/schema_columns_scanner.cpp @@ -119,8 +119,7 @@ std::string SchemaColumnsScanner::to_mysql_data_type_string(TColumnDesc& desc) { return "date"; case TPrimitiveType::DATETIME: return "datetime"; - case TPrimitiveType::DECIMALV2: - case TPrimitiveType::DECIMAL: { + case TPrimitiveType::DECIMALV2: { return "decimal"; } default: @@ -162,8 +161,7 @@ std::string SchemaColumnsScanner::type_to_string(TColumnDesc& desc) { return "date"; case TPrimitiveType::DATETIME: return "datetime"; - case TPrimitiveType::DECIMALV2: - case TPrimitiveType::DECIMAL: { + case TPrimitiveType::DECIMALV2: { std::stringstream stream; stream << "decimal("; if (desc.__isset.columnPrecision) { diff --git a/be/src/exec/tablet_sink.cpp b/be/src/exec/tablet_sink.cpp index 056b6dcaab..1b04e02bb7 100644 --- a/be/src/exec/tablet_sink.cpp +++ b/be/src/exec/tablet_sink.cpp @@ -30,8 +30,8 @@ #include "util/brpc_stub_cache.h" #include "util/debug/sanitizer_scopes.h" #include "util/monotime.h" -#include "util/uid_util.h" #include "util/time.h" +#include "util/uid_util.h" namespace doris { namespace stream_load { @@ -141,9 +141,8 @@ Status NodeChannel::open_wait() { _open_closure->join(); if (_open_closure->cntl.Failed()) { std::stringstream ss; - ss << "failed to open tablet writer, error=" - << berror(_open_closure->cntl.ErrorCode()) - << ", error_text=" << _open_closure->cntl.ErrorText(); + ss << "failed to open tablet writer, error=" << berror(_open_closure->cntl.ErrorCode()) + << ", error_text=" << _open_closure->cntl.ErrorText(); _cancelled = true; LOG(WARNING) << ss.str(); return Status::InternalError(ss.str()); @@ -168,36 +167,36 @@ Status NodeChannel::open_wait() { _cancel_with_msg(ss.str()); }); - _add_batch_closure->addSuccessHandler( - [this](const PTabletWriterAddBatchResult& result, bool is_last_rpc) { - Status status(result.status()); - if (status.ok()) { - if (is_last_rpc) { - for (auto& tablet : result.tablet_vec()) { - TTabletCommitInfo commit_info; - commit_info.tabletId = tablet.tablet_id(); - commit_info.backendId = _node_id; - _tablet_commit_infos.emplace_back(std::move(commit_info)); - } - _add_batches_finished = true; - } - } else { - std::stringstream ss; - // FIXME(cmy): There is a problem that when calling node_info, the node_info seems not initialized. - // But I don't know why. so here I print node_info()->id instead of node_info()->host - // to avoid BE crash. It needs further observation. - ss << name() << " add batch req success but status isn't ok, " - << print_load_info() << ", backend id=" << node_info()->id << ":" - << node_info()->brpc_port << ", errmsg=" << status.get_error_msg(); - _cancel_with_msg(ss.str()); + _add_batch_closure->addSuccessHandler([this](const PTabletWriterAddBatchResult& result, + bool is_last_rpc) { + Status status(result.status()); + if (status.ok()) { + if (is_last_rpc) { + for (auto& tablet : result.tablet_vec()) { + TTabletCommitInfo commit_info; + commit_info.tabletId = tablet.tablet_id(); + commit_info.backendId = _node_id; + _tablet_commit_infos.emplace_back(std::move(commit_info)); } + _add_batches_finished = true; + } + } else { + std::stringstream ss; + // FIXME(cmy): There is a problem that when calling node_info, the node_info seems not initialized. + // But I don't know why. so here I print node_info()->id instead of node_info()->host + // to avoid BE crash. It needs further observation. + ss << name() << " add batch req success but status isn't ok, " << print_load_info() + << ", backend id=" << node_info()->id << ":" << node_info()->brpc_port + << ", errmsg=" << status.get_error_msg(); + _cancel_with_msg(ss.str()); + } - if (result.has_execution_time_us()) { - _add_batch_counter.add_batch_execution_time_us += result.execution_time_us(); - _add_batch_counter.add_batch_wait_lock_time_us += result.wait_lock_time_us(); - _add_batch_counter.add_batch_num++; - } - }); + if (result.has_execution_time_us()) { + _add_batch_counter.add_batch_execution_time_us += result.execution_time_us(); + _add_batch_counter.add_batch_wait_lock_time_us += result.wait_lock_time_us(); + _add_batch_counter.add_batch_num++; + } + }); return status; } @@ -279,7 +278,8 @@ Status NodeChannel::close_wait(RuntimeState* state) { std::lock_guard l(_cancel_msg_lock); return Status::InternalError("wait close failed. " + _cancel_msg); } else { - return st.clone_and_prepend("already stopped, skip waiting for close. cancelled/!eos: "); + return st.clone_and_prepend( + "already stopped, skip waiting for close. cancelled/!eos: "); } } @@ -536,8 +536,9 @@ Status OlapTableSink::prepare(RuntimeState* state) { // profile must add to state's object pool _profile = state->obj_pool()->add(new RuntimeProfile("OlapTableSink")); - _mem_tracker = MemTracker::CreateTracker(-1, "OlapTableSink:" + std::to_string(state->load_job_id()), - state->instance_mem_tracker(), true, false); + _mem_tracker = + MemTracker::CreateTracker(-1, "OlapTableSink:" + std::to_string(state->load_job_id()), + state->instance_mem_tracker(), true, false); SCOPED_TIMER(_profile->total_time_counter()); @@ -572,20 +573,12 @@ Status OlapTableSink::prepare(RuntimeState* state) { _output_row_desc = _pool->add(new RowDescriptor(_output_tuple_desc, false)); _output_batch.reset(new RowBatch(*_output_row_desc, state->batch_size(), _mem_tracker.get())); - _max_decimal_val.resize(_output_tuple_desc->slots().size()); - _min_decimal_val.resize(_output_tuple_desc->slots().size()); - _max_decimalv2_val.resize(_output_tuple_desc->slots().size()); _min_decimalv2_val.resize(_output_tuple_desc->slots().size()); // check if need validate batch for (int i = 0; i < _output_tuple_desc->slots().size(); ++i) { auto slot = _output_tuple_desc->slots()[i]; switch (slot->type().type) { - case TYPE_DECIMAL: - _max_decimal_val[i].to_max_decimal(slot->type().precision, slot->type().scale); - _min_decimal_val[i].to_min_decimal(slot->type().precision, slot->type().scale); - _need_validate_data = true; - break; case TYPE_DECIMALV2: _max_decimalv2_val[i].to_max_decimal(slot->type().precision, slot->type().scale); _min_decimalv2_val[i].to_min_decimal(slot->type().precision, slot->type().scale); @@ -615,8 +608,10 @@ Status OlapTableSink::prepare(RuntimeState* state) { _open_timer = ADD_TIMER(_profile, "OpenTime"); _close_timer = ADD_TIMER(_profile, "CloseWaitTime"); _non_blocking_send_timer = ADD_TIMER(_profile, "NonBlockingSendTime"); - _non_blocking_send_work_timer = ADD_CHILD_TIMER(_profile, "NonBlockingSendWorkTime", "NonBlockingSendTime"); - _serialize_batch_timer = ADD_CHILD_TIMER(_profile, "SerializeBatchTime", "NonBlockingSendWorkTime"); + _non_blocking_send_work_timer = + ADD_CHILD_TIMER(_profile, "NonBlockingSendWorkTime", "NonBlockingSendTime"); + _serialize_batch_timer = + ADD_CHILD_TIMER(_profile, "SerializeBatchTime", "NonBlockingSendWorkTime"); _total_add_batch_exec_timer = ADD_TIMER(_profile, "TotalAddBatchExecTime"); _max_add_batch_exec_timer = ADD_TIMER(_profile, "MaxAddBatchExecTime"); _add_batch_number = ADD_COUNTER(_profile, "NumberBatchAdded", TUnit::UNIT); @@ -662,8 +657,8 @@ Status OlapTableSink::open(RuntimeState* state) { if (!st.ok()) { std::stringstream err; err << ch->name() << ": tablet open failed, " << ch->print_load_info() - << ", node=" << ch->node_info()->host << ":" - << ch->node_info()->brpc_port << ", errmsg=" << st.get_error_msg(); + << ", node=" << ch->node_info()->host << ":" << ch->node_info()->brpc_port + << ", errmsg=" << st.get_error_msg(); LOG(WARNING) << err.str(); index_channel->mark_as_failed(ch); ss << err.str() << "; "; @@ -755,8 +750,7 @@ Status OlapTableSink::close(RuntimeState* state, Status close_status) { std::unordered_map node_add_batch_counter_map; int64_t serialize_batch_ns = 0, mem_exceeded_block_ns = 0, queue_push_lock_ns = 0, actual_consume_ns = 0, total_add_batch_exec_time_ns = 0, - max_add_batch_exec_time_ns = 0, - total_add_batch_num = 0, num_node_channels = 0; + max_add_batch_exec_time_ns = 0, total_add_batch_num = 0, num_node_channels = 0; { SCOPED_TIMER(_close_timer); for (auto index_channel : _channels) { @@ -766,24 +760,24 @@ Status OlapTableSink::close(RuntimeState* state, Status close_status) { for (auto index_channel : _channels) { int64_t add_batch_exec_time = 0; - index_channel->for_each_node_channel([&status, &state, &node_add_batch_counter_map, - &serialize_batch_ns, &mem_exceeded_block_ns, - &queue_push_lock_ns, &actual_consume_ns, - &total_add_batch_exec_time_ns, &add_batch_exec_time, - &total_add_batch_num](NodeChannel* ch) { - auto s = ch->close_wait(state); - if (!s.ok()) { - // 'status' will store the last non-ok status of all channels - status = s; - LOG(WARNING) - << ch->name() << ": close channel failed, " << ch->print_load_info() - << ". error_msg=" << s.get_error_msg(); - } - ch->time_report(&node_add_batch_counter_map, &serialize_batch_ns, - &mem_exceeded_block_ns, &queue_push_lock_ns, - &actual_consume_ns, &total_add_batch_exec_time_ns, - &add_batch_exec_time, &total_add_batch_num); - }); + index_channel->for_each_node_channel( + [&status, &state, &node_add_batch_counter_map, &serialize_batch_ns, + &mem_exceeded_block_ns, &queue_push_lock_ns, &actual_consume_ns, + &total_add_batch_exec_time_ns, &add_batch_exec_time, + &total_add_batch_num](NodeChannel* ch) { + auto s = ch->close_wait(state); + if (!s.ok()) { + // 'status' will store the last non-ok status of all channels + status = s; + LOG(WARNING) << ch->name() << ": close channel failed, " + << ch->print_load_info() + << ". error_msg=" << s.get_error_msg(); + } + ch->time_report(&node_add_batch_counter_map, &serialize_batch_ns, + &mem_exceeded_block_ns, &queue_push_lock_ns, + &actual_consume_ns, &total_add_batch_exec_time_ns, + &add_batch_exec_time, &total_add_batch_num); + }); if (add_batch_exec_time > max_add_batch_exec_time_ns) { max_add_batch_exec_time_ns = add_batch_exec_time; @@ -941,26 +935,6 @@ int OlapTableSink::_validate_data(RuntimeState* state, RowBatch* batch, Bitmap* } break; } - case TYPE_DECIMAL: { - DecimalValue* dec_val = (DecimalValue*)slot; - if (dec_val->scale() > desc->type().scale) { - int code = dec_val->round(dec_val, desc->type().scale, HALF_UP); - if (code != E_DEC_OK) { - ss << "round one decimal failed.value=" << dec_val->to_string(); - row_valid = false; - continue; - } - } - if (*dec_val > _max_decimal_val[i] || *dec_val < _min_decimal_val[i]) { - ss << "decimal value is not valid for definition, column=" << desc->col_name() - << ", value=" << dec_val->to_string() - << ", precision=" << desc->type().precision - << ", scale=" << desc->type().scale; - row_valid = false; - continue; - } - break; - } case TYPE_DECIMALV2: { DecimalV2Value dec_val(reinterpret_cast(slot)->value); if (dec_val.greater_than_scale(desc->type().scale)) { diff --git a/be/src/exec/tablet_sink.h b/be/src/exec/tablet_sink.h index 5192137941..7f0dcb54ca 100644 --- a/be/src/exec/tablet_sink.h +++ b/be/src/exec/tablet_sink.h @@ -80,8 +80,7 @@ struct AddBatchCounter { template class ReusableClosure : public google::protobuf::Closure { public: - ReusableClosure() : cid(INVALID_BTHREAD_ID) { - } + ReusableClosure() : cid(INVALID_BTHREAD_ID) {} ~ReusableClosure() { // shouldn't delete when Run() is calling or going to be called, wait for current Run() done. join(); @@ -376,9 +375,6 @@ private: CountDownLatch _stop_background_threads_latch; scoped_refptr _sender_thread; - std::vector _max_decimal_val; - std::vector _min_decimal_val; - std::vector _max_decimalv2_val; std::vector _min_decimalv2_val; @@ -414,10 +410,10 @@ private: // the timeout of load channels opened by this tablet sink. in second int64_t _load_channel_timeout_s = 0; - // True if this sink has been closed once - bool _is_closed = false; - // Save the status of close() method - Status _close_status; + // True if this sink has been closed once + bool _is_closed = false; + // Save the status of close() method + Status _close_status; }; } // namespace stream_load diff --git a/be/src/exec/text_converter.hpp b/be/src/exec/text_converter.hpp index 5afdad3688..6b66755460 100644 --- a/be/src/exec/text_converter.hpp +++ b/be/src/exec/text_converter.hpp @@ -22,7 +22,6 @@ #include "olap/utils.h" #include "runtime/datetime_value.h" -#include "runtime/decimal_value.h" #include "runtime/decimalv2_value.h" #include "runtime/descriptors.h" #include "runtime/mem_pool.h" @@ -139,16 +138,6 @@ inline bool TextConverter::write_slot(const SlotDescriptor* slot_desc, Tuple* tu break; } - case TYPE_DECIMAL: { - DecimalValue* decimal_slot = reinterpret_cast(slot); - - if (decimal_slot->parse_from_str(data, len)) { - parse_result = StringParser::PARSE_FAILURE; - } - - break; - } - case TYPE_DECIMALV2: { DecimalV2Value decimal_slot; diff --git a/be/src/exprs/CMakeLists.txt b/be/src/exprs/CMakeLists.txt index f64b5ddc53..0268bce71b 100644 --- a/be/src/exprs/CMakeLists.txt +++ b/be/src/exprs/CMakeLists.txt @@ -34,7 +34,6 @@ add_library(Exprs compound_predicate.cpp conditional_functions.cpp conditional_functions_ir.cpp - decimal_operators.cpp decimalv2_operators.cpp time_operators.cpp es_functions.cpp diff --git a/be/src/exprs/agg_fn_evaluator.cpp b/be/src/exprs/agg_fn_evaluator.cpp index 67da8f3045..232be0aa09 100644 --- a/be/src/exprs/agg_fn_evaluator.cpp +++ b/be/src/exprs/agg_fn_evaluator.cpp @@ -44,7 +44,6 @@ using doris_udf::BigIntVal; using doris_udf::LargeIntVal; using doris_udf::FloatVal; using doris_udf::DoubleVal; -using doris_udf::DecimalVal; using doris_udf::DecimalV2Val; using doris_udf::DateTimeVal; using doris_udf::StringVal; @@ -324,11 +323,6 @@ inline void AggFnEvaluator::set_any_val(const void* slot, const TypeDescriptor& reinterpret_cast(dst)); return; - case TYPE_DECIMAL: - reinterpret_cast(slot)->to_decimal_val( - reinterpret_cast(dst)); - return; - case TYPE_DECIMALV2: reinterpret_cast(dst)->val = reinterpret_cast(slot)->value; @@ -399,11 +393,6 @@ inline void AggFnEvaluator::set_output_slot(const AnyVal* src, const SlotDescrip DateTimeValue::from_datetime_val(*reinterpret_cast(src)); return; - case TYPE_DECIMAL: - *reinterpret_cast(slot) = - DecimalValue::from_decimal_val(*reinterpret_cast(src)); - return; - case TYPE_DECIMALV2: *reinterpret_cast(slot) = reinterpret_cast(src)->val; return; @@ -564,13 +553,6 @@ bool AggFnEvaluator::count_distinct_data_filter(TupleRow* row, Tuple* dst) { break; } - case TYPE_DECIMAL: { - DecimalVal* value = reinterpret_cast(_staging_input_vals[i]); - memcpy(begin, value, sizeof(DecimalVal)); - begin += sizeof(DecimalVal); - break; - } - case TYPE_DECIMALV2: { DecimalV2Val* value = reinterpret_cast(_staging_input_vals[i]); memcpy(begin, value, sizeof(DecimalV2Val)); @@ -649,14 +631,6 @@ bool AggFnEvaluator::sum_distinct_data_filter(TupleRow* row, Tuple* dst) { return is_filter; } - case TYPE_DECIMAL: { - const DecimalVal* value = reinterpret_cast(_staging_input_vals[0]); - DecimalValue temp_value = DecimalValue::from_decimal_val(*value); - is_filter = is_in_hybridmap((void*)&(temp_value), dst, &is_add_buckets); - update_mem_trackers(is_filter, is_add_buckets, DECIMAL_SIZE); - return is_filter; - } - case TYPE_DECIMALV2: { const DecimalV2Val* value = reinterpret_cast(_staging_input_vals[0]); DecimalV2Value temp_value = DecimalV2Value::from_decimal_val(*value); @@ -931,13 +905,6 @@ void AggFnEvaluator::serialize_or_finalize(FunctionContext* agg_fn_ctx, Tuple* s break; } - case TYPE_DECIMAL: { - typedef DecimalVal (*Fn)(FunctionContext*, AnyVal*); - DecimalVal v = reinterpret_cast(fn)(agg_fn_ctx, _staging_intermediate_val); - set_output_slot(&v, dst_slot_desc, dst); - break; - } - case TYPE_DECIMALV2: { typedef DecimalV2Val (*Fn)(FunctionContext*, AnyVal*); DecimalV2Val v = reinterpret_cast(fn)(agg_fn_ctx, _staging_intermediate_val); diff --git a/be/src/exprs/agg_fn_evaluator.h b/be/src/exprs/agg_fn_evaluator.h index ca7b8134d2..83953a4e5e 100644 --- a/be/src/exprs/agg_fn_evaluator.h +++ b/be/src/exprs/agg_fn_evaluator.h @@ -141,7 +141,6 @@ public: static const size_t BIGINT_SIZE = sizeof(int64_t); static const size_t FLOAT_SIZE = sizeof(float); static const size_t DOUBLE_SIZE = sizeof(double); - static const size_t DECIMAL_SIZE = sizeof(DecimalValue); static const size_t DECIMALV2_SIZE = sizeof(DecimalV2Value); static const size_t LARGEINT_SIZE = sizeof(__int128); // DATETIME VAL has two part: packet_time is 8 byte, and type is 4 byte diff --git a/be/src/exprs/aggregate_functions.cpp b/be/src/exprs/aggregate_functions.cpp index 2f7132a10b..b5a80771c2 100644 --- a/be/src/exprs/aggregate_functions.cpp +++ b/be/src/exprs/aggregate_functions.cpp @@ -45,7 +45,6 @@ using doris_udf::BigIntVal; using doris_udf::LargeIntVal; using doris_udf::FloatVal; using doris_udf::DoubleVal; -using doris_udf::DecimalVal; using doris_udf::DecimalV2Val; using doris_udf::DateTimeVal; using doris_udf::StringVal; @@ -64,11 +63,6 @@ void AggregateFunctions::init_zero(FunctionContext*, T* dst) { dst->val = 0; } -template <> -void AggregateFunctions::init_zero(FunctionContext*, DecimalVal* dst) { - dst->set_to_zero(); -} - template <> void AggregateFunctions::init_zero(FunctionContext*, DecimalV2Val* dst) { dst->set_to_zero(); @@ -93,25 +87,6 @@ void AggregateFunctions::sum_remove(FunctionContext* ctx, const SRC_VAL& src, DS dst->val -= src.val; } -template <> -void AggregateFunctions::sum_remove(FunctionContext* ctx, const DecimalVal& src, DecimalVal* dst) { - if (ctx->impl()->num_removes() >= ctx->impl()->num_updates()) { - *dst = DecimalVal::null(); - return; - } - if (src.is_null) { - return; - } - if (dst->is_null) { - init_zero(ctx, dst); - } - - DecimalValue new_src = DecimalValue::from_decimal_val(src); - DecimalValue new_dst = DecimalValue::from_decimal_val(*dst); - new_dst = new_dst - new_src; - new_dst.to_decimal_val(dst); -} - template <> void AggregateFunctions::sum_remove(FunctionContext* ctx, const DecimalV2Val& src, DecimalV2Val* dst) { @@ -177,7 +152,7 @@ public: PercentileApproxState() : digest(new TDigest()) {} PercentileApproxState(double compression) : digest(new TDigest(compression)) {} ~PercentileApproxState() { delete digest; } - static constexpr double INIT_QUANTILE = -1.0; + static constexpr double INIT_QUANTILE = -1.0; TDigest* digest = nullptr; double targetQuantile = INIT_QUANTILE; @@ -283,11 +258,6 @@ struct AvgState { int64_t count = 0; }; -struct DecimalAvgState { - DecimalVal sum; - int64_t count; -}; - struct DecimalV2AvgState { DecimalV2Val sum; int64_t count = 0; @@ -300,16 +270,6 @@ void AggregateFunctions::avg_init(FunctionContext* ctx, StringVal* dst) { new (dst->ptr) AvgState; } -void AggregateFunctions::decimal_avg_init(FunctionContext* ctx, StringVal* dst) { - dst->is_null = false; - dst->len = sizeof(DecimalAvgState); - dst->ptr = ctx->allocate(dst->len); - // memset(dst->ptr, 0, sizeof(DecimalAvgState)); - DecimalAvgState* avg = reinterpret_cast(dst->ptr); - avg->count = 0; - avg->sum.set_to_zero(); -} - void AggregateFunctions::decimalv2_avg_init(FunctionContext* ctx, StringVal* dst) { dst->is_null = false; dst->len = sizeof(DecimalV2AvgState); @@ -331,23 +291,6 @@ void AggregateFunctions::avg_update(FunctionContext* ctx, const T& src, StringVa ++avg->count; } -void AggregateFunctions::decimal_avg_update(FunctionContext* ctx, const DecimalVal& src, - StringVal* dst) { - if (src.is_null) { - return; - } - DCHECK(dst->ptr != NULL); - DCHECK_EQ(sizeof(DecimalAvgState), dst->len); - DecimalAvgState* avg = reinterpret_cast(dst->ptr); - - DecimalValue v1 = DecimalValue::from_decimal_val(avg->sum); - DecimalValue v2 = DecimalValue::from_decimal_val(src); - DecimalValue v = v1 + v2; - v.to_decimal_val(&avg->sum); - - ++avg->count; -} - void AggregateFunctions::decimalv2_avg_update(FunctionContext* ctx, const DecimalV2Val& src, StringVal* dst) { if (src.is_null) { @@ -388,26 +331,6 @@ void AggregateFunctions::avg_remove(FunctionContext* ctx, const T& src, StringVa DCHECK_GE(avg->count, 0); } -void AggregateFunctions::decimal_avg_remove(doris_udf::FunctionContext* ctx, const DecimalVal& src, - StringVal* dst) { - // Remove doesn't need to explicitly check the number of calls to Update() or Remove() - // because Finalize() returns NULL if count is 0. - if (src.is_null) { - return; - } - DCHECK(dst->ptr != NULL); - DCHECK_EQ(sizeof(DecimalAvgState), dst->len); - DecimalAvgState* avg = reinterpret_cast(dst->ptr); - - DecimalValue v1 = DecimalValue::from_decimal_val(avg->sum); - DecimalValue v2 = DecimalValue::from_decimal_val(src); - DecimalValue v = v1 - v2; - v.to_decimal_val(&avg->sum); - - --avg->count; - DCHECK_GE(avg->count, 0); -} - void AggregateFunctions::decimalv2_avg_remove(doris_udf::FunctionContext* ctx, const DecimalV2Val& src, StringVal* dst) { // Remove doesn't need to explicitly check the number of calls to Update() or Remove() @@ -437,20 +360,6 @@ void AggregateFunctions::avg_merge(FunctionContext* ctx, const StringVal& src, S dst_struct->count += src_struct->count; } -void AggregateFunctions::decimal_avg_merge(FunctionContext* ctx, const StringVal& src, - StringVal* dst) { - const DecimalAvgState* src_struct = reinterpret_cast(src.ptr); - DCHECK(dst->ptr != NULL); - DCHECK_EQ(sizeof(DecimalAvgState), dst->len); - DecimalAvgState* dst_struct = reinterpret_cast(dst->ptr); - - DecimalValue v1 = DecimalValue::from_decimal_val(dst_struct->sum); - DecimalValue v2 = DecimalValue::from_decimal_val(src_struct->sum); - DecimalValue v = v1 + v2; - v.to_decimal_val(&dst_struct->sum); - dst_struct->count += src_struct->count; -} - void AggregateFunctions::decimalv2_avg_merge(FunctionContext* ctx, const StringVal& src, StringVal* dst) { DecimalV2AvgState src_struct; @@ -474,19 +383,6 @@ DoubleVal AggregateFunctions::avg_get_value(FunctionContext* ctx, const StringVa return DoubleVal(val_struct->sum / val_struct->count); } -DecimalVal AggregateFunctions::decimal_avg_get_value(FunctionContext* ctx, const StringVal& src) { - DecimalAvgState* val_struct = reinterpret_cast(src.ptr); - if (val_struct->count == 0) { - return DecimalVal::null(); - } - DecimalValue v1 = DecimalValue::from_decimal_val(val_struct->sum); - DecimalValue v = v1 / DecimalValue(val_struct->count); - DecimalVal res; - v.to_decimal_val(&res); - - return res; -} - DecimalV2Val AggregateFunctions::decimalv2_avg_get_value(FunctionContext* ctx, const StringVal& src) { DecimalV2AvgState* val_struct = reinterpret_cast(src.ptr); @@ -510,15 +406,6 @@ DoubleVal AggregateFunctions::avg_finalize(FunctionContext* ctx, const StringVal return result; } -DecimalVal AggregateFunctions::decimal_avg_finalize(FunctionContext* ctx, const StringVal& src) { - if (src.is_null) { - return DecimalVal::null(); - } - DecimalVal result = decimal_avg_get_value(ctx, src); - ctx->free(src.ptr); - return result; -} - DecimalV2Val AggregateFunctions::decimalv2_avg_finalize(FunctionContext* ctx, const StringVal& src) { DecimalV2Val result = decimalv2_avg_get_value(ctx, src); @@ -598,23 +485,6 @@ void AggregateFunctions::sum(FunctionContext* ctx, const SRC_VAL& src, DST_VAL* dst->val += src.val; } -template <> -void AggregateFunctions::sum(FunctionContext* ctx, const DecimalVal& src, DecimalVal* dst) { - if (src.is_null) { - return; - } - - if (dst->is_null) { - dst->is_null = false; - dst->set_to_zero(); - } - - DecimalValue new_src = DecimalValue::from_decimal_val(src); - DecimalValue new_dst = DecimalValue::from_decimal_val(*dst); - new_dst = new_dst + new_src; - new_dst.to_decimal_val(dst); -} - template <> void AggregateFunctions::sum(FunctionContext* ctx, const DecimalV2Val& src, DecimalV2Val* dst) { if (src.is_null) { @@ -668,24 +538,6 @@ void AggregateFunctions::max(FunctionContext*, const T& src, T* dst) { } } -template <> -void AggregateFunctions::min(FunctionContext*, const DecimalVal& src, DecimalVal* dst) { - if (src.is_null) { - return; - } - - if (dst->is_null) { - *dst = src; - } else { - DecimalValue new_src = DecimalValue::from_decimal_val(src); - DecimalValue new_dst = DecimalValue::from_decimal_val(*dst); - - if (new_src < new_dst) { - *dst = src; - } - } -} - template <> void AggregateFunctions::min(FunctionContext*, const DecimalV2Val& src, DecimalV2Val* dst) { if (src.is_null) { @@ -720,24 +572,6 @@ void AggregateFunctions::min(FunctionContext*, const LargeIntVal& src, LargeIntV } } -template <> -void AggregateFunctions::max(FunctionContext*, const DecimalVal& src, DecimalVal* dst) { - if (src.is_null) { - return; - } - - if (dst->is_null) { - *dst = src; - } else { - DecimalValue new_src = DecimalValue::from_decimal_val(src); - DecimalValue new_dst = DecimalValue::from_decimal_val(*dst); - - if (new_src > new_dst) { - *dst = src; - } - } -} - template <> void AggregateFunctions::max(FunctionContext*, const DecimalV2Val& src, DecimalV2Val* dst) { if (src.is_null) { @@ -1499,99 +1333,6 @@ private: FunctionContext::Type _type; }; -// multi distinct state for decimal -// serialize order type:int_len:frac_len:sign:int_len ... -class MultiDistinctDecimalState { -public: - static void create(StringVal* dst) { - dst->is_null = false; - const int state_size = sizeof(MultiDistinctDecimalState); - MultiDistinctDecimalState* state = new MultiDistinctDecimalState(); - state->_type = FunctionContext::TYPE_DECIMAL; - dst->len = state_size; - dst->ptr = (uint8_t*)state; - } - - static void destroy(const StringVal& dst) { delete (MultiDistinctDecimalState*)dst.ptr; } - - void update(DecimalVal& t) { _set.insert(DecimalValue::from_decimal_val(t)); } - - // type:one byte value:sizeof(T) - StringVal serialize(FunctionContext* ctx) { - const int serialized_set_length = - sizeof(uint8_t) + (DECIMAL_INT_LEN_BYTE_SIZE + DECIMAL_FRAC_BYTE_SIZE + - DECIMAL_SIGN_BYTE_SIZE + DECIMAL_BUFFER_BYTE_SIZE) * - _set.size(); - StringVal result(ctx, serialized_set_length); - uint8_t* writer = result.ptr; - *writer = (uint8_t)_type; - writer++; - // for int_length and frac_length, uint8_t will not overflow. - for (auto& value : _set) { - *writer = value._int_length; - writer += DECIMAL_INT_LEN_BYTE_SIZE; - *writer = value._frac_length; - writer += DECIMAL_FRAC_BYTE_SIZE; - *writer = value._sign; - writer += DECIMAL_SIGN_BYTE_SIZE; - memcpy(writer, value._buffer, DECIMAL_BUFFER_BYTE_SIZE); - writer += DECIMAL_BUFFER_BYTE_SIZE; - } - return result; - } - - void unserialize(StringVal& src) { - const uint8_t* reader = src.ptr; - // type - _type = (FunctionContext::Type)*reader; - reader++; - const uint8_t* end = src.ptr + src.len; - // value - while (reader < end) { - DecimalValue value; - value._int_length = *reader; - reader += DECIMAL_INT_LEN_BYTE_SIZE; - value._frac_length = *reader; - reader += DECIMAL_FRAC_BYTE_SIZE; - value._sign = *reader; - reader += DECIMAL_SIGN_BYTE_SIZE; - value._buffer_length = DECIMAL_BUFF_LENGTH; - memcpy(value._buffer, reader, DECIMAL_BUFFER_BYTE_SIZE); - reader += DECIMAL_BUFFER_BYTE_SIZE; - _set.insert(value); - } - } - - FunctionContext::Type set_type() { return _type; } - - // merge set - void merge(MultiDistinctDecimalState& state) { - _set.insert(state._set.begin(), state._set.end()); - } - - // count - BigIntVal count_finalize() { return BigIntVal(_set.size()); } - - DecimalVal sum_finalize() { - DecimalValue sum; - for (auto& value : _set) { - sum += value; - } - DecimalVal result; - sum.to_decimal_val(&result); - return result; - } - -private: - const int DECIMAL_INT_LEN_BYTE_SIZE = 1; - const int DECIMAL_FRAC_BYTE_SIZE = 1; - const int DECIMAL_SIGN_BYTE_SIZE = 1; - const int DECIMAL_BUFFER_BYTE_SIZE = 36; - - std::unordered_set _set; - FunctionContext::Type _type; -}; - class MultiDistinctDecimalV2State { public: static void create(StringVal* dst) { @@ -1760,10 +1501,6 @@ void AggregateFunctions::count_distinct_string_init(FunctionContext* ctx, String MultiDistinctStringCountState::create(dst); } -void AggregateFunctions::count_or_sum_distinct_decimal_init(FunctionContext* ctx, StringVal* dst) { - MultiDistinctDecimalState::create(dst); -} - void AggregateFunctions::count_or_sum_distinct_decimalv2_init(FunctionContext* ctx, StringVal* dst) { MultiDistinctDecimalV2State::create(dst); @@ -1792,14 +1529,6 @@ void AggregateFunctions::count_distinct_string_update(FunctionContext* ctx, Stri state->update(&sv); } -void AggregateFunctions::count_or_sum_distinct_decimal_update(FunctionContext* ctx, DecimalVal& src, - StringVal* dst) { - DCHECK(!dst->is_null); - if (src.is_null) return; - MultiDistinctDecimalState* state = reinterpret_cast(dst->ptr); - state->update(src); -} - void AggregateFunctions::count_or_sum_distinct_decimalv2_update(FunctionContext* ctx, DecimalV2Val& src, StringVal* dst) { DCHECK(!dst->is_null); @@ -1851,22 +1580,6 @@ void AggregateFunctions::count_distinct_string_merge(FunctionContext* ctx, Strin MultiDistinctStringCountState::destroy(src_state_val); } -void AggregateFunctions::count_or_sum_distinct_decimal_merge(FunctionContext* ctx, StringVal& src, - StringVal* dst) { - DCHECK(!dst->is_null); - DCHECK(!src.is_null); - MultiDistinctDecimalState* dst_state = reinterpret_cast(dst->ptr); - // unserialize src - StringVal src_state_val; - MultiDistinctDecimalState::create(&src_state_val); - MultiDistinctDecimalState* src_state = - reinterpret_cast(src_state_val.ptr); - src_state->unserialize(src); - DCHECK(dst_state->set_type() == src_state->set_type()); - dst_state->merge(*src_state); - MultiDistinctDecimalState::destroy(src_state_val); -} - void AggregateFunctions::count_or_sum_distinct_decimalv2_merge(FunctionContext* ctx, StringVal& src, StringVal* dst) { DCHECK(!dst->is_null); @@ -1924,16 +1637,6 @@ StringVal AggregateFunctions::count_distinct_string_serialize(FunctionContext* c return result; } -StringVal AggregateFunctions::count_or_sum_distinct_decimal_serialize(FunctionContext* ctx, - const StringVal& state_sv) { - DCHECK(!state_sv.is_null); - MultiDistinctDecimalState* state = reinterpret_cast(state_sv.ptr); - StringVal result = state->serialize(ctx); - // release original object - MultiDistinctDecimalState::destroy(state_sv); - return result; -} - StringVal AggregateFunctions::count_or_sum_distinct_decimalv2_serialize(FunctionContext* ctx, const StringVal& state_sv) { DCHECK(!state_sv.is_null); @@ -2010,15 +1713,6 @@ BigIntVal AggregateFunctions::sum_distinct_bigint_finalize(FunctionContext* ctx, return result; } -BigIntVal AggregateFunctions::count_distinct_decimal_finalize(FunctionContext* ctx, - const StringVal& state_sv) { - DCHECK(!state_sv.is_null); - MultiDistinctDecimalState* state = reinterpret_cast(state_sv.ptr); - BigIntVal result = state->count_finalize(); - MultiDistinctDecimalState::destroy(state_sv); - return result; -} - BigIntVal AggregateFunctions::count_distinct_decimalv2_finalize(FunctionContext* ctx, const StringVal& state_sv) { DCHECK(!state_sv.is_null); @@ -2029,15 +1723,6 @@ BigIntVal AggregateFunctions::count_distinct_decimalv2_finalize(FunctionContext* return result; } -DecimalVal AggregateFunctions::sum_distinct_decimal_finalize(FunctionContext* ctx, - const StringVal& state_sv) { - DCHECK(!state_sv.is_null); - MultiDistinctDecimalState* state = reinterpret_cast(state_sv.ptr); - DecimalVal result = state->sum_finalize(); - MultiDistinctDecimalState::destroy(state_sv); - return result; -} - DecimalV2Val AggregateFunctions::sum_distinct_decimalv2_finalize(FunctionContext* ctx, const StringVal& state_sv) { DCHECK(!state_sv.is_null); @@ -2084,13 +1769,16 @@ static double compute_knuth_variance(const KnuthVarianceState& state, bool pop) } // The algorithm is the same as above, using decimal as the intermediate variable -static DecimalV2Value decimalv2_compute_knuth_variance(const DecimalV2KnuthVarianceState& state, bool pop) { +static DecimalV2Value decimalv2_compute_knuth_variance(const DecimalV2KnuthVarianceState& state, + bool pop) { DecimalV2Value new_count = DecimalV2Value(); new_count.assign_from_double(state.count); if (state.count == 1) return new_count; DecimalV2Value new_m2 = DecimalV2Value::from_decimal_val(state.m2); - if (pop) return new_m2 / new_count; - else return new_m2 / new_count.assign_from_double(state.count - 1); + if (pop) + return new_m2 / new_count; + else + return new_m2 / new_count.assign_from_double(state.count - 1); } void AggregateFunctions::knuth_var_init(FunctionContext* ctx, StringVal* dst) { @@ -2108,7 +1796,7 @@ void AggregateFunctions::decimalv2_knuth_var_init(FunctionContext* ctx, StringVa // The memory for int128 need to be aligned by 16. // So the constructor has been used instead of allocating memory. // Also, it will be release in finalize. - dst->ptr = (uint8_t*) new DecimalV2KnuthVarianceState; + dst->ptr = (uint8_t*)new DecimalV2KnuthVarianceState; } template @@ -2125,16 +1813,17 @@ void AggregateFunctions::knuth_var_update(FunctionContext* ctx, const T& src, St state->count = temp; } -void AggregateFunctions::knuth_var_update(FunctionContext* ctx, const DecimalV2Val& src, StringVal* dst) { +void AggregateFunctions::knuth_var_update(FunctionContext* ctx, const DecimalV2Val& src, + StringVal* dst) { DCHECK(!dst->is_null); DCHECK_EQ(dst->len, sizeof(DecimalV2KnuthVarianceState)); if (src.is_null) return; DecimalV2KnuthVarianceState* state = reinterpret_cast(dst->ptr); - + DecimalV2Value new_src = DecimalV2Value::from_decimal_val(src); DecimalV2Value new_mean = DecimalV2Value::from_decimal_val(state->mean); DecimalV2Value new_m2 = DecimalV2Value::from_decimal_val(state->m2); - DecimalV2Value new_count = DecimalV2Value(); + DecimalV2Value new_count = DecimalV2Value(); new_count.assign_from_double(state->count); DecimalV2Value temp = DecimalV2Value(); @@ -2143,7 +1832,7 @@ void AggregateFunctions::knuth_var_update(FunctionContext* ctx, const DecimalV2V DecimalV2Value r = delta / temp; new_mean += r; // This may cause Decimal to overflow. When it overflows, m2 will be equal to 9223372036854775807999999999, - // which is the maximum value that DecimalV2Value can represent. When using double to store the intermediate result m2, + // which is the maximum value that DecimalV2Value can represent. When using double to store the intermediate result m2, // it can be expressed by scientific and technical methods and will not overflow. // Spark's handling of decimal overflow is to return null or report an error, which can be controlled by parameters. // Spark's handling of decimal reference: https://cloud.tencent.com/developer/news/483615 @@ -2173,12 +1862,13 @@ void AggregateFunctions::knuth_var_merge(FunctionContext* ctx, const StringVal& } void AggregateFunctions::decimalv2_knuth_var_merge(FunctionContext* ctx, const StringVal& src, - StringVal* dst) { + StringVal* dst) { DecimalV2KnuthVarianceState src_state; memcpy(&src_state, src.ptr, sizeof(DecimalV2KnuthVarianceState)); DCHECK(!dst->is_null); DCHECK_EQ(dst->len, sizeof(DecimalV2KnuthVarianceState)); - DecimalV2KnuthVarianceState* dst_state = reinterpret_cast(dst->ptr); + DecimalV2KnuthVarianceState* dst_state = + reinterpret_cast(dst->ptr); if (src_state.count == 0) return; DecimalV2Value new_src_mean = DecimalV2Value::from_decimal_val(src_state.mean); @@ -2193,7 +1883,8 @@ void AggregateFunctions::decimalv2_knuth_var_merge(FunctionContext* ctx, const S DecimalV2Value delta = new_dst_mean - new_src_mean; DecimalV2Value sum_count = new_dst_count + new_src_count; new_dst_mean = new_src_mean + delta * (new_dst_count / sum_count); - new_dst_m2 = (new_src_m2) + new_dst_m2 + (delta * delta) * (new_src_count * new_dst_count / sum_count); + new_dst_m2 = (new_src_m2) + new_dst_m2 + + (delta * delta) * (new_src_count * new_dst_count / sum_count); dst_state->count += src_state.count; new_dst_mean.to_decimal_val(&dst_state->mean); new_dst_m2.to_decimal_val(&dst_state->m2); @@ -2209,10 +1900,11 @@ DoubleVal AggregateFunctions::knuth_var_finalize(FunctionContext* ctx, const Str } DecimalV2Val AggregateFunctions::decimalv2_knuth_var_finalize(FunctionContext* ctx, - const StringVal& state_sv) { + const StringVal& state_sv) { DCHECK(!state_sv.is_null); DCHECK_EQ(state_sv.len, sizeof(DecimalV2KnuthVarianceState)); - DecimalV2KnuthVarianceState* state = reinterpret_cast(state_sv.ptr); + DecimalV2KnuthVarianceState* state = + reinterpret_cast(state_sv.ptr); if (state->count == 0 || state->count == 1) return DecimalV2Val::null(); DecimalV2Value variance = decimalv2_compute_knuth_variance(*state, false); DecimalV2Val res; @@ -2233,10 +1925,11 @@ DoubleVal AggregateFunctions::knuth_var_pop_finalize(FunctionContext* ctx, } DecimalV2Val AggregateFunctions::decimalv2_knuth_var_pop_finalize(FunctionContext* ctx, - const StringVal& state_sv) { + const StringVal& state_sv) { DCHECK(!state_sv.is_null); DCHECK_EQ(state_sv.len, sizeof(DecimalV2KnuthVarianceState)); - DecimalV2KnuthVarianceState* state = reinterpret_cast(state_sv.ptr); + DecimalV2KnuthVarianceState* state = + reinterpret_cast(state_sv.ptr); if (state->count == 0) return DecimalV2Val::null(); DecimalV2Value variance = decimalv2_compute_knuth_variance(*state, true); DecimalV2Val res; @@ -2257,10 +1950,11 @@ DoubleVal AggregateFunctions::knuth_stddev_finalize(FunctionContext* ctx, } DecimalV2Val AggregateFunctions::decimalv2_knuth_stddev_finalize(FunctionContext* ctx, - const StringVal& state_sv) { + const StringVal& state_sv) { DCHECK(!state_sv.is_null); DCHECK_EQ(state_sv.len, sizeof(DecimalV2KnuthVarianceState)); - DecimalV2KnuthVarianceState* state = reinterpret_cast(state_sv.ptr); + DecimalV2KnuthVarianceState* state = + reinterpret_cast(state_sv.ptr); if (state->count == 0 || state->count == 1) return DecimalV2Val::null(); DecimalV2Value variance = decimalv2_compute_knuth_variance(*state, false); variance = DecimalV2Value::sqrt(variance); @@ -2282,10 +1976,11 @@ DoubleVal AggregateFunctions::knuth_stddev_pop_finalize(FunctionContext* ctx, } DecimalV2Val AggregateFunctions::decimalv2_knuth_stddev_pop_finalize(FunctionContext* ctx, - const StringVal& state_sv) { + const StringVal& state_sv) { DCHECK(!state_sv.is_null); DCHECK_EQ(state_sv.len, sizeof(DecimalV2KnuthVarianceState)); - DecimalV2KnuthVarianceState* state = reinterpret_cast(state_sv.ptr); + DecimalV2KnuthVarianceState* state = + reinterpret_cast(state_sv.ptr); if (state->count == 0) return DecimalV2Val::null(); DecimalV2Value variance = decimalv2_compute_knuth_variance(*state, true); variance = DecimalV2Value::sqrt(variance); @@ -2528,9 +2223,6 @@ template void AggregateFunctions::sum_remove(FunctionContex template void AggregateFunctions::sum_remove(FunctionContext*, const DoubleVal& src, DoubleVal* dst); -template void AggregateFunctions::sum_remove(FunctionContext*, - const DecimalVal& src, - DecimalVal* dst); template void AggregateFunctions::sum_remove(FunctionContext*, const DecimalV2Val& src, DecimalV2Val* dst); @@ -2664,7 +2356,6 @@ template void AggregateFunctions::hll_update(FunctionContext*, const DoubleVal&, template void AggregateFunctions::hll_update(FunctionContext*, const StringVal&, StringVal*); template void AggregateFunctions::hll_update(FunctionContext*, const DateTimeVal&, StringVal*); template void AggregateFunctions::hll_update(FunctionContext*, const LargeIntVal&, StringVal*); -template void AggregateFunctions::hll_update(FunctionContext*, const DecimalVal&, StringVal*); template void AggregateFunctions::hll_update(FunctionContext*, const DecimalV2Val&, StringVal*); template void AggregateFunctions::count_or_sum_distinct_numeric_init( @@ -2825,20 +2516,11 @@ template void AggregateFunctions::first_val_rewrite_update(Function const DateTimeVal& src, const BigIntVal&, DateTimeVal* dst); -template void AggregateFunctions::first_val_rewrite_update(FunctionContext*, - const DecimalVal& src, - const BigIntVal&, - DecimalVal* dst); template void AggregateFunctions::first_val_rewrite_update(FunctionContext*, const DecimalV2Val& src, const BigIntVal&, DecimalV2Val* dst); -//template void AggregateFunctions::FirstValUpdate( -// doris_udf::FunctionContext*, impala::StringValue const&, impala::StringValue*); -template void AggregateFunctions::first_val_update( - doris_udf::FunctionContext*, doris_udf::DecimalVal const&, doris_udf::DecimalVal*); - template void AggregateFunctions::first_val_update( doris_udf::FunctionContext*, doris_udf::DecimalV2Val const&, doris_udf::DecimalV2Val*); @@ -2864,9 +2546,6 @@ template void AggregateFunctions::last_val_update(FunctionContext*, c template void AggregateFunctions::last_val_update(FunctionContext*, const DateTimeVal& src, DateTimeVal* dst); -template void AggregateFunctions::last_val_update(FunctionContext*, - const DecimalVal& src, - DecimalVal* dst); template void AggregateFunctions::last_val_update(FunctionContext*, const DecimalV2Val& src, DecimalV2Val* dst); @@ -2893,9 +2572,6 @@ template void AggregateFunctions::last_val_remove(FunctionContext*, c template void AggregateFunctions::last_val_remove(FunctionContext*, const DateTimeVal& src, DateTimeVal* dst); -template void AggregateFunctions::last_val_remove(FunctionContext*, - const DecimalVal& src, - DecimalVal* dst); template void AggregateFunctions::last_val_remove(FunctionContext*, const DecimalV2Val& src, DecimalV2Val* dst); @@ -2908,7 +2584,6 @@ template void AggregateFunctions::offset_fn_init(FunctionContext*, Bi template void AggregateFunctions::offset_fn_init(FunctionContext*, FloatVal*); template void AggregateFunctions::offset_fn_init(FunctionContext*, DoubleVal*); template void AggregateFunctions::offset_fn_init(FunctionContext*, DateTimeVal*); -template void AggregateFunctions::offset_fn_init(FunctionContext*, DecimalVal*); template void AggregateFunctions::offset_fn_init(FunctionContext*, DecimalV2Val*); template void AggregateFunctions::offset_fn_update(FunctionContext*, @@ -2947,10 +2622,6 @@ template void AggregateFunctions::offset_fn_update(FunctionContext* const BigIntVal&, const DateTimeVal&, DateTimeVal* dst); -template void AggregateFunctions::offset_fn_update(FunctionContext*, - const DecimalVal& src, - const BigIntVal&, const DecimalVal&, - DecimalVal* dst); template void AggregateFunctions::offset_fn_update(FunctionContext*, const DecimalV2Val& src, const BigIntVal&, diff --git a/be/src/exprs/aggregate_functions.h b/be/src/exprs/aggregate_functions.h index 8e2ea40ecc..39e9aa891b 100644 --- a/be/src/exprs/aggregate_functions.h +++ b/be/src/exprs/aggregate_functions.h @@ -109,29 +109,18 @@ public: const doris_udf::StringVal& val); // Avg for decimals. - static void decimal_avg_init(doris_udf::FunctionContext* ctx, doris_udf::StringVal* dst); static void decimalv2_avg_init(doris_udf::FunctionContext* ctx, doris_udf::StringVal* dst); - static void decimal_avg_update(doris_udf::FunctionContext* ctx, - const doris_udf::DecimalVal& src, doris_udf::StringVal* dst); static void decimalv2_avg_update(doris_udf::FunctionContext* ctx, const doris_udf::DecimalV2Val& src, doris_udf::StringVal* dst); - static void decimal_avg_merge(FunctionContext* ctx, const doris_udf::StringVal& src, - doris_udf::StringVal* dst); static void decimalv2_avg_merge(FunctionContext* ctx, const doris_udf::StringVal& src, doris_udf::StringVal* dst); static doris_udf::StringVal decimalv2_avg_serialize(doris_udf::FunctionContext* ctx, const doris_udf::StringVal& src); - static void decimal_avg_remove(doris_udf::FunctionContext* ctx, - const doris_udf::DecimalVal& src, doris_udf::StringVal* dst); static void decimalv2_avg_remove(doris_udf::FunctionContext* ctx, const doris_udf::DecimalV2Val& src, doris_udf::StringVal* dst); - static doris_udf::DecimalVal decimal_avg_get_value(doris_udf::FunctionContext* ctx, - const doris_udf::StringVal& val); static doris_udf::DecimalV2Val decimalv2_avg_get_value(doris_udf::FunctionContext* ctx, const doris_udf::StringVal& val); - static doris_udf::DecimalVal decimal_avg_finalize(doris_udf::FunctionContext* ctx, - const doris_udf::StringVal& val); static doris_udf::DecimalV2Val decimalv2_avg_finalize(doris_udf::FunctionContext* ctx, const doris_udf::StringVal& val); // SumUpdate, SumMerge @@ -207,8 +196,6 @@ public: doris_udf::StringVal* dst); static void count_or_sum_distinct_decimalv2_init(doris_udf::FunctionContext* ctx, doris_udf::StringVal* dst); - static void count_or_sum_distinct_decimal_update(FunctionContext* ctx, DecimalVal& src, - StringVal* dst); static void count_or_sum_distinct_decimalv2_update(FunctionContext* ctx, DecimalV2Val& src, StringVal* dst); static void count_or_sum_distinct_decimal_merge(FunctionContext* ctx, StringVal& src, @@ -223,8 +210,6 @@ public: const StringVal& state_sv); static BigIntVal count_distinct_decimalv2_finalize(FunctionContext* ctx, const StringVal& state_sv); - static DecimalVal sum_distinct_decimal_finalize(FunctionContext* ctx, - const StringVal& state_sv); static DecimalV2Val sum_distinct_decimalv2_finalize(FunctionContext* ctx, const StringVal& state_sv); @@ -265,11 +250,16 @@ public: // variance/stddev for decimals. static void decimalv2_knuth_var_init(FunctionContext* context, StringVal* val); static void knuth_var_update(FunctionContext* context, const DecimalV2Val& src, StringVal* val); - static void decimalv2_knuth_var_merge(FunctionContext* context, const StringVal& src, StringVal* val); - static DecimalV2Val decimalv2_knuth_var_finalize(FunctionContext* context, const StringVal& val); - static DecimalV2Val decimalv2_knuth_var_pop_finalize(FunctionContext* context, const StringVal& val); - static DecimalV2Val decimalv2_knuth_stddev_finalize(FunctionContext* context, const StringVal& val); - static DecimalV2Val decimalv2_knuth_stddev_pop_finalize(FunctionContext* context, const StringVal& val); + static void decimalv2_knuth_var_merge(FunctionContext* context, const StringVal& src, + StringVal* val); + static DecimalV2Val decimalv2_knuth_var_finalize(FunctionContext* context, + const StringVal& val); + static DecimalV2Val decimalv2_knuth_var_pop_finalize(FunctionContext* context, + const StringVal& val); + static DecimalV2Val decimalv2_knuth_stddev_finalize(FunctionContext* context, + const StringVal& val); + static DecimalV2Val decimalv2_knuth_stddev_pop_finalize(FunctionContext* context, + const StringVal& val); /// ----------------------------- Analytic Functions --------------------------------- /// Analytic functions implement the UDA interface (except Merge(), Serialize()) and are diff --git a/be/src/exprs/anyval_util.cpp b/be/src/exprs/anyval_util.cpp index e30bee239a..baff010e18 100644 --- a/be/src/exprs/anyval_util.cpp +++ b/be/src/exprs/anyval_util.cpp @@ -29,7 +29,6 @@ using doris_udf::BigIntVal; using doris_udf::LargeIntVal; using doris_udf::FloatVal; using doris_udf::DoubleVal; -using doris_udf::DecimalVal; using doris_udf::DecimalV2Val; using doris_udf::DateTimeVal; using doris_udf::StringVal; @@ -83,9 +82,6 @@ AnyVal* create_any_val(ObjectPool* pool, const TypeDescriptor& type) { case TYPE_OBJECT: return pool->add(new StringVal); - case TYPE_DECIMAL: - return pool->add(new DecimalVal); - case TYPE_DECIMALV2: return pool->add(new DecimalV2Val); @@ -148,11 +144,6 @@ FunctionContext::TypeDesc AnyValUtil::column_type_to_type_desc(const TypeDescrip out.type = FunctionContext::TYPE_CHAR; out.len = type.len; break; - case TYPE_DECIMAL: - out.type = FunctionContext::TYPE_DECIMAL; - // out.precision = type.precision; - // out.scale = type.scale; - break; case TYPE_DECIMALV2: out.type = FunctionContext::TYPE_DECIMALV2; // out.precision = type.precision; diff --git a/be/src/exprs/anyval_util.h b/be/src/exprs/anyval_util.h index e841cb16bf..daa1a0f514 100644 --- a/be/src/exprs/anyval_util.h +++ b/be/src/exprs/anyval_util.h @@ -69,11 +69,6 @@ public: return tv.hash(seed); } - static uint32_t hash(const doris_udf::DecimalVal& v, int seed) { - DecimalValue tv = DecimalValue::from_decimal_val(v); - return tv.hash(seed); - } - static uint32_t hash(const doris_udf::DecimalV2Val& v, int seed) { return HashUtil::hash(&v.val, 16, seed); } @@ -119,13 +114,6 @@ public: return HashUtil::fnv_hash64(&tv, 12, seed); } - // TODO(lingbin): fix this method. can not use sizeof directly, because there are a lot of - // storage way for one value. - static uint64_t hash64(const doris_udf::DecimalVal& v, int64_t seed) { - DecimalValue tv = DecimalValue::from_decimal_val(v); - return HashUtil::fnv_hash64(&tv, sizeof(DecimalValue), seed); - } - static uint64_t hash64(const doris_udf::DecimalV2Val& v, int64_t seed) { return HashUtil::fnv_hash64(&v.val, 16, seed); } @@ -171,11 +159,6 @@ public: return HashUtil::murmur_hash64A(&tv, 12, seed); } - static uint64_t hash64_murmur(const doris_udf::DecimalVal& v, int64_t seed) { - DecimalValue tv = DecimalValue::from_decimal_val(v); - return HashUtil::murmur_hash64A(&tv, sizeof(DecimalValue), seed); - } - static uint64_t hash64_murmur(const doris_udf::DecimalV2Val& v, int64_t seed) { return HashUtil::murmur_hash64A(&v.val, 16, seed); } @@ -221,9 +204,6 @@ public: case TYPE_DATETIME: return sizeof(doris_udf::DateTimeVal); - case TYPE_DECIMAL: - return sizeof(doris_udf::DecimalVal); - case TYPE_DECIMALV2: return sizeof(doris_udf::DecimalV2Val); @@ -260,8 +240,6 @@ public: case TYPE_DATETIME: case TYPE_DATE: return alignof(DateTimeVal); - case TYPE_DECIMAL: - return alignof(DecimalVal); case TYPE_DECIMALV2: return alignof(DecimalV2Val); default: @@ -355,10 +333,6 @@ public: reinterpret_cast(slot)->to_string_val( reinterpret_cast(dst)); return; - case TYPE_DECIMAL: - reinterpret_cast(slot)->to_decimal_val( - reinterpret_cast(dst)); - return; case TYPE_DECIMALV2: reinterpret_cast(dst)->val = reinterpret_cast(slot)->value; @@ -429,13 +403,6 @@ inline bool AnyValUtil::equals_internal(const DateTimeVal& x, const DateTimeVal& return x_tv == y_tv; } -template <> -inline bool AnyValUtil::equals_internal(const DecimalVal& x, const DecimalVal& y) { - DCHECK(!x.is_null); - DCHECK(!y.is_null); - return x == y; -} - template <> inline bool AnyValUtil::equals_internal(const DecimalV2Val& x, const DecimalV2Val& y) { DCHECK(!x.is_null); diff --git a/be/src/exprs/binary_predicate.cpp b/be/src/exprs/binary_predicate.cpp index 51e889e7b1..7d67b160b2 100644 --- a/be/src/exprs/binary_predicate.cpp +++ b/be/src/exprs/binary_predicate.cpp @@ -21,7 +21,6 @@ #include "gen_cpp/Exprs_types.h" #include "runtime/datetime_value.h" -#include "runtime/decimal_value.h" #include "runtime/decimalv2_value.h" #include "runtime/runtime_state.h" #include "runtime/string_value.h" @@ -55,8 +54,6 @@ Expr* BinaryPredicate::from_thrift(const TExprNode& node) { case TPrimitiveType::DATE: case TPrimitiveType::DATETIME: return new EqDateTimeValPred(node); - case TPrimitiveType::DECIMAL: - return new EqDecimalValPred(node); case TPrimitiveType::DECIMALV2: return new EqDecimalV2ValPred(node); default: @@ -87,8 +84,6 @@ Expr* BinaryPredicate::from_thrift(const TExprNode& node) { case TPrimitiveType::DATE: case TPrimitiveType::DATETIME: return new NeDateTimeValPred(node); - case TPrimitiveType::DECIMAL: - return new NeDecimalValPred(node); case TPrimitiveType::DECIMALV2: return new NeDecimalV2ValPred(node); default: @@ -119,8 +114,6 @@ Expr* BinaryPredicate::from_thrift(const TExprNode& node) { case TPrimitiveType::DATE: case TPrimitiveType::DATETIME: return new LtDateTimeValPred(node); - case TPrimitiveType::DECIMAL: - return new LtDecimalValPred(node); case TPrimitiveType::DECIMALV2: return new LtDecimalV2ValPred(node); default: @@ -151,8 +144,6 @@ Expr* BinaryPredicate::from_thrift(const TExprNode& node) { case TPrimitiveType::DATE: case TPrimitiveType::DATETIME: return new LeDateTimeValPred(node); - case TPrimitiveType::DECIMAL: - return new LeDecimalValPred(node); case TPrimitiveType::DECIMALV2: return new LeDecimalV2ValPred(node); default: @@ -183,8 +174,6 @@ Expr* BinaryPredicate::from_thrift(const TExprNode& node) { case TPrimitiveType::DATE: case TPrimitiveType::DATETIME: return new GtDateTimeValPred(node); - case TPrimitiveType::DECIMAL: - return new GtDecimalValPred(node); case TPrimitiveType::DECIMALV2: return new GtDecimalV2ValPred(node); default: @@ -215,8 +204,6 @@ Expr* BinaryPredicate::from_thrift(const TExprNode& node) { case TPrimitiveType::DATE: case TPrimitiveType::DATETIME: return new GeDateTimeValPred(node); - case TPrimitiveType::DECIMAL: - return new GeDecimalValPred(node); case TPrimitiveType::DECIMALV2: return new GeDecimalV2ValPred(node); default: @@ -247,8 +234,6 @@ Expr* BinaryPredicate::from_thrift(const TExprNode& node) { case TPrimitiveType::DATE: case TPrimitiveType::DATETIME: return new EqForNullDateTimeValPred(node); - case TPrimitiveType::DECIMAL: - return new EqForNullDecimalValPred(node); case TPrimitiveType::DECIMALV2: return new EqForNullDecimalV2ValPred(node); default: @@ -330,7 +315,6 @@ BINARY_PRED_FLOAT_FNS(DoubleVal, get_double_val); COMPLICATE_BINARY_PRED_FN(Gt##TYPE##Pred, TYPE, FN, DORIS_TYPE, FROM_FUNC, >) \ COMPLICATE_BINARY_PRED_FN(Ge##TYPE##Pred, TYPE, FN, DORIS_TYPE, FROM_FUNC, >=) -COMPLICATE_BINARY_PRED_FNS(DecimalVal, get_decimal_val, DecimalValue, from_decimal_val) COMPLICATE_BINARY_PRED_FNS(DecimalV2Val, get_decimalv2_val, DecimalV2Value, from_decimal_val) #define DATETIME_BINARY_PRED_FN(CLASS, OP, LLVM_PRED) \ @@ -441,7 +425,6 @@ BINARY_PRED_FOR_NULL_FLOAT_FNS(DoubleVal, get_double_val); #define COMPLICATE_BINARY_FOR_NULL_PRED_FNS(TYPE, FN, DORIS_TYPE, FROM_FUNC) \ COMPLICATE_BINARY_FOR_NULL_PRED_FN(EqForNull##TYPE##Pred, TYPE, FN, DORIS_TYPE, FROM_FUNC, ==) -COMPLICATE_BINARY_FOR_NULL_PRED_FNS(DecimalVal, get_decimal_val, DecimalValue, from_decimal_val) COMPLICATE_BINARY_FOR_NULL_PRED_FNS(DecimalV2Val, get_decimalv2_val, DecimalV2Value, from_decimal_val) diff --git a/be/src/exprs/binary_predicate.h b/be/src/exprs/binary_predicate.h index 2286362985..bbf68a30d6 100644 --- a/be/src/exprs/binary_predicate.h +++ b/be/src/exprs/binary_predicate.h @@ -70,7 +70,6 @@ BIN_PRED_CLASSES_DEFINE(FloatVal) BIN_PRED_CLASSES_DEFINE(DoubleVal) BIN_PRED_CLASSES_DEFINE(StringVal) BIN_PRED_CLASSES_DEFINE(DateTimeVal) -BIN_PRED_CLASSES_DEFINE(DecimalVal) BIN_PRED_CLASSES_DEFINE(DecimalV2Val) #define BIN_PRED_FOR_NULL_CLASS_DEFINE(CLASS) \ @@ -97,7 +96,6 @@ BIN_PRED_FOR_NULL_CLASSES_DEFINE(FloatVal) BIN_PRED_FOR_NULL_CLASSES_DEFINE(DoubleVal) BIN_PRED_FOR_NULL_CLASSES_DEFINE(StringVal) BIN_PRED_FOR_NULL_CLASSES_DEFINE(DateTimeVal) -BIN_PRED_FOR_NULL_CLASSES_DEFINE(DecimalVal) BIN_PRED_FOR_NULL_CLASSES_DEFINE(DecimalV2Val) } // namespace doris #endif diff --git a/be/src/exprs/bloomfilter_predicate.cpp b/be/src/exprs/bloomfilter_predicate.cpp index 34c51271c8..9f98c1da41 100644 --- a/be/src/exprs/bloomfilter_predicate.cpp +++ b/be/src/exprs/bloomfilter_predicate.cpp @@ -56,9 +56,6 @@ BloomFilterFuncBase* BloomFilterFuncBase::create_bloom_filter(MemTracker* tracke case TYPE_DATETIME: return new (std::nothrow) DateTimeBloomFilterFunc(tracker); - case TYPE_DECIMAL: - return new (std::nothrow) DecimalFilterFunc(tracker); - case TYPE_DECIMALV2: return new (std::nothrow) DecimalV2FilterFunc(tracker); diff --git a/be/src/exprs/bloomfilter_predicate.h b/be/src/exprs/bloomfilter_predicate.h index c7270558c1..21c7176df7 100644 --- a/be/src/exprs/bloomfilter_predicate.h +++ b/be/src/exprs/bloomfilter_predicate.h @@ -221,18 +221,6 @@ public: } }; -class DecimalFilterFunc : public BloomFilterFunc { -public: - DecimalFilterFunc(MemTracker* tracker) : BloomFilterFunc(tracker) {} - - virtual bool find_olap_engine(const void* data) { - int64_t int_value = *(int64_t*)(data); - int32_t frac_value = *(int32_t*)((char*)data + sizeof(int64_t)); - DecimalValue value(int_value, frac_value); - return _bloom_filter->test_bytes((char*)&value, sizeof(DecimalValue)); - } -}; - class DecimalV2FilterFunc : public BloomFilterFunc { public: DecimalV2FilterFunc(MemTracker* tracker) : BloomFilterFunc(tracker) {} diff --git a/be/src/exprs/case_expr.cpp b/be/src/exprs/case_expr.cpp index af5b093b64..5602d067e0 100644 --- a/be/src/exprs/case_expr.cpp +++ b/be/src/exprs/case_expr.cpp @@ -17,8 +17,8 @@ #include "exprs/case_expr.h" -#include "exprs/expr_context.h" #include "exprs/anyval_util.h" +#include "exprs/expr_context.h" #include "gen_cpp/Exprs_types.h" #include "runtime/runtime_state.h" @@ -112,9 +112,6 @@ void CaseExpr::get_child_val(int child_idx, ExprContext* ctx, TupleRow* row, Any case TYPE_OBJECT: *reinterpret_cast(dst) = _children[child_idx]->get_string_val(ctx, row); break; - case TYPE_DECIMAL: - *reinterpret_cast(dst) = _children[child_idx]->get_decimal_val(ctx, row); - break; case TYPE_DECIMALV2: *reinterpret_cast(dst) = _children[child_idx]->get_decimalv2_val(ctx, row); break; @@ -159,9 +156,6 @@ bool CaseExpr::any_val_eq(const TypeDescriptor& type, const AnyVal* v1, const An case TYPE_OBJECT: return AnyValUtil::equals(type, *reinterpret_cast(v1), *reinterpret_cast(v2)); - case TYPE_DECIMAL: - return AnyValUtil::equals(type, *reinterpret_cast(v1), - *reinterpret_cast(v2)); case TYPE_DECIMALV2: return AnyValUtil::equals(type, *reinterpret_cast(v1), *reinterpret_cast(v2)); @@ -226,7 +220,6 @@ CASE_COMPUTE_FN_WRAPPER(FloatVal, float_val) CASE_COMPUTE_FN_WRAPPER(DoubleVal, double_val) CASE_COMPUTE_FN_WRAPPER(StringVal, string_val) CASE_COMPUTE_FN_WRAPPER(DateTimeVal, datetime_val) -CASE_COMPUTE_FN_WRAPPER(DecimalVal, decimal_val) CASE_COMPUTE_FN_WRAPPER(DecimalV2Val, decimalv2_val) } // namespace doris diff --git a/be/src/exprs/case_expr.h b/be/src/exprs/case_expr.h index 33816bed43..dd10ceafce 100644 --- a/be/src/exprs/case_expr.h +++ b/be/src/exprs/case_expr.h @@ -40,7 +40,6 @@ public: virtual DoubleVal get_double_val(ExprContext* ctx, TupleRow* row); virtual StringVal get_string_val(ExprContext* ctx, TupleRow* row); virtual DateTimeVal get_datetime_val(ExprContext* ctx, TupleRow* row); - virtual DecimalVal get_decimal_val(ExprContext* ctx, TupleRow* row); virtual DecimalV2Val get_decimalv2_val(ExprContext* ctx, TupleRow* row); protected: diff --git a/be/src/exprs/cast_functions.cpp b/be/src/exprs/cast_functions.cpp index 351596f787..2c950e2dfd 100644 --- a/be/src/exprs/cast_functions.cpp +++ b/be/src/exprs/cast_functions.cpp @@ -20,6 +20,7 @@ #include #include "exprs/anyval_util.h" +#include "gutil/strings/numbers.h" #include "runtime/datetime_value.h" #include "runtime/string_value.h" #include "string_functions.h" diff --git a/be/src/exprs/conditional_functions.h b/be/src/exprs/conditional_functions.h index 51a7a6fe8b..c579fb98c3 100644 --- a/be/src/exprs/conditional_functions.h +++ b/be/src/exprs/conditional_functions.h @@ -50,7 +50,6 @@ public: virtual DoubleVal get_double_val(ExprContext* context, TupleRow* row); virtual StringVal get_string_val(ExprContext* context, TupleRow* row); virtual DateTimeVal get_datetime_val(ExprContext* context, TupleRow* row); - virtual DecimalVal get_decimal_val(ExprContext* context, TupleRow* row); virtual DecimalV2Val get_decimalv2_val(ExprContext* context, TupleRow* row); virtual LargeIntVal get_large_int_val(ExprContext* context, TupleRow* row); @@ -76,7 +75,6 @@ public: virtual DoubleVal get_double_val(ExprContext* context, TupleRow* row); virtual StringVal get_string_val(ExprContext* context, TupleRow* row); virtual DateTimeVal get_datetime_val(ExprContext* context, TupleRow* row); -// virtual DecimalVal get_decimal_val(ExprContext* context, TupleRow* row); virtual DecimalV2Val get_decimalv2_val(ExprContext* context, TupleRow* row); virtual LargeIntVal get_large_int_val(ExprContext* context, TupleRow* row); @@ -100,7 +98,6 @@ public: virtual DoubleVal get_double_val(ExprContext* context, TupleRow* row); virtual StringVal get_string_val(ExprContext* context, TupleRow* row); virtual DateTimeVal get_datetime_val(ExprContext* context, TupleRow* row); - virtual DecimalVal get_decimal_val(ExprContext* context, TupleRow* row); virtual DecimalV2Val get_decimalv2_val(ExprContext* context, TupleRow* row); virtual LargeIntVal get_large_int_val(ExprContext* context, TupleRow* row); @@ -127,7 +124,6 @@ public: virtual DoubleVal get_double_val(ExprContext* context, TupleRow* row); virtual StringVal get_string_val(ExprContext* context, TupleRow* row); virtual DateTimeVal get_datetime_val(ExprContext* context, TupleRow* row); - virtual DecimalVal get_decimal_val(ExprContext* context, TupleRow* row); virtual DecimalV2Val get_decimalv2_val(ExprContext* context, TupleRow* row); virtual LargeIntVal get_large_int_val(ExprContext* context, TupleRow* row); diff --git a/be/src/exprs/conditional_functions_ir.cpp b/be/src/exprs/conditional_functions_ir.cpp index a910274086..14412e0465 100644 --- a/be/src/exprs/conditional_functions_ir.cpp +++ b/be/src/exprs/conditional_functions_ir.cpp @@ -38,7 +38,6 @@ IF_NULL_COMPUTE_FUNCTION(FloatVal, float_val); IF_NULL_COMPUTE_FUNCTION(DoubleVal, double_val); IF_NULL_COMPUTE_FUNCTION(StringVal, string_val); IF_NULL_COMPUTE_FUNCTION(DateTimeVal, datetime_val); -IF_NULL_COMPUTE_FUNCTION(DecimalVal, decimal_val); IF_NULL_COMPUTE_FUNCTION(DecimalV2Val, decimalv2_val); IF_NULL_COMPUTE_FUNCTION(LargeIntVal, large_int_val); @@ -90,7 +89,6 @@ IF_COMPUTE_FUNCTION(FloatVal, float_val); IF_COMPUTE_FUNCTION(DoubleVal, double_val); IF_COMPUTE_FUNCTION(StringVal, string_val); IF_COMPUTE_FUNCTION(DateTimeVal, datetime_val); -IF_COMPUTE_FUNCTION(DecimalVal, decimal_val); IF_COMPUTE_FUNCTION(DecimalV2Val, decimalv2_val); IF_COMPUTE_FUNCTION(LargeIntVal, large_int_val); @@ -113,7 +111,6 @@ COALESCE_COMPUTE_FUNCTION(FloatVal, float_val); COALESCE_COMPUTE_FUNCTION(DoubleVal, double_val); COALESCE_COMPUTE_FUNCTION(StringVal, string_val); COALESCE_COMPUTE_FUNCTION(DateTimeVal, datetime_val); -COALESCE_COMPUTE_FUNCTION(DecimalVal, decimal_val); COALESCE_COMPUTE_FUNCTION(DecimalV2Val, decimalv2_val); COALESCE_COMPUTE_FUNCTION(LargeIntVal, large_int_val); diff --git a/be/src/exprs/decimal_operators.cpp b/be/src/exprs/decimal_operators.cpp deleted file mode 100644 index 48e1b9ac5c..0000000000 --- a/be/src/exprs/decimal_operators.cpp +++ /dev/null @@ -1,186 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#include "exprs/decimal_operators.h" - -#include - -#include -#include - -#include "exprs/anyval_util.h" -#include "exprs/case_expr.h" -#include "exprs/expr.h" -#include "runtime/tuple_row.h" -// #include "util/decimal_util.h" -#include "util/string_parser.hpp" - -namespace doris { - -void DecimalOperators::init() {} - -#define CAST_INT_TO_DECIMAL(from_type) \ - DecimalVal DecimalOperators::cast_to_decimal_val(FunctionContext* context, \ - const from_type& val) { \ - if (val.is_null) return DecimalVal::null(); \ - DecimalValue dv = val.val; \ - DecimalVal result; \ - dv.to_decimal_val(&result); \ - return result; \ - } - -#define CAST_INT_TO_DECIMALS() \ - CAST_INT_TO_DECIMAL(TinyIntVal); \ - CAST_INT_TO_DECIMAL(SmallIntVal); \ - CAST_INT_TO_DECIMAL(IntVal); \ - CAST_INT_TO_DECIMAL(BigIntVal); \ - CAST_INT_TO_DECIMAL(LargeIntVal); - -CAST_INT_TO_DECIMALS(); - -DecimalVal DecimalOperators::cast_to_decimal_val(FunctionContext* context, const FloatVal& val) { - if (val.is_null) { - return DecimalVal::null(); - } - DecimalValue dv; - dv.assign_from_float(val.val); - DecimalVal result; - dv.to_decimal_val(&result); - return result; -} - -DecimalVal DecimalOperators::cast_to_decimal_val(FunctionContext* context, const DoubleVal& val) { - if (val.is_null) { - return DecimalVal::null(); - } - DecimalValue dv; - dv.assign_from_double(val.val); - DecimalVal result; - dv.to_decimal_val(&result); - return result; -} - -DecimalVal DecimalOperators::cast_to_decimal_val(FunctionContext* context, const DateTimeVal& val) { - if (val.is_null) { - return DecimalVal::null(); - } - - DateTimeValue dt_value = DateTimeValue::from_datetime_val(val); - - DecimalValue dv = dt_value.to_int64(); - DecimalVal result; - dv.to_decimal_val(&result); - return result; -} - -DecimalVal DecimalOperators::cast_to_decimal_val(FunctionContext* context, const StringVal& val) { - if (val.is_null) { - return DecimalVal::null(); - } - DecimalValue dv; - if (dv.parse_from_str((const char*)val.ptr, val.len)) { - return DecimalVal::null(); - } - DecimalVal result; - dv.to_decimal_val(&result); - return result; -} - -#define CAST_DECIMAL_TO_INT(to_type, type_name) \ - to_type DecimalOperators::cast_to_##type_name(FunctionContext* context, \ - const DecimalVal& val) { \ - if (val.is_null) return to_type::null(); \ - DecimalValue dv = DecimalValue::from_decimal_val(val); \ - return to_type(dv); \ - } - -#define CAST_FROM_DECIMAL() \ - CAST_DECIMAL_TO_INT(BooleanVal, boolean_val); \ - CAST_DECIMAL_TO_INT(TinyIntVal, tiny_int_val); \ - CAST_DECIMAL_TO_INT(SmallIntVal, small_int_val); \ - CAST_DECIMAL_TO_INT(IntVal, int_val); \ - CAST_DECIMAL_TO_INT(BigIntVal, big_int_val); \ - CAST_DECIMAL_TO_INT(LargeIntVal, large_int_val); \ - CAST_DECIMAL_TO_INT(FloatVal, float_val); \ - CAST_DECIMAL_TO_INT(DoubleVal, double_val); - -CAST_FROM_DECIMAL(); - -StringVal DecimalOperators::cast_to_string_val(FunctionContext* ctx, const DecimalVal& val) { - if (val.is_null) { - return StringVal::null(); - } - const DecimalValue& dv = DecimalValue::from_decimal_val(val); - return AnyValUtil::from_string_temp(ctx, dv.to_string()); -} - -DateTimeVal DecimalOperators::cast_to_datetime_val(FunctionContext* context, - const DecimalVal& val) { - if (val.is_null) { - return DateTimeVal::null(); - } - const DecimalValue& dv = DecimalValue::from_decimal_val(val); - DateTimeValue dt; - if (!dt.from_date_int64(dv)) { - return DateTimeVal::null(); - } - DateTimeVal result; - dt.to_datetime_val(&result); - return result; -} - -#define DECIMAL_ARITHMETIC_OP(FN_NAME, OP) \ - DecimalVal DecimalOperators::FN_NAME##_decimal_val_decimal_val( \ - FunctionContext* context, const DecimalVal& v1, const DecimalVal& v2) { \ - if (v1.is_null || v2.is_null) return DecimalVal::null(); \ - DecimalValue iv1 = DecimalValue::from_decimal_val(v1); \ - DecimalValue iv2 = DecimalValue::from_decimal_val(v2); \ - DecimalValue ir = iv1 OP iv2; \ - DecimalVal result; \ - ir.to_decimal_val(&result); \ - return result; \ - } - -#define DECIMAL_ARITHMETIC_OPS() \ - DECIMAL_ARITHMETIC_OP(add, +); \ - DECIMAL_ARITHMETIC_OP(subtract, -); \ - DECIMAL_ARITHMETIC_OP(multiply, *); \ - DECIMAL_ARITHMETIC_OP(divide, /); \ - DECIMAL_ARITHMETIC_OP(mod, %); - -DECIMAL_ARITHMETIC_OPS(); - -#define DECIMAL_BINARY_PREDICATE_NONNUMERIC_FN(NAME, OP) \ - BooleanVal DecimalOperators::NAME##_decimal_val_decimal_val( \ - FunctionContext* c, const DecimalVal& v1, const DecimalVal& v2) { \ - if (v1.is_null || v2.is_null) return BooleanVal::null(); \ - DecimalValue iv1 = DecimalValue::from_decimal_val(v1); \ - DecimalValue iv2 = DecimalValue::from_decimal_val(v2); \ - return BooleanVal(iv1 OP iv2); \ - } - -#define BINARY_PREDICATE_NONNUMERIC_FNS() \ - DECIMAL_BINARY_PREDICATE_NONNUMERIC_FN(eq, ==); \ - DECIMAL_BINARY_PREDICATE_NONNUMERIC_FN(ne, !=); \ - DECIMAL_BINARY_PREDICATE_NONNUMERIC_FN(gt, >); \ - DECIMAL_BINARY_PREDICATE_NONNUMERIC_FN(lt, <); \ - DECIMAL_BINARY_PREDICATE_NONNUMERIC_FN(ge, >=); \ - DECIMAL_BINARY_PREDICATE_NONNUMERIC_FN(le, <=); - -BINARY_PREDICATE_NONNUMERIC_FNS(); - -} // namespace doris diff --git a/be/src/exprs/decimal_operators.h b/be/src/exprs/decimal_operators.h deleted file mode 100644 index 3710149217..0000000000 --- a/be/src/exprs/decimal_operators.h +++ /dev/null @@ -1,86 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#ifndef DORIS_BE_SRC_QUERY_EXPRS_DECIMAL_OPERATORS_H -#define DORIS_BE_SRC_QUERY_EXPRS_DECIMAL_OPERATORS_H - -#include - -#include "runtime/decimal_value.h" -#include "udf/udf.h" - -namespace doris { - -class Expr; -struct ExprValue; -class TupleRow; - -/// Implementation of the decimal operators. These include the cast, -/// arithmetic and binary operators. -class DecimalOperators { -public: - static void init(); - - static DecimalVal cast_to_decimal_val(FunctionContext*, const TinyIntVal&); - static DecimalVal cast_to_decimal_val(FunctionContext*, const SmallIntVal&); - static DecimalVal cast_to_decimal_val(FunctionContext*, const IntVal&); - static DecimalVal cast_to_decimal_val(FunctionContext*, const BigIntVal&); - static DecimalVal cast_to_decimal_val(FunctionContext*, const LargeIntVal&); - static DecimalVal cast_to_decimal_val(FunctionContext*, const FloatVal&); - static DecimalVal cast_to_decimal_val(FunctionContext*, const DoubleVal&); - static DecimalVal cast_to_decimal_val(FunctionContext*, const DateTimeVal&); - static DecimalVal cast_to_decimal_val(FunctionContext*, const StringVal&); - - static BooleanVal cast_to_boolean_val(FunctionContext*, const DecimalVal&); - static TinyIntVal cast_to_tiny_int_val(FunctionContext*, const DecimalVal&); - static SmallIntVal cast_to_small_int_val(FunctionContext*, const DecimalVal&); - static IntVal cast_to_int_val(FunctionContext*, const DecimalVal&); - static BigIntVal cast_to_big_int_val(FunctionContext*, const DecimalVal&); - static LargeIntVal cast_to_large_int_val(FunctionContext*, const DecimalVal&); - static FloatVal cast_to_float_val(FunctionContext*, const DecimalVal&); - static DoubleVal cast_to_double_val(FunctionContext*, const DecimalVal&); - static StringVal cast_to_string_val(FunctionContext*, const DecimalVal&); - static DateTimeVal cast_to_datetime_val(FunctionContext*, const DecimalVal&); - - static DecimalVal add_decimal_val_decimal_val(FunctionContext*, const DecimalVal&, - const DecimalVal&); - static DecimalVal subtract_decimal_val_decimal_val(FunctionContext*, const DecimalVal&, - const DecimalVal&); - static DecimalVal multiply_decimal_val_decimal_val(FunctionContext*, const DecimalVal&, - const DecimalVal&); - static DecimalVal divide_decimal_val_decimal_val(FunctionContext*, const DecimalVal&, - const DecimalVal&); - static DecimalVal mod_decimal_val_decimal_val(FunctionContext*, const DecimalVal&, - const DecimalVal&); - - static BooleanVal eq_decimal_val_decimal_val(FunctionContext*, const DecimalVal&, - const DecimalVal&); - static BooleanVal ne_decimal_val_decimal_val(FunctionContext*, const DecimalVal&, - const DecimalVal&); - static BooleanVal gt_decimal_val_decimal_val(FunctionContext*, const DecimalVal&, - const DecimalVal&); - static BooleanVal lt_decimal_val_decimal_val(FunctionContext*, const DecimalVal&, - const DecimalVal&); - static BooleanVal ge_decimal_val_decimal_val(FunctionContext*, const DecimalVal&, - const DecimalVal&); - static BooleanVal le_decimal_val_decimal_val(FunctionContext*, const DecimalVal&, - const DecimalVal&); -}; - -} // namespace doris - -#endif diff --git a/be/src/exprs/decimalv2_operators.cpp b/be/src/exprs/decimalv2_operators.cpp index 2c99c200ee..32f54d95ed 100644 --- a/be/src/exprs/decimalv2_operators.cpp +++ b/be/src/exprs/decimalv2_operators.cpp @@ -164,16 +164,6 @@ DateTimeVal DecimalV2Operators::cast_to_date_val(FunctionContext* context, return result; } -DecimalVal DecimalV2Operators::cast_to_decimal_val(FunctionContext* context, - const DecimalV2Val& val) { - if (val.is_null) return DecimalVal::null(); - DecimalV2Value v2(val.val); - DecimalValue dv(v2.int_value(), v2.frac_value()); - DecimalVal result; - dv.to_decimal_val(&result); - return result; -} - #define DECIMAL_ARITHMETIC_OP(FN_NAME, OP) \ DecimalV2Val DecimalV2Operators::FN_NAME##_decimalv2_val_decimalv2_val( \ FunctionContext* context, const DecimalV2Val& v1, const DecimalV2Val& v2) { \ diff --git a/be/src/exprs/decimalv2_operators.h b/be/src/exprs/decimalv2_operators.h index deb3bab055..243a153e12 100644 --- a/be/src/exprs/decimalv2_operators.h +++ b/be/src/exprs/decimalv2_operators.h @@ -56,7 +56,6 @@ public: static StringVal cast_to_string_val(FunctionContext*, const DecimalV2Val&); static DateTimeVal cast_to_datetime_val(FunctionContext*, const DecimalV2Val&); static DateTimeVal cast_to_date_val(FunctionContext*, const DecimalV2Val&); - static DecimalVal cast_to_decimal_val(FunctionContext*, const DecimalV2Val&); static DecimalV2Val add_decimalv2_val_decimalv2_val(FunctionContext*, const DecimalV2Val&, const DecimalV2Val&); diff --git a/be/src/exprs/expr.cpp b/be/src/exprs/expr.cpp index bb30e27690..480aac4e89 100644 --- a/be/src/exprs/expr.cpp +++ b/be/src/exprs/expr.cpp @@ -127,7 +127,6 @@ Expr::Expr(const TypeDescriptor& type) _node_type = (TExprNodeType::FLOAT_LITERAL); break; - case TYPE_DECIMAL: case TYPE_DECIMALV2: _node_type = (TExprNodeType::DECIMAL_LITERAL); break; @@ -186,7 +185,6 @@ Expr::Expr(const TypeDescriptor& type, bool is_slotref) _node_type = (TExprNodeType::FLOAT_LITERAL); break; - case TYPE_DECIMAL: case TYPE_DECIMALV2: _node_type = (TExprNodeType::DECIMAL_LITERAL); break; @@ -459,14 +457,6 @@ int Expr::compute_results_layout(const std::vector& exprs, std::vectortype().type == TYPE_CHAR || exprs[i]->type().type == TYPE_VARCHAR) { data[i].byte_size = 16; data[i].variable_length = true; - } else if (exprs[i]->type().type == TYPE_DECIMAL) { - data[i].byte_size = get_byte_size(exprs[i]->type().type); - - // Although the current decimal has a fix-length, for the - // same value, it will work out different hash value due to the - // different memory represent if the variable_length here is set - // to false, so we have to keep it. - data[i].variable_length = true; } else { data[i].byte_size = get_byte_size(exprs[i]->type().type); data[i].variable_length = false; @@ -720,10 +710,7 @@ doris_udf::AnyVal* Expr::get_const_val(ExprContext* context) { _constant_val.reset(new DateTimeVal(get_datetime_val(context, NULL))); break; } - case TYPE_DECIMAL: { - _constant_val.reset(new DecimalVal(get_decimal_val(context, NULL))); - break; - } + case TYPE_DECIMALV2: { _constant_val.reset(new DecimalV2Val(get_decimalv2_val(context, NULL))); break; @@ -805,12 +792,6 @@ DateTimeVal Expr::get_datetime_val(ExprContext* context, TupleRow* row) { return val; } -DecimalVal Expr::get_decimal_val(ExprContext* context, TupleRow* row) { - DecimalVal val; - // ((DecimalValue*)get_value(row))->to_decimal_val(&val); - return val; -} - DecimalV2Val Expr::get_decimalv2_val(ExprContext* context, TupleRow* row) { DecimalV2Val val; return val; diff --git a/be/src/exprs/expr.h b/be/src/exprs/expr.h index 7c59d2f778..d3bc711cc3 100644 --- a/be/src/exprs/expr.h +++ b/be/src/exprs/expr.h @@ -26,7 +26,6 @@ #include "exprs/expr_value.h" #include "gen_cpp/Opcodes_types.h" #include "runtime/datetime_value.h" -#include "runtime/decimal_value.h" #include "runtime/decimalv2_value.h" #include "runtime/descriptors.h" #include "runtime/string_value.h" @@ -112,7 +111,6 @@ public: // TODO(zc) // virtual ArrayVal GetArrayVal(ExprContext* context, TupleRow*); virtual DateTimeVal get_datetime_val(ExprContext* context, TupleRow*); - virtual DecimalVal get_decimal_val(ExprContext* context, TupleRow*); virtual DecimalV2Val get_decimalv2_val(ExprContext* context, TupleRow*); // Get the number of digits after the decimal that should be displayed for this @@ -431,7 +429,6 @@ private: static DoubleVal get_double_val(Expr* expr, ExprContext* context, TupleRow* row); static StringVal get_string_val(Expr* expr, ExprContext* context, TupleRow* row); static DateTimeVal get_datetime_val(Expr* expr, ExprContext* context, TupleRow* row); - static DecimalVal get_decimal_val(Expr* expr, ExprContext* context, TupleRow* row); static DecimalV2Val get_decimalv2_val(Expr* expr, ExprContext* context, TupleRow* row); /// Creates an expression tree rooted at 'root' via depth-first traversal. diff --git a/be/src/exprs/expr_context.cpp b/be/src/exprs/expr_context.cpp index 0aef99f3bd..25d11286a7 100644 --- a/be/src/exprs/expr_context.cpp +++ b/be/src/exprs/expr_context.cpp @@ -165,85 +165,6 @@ void ExprContext::free_local_allocations(const std::vector& fn } } -void ExprContext::get_value(TupleRow* row, bool as_ascii, TColumnValue* col_val) { -#if 0 - void* value = get_value(row); - if (as_ascii) { - RawValue::print_value(value, _root->_type, _root->_output_scale, &col_val->string_val); - col_val->__isset.string_val = true; - return; - } - if (value == NULL) { - return; - } - - StringValue* string_val = NULL; - std::string tmp; - switch (_root->_type.type) { - case TYPE_BOOLEAN: - col_val->__set_bool_val(*reinterpret_cast(value)); - break; - case TYPE_TINYINT: - col_val->__set_byte_val(*reinterpret_cast(value)); - break; - case TYPE_SMALLINT: - col_val->__set_short_val(*reinterpret_cast(value)); - break; - case TYPE_INT: - col_val->__set_int_val(*reinterpret_cast(value)); - break; - case TYPE_BIGINT: - col_val->__set_long_val(*reinterpret_cast(value)); - break; - case TYPE_FLOAT: - col_val->__set_double_val(*reinterpret_cast(value)); - break; - case TYPE_DOUBLE: - col_val->__set_double_val(*reinterpret_cast(value)); - break; -#if 0 - case TYPE_DECIMAL: - switch (_root->_type.GetByteSize()) { - case 4: - col_val->string_val = - reinterpret_cast(value)->ToString(_root->_type); - break; - case 8: - col_val->string_val = - reinterpret_cast(value)->ToString(_root->_type); - break; - case 16: - col_val->string_val = - reinterpret_cast(value)->ToString(_root->_type); - break; - default: - DCHECK(false) << "Bad Type: " << _root->_type; - } - col_val->__isset.string_val = true; - break; - case TYPE_VARCHAR: - string_val = reinterpret_cast(value); - tmp.assign(static_cast(string_val->ptr), string_val->len); - col_val->string_val.swap(tmp); - col_val->__isset.string_val = true; - break; - case TYPE_CHAR: - tmp.assign(StringValue::CharSlotToPtr(value, _root->_type), _root->_type.len); - col_val->string_val.swap(tmp); - col_val->__isset.string_val = true; - break; - case TYPE_TIMESTAMP: - RawValue::print_value( - value, _root->_type, _root->_output_scale_, &col_val->string_val); - col_val->__isset.string_val = true; - break; -#endif - default: - DCHECK(false) << "bad get_value() type: " << _root->_type; - } -#endif -} - bool ExprContext::is_nullable() { if (_root->is_slotref()) { return SlotRef::is_nullable(_root); @@ -357,14 +278,6 @@ void* ExprContext::get_value(Expr* e, TupleRow* row) { _result.datetime_val = DateTimeValue::from_datetime_val(v); return &_result.datetime_val; } - case TYPE_DECIMAL: { - DecimalVal v = e->get_decimal_val(this, row); - if (v.is_null) { - return NULL; - } - _result.decimal_val = DecimalValue::from_decimal_val(v); - return &_result.decimal_val; - } case TYPE_DECIMALV2: { DecimalV2Val v = e->get_decimalv2_val(this, row); if (v.is_null) { @@ -446,10 +359,6 @@ DateTimeVal ExprContext::get_datetime_val(TupleRow* row) { return _root->get_datetime_val(this, row); } -DecimalVal ExprContext::get_decimal_val(TupleRow* row) { - return _root->get_decimal_val(this, row); -} - DecimalV2Val ExprContext::get_decimalv2_val(TupleRow* row) { return _root->get_decimalv2_val(this, row); } diff --git a/be/src/exprs/expr_context.h b/be/src/exprs/expr_context.h index 280a3c62b8..a786c27832 100644 --- a/be/src/exprs/expr_context.h +++ b/be/src/exprs/expr_context.h @@ -81,23 +81,6 @@ public: /// result in result_. void* get_value(TupleRow* row); - /// Convenience function: extract value into col_val and sets the - /// appropriate __isset flag. - /// If the value is NULL and as_ascii is false, nothing is set. - /// If 'as_ascii' is true, writes the value in ascii into stringVal - /// (nulls turn into "NULL"); - /// if it is false, the specific field in col_val that receives the value is - /// based on the type of the expr: - /// TYPE_BOOLEAN: boolVal - /// TYPE_TINYINT/SMALLINT/INT: intVal - /// TYPE_BIGINT: longVal - /// TYPE_FLOAT/DOUBLE: doubleVal - /// TYPE_STRING: stringVal - /// TYPE_TIMESTAMP: stringVal - /// Note: timestamp is converted to string via RawValue::PrintValue because HiveServer2 - /// requires timestamp in a string format. - void get_value(TupleRow* row, bool as_ascii, TColumnValue* col_val); - /// Convenience functions: print value into 'str' or 'stream'. NULL turns into "NULL". void print_value(TupleRow* row, std::string* str); void print_value(void* value, std::string* str); @@ -138,7 +121,6 @@ public: // TODO(zc): // ArrayVal GetArrayVal(TupleRow* row); DateTimeVal get_datetime_val(TupleRow* row); - DecimalVal get_decimal_val(TupleRow* row); DecimalV2Val get_decimalv2_val(TupleRow* row); /// Frees all local allocations made by fn_contexts_. This can be called when result diff --git a/be/src/exprs/expr_ir.cpp b/be/src/exprs/expr_ir.cpp index ad0c0a07a1..02d223e715 100644 --- a/be/src/exprs/expr_ir.cpp +++ b/be/src/exprs/expr_ir.cpp @@ -29,7 +29,7 @@ void dummy(doris_udf::FunctionContext*, doris_udf::BooleanVal*, doris_udf::TinyIntVal*, doris_udf::SmallIntVal*, doris_udf::IntVal*, doris_udf::BigIntVal*, doris_udf::FloatVal*, doris_udf::DoubleVal*, doris_udf::StringVal*, doris_udf::DateTimeVal*, - doris_udf::DecimalVal*, doris::ExprContext*) {} + doris_udf::DecimalV2Val*, doris::ExprContext*) {} #endif // The following are compute functions that are cross-compiled to both native and IR @@ -71,9 +71,7 @@ StringVal Expr::get_string_val(Expr* expr, ExprContext* context, TupleRow* row) DateTimeVal Expr::get_datetime_val(Expr* expr, ExprContext* context, TupleRow* row) { return expr->get_datetime_val(context, row); } -DecimalVal Expr::get_decimal_val(Expr* expr, ExprContext* context, TupleRow* row) { - return expr->get_decimal_val(context, row); -} + DecimalV2Val Expr::get_decimalv2_val(Expr* expr, ExprContext* context, TupleRow* row) { return expr->get_decimalv2_val(context, row); } diff --git a/be/src/exprs/expr_value.h b/be/src/exprs/expr_value.h index 0b528828f8..a2f2dc876a 100644 --- a/be/src/exprs/expr_value.h +++ b/be/src/exprs/expr_value.h @@ -19,7 +19,6 @@ #define DORIS_BE_SRC_QUERY_EXPRS_EXPR_VALUE_H #include "runtime/datetime_value.h" -#include "runtime/decimal_value.h" #include "runtime/decimalv2_value.h" #include "runtime/string_value.h" #include "runtime/string_value.hpp" @@ -44,7 +43,6 @@ struct ExprValue { std::string string_data; StringValue string_val; DateTimeValue datetime_val; - DecimalValue decimal_val; DecimalV2Value decimalv2_val; ExprValue() @@ -59,7 +57,6 @@ struct ExprValue { string_data(), string_val(NULL, 0), datetime_val(), - decimal_val(), decimalv2_val(0) {} ExprValue(bool v) : bool_val(v) {} @@ -70,7 +67,7 @@ struct ExprValue { ExprValue(__int128 value) : large_int_val(value) {} ExprValue(float v) : float_val(v) {} ExprValue(double v) : double_val(v) {} - ExprValue(int64_t i, int32_t f) : decimal_val(i, f), decimalv2_val(i, f) {} + ExprValue(int64_t i, int32_t f) : decimalv2_val(i, f) {} // c'tor for string values ExprValue(const std::string& str) @@ -134,10 +131,6 @@ struct ExprValue { double_val = 0; return &double_val; - case TYPE_DECIMAL: - decimal_val.set_to_zero(); - return &decimal_val; - case TYPE_DECIMALV2: decimalv2_val.set_to_zero(); return &decimalv2_val; @@ -186,10 +179,6 @@ struct ExprValue { double_val = std::numeric_limits::min(); return &double_val; - case TYPE_DECIMAL: - decimal_val = DecimalValue::get_min_decimal(); - return &decimal_val; - case TYPE_DECIMALV2: decimalv2_val = DecimalV2Value::get_min_decimal(); return &decimalv2_val; @@ -238,10 +227,6 @@ struct ExprValue { double_val = std::numeric_limits::max(); return &double_val; - case TYPE_DECIMAL: - decimal_val = DecimalValue::get_max_decimal(); - return &decimal_val; - case TYPE_DECIMALV2: decimalv2_val = DecimalV2Value::get_max_decimal(); return &decimalv2_val; diff --git a/be/src/exprs/hll_function.cpp b/be/src/exprs/hll_function.cpp index 4771f132f9..fe33c11830 100644 --- a/be/src/exprs/hll_function.cpp +++ b/be/src/exprs/hll_function.cpp @@ -120,6 +120,5 @@ template void HllFunctions::hll_update(FunctionContext*, const DoubleVal&, Strin template void HllFunctions::hll_update(FunctionContext*, const StringVal&, StringVal*); template void HllFunctions::hll_update(FunctionContext*, const DateTimeVal&, StringVal*); template void HllFunctions::hll_update(FunctionContext*, const LargeIntVal&, StringVal*); -template void HllFunctions::hll_update(FunctionContext*, const DecimalVal&, StringVal*); template void HllFunctions::hll_update(FunctionContext*, const DecimalV2Val&, StringVal*); } // namespace doris diff --git a/be/src/exprs/hybrid_set.cpp b/be/src/exprs/hybrid_set.cpp index a79732373d..07ebbc8ca4 100644 --- a/be/src/exprs/hybrid_set.cpp +++ b/be/src/exprs/hybrid_set.cpp @@ -46,9 +46,6 @@ HybridSetBase* HybridSetBase::create_set(PrimitiveType type) { case TYPE_DATETIME: return new (std::nothrow) HybridSet(); - case TYPE_DECIMAL: - return new (std::nothrow) HybridSet(); - case TYPE_DECIMALV2: return new (std::nothrow) HybridSet(); diff --git a/be/src/exprs/hybrid_set.h b/be/src/exprs/hybrid_set.h index 23fc1abf66..495232f9af 100644 --- a/be/src/exprs/hybrid_set.h +++ b/be/src/exprs/hybrid_set.h @@ -18,13 +18,13 @@ #ifndef DORIS_BE_SRC_QUERY_EXPRS_HYBRID_SET_H #define DORIS_BE_SRC_QUERY_EXPRS_HYBRID_SET_H -#include #include +#include + #include "common/object_pool.h" #include "common/status.h" #include "runtime/datetime_value.h" -#include "runtime/decimal_value.h" #include "runtime/decimalv2_value.h" #include "runtime/primitive_type.h" #include "runtime/string_value.h" @@ -77,9 +77,7 @@ public: } } - void insert(void* data, size_t) override { - insert(data); - } + void insert(void* data, size_t) override { insert(data); } void insert(HybridSetBase* set) override { HybridSet* hybrid_set = reinterpret_cast*>(set); @@ -93,9 +91,7 @@ public: return !(it == _set.end()); } - bool find(void* data, size_t) override { - return find(data); - } + bool find(void* data, size_t) override { return find(data); } template class Iterator : public IteratorBase { @@ -139,7 +135,6 @@ public: _set.insert(str_value); } - void insert(HybridSetBase* set) override { StringValueSet* string_set = reinterpret_cast(set); _set.insert(string_set->_set.begin(), string_set->_set.end()); diff --git a/be/src/exprs/is_null_predicate.cpp b/be/src/exprs/is_null_predicate.cpp index 78ea27694f..5b041595fb 100644 --- a/be/src/exprs/is_null_predicate.cpp +++ b/be/src/exprs/is_null_predicate.cpp @@ -44,7 +44,6 @@ template BooleanVal IsNullPredicate::is_null(FunctionContext*, const FloatVal&); template BooleanVal IsNullPredicate::is_null(FunctionContext*, const DoubleVal&); template BooleanVal IsNullPredicate::is_null(FunctionContext*, const StringVal&); template BooleanVal IsNullPredicate::is_null(FunctionContext*, const DateTimeVal&); -template BooleanVal IsNullPredicate::is_null(FunctionContext*, const DecimalVal&); template BooleanVal IsNullPredicate::is_null(FunctionContext*, const DecimalV2Val&); template BooleanVal IsNullPredicate::is_not_null(FunctionContext*, const AnyVal&); @@ -58,7 +57,6 @@ template BooleanVal IsNullPredicate::is_not_null(FunctionContext*, const FloatVa template BooleanVal IsNullPredicate::is_not_null(FunctionContext*, const DoubleVal&); template BooleanVal IsNullPredicate::is_not_null(FunctionContext*, const StringVal&); template BooleanVal IsNullPredicate::is_not_null(FunctionContext*, const DateTimeVal&); -template BooleanVal IsNullPredicate::is_not_null(FunctionContext*, const DecimalVal&); template BooleanVal IsNullPredicate::is_not_null(FunctionContext*, const DecimalV2Val&); } // namespace doris diff --git a/be/src/exprs/literal.cpp b/be/src/exprs/literal.cpp index 11b458f23f..4ad17c39b5 100644 --- a/be/src/exprs/literal.cpp +++ b/be/src/exprs/literal.cpp @@ -85,12 +85,7 @@ Literal::Literal(const TExprNode& node) : Expr(node) { DCHECK(node.__isset.string_literal); _value.set_string_val(node.string_literal.value); break; - case TYPE_DECIMAL: { - DCHECK_EQ(node.node_type, TExprNodeType::DECIMAL_LITERAL); - DCHECK(node.__isset.decimal_literal); - _value.decimal_val = DecimalValue(node.decimal_literal.value); - break; - } + case TYPE_DECIMALV2: { DCHECK_EQ(node.node_type, TExprNodeType::DECIMAL_LITERAL); DCHECK(node.__isset.decimal_literal); @@ -145,13 +140,6 @@ DoubleVal Literal::get_double_val(ExprContext* context, TupleRow* row) { return DoubleVal(_value.double_val); } -DecimalVal Literal::get_decimal_val(ExprContext* context, TupleRow* row) { - DCHECK_EQ(_type.type, TYPE_DECIMAL) << _type; - DecimalVal dec_val; - _value.decimal_val.to_decimal_val(&dec_val); - return dec_val; -} - DecimalV2Val Literal::get_decimalv2_val(ExprContext* context, TupleRow* row) { DCHECK_EQ(_type.type, TYPE_DECIMALV2) << _type; DecimalV2Val dec_val; diff --git a/be/src/exprs/literal.h b/be/src/exprs/literal.h index 1b35336b71..4899116c42 100644 --- a/be/src/exprs/literal.h +++ b/be/src/exprs/literal.h @@ -40,7 +40,6 @@ public: virtual LargeIntVal get_large_int_val(ExprContext* context, TupleRow*); virtual FloatVal get_float_val(ExprContext* context, TupleRow*); virtual DoubleVal get_double_val(ExprContext* context, TupleRow*); - virtual DecimalVal get_decimal_val(ExprContext* context, TupleRow*); virtual DecimalV2Val get_decimalv2_val(ExprContext* context, TupleRow*); virtual DateTimeVal get_datetime_val(ExprContext* context, TupleRow*); virtual StringVal get_string_val(ExprContext* context, TupleRow* row); diff --git a/be/src/exprs/math_functions.cpp b/be/src/exprs/math_functions.cpp index 612f2e3ba8..40bb47a5a8 100644 --- a/be/src/exprs/math_functions.cpp +++ b/be/src/exprs/math_functions.cpp @@ -27,7 +27,6 @@ #include "common/compiler_util.h" #include "exprs/anyval_util.h" #include "exprs/expr.h" -#include "runtime/decimal_value.h" #include "runtime/decimalv2_value.h" #include "runtime/tuple_row.h" #include "util/string_parser.hpp" @@ -108,16 +107,6 @@ DoubleVal MathFunctions::e(FunctionContext* ctx) { return DoubleVal(M_E); } -DecimalVal MathFunctions::abs(FunctionContext* ctx, const doris_udf::DecimalVal& val) { - if (val.is_null) { - return DecimalVal::null(); - } else if (val.sign) { - return negative_decimal(ctx, val); - } else { - return positive_decimal(ctx, val); - } -} - DecimalV2Val MathFunctions::abs(FunctionContext* ctx, const doris_udf::DecimalV2Val& val) { if (val.is_null) { return DecimalV2Val::null(); @@ -576,10 +565,6 @@ DoubleVal MathFunctions::positive_double(FunctionContext* ctx, const DoubleVal& return val; } -DecimalVal MathFunctions::positive_decimal(FunctionContext* ctx, const DecimalVal& val) { - return val; -} - DecimalV2Val MathFunctions::positive_decimal(FunctionContext* ctx, const DecimalV2Val& val) { return val; } @@ -598,18 +583,6 @@ DoubleVal MathFunctions::negative_double(FunctionContext* ctx, const DoubleVal& return DoubleVal(-val.val); } -DecimalVal MathFunctions::negative_decimal(FunctionContext* ctx, const DecimalVal& val) { - if (val.is_null) { - return val; - } - const DecimalValue& dv1 = DecimalValue::from_decimal_val(val); - LOG(INFO) << dv1.to_string(); - DecimalVal result; - LOG(INFO) << (-dv1).to_string(); - (-dv1).to_decimal_val(&result); - return result; -} - DecimalV2Val MathFunctions::negative_decimal(FunctionContext* ctx, const DecimalV2Val& val) { if (val.is_null) { return val; @@ -659,7 +632,6 @@ LEAST_FNS(); #define LEAST_NONNUMERIC_FNS() \ LEAST_NONNUMERIC_FN(string_val, StringVal, StringValue); \ LEAST_NONNUMERIC_FN(datetime_val, DateTimeVal, DateTimeValue); \ - LEAST_NONNUMERIC_FN(decimal_val, DecimalVal, DecimalValue); \ LEAST_NONNUMERIC_FN(decimal_val, DecimalV2Val, DecimalV2Value); LEAST_NONNUMERIC_FNS(); @@ -703,7 +675,6 @@ GREATEST_FNS(); #define GREATEST_NONNUMERIC_FNS() \ GREATEST_NONNUMERIC_FN(string_val, StringVal, StringValue); \ GREATEST_NONNUMERIC_FN(datetime_val, DateTimeVal, DateTimeValue); \ - GREATEST_NONNUMERIC_FN(decimal_val, DecimalVal, DecimalValue); \ GREATEST_NONNUMERIC_FN(decimal_val, DecimalV2Val, DecimalV2Value); GREATEST_NONNUMERIC_FNS(); @@ -746,23 +717,6 @@ void* MathFunctions::greatest_double(Expr* e, TupleRow* row) { return &e->children()[result_idx]->_result.double_val; } -void* MathFunctions::greatest_decimal(Expr* e, TupleRow* row) { - DCHECK_GE(e->get_num_children(), 1); - int32_t num_args = e->get_num_children(); - int result_idx = 0; - // NOTE: loop index starts at 0, so If frist arg is NULL, we can return early.. - for (int i = 0; i < num_args; ++i) { - DecimalValue* arg = reinterpret_cast(e->children()[i]->get_value(row)); - if (arg == NULL) { - return NULL; - } - if (*arg > *reinterpret_cast(e->children()[result_idx]->get_value(row))) { - result_idx = i; - } - } - return &e->children()[result_idx]->_result.decimal_val; -} - void* MathFunctions::greatest_string(Expr* e, TupleRow* row) { DCHECK_GE(e->get_num_children(), 1); int32_t num_args = e->get_num_children(); @@ -834,23 +788,6 @@ void* MathFunctions::least_double(Expr* e, TupleRow* row) { return &e->children()[result_idx]->_result.double_val; } -void* MathFunctions::least_decimal(Expr* e, TupleRow* row) { - DCHECK_GE(e->get_num_children(), 1); - int32_t num_args = e->get_num_children(); - int result_idx = 0; - // NOTE: loop index starts at 0, so If frist arg is NULL, we can return early.. - for (int i = 0; i < num_args; ++i) { - DecimalValue* arg = reinterpret_cast(e->children()[i]->get_value(row)); - if (arg == NULL) { - return NULL; - } - if (*arg < *reinterpret_cast(e->children()[result_idx]->get_value(row))) { - result_idx = i; - } - } - return &e->children()[result_idx]->_result.decimal_val; -} - void* MathFunctions::least_decimalv2(Expr* e, TupleRow* row) { DCHECK_GE(e->get_num_children(), 1); int32_t num_args = e->get_num_children(); diff --git a/be/src/exprs/math_functions.h b/be/src/exprs/math_functions.h index bfef5957c5..5d1258e8ac 100644 --- a/be/src/exprs/math_functions.h +++ b/be/src/exprs/math_functions.h @@ -37,7 +37,6 @@ public: static doris_udf::DoubleVal abs(doris_udf::FunctionContext*, const doris_udf::DoubleVal&); static doris_udf::FloatVal abs(doris_udf::FunctionContext*, const doris_udf::FloatVal&); - static doris_udf::DecimalVal abs(doris_udf::FunctionContext*, const doris_udf::DecimalVal&); static doris_udf::DecimalV2Val abs(doris_udf::FunctionContext*, const doris_udf::DecimalV2Val&); // For integer math, we have to promote ABS() to the next highest integer type because @@ -131,16 +130,12 @@ public: const doris_udf::BigIntVal& val); static doris_udf::DoubleVal positive_double(doris_udf::FunctionContext* ctx, const doris_udf::DoubleVal& val); - static doris_udf::DecimalVal positive_decimal(doris_udf::FunctionContext* ctx, - const doris_udf::DecimalVal& val); static doris_udf::DecimalV2Val positive_decimal(doris_udf::FunctionContext* ctx, const doris_udf::DecimalV2Val& val); static doris_udf::BigIntVal negative_bigint(doris_udf::FunctionContext* ctx, const doris_udf::BigIntVal& val); static doris_udf::DoubleVal negative_double(doris_udf::FunctionContext* ctx, const doris_udf::DoubleVal& val); - static doris_udf::DecimalVal negative_decimal(doris_udf::FunctionContext* ctx, - const doris_udf::DecimalVal& val); static doris_udf::DecimalV2Val negative_decimal(doris_udf::FunctionContext* ctx, const doris_udf::DecimalV2Val& val); @@ -180,10 +175,6 @@ public: const doris_udf::DateTimeVal* val); static doris_udf::DateTimeVal greatest(doris_udf::FunctionContext* ctx, int num_args, const doris_udf::DateTimeVal* val); - static doris_udf::DecimalVal least(doris_udf::FunctionContext* ctx, int num_args, - const doris_udf::DecimalVal* val); - static doris_udf::DecimalVal greatest(doris_udf::FunctionContext* ctx, int num_args, - const doris_udf::DecimalVal* val); static doris_udf::DecimalV2Val least(doris_udf::FunctionContext* ctx, int num_args, const doris_udf::DecimalV2Val* val); static doris_udf::DecimalV2Val greatest(doris_udf::FunctionContext* ctx, int num_args, diff --git a/be/src/exprs/new_agg_fn_evaluator.cc b/be/src/exprs/new_agg_fn_evaluator.cc index 952f9fe9b5..8286732579 100644 --- a/be/src/exprs/new_agg_fn_evaluator.cc +++ b/be/src/exprs/new_agg_fn_evaluator.cc @@ -275,10 +275,7 @@ void NewAggFnEvaluator::SetDstSlot(const AnyVal* src, const SlotDescriptor& dst_ *reinterpret_cast(slot) = DateTimeValue::from_datetime_val(*reinterpret_cast(src)); return; - case TYPE_DECIMAL: - *reinterpret_cast(slot) = - DecimalValue::from_decimal_val(*reinterpret_cast(src)); - return; + case TYPE_DECIMALV2: *reinterpret_cast(slot) = reinterpret_cast(src)->val; return; @@ -376,11 +373,6 @@ inline void NewAggFnEvaluator::set_any_val(const void* slot, const TypeDescripto reinterpret_cast(dst)); return; - case TYPE_DECIMAL: - reinterpret_cast(slot)->to_decimal_val( - reinterpret_cast(dst)); - return; - case TYPE_DECIMALV2: reinterpret_cast(dst)->val = reinterpret_cast(slot)->value; @@ -617,12 +609,6 @@ void NewAggFnEvaluator::SerializeOrFinalize(Tuple* src, const SlotDescriptor& ds SetDstSlot(&v, dst_slot_desc, dst); break; } - case TYPE_DECIMAL: { - typedef DecimalVal (*Fn)(FunctionContext*, AnyVal*); - DecimalVal v = reinterpret_cast(fn)(agg_fn_ctx_.get(), staging_intermediate_val_); - SetDstSlot(&v, dst_slot_desc, dst); - break; - } case TYPE_DECIMALV2: { typedef DecimalV2Val (*Fn)(FunctionContext*, AnyVal*); DecimalV2Val v = reinterpret_cast(fn)(agg_fn_ctx_.get(), staging_intermediate_val_); diff --git a/be/src/exprs/new_agg_fn_evaluator.h b/be/src/exprs/new_agg_fn_evaluator.h index ecf13d7376..f1c13e49c1 100644 --- a/be/src/exprs/new_agg_fn_evaluator.h +++ b/be/src/exprs/new_agg_fn_evaluator.h @@ -161,7 +161,6 @@ public: static const size_t BIGINT_SIZE = sizeof(int64_t); static const size_t FLOAT_SIZE = sizeof(float); static const size_t DOUBLE_SIZE = sizeof(double); - static const size_t DECIMAL_SIZE = sizeof(DecimalValue); static const size_t DECIMALV2_SIZE = sizeof(DecimalV2Value); static const size_t LARGEINT_SIZE = sizeof(__int128); diff --git a/be/src/exprs/new_in_predicate.cpp b/be/src/exprs/new_in_predicate.cpp index 20730aad2a..c713b82f8f 100644 --- a/be/src/exprs/new_in_predicate.cpp +++ b/be/src/exprs/new_in_predicate.cpp @@ -44,11 +44,6 @@ DateTimeValue get_val(const FunctionContext::TypeDesc* type, const DateTimeVal& return DateTimeValue::from_datetime_val(x); } -template <> -DecimalValue get_val(const FunctionContext::TypeDesc* type, const DecimalVal& x) { - return DecimalValue::from_decimal_val(x); -} - template <> DecimalV2Value get_val(const FunctionContext::TypeDesc* type, const DecimalV2Val& x) { return DecimalV2Value::from_decimal_val(x); @@ -181,7 +176,6 @@ IN_FUNCTIONS(FloatVal, float, float_val) IN_FUNCTIONS(DoubleVal, double, double_val) IN_FUNCTIONS(StringVal, StringValue, string_val) IN_FUNCTIONS(DateTimeVal, DateTimeValue, datetime_val) -IN_FUNCTIONS(DecimalVal, DecimalValue, decimal_val) IN_FUNCTIONS(DecimalV2Val, DecimalV2Value, decimalv2_val) IN_FUNCTIONS(LargeIntVal, __int128, large_int_val) diff --git a/be/src/exprs/new_in_predicate.h b/be/src/exprs/new_in_predicate.h index 161700734c..e71917d942 100644 --- a/be/src/exprs/new_in_predicate.h +++ b/be/src/exprs/new_in_predicate.h @@ -271,46 +271,24 @@ public: const doris_udf::DateTimeVal& val, int num_args, const doris_udf::DateTimeVal* args); - static doris_udf::BooleanVal in_iterate(doris_udf::FunctionContext* context, - const doris_udf::DecimalVal& val, int num_args, - const doris_udf::DecimalVal* args); - static doris_udf::BooleanVal in_iterate(doris_udf::FunctionContext* context, const doris_udf::DecimalV2Val& val, int num_args, const doris_udf::DecimalV2Val* args); - static doris_udf::BooleanVal not_in_iterate(doris_udf::FunctionContext* context, - const doris_udf::DecimalVal& val, int num_args, - const doris_udf::DecimalVal* args); - static doris_udf::BooleanVal not_in_iterate(doris_udf::FunctionContext* context, const doris_udf::DecimalV2Val& val, int num_args, const doris_udf::DecimalV2Val* args); - static void set_lookup_prepare_decimal_val( - doris_udf::FunctionContext* ctx, doris_udf::FunctionContext::FunctionStateScope scope); - static void set_lookup_prepare_decimalv2_val( doris_udf::FunctionContext* ctx, doris_udf::FunctionContext::FunctionStateScope scope); - static void set_lookup_close_decimal_val(doris_udf::FunctionContext* ctx, - doris_udf::FunctionContext::FunctionStateScope scope); - static void set_lookup_close_decimalv2_val( doris_udf::FunctionContext* ctx, doris_udf::FunctionContext::FunctionStateScope scope); - static doris_udf::BooleanVal in_set_lookup(doris_udf::FunctionContext* context, - const doris_udf::DecimalVal& val, int num_args, - const doris_udf::DecimalVal* args); - static doris_udf::BooleanVal in_set_lookup(doris_udf::FunctionContext* context, const doris_udf::DecimalV2Val& val, int num_args, const doris_udf::DecimalV2Val* args); - static doris_udf::BooleanVal not_in_set_lookup(doris_udf::FunctionContext* context, - const doris_udf::DecimalVal& val, int num_args, - const doris_udf::DecimalVal* args); - static doris_udf::BooleanVal not_in_set_lookup(doris_udf::FunctionContext* context, const doris_udf::DecimalV2Val& val, int num_args, const doris_udf::DecimalV2Val* args); diff --git a/be/src/exprs/null_literal.cpp b/be/src/exprs/null_literal.cpp index cda5670b67..c2bafe8d9a 100644 --- a/be/src/exprs/null_literal.cpp +++ b/be/src/exprs/null_literal.cpp @@ -63,10 +63,6 @@ DateTimeVal NullLiteral::get_datetime_val(ExprContext*, TupleRow*) { return DateTimeVal::null(); } -DecimalVal NullLiteral::get_decimal_val(ExprContext*, TupleRow*) { - return DecimalVal::null(); -} - DecimalV2Val NullLiteral::get_decimalv2_val(ExprContext*, TupleRow*) { return DecimalV2Val::null(); } diff --git a/be/src/exprs/null_literal.h b/be/src/exprs/null_literal.h index 000f080990..242e23e6fc 100644 --- a/be/src/exprs/null_literal.h +++ b/be/src/exprs/null_literal.h @@ -40,7 +40,6 @@ public: virtual doris_udf::DoubleVal get_double_val(ExprContext*, TupleRow*); virtual doris_udf::StringVal get_string_val(ExprContext*, TupleRow*); virtual doris_udf::DateTimeVal get_datetime_val(ExprContext*, TupleRow*); - virtual doris_udf::DecimalVal get_decimal_val(ExprContext*, TupleRow*); virtual doris_udf::DecimalV2Val get_decimalv2_val(ExprContext*, TupleRow*); protected: diff --git a/be/src/exprs/runtime_filter.cpp b/be/src/exprs/runtime_filter.cpp index b83f8fcb43..c067798063 100644 --- a/be/src/exprs/runtime_filter.cpp +++ b/be/src/exprs/runtime_filter.cpp @@ -161,9 +161,6 @@ MinMaxFuncBase* MinMaxFuncBase::create_minmax_filter(PrimitiveType type) { case TYPE_DATETIME: return new (std::nothrow) MinMaxNumFunc(); - case TYPE_DECIMAL: - return new (std::nothrow) MinMaxNumFunc(); - case TYPE_DECIMALV2: return new (std::nothrow) MinMaxNumFunc(); @@ -205,7 +202,6 @@ TExprNodeType::type get_expr_node_type(PrimitiveType type) { return TExprNodeType::FLOAT_LITERAL; break; - case TYPE_DECIMAL: case TYPE_DECIMALV2: return TExprNodeType::DECIMAL_LITERAL; @@ -248,8 +244,6 @@ PColumnType to_proto(PrimitiveType type) { return PColumnType::COLUMN_TYPE_DATE; case TYPE_DATETIME: return PColumnType::COLUMN_TYPE_DATETIME; - case TYPE_DECIMAL: - return PColumnType::COLUMN_TYPE_DECIMAL; case TYPE_DECIMALV2: return PColumnType::COLUMN_TYPE_DECIMALV2; case TYPE_CHAR: @@ -287,8 +281,6 @@ PrimitiveType to_primitive_type(PColumnType type) { return TYPE_DATE; case PColumnType::COLUMN_TYPE_DATETIME: return TYPE_DATETIME; - case PColumnType::COLUMN_TYPE_DECIMAL: - return TYPE_DECIMAL; case PColumnType::COLUMN_TYPE_DECIMALV2: return TYPE_DECIMALV2; case PColumnType::COLUMN_TYPE_VARCHAR: @@ -401,12 +393,6 @@ Expr* create_literal(ObjectPool* pool, PrimitiveType type, const void* data) { node.__set_date_literal(dateLiteral); break; } - case TYPE_DECIMAL: { - TDecimalLiteral decimalLiteral; - decimalLiteral.__set_value(reinterpret_cast(data)->to_string()); - node.__set_decimal_literal(decimalLiteral); - break; - } case TYPE_DECIMALV2: { TDecimalLiteral decimalLiteral; decimalLiteral.__set_value(reinterpret_cast(data)->to_string()); @@ -1017,13 +1003,6 @@ void IRuntimeFilter::to_protobuf(PMinMaxFilter* filter) { filter->mutable_max_val()->set_stringval(convert_buffer); return; } - case TYPE_DECIMAL: { - filter->mutable_min_val()->set_stringval( - reinterpret_cast(min_data)->to_string()); - filter->mutable_max_val()->set_stringval( - reinterpret_cast(max_data)->to_string()); - return; - } case TYPE_DECIMALV2: { filter->mutable_min_val()->set_stringval( reinterpret_cast(min_data)->to_string()); diff --git a/be/src/exprs/scalar_fn_call.cpp b/be/src/exprs/scalar_fn_call.cpp index 45820105b0..5ed75166cc 100644 --- a/be/src/exprs/scalar_fn_call.cpp +++ b/be/src/exprs/scalar_fn_call.cpp @@ -421,7 +421,6 @@ typedef FloatVal (*FloatWrapper)(ExprContext*, TupleRow*); typedef DoubleVal (*DoubleWrapper)(ExprContext*, TupleRow*); typedef StringVal (*StringWrapper)(ExprContext*, TupleRow*); typedef DateTimeVal (*DatetimeWrapper)(ExprContext*, TupleRow*); -typedef DecimalVal (*DecimalWrapper)(ExprContext*, TupleRow*); typedef DecimalV2Val (*DecimalV2Wrapper)(ExprContext*, TupleRow*); // TODO: macroify this? @@ -526,16 +525,6 @@ DateTimeVal ScalarFnCall::get_datetime_val(ExprContext* context, TupleRow* row) return fn(context, row); } -DecimalVal ScalarFnCall::get_decimal_val(ExprContext* context, TupleRow* row) { - DCHECK_EQ(_type.type, TYPE_DECIMAL); - DCHECK(context != NULL); - if (_scalar_fn_wrapper == NULL) { - return interpret_eval(context, row); - } - DecimalWrapper fn = reinterpret_cast(_scalar_fn_wrapper); - return fn(context, row); -} - DecimalV2Val ScalarFnCall::get_decimalv2_val(ExprContext* context, TupleRow* row) { DCHECK_EQ(_type.type, TYPE_DECIMALV2); DCHECK(context != NULL); diff --git a/be/src/exprs/scalar_fn_call.h b/be/src/exprs/scalar_fn_call.h index 8e48360b36..8b81498d53 100644 --- a/be/src/exprs/scalar_fn_call.h +++ b/be/src/exprs/scalar_fn_call.h @@ -76,7 +76,6 @@ protected: virtual doris_udf::DoubleVal get_double_val(ExprContext* context, TupleRow*); virtual doris_udf::StringVal get_string_val(ExprContext* context, TupleRow*); virtual doris_udf::DateTimeVal get_datetime_val(ExprContext* context, TupleRow*); - virtual doris_udf::DecimalVal get_decimal_val(ExprContext* context, TupleRow*); virtual doris_udf::DecimalV2Val get_decimalv2_val(ExprContext* context, TupleRow*); // virtual doris_udf::ArrayVal GetArrayVal(ExprContext* context, TupleRow*); diff --git a/be/src/exprs/slot_ref.cpp b/be/src/exprs/slot_ref.cpp index dc1c98b58c..a12e4b627c 100644 --- a/be/src/exprs/slot_ref.cpp +++ b/be/src/exprs/slot_ref.cpp @@ -224,17 +224,6 @@ DateTimeVal SlotRef::get_datetime_val(ExprContext* context, TupleRow* row) { return result; } -DecimalVal SlotRef::get_decimal_val(ExprContext* context, TupleRow* row) { - DCHECK_EQ(_type.type, TYPE_DECIMAL); - Tuple* t = row->get_tuple(_tuple_idx); - if (t == NULL || t->is_null(_null_indicator_offset)) { - return DecimalVal::null(); - } - DecimalVal dec_val; - reinterpret_cast(t->get_slot(_slot_offset))->to_decimal_val(&dec_val); - return dec_val; -} - DecimalV2Val SlotRef::get_decimalv2_val(ExprContext* context, TupleRow* row) { DCHECK_EQ(_type.type, TYPE_DECIMALV2); Tuple* t = row->get_tuple(_tuple_idx); diff --git a/be/src/exprs/slot_ref.h b/be/src/exprs/slot_ref.h index 26806255f4..b3244ce2aa 100644 --- a/be/src/exprs/slot_ref.h +++ b/be/src/exprs/slot_ref.h @@ -67,7 +67,6 @@ public: virtual doris_udf::DoubleVal get_double_val(ExprContext* context, TupleRow*); virtual doris_udf::StringVal get_string_val(ExprContext* context, TupleRow*); virtual doris_udf::DateTimeVal get_datetime_val(ExprContext* context, TupleRow*); - virtual doris_udf::DecimalVal get_decimal_val(ExprContext* context, TupleRow*); virtual doris_udf::DecimalV2Val get_decimalv2_val(ExprContext* context, TupleRow*); // virtual doris_udf::ArrayVal GetArrayVal(ExprContext* context, TupleRow*); diff --git a/be/src/exprs/string_functions.cpp b/be/src/exprs/string_functions.cpp index 8f69797be5..7f9e80b394 100644 --- a/be/src/exprs/string_functions.cpp +++ b/be/src/exprs/string_functions.cpp @@ -890,18 +890,6 @@ StringVal StringFunctions::money_format(FunctionContext* context, const DoubleVa return do_money_format(context, std::to_string(v_cent)); } -StringVal StringFunctions::money_format(FunctionContext* context, const DecimalVal& v) { - if (v.is_null) { - return StringVal::null(); - } - - DecimalValue rounded; - DecimalValue::from_decimal_val(v).round(&rounded, 2, HALF_UP); - DecimalValue tmp(std::string_view("100")); - DecimalValue result = rounded * tmp; - return do_money_format(context, result.to_string()); -} - StringVal StringFunctions::money_format(FunctionContext* context, const DecimalV2Val& v) { if (v.is_null) { return StringVal::null(); diff --git a/be/src/exprs/string_functions.h b/be/src/exprs/string_functions.h index 7237f9f44c..58bdba5591 100644 --- a/be/src/exprs/string_functions.h +++ b/be/src/exprs/string_functions.h @@ -139,9 +139,6 @@ public: static doris_udf::StringVal money_format(doris_udf::FunctionContext* context, const doris_udf::DoubleVal& v); - static doris_udf::StringVal money_format(doris_udf::FunctionContext* context, - const doris_udf::DecimalVal& v); - static doris_udf::StringVal money_format(doris_udf::FunctionContext* context, const doris_udf::DecimalV2Val& v); diff --git a/be/src/exprs/time_operators.cpp b/be/src/exprs/time_operators.cpp index ad22e0c397..87cf7fb0ac 100644 --- a/be/src/exprs/time_operators.cpp +++ b/be/src/exprs/time_operators.cpp @@ -64,8 +64,4 @@ StringVal TimeOperators::cast_to_string_val(FunctionContext* ctx, const DoubleVa DateTimeVal TimeOperators::cast_to_datetime_val(FunctionContext* context, const DoubleVal& val) { return DateTimeVal::null(); } - -DecimalVal TimeOperators::cast_to_decimal_val(FunctionContext* context, const DoubleVal& val) { - return DecimalVal::null(); -} } // namespace doris diff --git a/be/src/exprs/time_operators.h b/be/src/exprs/time_operators.h index a844587b9e..03e869c92a 100644 --- a/be/src/exprs/time_operators.h +++ b/be/src/exprs/time_operators.h @@ -43,7 +43,6 @@ public: static DoubleVal cast_to_double_val(FunctionContext*, const DoubleVal&); static StringVal cast_to_string_val(FunctionContext*, const DoubleVal&); static DateTimeVal cast_to_datetime_val(FunctionContext*, const DoubleVal&); - static DecimalVal cast_to_decimal_val(FunctionContext*, const DoubleVal&); }; } // namespace doris #endif diff --git a/be/src/exprs/topn_function.cpp b/be/src/exprs/topn_function.cpp index 5ea160f184..e956e5e627 100644 --- a/be/src/exprs/topn_function.cpp +++ b/be/src/exprs/topn_function.cpp @@ -16,30 +16,31 @@ // under the License. #include "exprs/topn_function.h" -#include "util/topn_counter.h" + #include "util/slice.h" +#include "util/topn_counter.h" namespace doris { using doris_udf::AnyVal; -void TopNFunctions::init() { -} +void TopNFunctions::init() {} -void TopNFunctions::topn_init(FunctionContext* ctx, StringVal *dst) { +void TopNFunctions::topn_init(FunctionContext* ctx, StringVal* dst) { dst->is_null = false; dst->len = sizeof(TopNCounter); const AnyVal* space_expand_rate_val = ctx->get_constant_arg(2); if (space_expand_rate_val != nullptr) { int32_t space_expand_rate = reinterpret_cast(space_expand_rate_val)->val; - dst->ptr = (uint8_t *) new TopNCounter(space_expand_rate); + dst->ptr = (uint8_t*)new TopNCounter(space_expand_rate); return; } - dst->ptr = (uint8_t *) new TopNCounter(); + dst->ptr = (uint8_t*)new TopNCounter(); } template -void TopNFunctions::topn_update(FunctionContext*, const T& src, const IntVal& topn, StringVal* dst) { +void TopNFunctions::topn_update(FunctionContext*, const T& src, const IntVal& topn, + StringVal* dst) { if (src.is_null) { return; } @@ -49,8 +50,8 @@ void TopNFunctions::topn_update(FunctionContext*, const T& src, const IntVal& to } template -void TopNFunctions::topn_update(FunctionContext *, const T &src, const IntVal &topn, const IntVal &space_expand_rate, - StringVal *dst) { +void TopNFunctions::topn_update(FunctionContext*, const T& src, const IntVal& topn, + const IntVal& space_expand_rate, StringVal* dst) { if (src.is_null) { return; } @@ -59,7 +60,7 @@ void TopNFunctions::topn_update(FunctionContext *, const T &src, const IntVal &t dst_topn->add_item(src); } -void TopNFunctions::topn_merge(FunctionContext* ctx, const StringVal &src, StringVal *dst) { +void TopNFunctions::topn_merge(FunctionContext* ctx, const StringVal& src, StringVal* dst) { if (src.is_null) { return; } @@ -67,7 +68,7 @@ void TopNFunctions::topn_merge(FunctionContext* ctx, const StringVal &src, Strin dst_topn->merge(TopNCounter(Slice(src.ptr, src.len))); } -StringVal TopNFunctions::topn_serialize(FunctionContext *ctx, const StringVal &src) { +StringVal TopNFunctions::topn_serialize(FunctionContext* ctx, const StringVal& src) { auto* src_topn = reinterpret_cast(src.ptr); std::string buffer; @@ -78,7 +79,7 @@ StringVal TopNFunctions::topn_serialize(FunctionContext *ctx, const StringVal &s return result; } -StringVal TopNFunctions::topn_finalize(FunctionContext* ctx, const StringVal &src) { +StringVal TopNFunctions::topn_finalize(FunctionContext* ctx, const StringVal& src) { auto* src_topn = reinterpret_cast(src.ptr); std::string result_str; src_topn->finalize(result_str); @@ -90,30 +91,50 @@ StringVal TopNFunctions::topn_finalize(FunctionContext* ctx, const StringVal &sr return result; } -template void TopNFunctions::topn_update(FunctionContext*, const BooleanVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext *, const TinyIntVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext *, const SmallIntVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext *, const IntVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext *, const BigIntVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext *, const FloatVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext *, const DoubleVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext *, const StringVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const DateTimeVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const LargeIntVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const DecimalVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const DecimalV2Val&, const IntVal&, StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const BooleanVal&, const IntVal&, + StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const TinyIntVal&, const IntVal&, + StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const SmallIntVal&, const IntVal&, + StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const IntVal&, const IntVal&, + StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const BigIntVal&, const IntVal&, + StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const FloatVal&, const IntVal&, + StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const DoubleVal&, const IntVal&, + StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const StringVal&, const IntVal&, + StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const DateTimeVal&, const IntVal&, + StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const LargeIntVal&, const IntVal&, + StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const DecimalV2Val&, const IntVal&, + StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const BooleanVal&, const IntVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext *, const TinyIntVal&, const IntVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext *, const SmallIntVal&, const IntVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext *, const IntVal&, const IntVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext *, const BigIntVal&, const IntVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext *, const FloatVal&, const IntVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext *, const DoubleVal&, const IntVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext *, const StringVal&, const IntVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const DateTimeVal&, const IntVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const LargeIntVal&, const IntVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const DecimalVal&, const IntVal&, const IntVal&, StringVal*); -template void TopNFunctions::topn_update(FunctionContext*, const DecimalV2Val&, const IntVal&, const IntVal&, StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const BooleanVal&, const IntVal&, + const IntVal&, StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const TinyIntVal&, const IntVal&, + const IntVal&, StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const SmallIntVal&, const IntVal&, + const IntVal&, StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const IntVal&, const IntVal&, + const IntVal&, StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const BigIntVal&, const IntVal&, + const IntVal&, StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const FloatVal&, const IntVal&, + const IntVal&, StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const DoubleVal&, const IntVal&, + const IntVal&, StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const StringVal&, const IntVal&, + const IntVal&, StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const DateTimeVal&, const IntVal&, + const IntVal&, StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const LargeIntVal&, const IntVal&, + const IntVal&, StringVal*); +template void TopNFunctions::topn_update(FunctionContext*, const DecimalV2Val&, const IntVal&, + const IntVal&, StringVal*); -} \ No newline at end of file +} // namespace doris \ No newline at end of file diff --git a/be/src/exprs/udf_builtins.cpp b/be/src/exprs/udf_builtins.cpp index ba218b4bf9..5407be7fa3 100644 --- a/be/src/exprs/udf_builtins.cpp +++ b/be/src/exprs/udf_builtins.cpp @@ -32,7 +32,6 @@ using doris_udf::BigIntVal; using doris_udf::LargeIntVal; using doris_udf::FloatVal; using doris_udf::DoubleVal; -using doris_udf::DecimalVal; using doris_udf::DecimalV2Val; using doris_udf::StringVal; using doris_udf::AnyVal; @@ -45,15 +44,6 @@ DoubleVal UdfBuiltins::abs(FunctionContext* context, const DoubleVal& v) { return DoubleVal(fabs(v.val)); } -DecimalVal UdfBuiltins::decimal_abs(FunctionContext* context, const DecimalVal& v) { - if (v.is_null) { - return v; - } - DecimalVal result = v; - result.set_to_abs_value(); - return result; -} - DecimalV2Val UdfBuiltins::decimal_abs(FunctionContext* context, const DecimalV2Val& v) { if (v.is_null) { return v; diff --git a/be/src/exprs/udf_builtins.h b/be/src/exprs/udf_builtins.h index 40b994d1ba..c76dd7a724 100644 --- a/be/src/exprs/udf_builtins.h +++ b/be/src/exprs/udf_builtins.h @@ -30,8 +30,6 @@ class UdfBuiltins { public: static doris_udf::DoubleVal abs(doris_udf::FunctionContext* context, const doris_udf::DoubleVal& v); - static doris_udf::DecimalVal decimal_abs(doris_udf::FunctionContext* context, - const doris_udf::DecimalVal& v); static doris_udf::DecimalV2Val decimal_abs(doris_udf::FunctionContext* context, const doris_udf::DecimalV2Val& v); static doris_udf::BigIntVal add_two_number(doris_udf::FunctionContext* context, diff --git a/be/src/olap/base_tablet.h b/be/src/olap/base_tablet.h index 03b7c819de..9d0e3319b2 100644 --- a/be/src/olap/base_tablet.h +++ b/be/src/olap/base_tablet.h @@ -93,7 +93,7 @@ inline DataDir* BaseTablet::data_dir() const { return _data_dir; } -inline string BaseTablet::tablet_path() const { +inline std::string BaseTablet::tablet_path() const { return _tablet_path; } diff --git a/be/src/olap/delete_handler.h b/be/src/olap/delete_handler.h index c595d9b7ef..78e7edd671 100644 --- a/be/src/olap/delete_handler.h +++ b/be/src/olap/delete_handler.h @@ -59,15 +59,14 @@ private: // 2. For decimal, check whether precision or scale is overflow // 3. For date and datetime, check format and value // 4. For char and varchar, check length - bool is_condition_value_valid(const TabletColumn& column, - const std::string& condition_op, - const string& value_str); + bool is_condition_value_valid(const TabletColumn& column, const std::string& condition_op, + const std::string& value_str); }; // Represent a delete condition. struct DeleteConditions { - int64_t filter_version = 0; // The version of this condition - Conditions* del_cond = nullptr; // The delete condition + int64_t filter_version = 0; // The version of this condition + Conditions* del_cond = nullptr; // The delete condition std::vector column_predicate_vec; }; @@ -89,9 +88,7 @@ struct DeleteConditions { class DeleteHandler { public: DeleteHandler() = default; - ~DeleteHandler() { - finalize(); - } + ~DeleteHandler() { finalize(); } // Initialize DeleteHandler, use the delete conditions of this tablet whose version less than or equal to // 'version' to fill '_del_conds'. @@ -131,9 +128,9 @@ public: // Return all the delete conditions. const std::vector& get_delete_conditions() const { return _del_conds; } - void get_delete_conditions_after_version(int64_t version, - std::vector* delete_conditions, - AndBlockColumnPredicate* and_block_column_predicate_ptr) const; + void get_delete_conditions_after_version( + int64_t version, std::vector* delete_conditions, + AndBlockColumnPredicate* and_block_column_predicate_ptr) const; private: // Use regular expression to extract 'column_name', 'op' and 'operands' diff --git a/be/src/olap/storage_engine.h b/be/src/olap/storage_engine.h index 26afb53922..72e486fbb4 100644 --- a/be/src/olap/storage_engine.h +++ b/be/src/olap/storage_engine.h @@ -245,11 +245,13 @@ private: void _start_disk_stat_monitor(); void _compaction_tasks_producer_callback(); - vector _generate_compaction_tasks(CompactionType compaction_type, - std::vector& data_dirs, - bool check_score); - void _push_tablet_into_submitted_compaction(TabletSharedPtr tablet, CompactionType compaction_type); - void _pop_tablet_from_submitted_compaction(TabletSharedPtr tablet, CompactionType compaction_type); + std::vector _generate_compaction_tasks(CompactionType compaction_type, + std::vector& data_dirs, + bool check_score); + void _push_tablet_into_submitted_compaction(TabletSharedPtr tablet, + CompactionType compaction_type); + void _pop_tablet_from_submitted_compaction(TabletSharedPtr tablet, + CompactionType compaction_type); Status _init_stream_load_recorder(const std::string& stream_load_record_path); diff --git a/be/src/olap/tablet.h b/be/src/olap/tablet.h index 6bbb21f88b..76649a3c77 100644 --- a/be/src/olap/tablet.h +++ b/be/src/olap/tablet.h @@ -91,16 +91,17 @@ public: inline double bloom_filter_fpp() const; inline size_t next_unique_id() const; inline size_t row_size() const; - inline int32_t field_index(const string& field_name) const; + inline int32_t field_index(const std::string& field_name) const; // operation in rowsets OLAPStatus add_rowset(RowsetSharedPtr rowset, bool need_persist = true); - void modify_rowsets(vector& to_add, - vector& to_delete); + void modify_rowsets(std::vector& to_add, + std::vector& to_delete); // _rs_version_map and _stale_rs_version_map should be protected by _meta_lock // The caller must call hold _meta_lock when call this two function. - const RowsetSharedPtr get_rowset_by_version(const Version& version, bool find_is_stale = false) const; + const RowsetSharedPtr get_rowset_by_version(const Version& version, + bool find_is_stale = false) const; const RowsetSharedPtr get_stale_rowset_by_version(const Version& version) const; const RowsetSharedPtr rowset_with_max_version() const; @@ -113,19 +114,19 @@ public: void delete_expired_stale_rowset(); OLAPStatus capture_consistent_versions(const Version& spec_version, - vector* version_path) const; + std::vector* version_path) const; OLAPStatus check_version_integrity(const Version& version); bool check_version_exist(const Version& version) const; void acquire_version_and_rowsets(std::vector>* version_rowsets) const; OLAPStatus capture_consistent_rowsets(const Version& spec_version, - vector* rowsets) const; + std::vector* rowsets) const; OLAPStatus capture_rs_readers(const Version& spec_version, - vector* rs_readers, + std::vector* rs_readers, std::shared_ptr parent_tracker = nullptr) const; - OLAPStatus capture_rs_readers(const vector& version_path, - vector* rs_readers, + OLAPStatus capture_rs_readers(const std::vector& version_path, + std::vector* rs_readers, std::shared_ptr parent_tracker = nullptr) const; DelPredicateArray delete_predicates() { return _tablet_meta->delete_predicates(); } @@ -136,7 +137,8 @@ public: // message for alter task AlterTabletTaskSharedPtr alter_task(); void add_alter_task(int64_t related_tablet_id, int32_t related_schema_hash, - const vector& versions_to_alter, const AlterTabletType alter_type); + const std::vector& versions_to_alter, + const AlterTabletType alter_type); void delete_alter_task(); OLAPStatus set_alter_state(AlterTabletState state); @@ -165,15 +167,16 @@ public: // operation for compaction bool can_do_compaction(); - uint32_t calc_compaction_score(CompactionType compaction_type, - std::shared_ptr cumulative_compaction_policy); + uint32_t calc_compaction_score( + CompactionType compaction_type, + std::shared_ptr cumulative_compaction_policy); static void compute_version_hash_from_rowsets(const std::vector& rowsets, VersionHash* version_hash); // operation for clone - void calc_missed_versions(int64_t spec_version, vector* missed_versions); + void calc_missed_versions(int64_t spec_version, std::vector* missed_versions); void calc_missed_versions_unlocked(int64_t spec_version, - vector* missed_versions) const; + std::vector* missed_versions) const; // This function to find max continuous version from the beginning. // For example: If there are 1, 2, 3, 5, 6, 7 versions belongs tablet, then 3 is target. @@ -181,7 +184,7 @@ public: // operation for query OLAPStatus split_range(const OlapTuple& start_key_strings, const OlapTuple& end_key_strings, - uint64_t request_block_row_count, vector* ranges); + uint64_t request_block_row_count, std::vector* ranges); void set_bad(bool is_bad) { _is_bad = is_bad; } @@ -227,7 +230,7 @@ public: // eco mode also means save money in palo inline bool in_eco_mode() { return false; } - // return true if the checkpoint is actually done + // return true if the checkpoint is actually done bool do_tablet_meta_checkpoint(); // Check whether the rowset is useful or not, unuseful rowset can be swept up then. @@ -247,7 +250,8 @@ public: double calculate_scan_frequency(); - int64_t prepare_compaction_and_calculate_permits(CompactionType compaction_type, TabletSharedPtr tablet); + int64_t prepare_compaction_and_calculate_permits(CompactionType compaction_type, + TabletSharedPtr tablet); void execute_compaction(CompactionType compaction_type); void reset_compaction(CompactionType compaction_type); @@ -265,8 +269,8 @@ private: /// Delete stale rowset by version. This method not only delete the version in expired rowset map, /// but also delete the version in rowset meta vector. void _delete_stale_rowset_by_version(const Version& version); - OLAPStatus _capture_consistent_rowsets_unlocked(const vector& version_path, - vector* rowsets) const; + OLAPStatus _capture_consistent_rowsets_unlocked(const std::vector& version_path, + std::vector* rowsets) const; const uint32_t _calc_cumulative_compaction_score( std::shared_ptr cumulative_compaction_policy); @@ -367,7 +371,8 @@ inline const int64_t Tablet::cumulative_layer_point() const { inline void Tablet::set_cumulative_layer_point(int64_t new_point) { // cumulative point should only be reset to -1, or be increased CHECK(new_point == Tablet::K_INVALID_CUMULATIVE_POINT || new_point >= _cumulative_point) - << "Unexpected cumulative point: " << new_point << ", origin: " << _cumulative_point.load(); + << "Unexpected cumulative point: " << new_point + << ", origin: " << _cumulative_point.load(); _cumulative_point = new_point; } @@ -429,7 +434,7 @@ inline size_t Tablet::next_unique_id() const { return _schema.next_column_unique_id(); } -inline int32_t Tablet::field_index(const string& field_name) const { +inline int32_t Tablet::field_index(const std::string& field_name) const { return _schema.field_index(field_name); } diff --git a/be/src/olap/tablet_manager.h b/be/src/olap/tablet_manager.h index 9af7950635..5cdd2d22d9 100644 --- a/be/src/olap/tablet_manager.h +++ b/be/src/olap/tablet_manager.h @@ -70,11 +70,10 @@ public: OLAPStatus drop_tablets_on_error_root_path(const std::vector& tablet_info_vec); - TabletSharedPtr find_best_tablet_to_compaction(CompactionType compaction_type, - DataDir* data_dir, - const std::unordered_set& tablet_submitted_compaction, - uint32_t* score, - std::shared_ptr cumulative_compaction_policy); + TabletSharedPtr find_best_tablet_to_compaction( + CompactionType compaction_type, DataDir* data_dir, + const std::unordered_set& tablet_submitted_compaction, uint32_t* score, + std::shared_ptr cumulative_compaction_policy); TabletSharedPtr get_tablet(TTabletId tablet_id, SchemaHash schema_hash, bool include_deleted = false, std::string* err = nullptr); @@ -104,7 +103,8 @@ public: // where we should change tablet status from shutdown back to running OLAPStatus load_tablet_from_meta(DataDir* data_dir, TTabletId tablet_id, TSchemaHash schema_hash, const std::string& header, - bool update_meta, bool force = false, bool restore = false, bool check_path=true); + bool update_meta, bool force = false, bool restore = false, + bool check_path = true); OLAPStatus load_tablet_from_dir(DataDir* data_dir, TTabletId tablet_id, SchemaHash schema_hash, const std::string& schema_hash_path, bool force = false, @@ -125,7 +125,7 @@ public: bool try_schema_change_lock(TTabletId tablet_id); void try_delete_unused_tablet_path(DataDir* data_dir, TTabletId tablet_id, - SchemaHash schema_hash, const string& schema_hash_path); + SchemaHash schema_hash, const std::string& schema_hash_path); void update_root_path_info(std::map* path_map, size_t* tablet_counter); @@ -134,14 +134,14 @@ public: void do_tablet_meta_checkpoint(DataDir* data_dir); - void obtain_specific_quantity_tablets(vector& tablets_info, int64_t num); + void obtain_specific_quantity_tablets(std::vector& tablets_info, int64_t num); void register_clone_tablet(int64_t tablet_id); void unregister_clone_tablet(int64_t tablet_id); void get_tablets_distribution_on_different_disks( - std::map> &tablets_num_on_disk, - std::map>> &tablets_info_on_disk); + std::map>& tablets_num_on_disk, + std::map>>& tablets_info_on_disk); private: // Add a tablet pointer to StorageEngine diff --git a/be/src/olap/tablet_meta.cpp b/be/src/olap/tablet_meta.cpp index 1acf76c466..866dda1107 100644 --- a/be/src/olap/tablet_meta.cpp +++ b/be/src/olap/tablet_meta.cpp @@ -125,8 +125,7 @@ TabletMeta::TabletMeta(int64_t table_id, int64_t partition_id, int64_t tablet_id string data_type; EnumToString(TPrimitiveType, tcolumn.column_type.type, data_type); column->set_type(data_type); - if (tcolumn.column_type.type == TPrimitiveType::DECIMAL || - tcolumn.column_type.type == TPrimitiveType::DECIMALV2) { + if (tcolumn.column_type.type == TPrimitiveType::DECIMALV2) { column->set_precision(tcolumn.column_type.precision); column->set_frac(tcolumn.column_type.scale); } diff --git a/be/src/olap/tablet_schema.cpp b/be/src/olap/tablet_schema.cpp index 67279f950a..96b35b80f2 100644 --- a/be/src/olap/tablet_schema.cpp +++ b/be/src/olap/tablet_schema.cpp @@ -244,7 +244,6 @@ uint32_t TabletColumn::get_field_length_by_type(TPrimitiveType::type type, uint3 case TPrimitiveType::VARCHAR: case TPrimitiveType::HLL: return string_length + sizeof(OLAP_STRING_MAX_LENGTH); - case TPrimitiveType::DECIMAL: case TPrimitiveType::DECIMALV2: return 12; // use 12 bytes in olap engine. default: diff --git a/be/src/olap/types.h b/be/src/olap/types.h index b070e38d80..6c74b2c34c 100644 --- a/be/src/olap/types.h +++ b/be/src/olap/types.h @@ -26,6 +26,7 @@ #include #include "gen_cpp/segment_v2.pb.h" // for ColumnMetaPB +#include "gutil/strings/numbers.h" #include "olap/collection.h" #include "olap/decimal12.h" #include "olap/olap_common.h" diff --git a/be/src/runtime/CMakeLists.txt b/be/src/runtime/CMakeLists.txt index 8f7bd9eb16..9372f0dafb 100644 --- a/be/src/runtime/CMakeLists.txt +++ b/be/src/runtime/CMakeLists.txt @@ -48,7 +48,6 @@ set(RUNTIME_FILES string_value.cpp thread_resource_mgr.cpp # timestamp_value.cpp - decimal_value.cpp decimalv2_value.cpp large_int_value.cpp tuple.cpp diff --git a/be/src/runtime/decimal_value.cpp b/be/src/runtime/decimal_value.cpp deleted file mode 100644 index 15ba6f938b..0000000000 --- a/be/src/runtime/decimal_value.cpp +++ /dev/null @@ -1,1242 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#include "runtime/decimal_value.h" - -#include -#include -#include - -namespace doris { - -// set the 1st param if the second param is smaller. -template -inline void set_if_smaller(T* num1_ptr, const T num2) { - if (*num1_ptr > num2) { - *num1_ptr = num2; - } -} - -// set the 1st param if the second param is smaller. -template -inline void set_if_bigger(T* num1_ptr, const T num2) { - if (*num1_ptr < num2) { - *num1_ptr = num2; - } -} - -// util function: check if there is error and fix it. -inline void fix_intg_frac_error(const int32_t len, int32_t* int_len, int32_t* frac_len, - int32_t* error) { - if (*int_len + *frac_len > len) { - if (*int_len > len) { - *int_len = len; - *frac_len = 0; - *error = E_DEC_OVERFLOW; - } else { - *frac_len = len - *int_len; - *error = E_DEC_TRUNCATED; - } - } else { - *error = E_DEC_OK; - } -} - -// Note: the carry <= 1, so for the sum of three number(value1, value2, *carry), -// the maximum value of carry is 1. -inline void add(const int32_t value1, const int32_t value2, int32_t* to, int32_t* carry) { - int32_t sum = value1 + value2 + *carry; - *carry = (sum >= DIG_BASE) ? 1 : 0; - if (*carry) { - sum -= DIG_BASE; - } - *to = sum; -} - -// to = value1 - value2 -inline void sub(const int32_t value1, const int32_t value2, int32_t* to, int32_t* carry) { - int32_t a = value1 - value2 - *carry; - *carry = (a < 0) ? 1 : 0; - if (*carry) { - a += DIG_BASE; - } - *to = a; -} - -// Note: the input carry may > 1, after the summation process of three number (value1, value2, *carry), -// the maximum value of carry may be 2, when sum() >= 2 * DIG_BASE. -inline void add2(const int32_t value1, const int32_t value2, int32_t* to, int32_t* carry) { - // NOTE: When three int32_t integers (the maximum value of each number is 10 ^ 9 - 1) are added, - // because the maximum value of int32_t is 2147483647, the result may overflow, so it is - // necessary to convert int32_t to int64_t. - int64_t sum = (int64_t)value1 + value2 + *carry; - *carry = (sum >= DIG_BASE) ? 1 : 0; - if (*carry) { - sum -= DIG_BASE; - } - if (sum >= DIG_BASE) { - sum -= DIG_BASE; - ++(*carry); - } - // the value of sum must small than DIG_BASE here - *to = (int32_t)sum; -} - -// to = value1 - value2 ƒ -inline void sub2(const int32_t value1, const int32_t value2, int32_t* to, int32_t* carry) { - int32_t a = value1 - value2 - *carry; - *carry = (a < 0) ? 1 : 0; - if (*carry) { - a += DIG_BASE; - } - if (a < 0) { - a += DIG_BASE; - ++(*carry); - } - *to = a; -} - -int32_t do_add(const DecimalValue& value1, const DecimalValue& value2, DecimalValue* to) { - int32_t intg1 = round_up(value1._int_length); - int32_t intg2 = round_up(value2._int_length); - int32_t frac1 = round_up(value1._frac_length); - int32_t frac2 = round_up(value2._frac_length); - int32_t frac0 = std::max(frac1, frac2); - int32_t intg0 = std::max(intg1, intg2); - - // Is there a need for extra word because of carry? - int32_t first_big_digit_sum = intg1 > intg2 ? value1._buffer[0] - : intg2 > intg1 ? value2._buffer[0] - : value1._buffer[0] + value2._buffer[0]; - if (first_big_digit_sum > DIG_MAX - 1) { - // yes, there is - ++intg0; - to->_buffer[0] = 0; // for safety - } - - to->_sign = value1._sign; - - int32_t error = E_DEC_OK; - fix_intg_frac_error(to->_buffer_length, &intg0, &frac0, &error); - if (error == E_DEC_OVERFLOW) { - to->to_max_decimal(to->_buffer_length * DIG_PER_DEC1, 0); - return error; - } - - int32_t* buf0 = to->_buffer + intg0 + frac0; - to->_int_length = intg0 * DIG_PER_DEC1; - to->_frac_length = std::max(value1._frac_length, value2._frac_length); - if (error) { // E_DEC_TRUNCATED - int32_t to_frac_length = to->_frac_length; - //ATTN: _int_length is bit-field struct member, can not take address directly. - set_if_smaller(&to_frac_length, frac0 * DIG_PER_DEC1); - to->_frac_length = to_frac_length; - set_if_smaller(&frac1, frac0); - set_if_smaller(&frac2, frac0); - set_if_smaller(&intg1, intg0); - set_if_smaller(&intg2, intg0); - } - - // part 1 - max(frac) ... min (frac) - const int32_t* buf1 = nullptr; - const int32_t* buf2 = nullptr; - const int32_t* stop = nullptr; - const int32_t* stop2 = nullptr; - if (frac1 > frac2) { - buf1 = value1._buffer + intg1 + frac1; - stop = value1._buffer + intg1 + frac2; - buf2 = value2._buffer + intg2 + frac2; - stop2 = value1._buffer + ((intg1 > intg2) ? (intg1 - intg2) : 0); - } else { - buf1 = value2._buffer + intg2 + frac2; - stop = value2._buffer + intg2 + frac1; - buf2 = value1._buffer + intg1 + frac1; - stop2 = value2._buffer + ((intg2 > intg1) ? (intg2 - intg1) : 0); - } - while (buf1 > stop) { - *--buf0 = *--buf1; - } - - // part 2 - min(frac) ... min(intg) - int32_t carry = 0; - while (buf1 > stop2) { - add(*--buf1, *--buf2, --buf0, &carry); - } - - // part 3 - min(intg) ... max(intg) - if (intg1 > intg2) { - stop = value1._buffer; - buf1 = stop + intg1 - intg2; - } else { - stop = value2._buffer; - buf1 = stop + intg2 - intg1; - } - while (buf1 > stop) { - add(*--buf1, 0, --buf0, &carry); - } - - if (carry) { - *--buf0 = 1; - } - - return error; -} - -// to=value1-value2. -// if to==0, return -1/0/+1 - the result of the comparison -int do_sub(const DecimalValue& value1, const DecimalValue& value2, DecimalValue* to) { - int32_t intg1 = round_up(value1._int_length); - int32_t intg2 = round_up(value2._int_length); - int32_t frac1 = round_up(value1._frac_length); - int32_t frac2 = round_up(value2._frac_length); - int32_t frac0 = std::max(frac1, frac2); - int32_t error = E_DEC_OK; - int32_t carry = 0; - - // let carry:=1 if value2 > value1 - // TODO(lingbin): add another variable 'is_bigger' to replace 'carry' to make carry only - // has one meaning - const int32_t* buf1 = value1._buffer; - const int32_t* start1 = buf1; - const int32_t* stop1 = buf1 + intg1; - const int32_t* buf2 = value2._buffer; - const int32_t* start2 = buf2; - const int32_t* stop2 = buf2 + intg2; - // ignore leading zeroes - if (*buf1 == 0) { - while (buf1 < stop1 && *buf1 == 0) { - buf1++; - } - start1 = buf1; - intg1 = (int32_t)(stop1 - buf1); - } - if (*buf2 == 0) { - while (buf2 < stop2 && *buf2 == 0) { - buf2++; - } - start2 = buf2; - intg2 = (int32_t)(stop2 - buf2); - } - if (intg2 > intg1) { - carry = 1; - } else if (intg2 == intg1) { - const int32_t* end1 = stop1 + (frac1 - 1); - const int32_t* end2 = stop2 + (frac2 - 1); - // ignore trailing zeroes - while ((buf1 <= end1) && (*end1 == 0)) { - end1--; - } - while ((buf2 <= end2) && (*end2 == 0)) { - end2--; - } - - frac1 = (int32_t)(end1 - stop1) + 1; - frac2 = (int32_t)(end2 - stop2) + 1; - while (buf1 <= end1 && buf2 <= end2 && *buf1 == *buf2) { - buf1++; - buf2++; - } - - if (buf1 <= end1) { - if (buf2 <= end2) { // not equal - carry = (*buf2 > *buf1); - } else { // value1 is longer, so value1 > value2 - carry = 0; - } - } else { - if (buf2 <= end2) { // value2 is longer - carry = 1; - } else { // short-circuit everything: value1 == value2 - if (to == nullptr) { // for decimal_cmp() - return 0; - } - to->set_to_zero(); - return E_DEC_OK; - } - } - } - - if (to == nullptr) { // decimal_cmp(), not equal - return (carry == value1._sign) ? 1 : -1; - } - - to->_sign = value1._sign; - - DecimalValue value_big = value1; - DecimalValue value_small = value2; - - // ensure that always value1 > value2 (and intg1 >= intg2) - if (carry) { - std::swap(value_big, value_small); - std::swap(start1, start2); - std::swap(intg1, intg2); - std::swap(frac1, frac2); - to->_sign = 1 - to->_sign; - } - - fix_intg_frac_error(to->_buffer_length, &intg1, &frac0, &error); - int32_t* buf0 = to->_buffer + intg1 + frac0; - - to->_frac_length = std::max(value_big._frac_length, value_small._frac_length); - to->_int_length = intg1 * DIG_PER_DEC1; - if (error) { // must be E_DEC_TRUNCATE. - int32_t temp_to_frac_length = to->_frac_length; - set_if_smaller(&temp_to_frac_length, frac0 * DIG_PER_DEC1); - to->_frac_length = temp_to_frac_length; - - set_if_smaller(&frac1, frac0); - set_if_smaller(&frac2, frac0); - set_if_smaller(&intg2, intg1); - } - carry = 0; - - // part 1 - max(frac) ... min (frac) - if (frac1 > frac2) { - buf1 = start1 + intg1 + frac1; - stop1 = start1 + intg1 + frac2; - buf2 = start2 + intg2 + frac2; - while (frac0-- > frac1) { //occur when there are trailing zeroes - *--buf0 = 0; - } - while (buf1 > stop1) { - *--buf0 = *--buf1; - } - } else { - buf1 = start1 + intg1 + frac1; - buf2 = start2 + intg2 + frac2; - stop2 = start2 + intg2 + frac1; - while (frac0-- > frac2) { - *--buf0 = 0; - } - while (buf2 > stop2) { - sub(0, *--buf2, --buf0, &carry); - } - } - - // part 2 - min(frac) ... intg2 - while (buf2 > start2) { - sub(*--buf1, *--buf2, --buf0, &carry); - } - - // part 3 - intg2 ... intg1 */ - while (carry && buf1 > start1) { - sub(*--buf1, 0, --buf0, &carry); - } - - while (buf1 > start1) { - *--buf0 = *--buf1; - } - - while (buf0 > to->_buffer) { // TODO(lingbin): will not happen? - *--buf0 = 0; - } - - return error; -} - -// multiply two decimals -// @return E_DEC_OK/E_DEC_TRUNCATED/E_DEC_OVERFLOW; -// -// NOTE: -// in this implementation, with sizeof(big_digit_type)=4 we have DIG_PER_DEC1=9, -// and 63-digit number will take only 7 big_digit_type words (basically a 7-digit -// "base 999999999" number). Thus there's no need in fast multiplication -// algorithms, 7-digit numbers can be multiplied with a naive O(n*n) -// method. -// XXX if this library is to be used with huge numbers of thousands of -// digits, fast multiplication must be implemented. -int do_mul(const DecimalValue& value1, const DecimalValue& value2, DecimalValue* to) { - int32_t intg1 = round_up(value1._int_length); - int32_t intg2 = round_up(value2._int_length); - int32_t frac1 = round_up(value1._frac_length); - int32_t frac2 = round_up(value2._frac_length); - int32_t intg0 = round_up(value1._int_length + value2._int_length); - int32_t frac0 = frac1 + frac2; - int32_t error = E_DEC_OK; - - const int32_t* buf1 = value1._buffer + intg1; - const int32_t* buf2 = value2._buffer + intg2; - - // If E_DEC_OVERFLOW, save 'ideal' values. Note that no need to calculate fraction now. - int32_t temp_intg = intg0; - // if E_DEC_TRUNCATE, use to - int32_t temp_frac = frac0; - fix_intg_frac_error(to->_buffer_length, &intg0, &frac0, &error); // bound size - to->_sign = (value1._sign != value2._sign) ? true : false; - to->_int_length = intg0 * DIG_PER_DEC1; - to->_frac_length = value1._frac_length + value2._frac_length; // store size in digits - - int32_t temp_to_frac_length = to->_frac_length; - //ATTN: _int_length is bit-field struct member, can not take address directly. - set_if_smaller(&temp_to_frac_length, NOT_FIXED_DEC); - to->_frac_length = temp_to_frac_length; - if (error) { - int32_t temp_to_int_length = to->_int_length; - set_if_smaller(&temp_to_int_length, intg0 * DIG_PER_DEC1); - to->_int_length = temp_to_int_length; - - int32_t temp_to_frac_length = to->_frac_length; - set_if_smaller(&temp_to_frac_length, frac0 * DIG_PER_DEC1); - to->_frac_length = temp_to_frac_length; - - if (temp_intg > intg0) { // bounded integer-part, E_DEC_OVERFLOW - temp_intg -= intg0; - temp_frac = temp_intg >> 1; - intg1 -= temp_frac; - intg2 -= temp_intg - temp_frac; - frac1 = frac2 = 0; // frac0 is already 0 here - } else { // bounded fract part, E_DEC_TRUNCATE - temp_frac -= frac0; - temp_intg = temp_frac >> 1; - if (frac1 <= frac2) { - frac1 -= temp_intg; - frac2 -= temp_frac - temp_intg; - } else { - frac2 -= temp_intg; - frac1 -= temp_frac - temp_intg; - } - } - } - int32_t* start0 = to->_buffer + intg0 + frac0 - 1; - const int32_t* start2 = buf2 + frac2 - 1; - const int32_t* stop1 = buf1 - intg1; - const int32_t* stop2 = buf2 - intg2; - int32_t* buf0 = nullptr; - int32_t carry = 0; - - memset(to->_buffer, 0, (intg0 + frac0) * sizeof(int32_t)); - for (buf1 += frac1 - 1; buf1 >= stop1; buf1--, start0--) { - carry = 0; - for (buf0 = start0, buf2 = start2; buf2 >= stop2; buf2--, buf0--) { - int64_t mul_result = ((int64_t)*buf1) * ((int64_t)*buf2); - int32_t high = (int32_t)(mul_result / DIG_BASE); - int32_t low = (int32_t)(mul_result - ((int64_t)high) * DIG_BASE); - add2(*buf0, low, buf0, &carry); - carry += high; - } - if (carry) { - if (buf0 < to->_buffer) { - return E_DEC_OVERFLOW; - } - add2(*buf0, 0, buf0, &carry); - } - // may carry again. - for (buf0--; carry; buf0--) { - if (buf0 < to->_buffer) { - return E_DEC_OVERFLOW; - } - add2(*buf0, 0, buf0, &carry); - } - } - - // Now we have to check for '-0.000' case - if (to->_sign) { - int32_t* buf = to->_buffer; - int32_t* end = to->_buffer + intg0 + frac0; - for (; buf < end; ++buf) { - if (*buf) { - break; - } - } - if (buf == end) { - // We got decimal zero - to->set_to_zero(); - } - } - - // remove leading zeros. - buf1 = to->_buffer; - int32_t d_to_move = intg0 + round_up(to->_frac_length); - while ((*buf1 == 0) && (to->_int_length > DIG_PER_DEC1)) { - ++buf1; - to->_int_length -= DIG_PER_DEC1; - d_to_move--; - } - if (to->_buffer < buf1) { - int32_t* cur_d = to->_buffer; - for (; d_to_move--; cur_d++, buf1++) { - *cur_d = *buf1; - } - } - - return error; -} - -// if N1/N2 mod==NULL; if N1%N2 to==NULL; -int do_div_mod(const DecimalValue& value1, const DecimalValue& value2, DecimalValue* to, - DecimalValue* mod) { - int32_t frac1 = round_up(value1._frac_length) * DIG_PER_DEC1; - int32_t frac2 = round_up(value2._frac_length) * DIG_PER_DEC1; - int32_t prec1 = value1._int_length + frac1; - int32_t prec2 = value2._int_length + frac2; - int32_t error = E_DEC_OK; - - if (mod) { - to = mod; - } - - const int32_t* buff1 = value1._buffer; - const int32_t* buff2 = value2._buffer; - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Warray-bounds" - // removing all the leading zeros - // process value2 - int32_t first_big_digit_length = (prec2 - 1) % DIG_PER_DEC1 + 1; - while (prec2 > 0 && *buff2 == 0) { - prec2 -= first_big_digit_length; - first_big_digit_length = DIG_PER_DEC1; - ++buff2; - } - if (prec2 <= 0) { // short-circuit everything, value2 == 0 - return E_DEC_DIV_ZERO; - } - first_big_digit_length = (prec2 - 1) % DIG_PER_DEC1 + 1; - for (; *buff2 < powers10[--first_big_digit_length];) { - --prec2; - } - - // process value1 - first_big_digit_length = (prec1 - 1) % DIG_PER_DEC1 + 1; - while (prec1 > 0 && *buff1 == 0) { - prec1 -= first_big_digit_length; - first_big_digit_length = DIG_PER_DEC1; - ++buff1; - } - if (prec1 <= 0) { // short-circuit everything, value1 == 0 - to->set_to_zero(); - return E_DEC_OK; - } - first_big_digit_length = (prec1 - 1) % DIG_PER_DEC1 + 1; - for (; *buff1 < powers10[--first_big_digit_length];) { - --prec1; - } -#pragma GCC diagnostic pop - - // 比较两个数的整形部分,得到结果的intg。 如果被除数较小,intg=0. - int32_t dintg = (prec1 - frac1) - (prec2 - frac2) + (*buff1 >= *buff2); - int32_t intg0 = 0; // big digit length - int32_t frac0 = 0; - if (dintg < 0) { - dintg /= DIG_PER_DEC1; - intg0 = 0; - } else { - intg0 = round_up(dintg); - } - - if (mod) { - // we are calculating N1 % N2. The result will have - // 1) frac = max(frac1, frac2), as for subtraction - // 2) intg = intg2. - to->_sign = value1._sign; - to->_frac_length = std::max(value1._frac_length, value2._frac_length); - frac0 = 0; - } else { - // we are calculating N1/N2. - // N1 is in the buff1, has prec1 digits; N2 is in the buff2, has prec2 digits. - // Scales are frac1 and frac2 accordingly. - // Thus, the result will have - // 1) frac = round_up(frac1 + frac2) - // 2) intg = (prec1 - frac1) - (prec2 - frac2) + 1 - // 3) prec = intg + frac - - frac0 = round_up(frac1 + frac2); - if (frac0 == 0) { - frac0 = 1; - } - fix_intg_frac_error(to->_buffer_length, &intg0, &frac0, &error); - - to->_sign = (value1._sign != value2._sign); - to->_int_length = intg0 * DIG_PER_DEC1; - to->_frac_length = frac0 * DIG_PER_DEC1; - } - - int32_t* buff0 = to->_buffer; - int32_t* stop0 = buff0 + intg0 + frac0; - int32_t div_mod = !(mod); // true when do div, false when do mod. - if (div_mod) { // do div - while (dintg++ < 0 && buff0 < &(to->_buffer[to->_buffer_length])) { - *buff0++ = 0; - } - } - - int32_t i = round_up(prec1); - int32_t len1 = i + round_up(2 * frac2 + 1) + 1; - set_if_bigger(&len1, 3); - int32_t* tmp1 = new (std::nothrow) int32_t[len1 * sizeof(int32_t)]; - if (tmp1 == nullptr) { - return E_DEC_OOM; - } - memcpy(tmp1, buff1, i * sizeof(int32_t)); - memset(tmp1 + i, 0, (len1 - i) * sizeof(int32_t)); - - int32_t* start1 = tmp1; - int32_t* stop1 = start1 + len1; - const int32_t* start2 = buff2; - const int32_t* stop2 = buff2 + round_up(prec2) - 1; - - // removing end zeroes - while (*stop2 == 0 && stop2 >= start2) { - --stop2; - } - int32_t len2 = (int32_t)((stop2++) - start2); - - // calculating norm2 (normalized *start2) - we need *start2 to be large - // (at least > DIG_BASE/2), but unlike Knuth's Alg. D we don't want to - // normalize input numbers (as we don't make a copy of the divisor). - // Thus we normalize first big_digit_type of buf2 only, and we'll normalize *start1 - // on the fly for the purpose of guesstimation only. - // It's also faster, as we're saving on normalization of buf2 - int64_t norm_factor = DIG_BASE / (*start2 + 1); - int32_t norm2 = (int32_t)(norm_factor * start2[0]); - if (len2 > 0) { - norm2 += (int32_t)(norm_factor * start2[1] / DIG_BASE); - } - - int32_t dcarry; - if (*start1 < *start2) { - dcarry = *start1++; - } else { - dcarry = 0; - } - - int64_t guess = 0; - // main loop - for (; buff0 < stop0; buff0++) { - // short-circuit, if possible - if (dcarry == 0 && *start1 < *start2) { - guess = 0; - } else { - // D3: make a guess - int64_t x = start1[0] + ((int64_t)dcarry) * DIG_BASE; - int64_t y = start1[1]; - guess = (norm_factor * x + norm_factor * y / DIG_BASE) / norm2; - if (guess >= DIG_BASE) { - guess = DIG_BASE - 1; - } - if (len2 > 0) { - // hmm, this is a suspicious trick - I removed normalization here - if (start2[1] * guess > (x - guess * start2[0]) * DIG_BASE + y) { - guess--; - } - if (start2[1] * guess > (x - guess * start2[0]) * DIG_BASE + y) { - guess--; - } - } - - // D4: multiply and subtract - buff2 = stop2; - int32_t* temp_prt = start1 + len2; - int32_t carry = 0; - for (; buff2 > start2; --temp_prt) { - int32_t high; - int32_t low; - x = guess * (*--buff2); - high = (int32_t)(x / DIG_BASE); - low = (int32_t)(x - ((int64_t)high) * DIG_BASE); - sub2(*temp_prt, low, temp_prt, &carry); - carry += high; - } - carry = dcarry < carry; - - // D5: check the remainder - if (carry) { - // D6: correct the guess - guess--; - buff2 = stop2; - temp_prt = start1 + len2; - for (carry = 0; buff2 > start2; temp_prt--) { - add(*temp_prt, *--buff2, temp_prt, &carry); - } - } - } - if (div_mod) { - *buff0 = (int32_t)guess; - } - dcarry = *start1; - ++start1; - } - - do { - if (mod) { - // now the result is in tmp1, it has - // intg=prec1-frac1 - // frac=max(frac1, frac2)=to->frac - if (dcarry) { - *--start1 = dcarry; - } - buff0 = to->_buffer; - intg0 = (int)(round_up(prec1 - frac1) - (start1 - tmp1)); - frac0 = round_up(to->_frac_length); - error = E_DEC_OK; - if (frac0 == 0 && intg0 == 0) { - to->set_to_zero(); - break; - } - if (intg0 <= 0) { - if (-intg0 >= to->_buffer_length) { - error = E_DEC_TRUNCATED; - to->set_to_zero(); - break; - } - stop1 = start1 + frac0 + intg0; - frac0 += intg0; - to->_int_length = 0; - while (intg0++ < 0) { - *buff0++ = 0; - } - } else { - if (intg0 > to->_buffer_length) { - frac0 = 0; - intg0 = to->_buffer_length; - error = E_DEC_OVERFLOW; - break; - } - stop1 = start1 + frac0 + intg0; - to->_int_length = std::min(intg0 * DIG_PER_DEC1, (int)value2._int_length); - } - if (intg0 + frac0 > to->_buffer_length) { - stop1 -= frac0 + intg0 - to->_buffer_length; - frac0 = to->_buffer_length - intg0; - to->_frac_length = frac0 * DIG_PER_DEC1; - error = E_DEC_TRUNCATED; - } - while (start1 < stop1) { - *buff0++ = *start1++; - } - } - } while (0); - - delete[] tmp1; - int32_t to_int_length = 0; - const int32_t* first_no_zero = to->get_first_no_zero_index(&to_int_length); - to->_int_length = to_int_length; - if (to->_buffer != first_no_zero) { - memmove(to->_buffer, first_no_zero, - (round_up(to->_int_length) + round_up(to->_frac_length)) * sizeof(int32_t)); - } - return error; -} - -// TODO(lingbin): if ignore do_add's error code -DecimalValue operator+(const DecimalValue& v1, const DecimalValue& v2) { - DecimalValue result; - if (v1._sign == v2._sign) { - do_add(v1, v2, &result); - } else { - do_sub(v1, v2, &result); - } - return result; -} - -DecimalValue operator-(const DecimalValue& v1, const DecimalValue& v2) { - DecimalValue result; - if (v1._sign == v2._sign) { - do_sub(v1, v2, &result); - } else { - do_add(v1, v2, &result); - } - return result; -} - -DecimalValue operator*(const DecimalValue& v1, const DecimalValue& v2) { - DecimalValue result; - do_mul(v1, v2, &result); - return result; -} - -DecimalValue operator/(const DecimalValue& v1, const DecimalValue& v2) { - DecimalValue result; - do_div_mod(v1, v2, &result, nullptr); - return result; -} - -DecimalValue operator%(const DecimalValue& v1, const DecimalValue& v2) { - DecimalValue result; - do_div_mod(v1, v2, nullptr, &result); - return result; -} - -std::ostream& operator<<(std::ostream& os, DecimalValue const& decimal_value) { - return os << decimal_value.to_string(); -} - -std::istream& operator>>(std::istream& ism, DecimalValue& decimal_value) { - std::string str_buff; - ism >> str_buff; - decimal_value.parse_from_str(str_buff.c_str(), str_buff.size()); - return ism; -} - -DecimalValue operator-(const DecimalValue& v) { - DecimalValue result = v; - result._sign = !result._sign; - return result; -} - -DecimalValue& DecimalValue::operator+=(const DecimalValue& other) { - *this = *this + other; - return *this; -} - -int DecimalValue::parse_from_str(const char* decimal_str, int32_t length) { - set_to_zero(); - const char* begin = decimal_str; - const char* end = decimal_str + length; - int32_t error = E_DEC_OK; - - // ignore leading spaces - while (begin < end && std::isspace(*begin)) { - ++begin; - } - if (begin == end) { - set_to_zero(); - return E_DEC_BAD_NUM; - } - - // positive or negative - if (*begin == '-') { - _sign = true; - ++begin; - } else if (*begin == '+') { - _sign = false; - ++begin; - } else { - _sign = false; - } - - // count int_length and frac_length - const char* temp_ptr = begin; - const char* frac_ptr = nullptr; - // after this loop, 'begin' point to the first non digital position - while (begin < end && std::isdigit(*begin)) { - ++begin; - } - int32_t int_len = (int32_t)(begin - temp_ptr); - int32_t frac_len = 0; - if (begin < end && *begin == '.') { - frac_ptr = begin + 1; - while (frac_ptr < end && std::isdigit(*frac_ptr)) { - ++frac_ptr; - } - frac_len = frac_ptr - begin - 1; // -1 for char '.' - } else { - frac_len = 0; - frac_ptr = begin; - } - - // bad num like " a" - if ((int_len + frac_len) == 0) { - set_to_zero(); - return E_DEC_BAD_NUM; - } - - int32_t int_big_digit_len = round_up(int_len); - int32_t frac_big_digit_len = round_up(frac_len); - fix_intg_frac_error(_buffer_length, &int_big_digit_len, &frac_big_digit_len, &error); - if (error) { - frac_len = frac_big_digit_len * DIG_PER_DEC1; - if (error == E_DEC_OVERFLOW) { - int_len = int_big_digit_len * DIG_PER_DEC1; - } - } - - _int_length = int_len; - _frac_length = frac_len; - temp_ptr = begin; - - // fill int value - int32_t* buff = _buffer + int_big_digit_len; - int32_t value = 0; - int32_t index_in_powers10 = 0; - for (; int_len > 0; --int_len) { - value += (*--temp_ptr - '0') * powers10[index_in_powers10]; - ++index_in_powers10; - if (index_in_powers10 == DIG_PER_DEC1) { - *--buff = value; - value = 0; - index_in_powers10 = 0; - } - } - if (index_in_powers10) { - *--buff = value; - } - - // fill fraction value - buff = _buffer + int_big_digit_len; - temp_ptr = begin; - for (value = 0, index_in_powers10 = 0; frac_len > 0; --frac_len) { - value = (*++temp_ptr - '0') + value * 10; - ++index_in_powers10; - if (index_in_powers10 == DIG_PER_DEC1) { - *buff++ = value; - value = 0; - index_in_powers10 = 0; - } - } - if (index_in_powers10) { - *buff = value * powers10[DIG_PER_DEC1 - index_in_powers10]; - } - - // TODO: we do not support decimal in scientific notation - if ((frac_ptr + 1) < end && (*frac_ptr == 'e' || *frac_ptr == 'E')) { - // return E_DEC_BAD_NUM; - int64_t exponent = strtoll(frac_ptr + 1, (char**)&end, 10); - if (end != frac_ptr + 1) { // If at least one digit - if (errno) { // system error number, it is thread local - set_to_zero(); - return E_DEC_BAD_NUM; - } - if (exponent > (INT_MAX / 2) || (errno == 0 && exponent < 0)) { - set_to_zero(); - return E_DEC_OVERFLOW; - } - if (exponent < INT_MAX / 2 && error != E_DEC_OVERFLOW) { - set_to_zero(); - return E_DEC_TRUNCATED; - } - if (error != E_DEC_OVERFLOW) { - // error = shift((int32_t) exponent); - } - } - } - if (_sign && is_zero()) { - _sign = false; - } - return error; -} - -// TODO(lingbin): should be refactored with to_string(int scale) -std::string DecimalValue::to_string() const { - // Ignore trailing zeroes - int32_t intg = round_up(_int_length); - int32_t frac = round_up(_frac_length); - const int32_t* frac_begin = _buffer + intg; - const int32_t* frac_end = frac_begin + (frac - 1); - - const int32_t* buff = frac_end; - while ((buff < frac_end) && (*buff == 0)) { - --buff; - } - - int32_t actual_frac = (int32_t)(buff - frac_begin) + 1; - int32_t actual_frac_len = actual_frac * DIG_PER_DEC1; - - // Count the number of zeroes at the end of last "big digit" number - if (actual_frac_len > 0) { - int32_t last_big_digit = *buff; - while ((last_big_digit > 0) && (last_big_digit % 10) == 0) { - --actual_frac_len; - last_big_digit /= 10; - } - } - - return to_string(actual_frac_len); -} - -std::string DecimalValue::to_string(int scale) const { - int32_t temp_intg = _int_length; - int32_t temp_frac = _frac_length; - if (temp_frac > scale) { - temp_frac = scale; - } - const int32_t* buff_no_zero = get_first_no_zero_index(&temp_intg); - - int32_t temp = 0; - if ((temp_intg + temp_frac) == 0) { - temp_intg = 1; - buff_no_zero = &temp; - } - - int32_t int_str_length = temp_intg; - if (temp_intg == 0) { - int_str_length = 1; - } - int32_t length = (_sign ? 1 : 0) + int_str_length + (temp_frac ? 1 : 0) + temp_frac; - - char result_str[DECIMAL_MAX_STR_LENGTH + 1]; - char* result_ptr = result_str; - - result_ptr[length] = '\0'; - if (_sign) { - *result_ptr++ = '-'; - } - if (temp_frac) { - char* char_point = result_ptr + int_str_length; - int32_t fill_length = scale - temp_frac; - const int32_t* buff = buff_no_zero + round_up(temp_intg); - *char_point++ = '.'; - for (; temp_frac > 0; temp_frac -= DIG_PER_DEC1) { - int32_t m = *buff++; - for (int32_t i = std::min(temp_frac, DIG_PER_DEC1); i; --i) { - int32_t n = m / DIG_MASK; - *char_point++ = '0' + n; - m -= n * DIG_MASK; - m *= 10; - } - } - while (fill_length-- > 0) { - *result_ptr = '0'; // use char '0' to fill - } - } - - if (temp_intg) { - char* char_point = result_ptr + int_str_length; - const int32_t* buff = buff_no_zero + round_up(temp_intg); - for (; temp_intg > 0; temp_intg -= DIG_PER_DEC1) { - int32_t m = *--buff; - for (int32_t i = std::min(temp_intg, DIG_PER_DEC1); i; --i) { - int32_t n = m / 10; - *--char_point = '0' + (m - n * 10); - m = n; - } - } - } else { - *result_ptr = '0'; - } - - return std::string(result_str, length); -} - -// NOTE: only change abstract value, do not change sign -void DecimalValue::to_max_decimal(int32_t precision, int32_t frac) { - int32_t* buf = _buffer; - - _int_length = precision - frac; - int32_t intpart = precision - frac; - if (intpart) { - int32_t firstdigits = intpart % DIG_PER_DEC1; - if (firstdigits) { - *buf++ = powers10[firstdigits] - 1; // get 9 99 999 ... - } - for (intpart /= DIG_PER_DEC1; intpart; intpart--) { - *buf++ = DIG_MAX; - } - } - - _frac_length = frac; - if (frac) { - int32_t lastdigits = frac % DIG_PER_DEC1; - for (frac /= DIG_PER_DEC1; frac; frac--) { - *buf++ = DIG_MAX; - } - if (lastdigits) { - *buf = frac_max[lastdigits - 1]; - } - } -} - -std::size_t hash_value(DecimalValue const& value) { - return value.hash(0); -} - -int DecimalValue::round(DecimalValue* to, int scale, DecimalRoundMode mode) { - int frac0 = scale > 0 ? round_up(scale) : (scale + 1) / DIG_PER_DEC1; - int frac1 = round_up(_frac_length); - int intg0 = round_up(_int_length); - int error = E_DEC_OK; - int len = _buffer_length; - - int32_t* buf0 = _buffer; - int32_t* buf1 = to->_buffer; - int32_t x = 0; - int32_t y = 0; - int32_t carry = 0; - int first_dig = 0; - - int round_digit = 0; - switch (mode) { - case HALF_UP: - case HALF_EVEN: - round_digit = 5; - break; - case CEILING: - round_digit = _sign ? 10 : 0; - break; - case FLOOR: - round_digit = _sign ? 0 : 10; - break; - case TRUNCATE: - round_digit = 10; - break; - default: - return E_DEC_ERROR; - } - - // input is too large, make it meaningful - if (frac0 + intg0 > len) { - frac0 = len - intg0; - scale = frac0 * DIG_PER_DEC1; - error = E_DEC_TRUNCATED; - } - // zero - if (scale + _int_length < 0) { - to->set_to_zero(); - return E_DEC_OK; - } - // normal case copy - if (to != this) { - int32_t* p0 = buf0 + intg0 + std::max(frac1, frac0); - int32_t* p1 = buf1 + intg0 + std::max(frac1, frac0); - - while (buf0 < p0) { - *(--p1) = *(--p0); - } - - buf0 = to->_buffer; - buf1 = to->_buffer; - to->_sign = _sign; - to->_int_length = std::min(intg0, len) * DIG_PER_DEC1; - } - // no need to trunk - if (frac0 > frac1) { - buf1 += intg0 + frac1; - while (frac0-- > frac1) { - *buf1++ = 0; - } - to->_frac_length = scale; - return error; - } - if (scale >= _frac_length) { - /* nothing to do */ - to->_frac_length = scale; - return error; - } - - buf0 += intg0 + frac0 - 1; - buf1 += intg0 + frac0 - 1; - if (scale == frac0 * DIG_PER_DEC1) { - bool do_inc = false; - switch (round_digit) { - case 0: { - int32_t* p0 = buf0 + (frac1 - frac0); - for (; p0 > buf0; p0--) { - if (*p0) { - do_inc = true; - break; - } - } - break; - } - case 5: { - x = buf0[1] / DIG_MASK; - do_inc = (x > 5) || ((x == 5) && (mode == HALF_UP || (frac0 + intg0 > 0 && *buf0 & 1))); - break; - } - default: - break; - } - if (do_inc) { - if (frac0 + intg0 > 0) { - (*buf1)++; - } else { - *(++buf1) = DIG_BASE; - } - } else if (frac0 + intg0 == 0) { - to->set_to_zero(); - return E_DEC_OK; - } - } else { - /* TODO - fix this code as it won't work for CEILING mode */ - int pos = frac0 * DIG_PER_DEC1 - scale - 1; - x = *buf1 / powers10[pos]; - y = x % 10; - if (y > round_digit || (round_digit == 5 && y == 5 && (mode == HALF_UP || (x / 10) & 1))) { - x += 10; - } - *buf1 = powers10[pos] * (x - y); - } - /* - In case we're rounding e.g. 1.5e9 to 2.0e9, the decimal_digit_t's inside - the buffer are as follows. - - Before <1, 5e8> - After <2, 5e8> - - Hence we need to set the 2nd field to 0. - The same holds if we round 1.5e-9 to 2e-9. - */ - if (frac0 < frac1) { - int32_t* buf = to->_buffer + ((scale == 0 && intg0 == 0) ? 1 : intg0 + frac0); - int32_t* end = to->_buffer + len; - while (buf < end) { - *buf++ = 0; - } - } - if (*buf1 >= DIG_BASE) { - carry = 1; - *buf1 -= DIG_BASE; - while (carry && --buf1 >= to->_buffer) { - add(0, *buf1, buf1, &carry); - } - if (carry) { - /* shifting the number to create space for new digit */ - if (frac0 + intg0 >= len) { - frac0--; - scale = frac0 * DIG_PER_DEC1; - error = E_DEC_TRUNCATED; /* XXX */ - } - for (buf1 = to->_buffer + intg0 + std::max(frac0, 0); buf1 > to->_buffer; buf1--) { - /* Avoid out-of-bounds write. */ - if (buf1 < to->_buffer + len) { - buf1[0] = buf1[-1]; - } else { - error = E_DEC_OVERFLOW; - } - } - *buf1 = 1; - /* We cannot have more than 9 * 9 = 81 digits. */ - if (to->_int_length < len * DIG_PER_DEC1) { - to->_int_length++; - } else { - error = E_DEC_OVERFLOW; - } - } - } else { - for (;;) { - if (*buf1) { - break; - } - if (buf1-- == to->_buffer) { - /* making 'zero' with the proper scale */ - int32_t* p0 = to->_buffer + frac0 + 1; - to->_int_length = 1; - to->_frac_length = std::max(scale, 0); - to->_sign = 0; - for (buf1 = to->_buffer; buf1 < p0; buf1++) { - *buf1 = 0; - } - return E_DEC_OK; - } - } - } - - /* Here we check 999.9 -> 1000 case when we need to increase intg */ - first_dig = to->_int_length % DIG_PER_DEC1; - if (first_dig && (*buf1 >= powers10[first_dig])) { - to->_int_length++; - } - - if (scale < 0) { - scale = 0; - } - - to->_frac_length = scale; - return error; -} - -} // end namespace doris diff --git a/be/src/runtime/decimal_value.h b/be/src/runtime/decimal_value.h deleted file mode 100644 index 1eb6f3aa31..0000000000 --- a/be/src/runtime/decimal_value.h +++ /dev/null @@ -1,544 +0,0 @@ -// Licensed to the Apache Software Foundation (ASF) under one -// or more contributor license agreements. See the NOTICE file -// distributed with this work for additional information -// regarding copyright ownership. The ASF licenses this file -// to you under the Apache License, Version 2.0 (the -// "License"); you may not use this file except in compliance -// with the License. You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. See the License for the -// specific language governing permissions and limitations -// under the License. - -#ifndef DORIS_BE_SRC_QUERY_RUNTIME_DECIMAL_VALUE_H -#define DORIS_BE_SRC_QUERY_RUNTIME_DECIMAL_VALUE_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "common/logging.h" -#include "gutil/strings/numbers.h" -#include "udf/udf.h" -#include "util/hash_util.hpp" -#include "util/mysql_global.h" - -namespace doris { - -// The number of digits per "big digits" -static const int32_t DIG_PER_DEC1 = 9; -// Maximum length of buffer, whose item is our "big digits" (uint32), -static const int32_t DECIMAL_BUFF_LENGTH = 9; -// The maximum number of digits that my_decimal can possibly contain -static const int32_t DECIMAL_MAX_POSSIBLE_PRECISION = DECIMAL_BUFF_LENGTH * 9; - -// Maximum guaranteed precision of number in decimal digits (number of our -// digits * number of decimal digits in one our big digit - number of decimal -// digits in one our big digit decreased by 1 (because we always put decimal -// point on the border of our big digits)) -static const int32_t DECIMAL_MAX_PRECISION = DECIMAL_MAX_POSSIBLE_PRECISION - 8 * 2; -static const int32_t DECIMAL_MAX_SCALE = 30; -// NOT_FIXED_DEC is defined in mysql_com.h -#ifndef NOT_FIXED_DEC -static const int32_t NOT_FIXED_DEC = 31; -#endif -// maximum length of string representation (number of maximum decimal -// digits + 1 position for sign + 1 position for decimal point, no terminator) -static const int32_t DECIMAL_MAX_STR_LENGTH = (DECIMAL_MAX_POSSIBLE_PRECISION + 2); - -static const int32_t DIG_MASK = 100000000; // 10^8 -static const int32_t DIG_BASE = 1000000000; // 10^9 -static const int32_t DIG_MAX = DIG_BASE - 1; - -static const int32_t powers10[DIG_PER_DEC1 + 1] = { - 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000}; -static const int32_t frac_max[DIG_PER_DEC1 - 1] = {900000000, 990000000, 999000000, 999900000, - 999990000, 999999000, 999999900, 999999990}; - -// TODO(lingbin): add to mysql result if we support "show warning" in our mysql protocol? -enum DecimalError { - E_DEC_OK = 0, - E_DEC_TRUNCATED = 1, - E_DEC_OVERFLOW = 2, - E_DEC_DIV_ZERO = 4, - E_DEC_BAD_NUM = 8, - E_DEC_OOM = 16, - - E_DEC_ERROR = 31, - E_DEC_FATAL_ERROR = 30 -}; - -enum DecimalRoundMode { HALF_UP = 1, HALF_EVEN = 2, CEILING = 3, FLOOR = 4, TRUNCATE = 5 }; - -// Type T should be an integer: int8_t, int16_t... -template -inline T round_up(T length); - -// Internally decimal numbers are stored base 10^9 (see DIG_BASE) -// So one variable of type big_digit_type is limited: -// 0 < decimal_digit <= DIG_MAX < DIG_BASE -class DecimalValue { -public: - friend DecimalValue operator+(const DecimalValue& v1, const DecimalValue& v2); - friend DecimalValue operator-(const DecimalValue& v1, const DecimalValue& v2); - friend DecimalValue operator*(const DecimalValue& v1, const DecimalValue& v2); - friend DecimalValue operator/(const DecimalValue& v1, const DecimalValue& v2); - friend int32_t do_add(const DecimalValue& value1, const DecimalValue& value2, DecimalValue* to); - friend int32_t do_sub(const DecimalValue& value1, const DecimalValue& value2, DecimalValue* to); - friend int do_mul(const DecimalValue& value1, const DecimalValue& value2, DecimalValue* to); - friend int do_div_mod(const DecimalValue& value1, const DecimalValue& value2, DecimalValue* to, - DecimalValue* mod); - friend std::istream& operator>>(std::istream& ism, DecimalValue& decimal_value); - - friend DecimalValue operator-(const DecimalValue& v); - - DecimalValue() : _buffer_length(DECIMAL_BUFF_LENGTH) { set_to_zero(); } - - DecimalValue(const std::string& decimal_str) : _buffer_length(DECIMAL_BUFF_LENGTH) { - parse_from_str(decimal_str.data(), decimal_str.size()); - } - - DecimalValue(const std::string_view& decimal_str) : _buffer_length(DECIMAL_BUFF_LENGTH) { - parse_from_str(decimal_str.data(), decimal_str.size()); - } - - // Construct from olap engine - // Note: the base is 10^9 for parameter frac_value, which means the max length of fraction part - // is 9, and the parameter frac_value need to be divided by 10^9. - DecimalValue(int64_t int_value, int64_t frac_value) : _buffer_length(DECIMAL_BUFF_LENGTH) { - set_to_zero(); - if (int_value < 0 || frac_value < 0) { - _sign = true; - } else { - _sign = false; - } - - int32_t big_digit_length = copy_int_to_decimal_int(std::abs(int_value), _buffer); - _int_length = big_digit_length * DIG_PER_DEC1; - _frac_length = copy_int_to_decimal_frac(std::abs(frac_value), _buffer + big_digit_length); - } - - DecimalValue(int64_t int_value) : _buffer_length(DECIMAL_BUFF_LENGTH) { - set_to_zero(); - _sign = int_value < 0 ? true : false; - - int32_t big_digit_length = copy_int_to_decimal_int(std::abs(int_value), _buffer); - _int_length = big_digit_length * DIG_PER_DEC1; - _frac_length = 0; - } - - DecimalValue& assign_from_float(const float float_value) { - // buffer is short, sign and '\0' is the 2. - char buffer[MAX_FLOAT_STR_LENGTH + 2]; - buffer[0] = '\0'; - int length = FloatToBuffer(float_value, MAX_FLOAT_STR_LENGTH, buffer); - DCHECK(length >= 0) << "gcvt float failed, float value=" << float_value; - parse_from_str(buffer, length); - return *this; - } - - DecimalValue& assign_from_double(const double double_value) { - char buffer[MAX_DOUBLE_STR_LENGTH + 2]; - buffer[0] = '\0'; - int length = DoubleToBuffer(double_value, MAX_DOUBLE_STR_LENGTH, buffer); - DCHECK(length >= 0) << "gcvt double failed, double value=" << double_value; - parse_from_str(buffer, length); - return *this; - } - - // These cast functions are needed in "functions.cc", which is generated by python script. - // e.g. "ComputeFunctions::Cast_DecimalValue_double()" - // Discard the scale part - // ATTN: invoker must make sure no OVERFLOW - operator int64_t() const { - const int32_t* buff = _buffer; - int64_t result = 0; - - int32_t int_length = _int_length; - for (int32_t i = 0; int_length > 0; ++i) { - result = (result * DIG_BASE) + *(buff + i); - int_length -= DIG_PER_DEC1; - } - - // negative - if (_sign) { - result = -result; - } - - return result; - } - - // These cast functions are needed in "functions.cc", which is generated by python script. - // e.g. "ComputeFunctions::Cast_DecimalValue_double()" - // Discard the scale part - // ATTN: invoker must make sure no OVERFLOW - operator __int128() const { - const int32_t* buff = _buffer; - __int128 result = 0; - - int32_t int_length = _int_length; - for (int32_t i = 0; int_length > 0; ++i) { - result = (result * DIG_BASE) + *(buff + i); - int_length -= DIG_PER_DEC1; - } - - // negative - if (_sign) { - result = -result; - } - - return result; - } - - operator bool() const { return !is_zero(); } - - operator int8_t() const { return static_cast(operator int64_t()); } - - operator int16_t() const { return static_cast(operator int64_t()); } - - operator int32_t() const { return static_cast(operator int64_t()); } - - operator size_t() const { return static_cast(operator int64_t()); } - - operator float() const { return (float)operator double(); } - - operator double() const { - std::string str_buff = to_string(); - double result = std::strtod(str_buff.c_str(), nullptr); - return result; - } - - DecimalValue& operator+=(const DecimalValue& other); - - // To be Compatible with OLAP - // ATTN: NO-OVERFLOW should be guaranteed. - int64_t int_value() const { return operator int64_t(); } - - // To be Compatible with OLAP - // NOTE: return a negative value if decimal is negative. - // ATTN: the max length of fraction part in OLAP is 9, so the 'big digits' except the first one - // will be truncated. - int32_t frac_value() const { - const int32_t intg = round_up(_int_length); - const int32_t frac = round_up(_frac_length); - const int32_t* frac_begin = _buffer + intg; - int32_t frac_val = (frac != 0) ? *frac_begin : 0; - frac_val = (_sign == true) ? -frac_val : frac_val; - return frac_val; - } - - bool equal(const DecimalValue& other) const { return (*this - other).is_zero(); } - - bool bigger(const DecimalValue& other) const { return (other - *this)._sign; } - - bool smaller(const DecimalValue& other) const { return (*this - other)._sign; } - - bool operator==(const DecimalValue& other) const { return equal(other); } - - bool operator!=(const DecimalValue& other) const { return !equal(other); } - - bool operator<=(const DecimalValue& other) const { return !bigger(other); } - - bool operator>=(const DecimalValue& other) const { return !smaller(other); } - - bool operator<(const DecimalValue& other) const { return smaller(other); } - - bool operator>(const DecimalValue& other) const { return bigger(other); } - - // change to maximum value for given precision and scale - // precision/scale - see decimal_bin_size() below - // to - decimal where where the result will be stored - // to->buf and to->len must be set. - void to_max_decimal(int precision, int frac); - void to_min_decimal(int precision, int frac) { - to_max_decimal(precision, frac); - _sign = -1; - } - - // The maximum of fraction part is "scale". - // If the length of fraction part is less than "scale", '0' will be filled. - std::string to_string(int scale) const; - // Output actual "scale", remove ending zeroes. - std::string to_string() const; - - // Convert string to decimal - // @param from - value to convert. Doesn't have to be \0 terminated! - // will stop at the fist non-digit char(nor '.' 'e' 'E'), - // or reaches the length - // @param length - maximum length - // @return error number. - // - // E_DEC_OK/E_DEC_TRUNCATED/E_DEC_OVERFLOW/E_DEC_BAD_NUM/E_DEC_OOM - // In case of E_DEC_FATAL_ERROR *to is set to decimal zero - // (to make error handling easier) - // - // e.g. "1.2" ".2" "1.2e-3" "1.2e3" - int parse_from_str(const char* decimal_str, int32_t length); - - std::string get_debug_info() const { - std::stringstream ss; - ss << "_int_length: " << _int_length << "; " - << "_frac_length: " << _frac_length << "; " - << "_sign: " << _sign << "; " - << "_buffer_length: " << _buffer_length << "; "; - ss << "_buffer: ["; - for (int i = 0; i < DIG_PER_DEC1; ++i) { - ss << _buffer[i] << ", "; - } - ss << "]; "; - return ss.str(); - } - - static DecimalValue get_min_decimal() { - DecimalValue value; - value._sign = true; - value._int_length = DECIMAL_MAX_POSSIBLE_PRECISION; - value._frac_length = 0; - for (int i = 0; i < DIG_PER_DEC1; ++i) { - value._buffer[i] = DIG_BASE - 1; - } - return value; - } - - static DecimalValue get_max_decimal() { - DecimalValue value; - value._sign = false; - value._int_length = DECIMAL_MAX_POSSIBLE_PRECISION; - value._frac_length = 0; - for (int i = 0; i < DIG_PER_DEC1; ++i) { - value._buffer[i] = DIG_BASE - 1; - } - return value; - } - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Warray-bounds" -#pragma GCC diagnostic ignored "-Wstringop-overflow=" - - static DecimalValue from_decimal_val(const doris_udf::DecimalVal& val) { - DecimalValue result; - result._int_length = val.int_len; - result._frac_length = val.frac_len; - result._sign = val.sign; - - result._buffer_length = DECIMAL_BUFF_LENGTH; - memcpy(result._buffer, val.buffer, sizeof(int32_t) * DECIMAL_BUFF_LENGTH); - return result; - } -#pragma GCC diagnostic pop - - void to_decimal_val(doris_udf::DecimalVal* value) const { - value->int_len = _int_length; - value->frac_len = _frac_length; - value->sign = _sign; - memcpy(value->buffer, _buffer, sizeof(int32_t) * DECIMAL_BUFF_LENGTH); - } - - // set DecimalValue to zero - void set_to_zero() { - _buffer_length = DECIMAL_BUFF_LENGTH; - memset(_buffer, 0, sizeof(int32_t) * DECIMAL_BUFF_LENGTH); - _int_length = 1; - _frac_length = 0; - _sign = false; - } - - void to_abs_value() { _sign = false; } - - uint32_t hash_uint(uint32_t value, uint32_t seed) const { - return HashUtil::hash(&value, sizeof(value), seed); - } - - uint32_t hash(uint32_t seed) const { - uint32_t int_len = round_up(_int_length); - uint32_t frac_len = round_up(_frac_length); - int idx = 0; - while (idx < int_len && _buffer[idx] == 0) { - idx++; - } - while (idx < int_len) { - // Hash - seed = hash_uint(_buffer[idx++], seed); - } - idx = int_len + frac_len; - while (idx > int_len && _buffer[idx - 1] == 0) { - idx--; - } - while (idx > int_len) { - // Hash - seed = hash_uint(_buffer[--idx], seed); - } - // Hash sign - return hash_uint(_sign, seed); - } - - int32_t precision() const { return _int_length + _frac_length; } - - int32_t scale() const { return _frac_length; } - - int round(DecimalValue* to, int scale, DecimalRoundMode mode); - -private: - friend class MultiDistinctDecimalState; - - bool is_zero() const { - const int32_t* buff = _buffer; - const int32_t* end = buff + round_up(_int_length) + round_up(_frac_length); - while (buff < end) { - if (*buff++) { - return false; - } - } - return true; - } - - // TODO(lingbin): complete this function - int shift(int32_t shift) { return 0; } - - // Invoker make sure buff has enough space. - // return the number of "big digits". - int copy_int_to_decimal_int(int64_t int_value, int32_t* buff); - - // ATTN: the max length of fraction part is 9 for now, so we can directly assign parameter - // frac_value to buff member. - int copy_int_to_decimal_frac(int64_t frac_value, int32_t* buff); - - const int32_t* get_first_no_zero_index(int32_t* int_digit_num) const; - - // _int_length is the number of *decimal* digits (NOT number of big_digit_type's !) - // before the point - // _frac_length is the number of decimal digits after the point - // _buffer_length is the length of buf (length of allocated space) in big_digit_type's, - // not in bytes - // _sign false means positive, true means negative - // _buffer is an array of big_digit_type's - // TODO(zc): use int64_t to aligned to 8 - int32_t _int_length : 8; - int32_t _frac_length : 8; - int32_t _buffer_length : 8; - bool _sign; - int32_t _buffer[DECIMAL_BUFF_LENGTH]; -}; - -DecimalValue operator+(const DecimalValue& v1, const DecimalValue& v2); -DecimalValue operator-(const DecimalValue& v1, const DecimalValue& v2); -DecimalValue operator*(const DecimalValue& v1, const DecimalValue& v2); -DecimalValue operator/(const DecimalValue& v1, const DecimalValue& v2); -DecimalValue operator%(const DecimalValue& v1, const DecimalValue& v2); - -DecimalValue operator-(const DecimalValue& v); - -std::ostream& operator<<(std::ostream& os, DecimalValue const& decimal_value); -std::istream& operator>>(std::istream& ism, DecimalValue& decimal_value); - -// TODO(lingbin) discard the fraction part? -int64_t operator&(const DecimalValue& v1, const DecimalValue& v2); -int64_t operator|(const DecimalValue& v1, const DecimalValue& v2); -int64_t operator^(const DecimalValue& v1, const DecimalValue& v2); -int64_t operator~(const DecimalValue& v1); - -// help to get the number of decimal_digit_t's digits -// e.g. for 1234567891.222 . intg=10, ROUND_UP(10) = 2. -// It means in decimal_digit_t type buff, -// it takes '2' bytes to store integer part -template -inline T round_up(T length) { - return (T)((length + DIG_PER_DEC1 - 1) / DIG_PER_DEC1); -} - -inline int DecimalValue::copy_int_to_decimal_int(int64_t int_value, int32_t* buff) { - int64_t dividend = int_value; - int32_t temp_buff[DECIMAL_BUFF_LENGTH]; - int32_t index = 0; // index in temp_buffer - - if (int_value == 0) { - _int_length = 0; - return 0; - } - - int64_t quotient = 0; - do { - temp_buff[index++] = dividend % DIG_BASE; - quotient = dividend / DIG_BASE; - dividend = quotient; - } while (quotient != 0); - - for (int32_t i = 0; i < index; ++i) { - buff[i] = temp_buff[index - i - 1]; - } - return index; -} - -inline int32_t DecimalValue::copy_int_to_decimal_frac(int64_t frac_value, int32_t* buff) { - if (frac_value == 0) { - return 0; - } - int32_t abs_frac_value = std::abs(frac_value); - if (std::abs(frac_value > DIG_BASE)) { - *buff = DIG_MAX; - return DIG_PER_DEC1; - } - - *buff = abs_frac_value; - // Count digit length: (DIG_PER_DEC1 - the number of ending zeroes) - int32_t frac_len = DIG_PER_DEC1; - int32_t quotient = 0; - while ((quotient = frac_value % 10) == 0) { - frac_value /= 10; - --frac_len; - } - - return frac_len; -} - -inline const int32_t* DecimalValue::get_first_no_zero_index(int32_t* int_digit_num) const { - int32_t temp_intg = _int_length; - const int32_t* buff = _buffer; - int32_t first_big_digit_num = (temp_intg - 1) % DIG_PER_DEC1 + 1; - - while (temp_intg > 0 && *buff == 0) { - temp_intg -= first_big_digit_num; - first_big_digit_num = DIG_PER_DEC1; - ++buff; - } - -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Warray-bounds" - // When the value of a "big digit" is "000099999", its 'intg' may be 5/6/7/8/9, - // we get accurate 'intg' here and the first no zero index of buff - if (temp_intg > 0) { - first_big_digit_num = (temp_intg - 1) % DIG_PER_DEC1 + 1; - for (; *buff < powers10[first_big_digit_num - 1]; --first_big_digit_num) { - --temp_intg; - } - } else { - temp_intg = 0; - } -#pragma GCC diagnostic pop - *int_digit_num = temp_intg; - return buff; -} - -std::size_t hash_value(DecimalValue const& value); - -} // end namespace doris - -namespace std { -template <> -struct hash { - size_t operator()(const doris::DecimalValue& v) const { return doris::hash_value(v); } -}; -} // namespace std - -#endif // DORIS_BE_SRC_QUERY_RUNTIME_DECIMAL_VALUE_H diff --git a/be/src/runtime/decimalv2_value.h b/be/src/runtime/decimalv2_value.h index 8a790557fe..632f252a9f 100644 --- a/be/src/runtime/decimalv2_value.h +++ b/be/src/runtime/decimalv2_value.h @@ -28,14 +28,28 @@ #include #include "common/logging.h" -#include "runtime/decimal_value.h" #include "udf/udf.h" #include "util/hash_util.hpp" +#include "util/mysql_global.h" namespace doris { typedef __int128_t int128_t; +enum DecimalError { + E_DEC_OK = 0, + E_DEC_TRUNCATED = 1, + E_DEC_OVERFLOW = 2, + E_DEC_DIV_ZERO = 4, + E_DEC_BAD_NUM = 8, + E_DEC_OOM = 16, + + E_DEC_ERROR = 31, + E_DEC_FATAL_ERROR = 30 +}; + +enum DecimalRoundMode { HALF_UP = 1, HALF_EVEN = 2, CEILING = 3, FLOOR = 4, TRUNCATE = 5 }; + class DecimalV2Value { public: friend DecimalV2Value operator+(const DecimalV2Value& v1, const DecimalV2Value& v2); diff --git a/be/src/runtime/descriptor_helper.h b/be/src/runtime/descriptor_helper.h index c8532291ab..ec7af6b387 100644 --- a/be/src/runtime/descriptor_helper.h +++ b/be/src/runtime/descriptor_helper.h @@ -64,17 +64,17 @@ public: _slot_desc.slotType = get_common_type(to_thrift(type)); return *this; } + TSlotDescriptorBuilder& decimal_type(int precision, int scale) { + _slot_desc.slotType = get_common_type(to_thrift(TYPE_DECIMALV2)); + _slot_desc.slotType.types[0].scalar_type.__set_precision(precision); + _slot_desc.slotType.types[0].scalar_type.__set_scale(scale); + return *this; + } TSlotDescriptorBuilder& string_type(int len) { _slot_desc.slotType = get_common_type(to_thrift(TYPE_VARCHAR)); _slot_desc.slotType.types[0].scalar_type.__set_len(len); return *this; } - TSlotDescriptorBuilder& decimal_type(int precision, int scale) { - _slot_desc.slotType = get_common_type(to_thrift(TYPE_DECIMAL)); - _slot_desc.slotType.types[0].scalar_type.__set_precision(precision); - _slot_desc.slotType.types[0].scalar_type.__set_scale(scale); - return *this; - } TSlotDescriptorBuilder& nullable(bool nullable) { _slot_desc.nullIndicatorByte = (nullable) ? 0 : -1; return *this; diff --git a/be/src/runtime/dpp_sink.cpp b/be/src/runtime/dpp_sink.cpp index 3b6d325179..52e6a59d24 100644 --- a/be/src/runtime/dpp_sink.cpp +++ b/be/src/runtime/dpp_sink.cpp @@ -447,22 +447,7 @@ Status Translator::create_value_updaters() { } break; } - case TYPE_DECIMAL: { - switch (_rollup_schema.value_ops()[i]) { - case TAggregationType::MAX: - _value_updaters.push_back(update_max); - break; - case TAggregationType::MIN: - _value_updaters.push_back(update_min); - break; - case TAggregationType::SUM: - _value_updaters.push_back(update_sum); - break; - default: - _value_updaters.push_back(fake_update); - } - break; - } + case TYPE_DECIMALV2: { switch (_rollup_schema.value_ops()[i]) { case TAggregationType::MAX: diff --git a/be/src/runtime/dpp_writer.cpp b/be/src/runtime/dpp_writer.cpp index 5e98e01fe5..a61facf1e2 100644 --- a/be/src/runtime/dpp_writer.cpp +++ b/be/src/runtime/dpp_writer.cpp @@ -206,14 +206,6 @@ Status DppWriter::append_one_row(TupleRow* row) { append_to_buf(str_val->ptr, str_val->len); break; } - case TYPE_DECIMAL: { - const DecimalValue* decimal_val = reinterpret_cast(item); - int64_t int_val = decimal_val->int_value(); - int32_t frac_val = decimal_val->frac_value(); - append_to_buf(&int_val, sizeof(int_val)); - append_to_buf(&frac_val, sizeof(frac_val)); - break; - } case TYPE_DECIMALV2: { const DecimalV2Value decimal_val(reinterpret_cast(item)->value); int64_t int_val = decimal_val.int_value(); diff --git a/be/src/runtime/export_sink.cpp b/be/src/runtime/export_sink.cpp index 5e4d2cc985..1aaaade101 100644 --- a/be/src/runtime/export_sink.cpp +++ b/be/src/runtime/export_sink.cpp @@ -26,6 +26,7 @@ #include "exec/s3_writer.h" #include "exprs/expr.h" #include "exprs/expr_context.h" +#include "gutil/strings/numbers.h" #include "runtime/mem_tracker.h" #include "runtime/mysql_table_sink.h" #include "runtime/row_batch.h" @@ -70,9 +71,7 @@ Status ExportSink::prepare(RuntimeState* state) { _profile = state->obj_pool()->add(new RuntimeProfile(title.str())); SCOPED_TIMER(_profile->total_time_counter()); - _mem_tracker = MemTracker::CreateTracker( - -1, - "ExportSink", state->instance_mem_tracker()); + _mem_tracker = MemTracker::CreateTracker(-1, "ExportSink", state->instance_mem_tracker()); // Prepare the exprs to run. RETURN_IF_ERROR(Expr::prepare(_output_expr_ctxs, state, _row_desc, _mem_tracker)); @@ -190,19 +189,7 @@ Status ExportSink::gen_row_buffer(TupleRow* row, std::stringstream* ss) { } break; } - case TYPE_DECIMAL: { - const DecimalValue* decimal_val = reinterpret_cast(item); - std::string decimal_str; - int output_scale = _output_expr_ctxs[i]->root()->output_scale(); - if (output_scale > 0 && output_scale <= 30) { - decimal_str = decimal_val->to_string(output_scale); - } else { - decimal_str = decimal_val->to_string(); - } - (*ss) << decimal_str; - break; - } case TYPE_DECIMALV2: { const DecimalV2Value decimal_val( reinterpret_cast(item)->value); @@ -268,8 +255,9 @@ Status ExportSink::open_file_writer() { break; } case TFileType::FILE_S3: { - S3Writer* s3_writer = new S3Writer( _t_export_sink.properties, - _t_export_sink.export_path + "/" + file_name, 0 /* offset */); + S3Writer* s3_writer = + new S3Writer(_t_export_sink.properties, + _t_export_sink.export_path + "/" + file_name, 0 /* offset */); RETURN_IF_ERROR(s3_writer->open()); _file_writer.reset(s3_writer); break; diff --git a/be/src/runtime/file_result_writer.cpp b/be/src/runtime/file_result_writer.cpp index 48f73d80dd..197af11841 100644 --- a/be/src/runtime/file_result_writer.cpp +++ b/be/src/runtime/file_result_writer.cpp @@ -41,8 +41,7 @@ const size_t FileResultWriter::OUTSTREAM_BUFFER_SIZE_BYTES = 1024 * 1024; FileResultWriter::FileResultWriter(const ResultFileOptions* file_opts, const std::vector& output_expr_ctxs, - RuntimeProfile* parent_profile, - BufferControlBlock* sinker) + RuntimeProfile* parent_profile, BufferControlBlock* sinker) : _file_opts(file_opts), _output_expr_ctxs(output_expr_ctxs), _parent_profile(parent_profile), @@ -89,11 +88,11 @@ Status FileResultWriter::_get_success_file_name(std::string* file_name) { // Doris is not responsible for ensuring the correctness of the path. // This is just to prevent overwriting the existing file. if (FileUtils::check_exist(*file_name)) { - return Status::InternalError("File already exists: " + *file_name - + ". Host: " + BackendOptions::get_localhost()); + return Status::InternalError("File already exists: " + *file_name + + ". Host: " + BackendOptions::get_localhost()); } } - + return Status::OK(); } @@ -125,7 +124,8 @@ Status FileResultWriter::_create_file_writer(const std::string& file_name) { strings::Substitute("unsupported file format: $0", _file_opts->file_format)); } LOG(INFO) << "create file for exporting query result. file name: " << file_name - << ". query id: " << print_id(_state->query_id()) << " format:" << _file_opts->file_format; + << ". query id: " << print_id(_state->query_id()) + << " format:" << _file_opts->file_format; return Status::OK(); } @@ -141,11 +141,11 @@ Status FileResultWriter::_get_next_file_name(std::string* file_name) { // Doris is not responsible for ensuring the correctness of the path. // This is just to prevent overwriting the existing file. if (FileUtils::check_exist(*file_name)) { - return Status::InternalError("File already exists: " + *file_name - + ". Host: " + BackendOptions::get_localhost()); + return Status::InternalError("File already exists: " + *file_name + + ". Host: " + BackendOptions::get_localhost()); } } - + return Status::OK(); } @@ -270,18 +270,6 @@ Status FileResultWriter::_write_one_row_as_csv(TupleRow* row) { } break; } - case TYPE_DECIMAL: { - const DecimalValue* decimal_val = reinterpret_cast(item); - std::string decimal_str; - int output_scale = _output_expr_ctxs[i]->root()->output_scale(); - if (output_scale > 0 && output_scale <= 30) { - decimal_str = decimal_val->to_string(output_scale); - } else { - decimal_str = decimal_val->to_string(); - } - _plain_text_outstream << decimal_str; - break; - } case TYPE_DECIMALV2: { const DecimalV2Value decimal_val( reinterpret_cast(item)->value); @@ -375,7 +363,7 @@ Status FileResultWriter::_close_file_writer(bool done, bool only_close) { // All data is written to file, send statistic result if (_file_opts->success_file_name != "") { // write success file, just need to touch an empty file - RETURN_IF_ERROR(_create_success_file()); + RETURN_IF_ERROR(_create_success_file()); } RETURN_IF_ERROR(_send_result()); } @@ -393,9 +381,9 @@ Status FileResultWriter::_send_result() { // The type of these field should be conssitent with types defined // in OutFileClause.java of FE. MysqlRowBuffer row_buffer; - row_buffer.push_int(_file_idx); // file number + row_buffer.push_int(_file_idx); // file number row_buffer.push_bigint(_written_rows_counter->value()); // total rows - row_buffer.push_bigint(_written_data_bytes->value()); // file size + row_buffer.push_bigint(_written_data_bytes->value()); // file size std::string localhost = BackendOptions::get_localhost(); row_buffer.push_string(localhost.c_str(), localhost.length()); // url diff --git a/be/src/runtime/large_int_value.h b/be/src/runtime/large_int_value.h index 2ce39d5fe6..7bc231c5cf 100644 --- a/be/src/runtime/large_int_value.h +++ b/be/src/runtime/large_int_value.h @@ -26,7 +26,6 @@ #include #include -#include "runtime/decimal_value.h" #include "udf/udf.h" #include "util/hash_util.hpp" diff --git a/be/src/runtime/mysql_result_writer.cpp b/be/src/runtime/mysql_result_writer.cpp index b593ed6c20..3cad9d6ac7 100644 --- a/be/src/runtime/mysql_result_writer.cpp +++ b/be/src/runtime/mysql_result_writer.cpp @@ -155,21 +155,6 @@ Status MysqlResultWriter::_add_one_row(TupleRow* row) { break; } - case TYPE_DECIMAL: { - const DecimalValue* decimal_val = reinterpret_cast(item); - std::string decimal_str; - int output_scale = _output_expr_ctxs[i]->root()->output_scale(); - - if (output_scale > 0 && output_scale <= 30) { - decimal_str = decimal_val->to_string(output_scale); - } else { - decimal_str = decimal_val->to_string(); - } - - buf_ret = _row_buffer->push_string(decimal_str.c_str(), decimal_str.length()); - break; - } - case TYPE_DECIMALV2: { DecimalV2Value decimal_val(reinterpret_cast(item)->value); std::string decimal_str; @@ -227,7 +212,6 @@ Status MysqlResultWriter::append_row_batch(const RowBatch* batch) { } } - if (status.ok()) { SCOPED_TIMER(_result_send_timer); // push this batch to back diff --git a/be/src/runtime/mysql_table_writer.cpp b/be/src/runtime/mysql_table_writer.cpp index ba7daeec60..620e3f5eb0 100644 --- a/be/src/runtime/mysql_table_writer.cpp +++ b/be/src/runtime/mysql_table_writer.cpp @@ -135,19 +135,7 @@ Status MysqlTableWriter::insert_row(TupleRow* row) { } break; } - case TYPE_DECIMAL: { - const DecimalValue* decimal_val = reinterpret_cast(item); - std::string decimal_str; - int output_scale = _output_expr_ctxs[i]->root()->output_scale(); - if (output_scale > 0 && output_scale <= 30) { - decimal_str = decimal_val->to_string(output_scale); - } else { - decimal_str = decimal_val->to_string(); - } - ss << decimal_str; - break; - } case TYPE_DECIMALV2: { const DecimalV2Value decimal_val(reinterpret_cast(item)->value); std::string decimal_str; diff --git a/be/src/runtime/primitive_type.cpp b/be/src/runtime/primitive_type.cpp index e85193d057..66a7620d83 100644 --- a/be/src/runtime/primitive_type.cpp +++ b/be/src/runtime/primitive_type.cpp @@ -80,9 +80,6 @@ PrimitiveType thrift_to_type(TPrimitiveType::type ttype) { case TPrimitiveType::BINARY: return TYPE_BINARY; - case TPrimitiveType::DECIMAL: - return TYPE_DECIMAL; - case TPrimitiveType::DECIMALV2: return TYPE_DECIMALV2; @@ -147,9 +144,6 @@ TPrimitiveType::type to_thrift(PrimitiveType ptype) { case TYPE_BINARY: return TPrimitiveType::BINARY; - case TYPE_DECIMAL: - return TPrimitiveType::DECIMAL; - case TYPE_DECIMALV2: return TPrimitiveType::DECIMALV2; @@ -214,9 +208,6 @@ std::string type_to_string(PrimitiveType t) { case TYPE_BINARY: return "BINARY"; - case TYPE_DECIMAL: - return "DECIMAL"; - case TYPE_DECIMALV2: return "DECIMALV2"; @@ -282,9 +273,6 @@ std::string type_to_odbc_string(PrimitiveType t) { case TYPE_BINARY: return "binary"; - case TYPE_DECIMAL: - return "decimal"; - case TYPE_DECIMALV2: return "decimalv2"; diff --git a/be/src/runtime/primitive_type.h b/be/src/runtime/primitive_type.h index 4eceede859..a7c11fa38b 100644 --- a/be/src/runtime/primitive_type.h +++ b/be/src/runtime/primitive_type.h @@ -24,7 +24,6 @@ #include "gen_cpp/Opcodes_types.h" #include "gen_cpp/Types_types.h" #include "runtime/datetime_value.h" -#include "runtime/decimal_value.h" #include "runtime/decimalv2_value.h" #include "runtime/large_int_value.h" #include "runtime/string_value.h" @@ -46,9 +45,9 @@ enum PrimitiveType { TYPE_DATE, /* 11 */ TYPE_DATETIME, /* 12 */ TYPE_BINARY, - /* 13 */ // Not implemented - TYPE_DECIMAL, /* 14 */ - TYPE_CHAR, /* 15 */ + /* 13 */ // Not implemented + TYPE_DECIMAL_DEPRACTED, /* 14 */ + TYPE_CHAR, /* 15 */ TYPE_STRUCT, /* 16 */ TYPE_ARRAY, /* 17 */ @@ -68,7 +67,6 @@ inline bool is_enumeration_type(PrimitiveType type) { case TYPE_CHAR: case TYPE_VARCHAR: case TYPE_DATETIME: - case TYPE_DECIMAL: case TYPE_DECIMALV2: case TYPE_BOOLEAN: case TYPE_HLL: @@ -129,9 +127,6 @@ inline int get_byte_size(PrimitiveType type) { case TYPE_DECIMALV2: return 16; - case TYPE_DECIMAL: - return 40; - case INVALID_TYPE: default: DCHECK(false); @@ -169,9 +164,6 @@ inline int get_real_byte_size(PrimitiveType type) { case TYPE_DECIMALV2: return 16; - case TYPE_DECIMAL: - return 40; - case TYPE_LARGEINT: return 16; @@ -215,9 +207,6 @@ inline int get_slot_size(PrimitiveType type) { // This is the size of the slot, the actual size of the data is 12. return 16; - case TYPE_DECIMAL: - return sizeof(DecimalValue); - case TYPE_DECIMALV2: return 16; diff --git a/be/src/runtime/raw_value.cpp b/be/src/runtime/raw_value.cpp index 4bdf7cbf8a..280fd301b7 100644 --- a/be/src/runtime/raw_value.cpp +++ b/be/src/runtime/raw_value.cpp @@ -80,10 +80,6 @@ void RawValue::print_value_as_bytes(const void* value, const TypeDescriptor& typ stream->write(chars, sizeof(DateTimeValue)); break; - case TYPE_DECIMAL: - stream->write(chars, sizeof(DecimalValue)); - break; - case TYPE_DECIMALV2: stream->write(chars, sizeof(DecimalV2Value)); break; @@ -161,10 +157,6 @@ void RawValue::print_value(const void* value, const TypeDescriptor& type, int sc *stream << *reinterpret_cast(value); break; - case TYPE_DECIMAL: - *stream << reinterpret_cast(value)->to_string(); - break; - case TYPE_DECIMALV2: *stream << DecimalV2Value(reinterpret_cast(value)->value).to_string(); break; @@ -279,10 +271,6 @@ void RawValue::write(const void* value, void* dst, const TypeDescriptor& type, M *reinterpret_cast(dst) = *reinterpret_cast(value); break; - case TYPE_DECIMAL: - *reinterpret_cast(dst) = *reinterpret_cast(value); - break; - case TYPE_DECIMALV2: *reinterpret_cast(dst) = *reinterpret_cast(value); break; @@ -353,9 +341,6 @@ void RawValue::write(const void* value, const TypeDescriptor& type, void* dst, u *buf += dest->len; break; } - case TYPE_DECIMAL: - *reinterpret_cast(dst) = *reinterpret_cast(value); - break; case TYPE_DECIMALV2: *reinterpret_cast(dst) = *reinterpret_cast(value); diff --git a/be/src/runtime/raw_value.h b/be/src/runtime/raw_value.h index 761e59e0ea..53e2a7857a 100644 --- a/be/src/runtime/raw_value.h +++ b/be/src/runtime/raw_value.h @@ -153,10 +153,6 @@ inline bool RawValue::lt(const void* v1, const void* v2, const TypeDescriptor& t return *reinterpret_cast(v1) < *reinterpret_cast(v2); - case TYPE_DECIMAL: - return *reinterpret_cast(v1) < - *reinterpret_cast(v2); - case TYPE_DECIMALV2: return reinterpret_cast(v1)->value < reinterpret_cast(v2)->value; @@ -208,10 +204,6 @@ inline bool RawValue::eq(const void* v1, const void* v2, const TypeDescriptor& t return *reinterpret_cast(v1) == *reinterpret_cast(v2); - case TYPE_DECIMAL: - return *reinterpret_cast(v1) == - *reinterpret_cast(v2); - case TYPE_DECIMALV2: return reinterpret_cast(v1)->value == reinterpret_cast(v2)->value; @@ -272,9 +264,6 @@ inline uint32_t RawValue::get_hash_value(const void* v, const PrimitiveType& typ case TYPE_DATETIME: return HashUtil::hash(v, 16, seed); - case TYPE_DECIMAL: - return HashUtil::hash(v, 40, seed); - case TYPE_DECIMALV2: return HashUtil::hash(v, 16, seed); @@ -330,9 +319,6 @@ inline uint32_t RawValue::get_hash_value_fvn(const void* v, const PrimitiveType& case TYPE_DATETIME: return HashUtil::fnv_hash(v, 16, seed); - case TYPE_DECIMAL: - return ((DecimalValue*)v)->hash(seed); - case TYPE_DECIMALV2: return HashUtil::fnv_hash(v, 16, seed); @@ -395,13 +381,6 @@ inline uint32_t RawValue::zlib_crc32(const void* v, const TypeDescriptor& type, return HashUtil::zlib_crc_hash(buf, end - buf - 1, seed); } - case TYPE_DECIMAL: { - const DecimalValue* dec_val = (const DecimalValue*)v; - int64_t int_val = dec_val->int_value(); - int32_t frac_val = dec_val->frac_value(); - seed = HashUtil::zlib_crc_hash(&int_val, sizeof(int_val), seed); - return HashUtil::zlib_crc_hash(&frac_val, sizeof(frac_val), seed); - } case TYPE_DECIMALV2: { const DecimalV2Value* dec_val = (const DecimalV2Value*)v; diff --git a/be/src/runtime/raw_value_ir.cpp b/be/src/runtime/raw_value_ir.cpp index d2e046c697..56ab7f5f4d 100644 --- a/be/src/runtime/raw_value_ir.cpp +++ b/be/src/runtime/raw_value_ir.cpp @@ -25,8 +25,6 @@ int RawValue::compare(const void* v1, const void* v2, const TypeDescriptor& type const StringValue* string_value2; const DateTimeValue* ts_value1; const DateTimeValue* ts_value2; - const DecimalValue* decimal_value1; - const DecimalValue* decimal_value2; float f1 = 0; float f2 = 0; double d1 = 0; @@ -92,12 +90,6 @@ int RawValue::compare(const void* v1, const void* v2, const TypeDescriptor& type ts_value2 = reinterpret_cast(v2); return *ts_value1 > *ts_value2 ? 1 : (*ts_value1 < *ts_value2 ? -1 : 0); - case TYPE_DECIMAL: - decimal_value1 = reinterpret_cast(v1); - decimal_value2 = reinterpret_cast(v2); - return (*decimal_value1 > *decimal_value2) ? 1 - : (*decimal_value1 < *decimal_value2 ? -1 : 0); - case TYPE_DECIMALV2: { DecimalV2Value decimal_value1(reinterpret_cast(v1)->value); DecimalV2Value decimal_value2(reinterpret_cast(v2)->value); diff --git a/be/src/runtime/tuple.h b/be/src/runtime/tuple.h index 2d66f917f7..b0b0f7b765 100644 --- a/be/src/runtime/tuple.h +++ b/be/src/runtime/tuple.h @@ -159,11 +159,6 @@ public: return reinterpret_cast(reinterpret_cast(this) + offset); } - DecimalValue* get_decimal_slot(int offset) { - DCHECK(offset != -1); // -1 offset indicates non-materialized slot - return reinterpret_cast(reinterpret_cast(this) + offset); - } - DecimalV2Value* get_decimalv2_slot(int offset) { DCHECK(offset != -1); // -1 offset indicates non-materialized slot return reinterpret_cast(reinterpret_cast(this) + offset); diff --git a/be/src/runtime/type_limit.h b/be/src/runtime/type_limit.h index 62247298cf..d46a3bc320 100644 --- a/be/src/runtime/type_limit.h +++ b/be/src/runtime/type_limit.h @@ -19,7 +19,6 @@ #define DORIS_BE_RUNTIME_TYPE_LIMIT_H #include "runtime/datetime_value.h" -#include "runtime/decimal_value.h" #include "runtime/decimalv2_value.h" #include "runtime/string_value.h" @@ -27,52 +26,26 @@ namespace doris { template struct type_limit { - static T min() { - return std::numeric_limits::min(); - } - static T max() { - return std::numeric_limits::max(); - } + static T min() { return std::numeric_limits::min(); } + static T max() { return std::numeric_limits::max(); } }; template <> struct type_limit { - static StringValue min() { - return StringValue::min_string_val(); - } - static StringValue max() { - return StringValue::max_string_val(); - } -}; - -template <> -struct type_limit { - static DecimalValue min() { - return DecimalValue::get_min_decimal(); - } - static DecimalValue max() { - return DecimalValue::get_max_decimal(); - } + static StringValue min() { return StringValue::min_string_val(); } + static StringValue max() { return StringValue::max_string_val(); } }; template <> struct type_limit { - static DecimalV2Value min() { - return DecimalV2Value::get_min_decimal(); - } - static DecimalV2Value max() { - return DecimalV2Value::get_max_decimal(); - } + static DecimalV2Value min() { return DecimalV2Value::get_min_decimal(); } + static DecimalV2Value max() { return DecimalV2Value::get_max_decimal(); } }; template <> struct type_limit { - static DateTimeValue min() { - return DateTimeValue::datetime_min_value(); - } - static DateTimeValue max() { - return DateTimeValue::datetime_max_value(); - } + static DateTimeValue min() { return DateTimeValue::datetime_min_value(); } + static DateTimeValue max() { return DateTimeValue::datetime_max_value(); } }; } // namespace doris diff --git a/be/src/runtime/types.cpp b/be/src/runtime/types.cpp index 1953c22526..3ebd2644b8 100644 --- a/be/src/runtime/types.cpp +++ b/be/src/runtime/types.cpp @@ -35,7 +35,7 @@ TypeDescriptor::TypeDescriptor(const std::vector& types, int* idx) if (type == TYPE_CHAR || type == TYPE_VARCHAR || type == TYPE_HLL) { DCHECK(scalar_type.__isset.len); len = scalar_type.len; - } else if (type == TYPE_DECIMAL || type == TYPE_DECIMALV2) { + } else if (type == TYPE_DECIMALV2) { DCHECK(scalar_type.__isset.precision); DCHECK(scalar_type.__isset.scale); precision = scalar_type.precision; @@ -102,7 +102,7 @@ void TypeDescriptor::to_thrift(TTypeDesc* thrift_type) const { if (type == TYPE_CHAR || type == TYPE_VARCHAR || type == TYPE_HLL) { // DCHECK_NE(len, -1); scalar_type.__set_len(len); - } else if (type == TYPE_DECIMAL || type == TYPE_DECIMALV2) { + } else if (type == TYPE_DECIMALV2) { DCHECK_NE(precision, -1); DCHECK_NE(scale, -1); scalar_type.__set_precision(precision); @@ -119,7 +119,7 @@ void TypeDescriptor::to_protobuf(PTypeDesc* ptype) const { scalar_type->set_type(doris::to_thrift(type)); if (type == TYPE_CHAR || type == TYPE_VARCHAR || type == TYPE_HLL) { scalar_type->set_len(len); - } else if (type == TYPE_DECIMAL || type == TYPE_DECIMALV2) { + } else if (type == TYPE_DECIMALV2) { DCHECK_NE(precision, -1); DCHECK_NE(scale, -1); scalar_type->set_precision(precision); @@ -141,7 +141,7 @@ TypeDescriptor::TypeDescriptor(const google::protobuf::RepeatedPtrField_impl->_intermediate_type = intermediate_type; ctx->_impl->_return_type = return_type; ctx->_impl->_arg_types = arg_types; - // UDFs may manipulate DecimalVal arguments via SIMD instructions such as 'movaps' - // that require 16-byte memory alignment. - // ctx->_impl->_varargs_buffer = - // reinterpret_cast(aligned_malloc(varargs_buffer_size, 16)); ctx->_impl->_varargs_buffer = reinterpret_cast(malloc(varargs_buffer_size)); ctx->_impl->_varargs_buffer_size = varargs_buffer_size; ctx->_impl->_debug = debug; @@ -421,21 +416,6 @@ void StringVal::append(FunctionContext* ctx, const uint8_t* buf, size_t buf_len, } } -bool DecimalVal::operator==(const DecimalVal& other) const { - if (is_null && other.is_null) { - return true; - } - - if (is_null || other.is_null) { - return false; - } - - // TODO(lingbin): implement DecimalVal's own cmp method - doris::DecimalValue value1 = doris::DecimalValue::from_decimal_val(*this); - doris::DecimalValue value2 = doris::DecimalValue::from_decimal_val(other); - return value1 == value2; -} - const FunctionContext::TypeDesc* FunctionContext::get_arg_type(int arg_idx) const { if (arg_idx < 0 || arg_idx >= _impl->_arg_types.size()) { return NULL; diff --git a/be/src/udf/udf.h b/be/src/udf/udf.h index 3331de208c..cd6400f456 100644 --- a/be/src/udf/udf.h +++ b/be/src/udf/udf.h @@ -42,7 +42,6 @@ struct IntVal; struct BigIntVal; struct StringVal; struct DateTimeVal; -struct DecimalVal; struct DecimalV2Val; struct HllVal; @@ -66,7 +65,7 @@ public: TYPE_LARGEINT, TYPE_FLOAT, TYPE_DOUBLE, - TYPE_DECIMAL, + TYPE_DECIMAL_DEPRACTED, TYPE_DATE, TYPE_DATETIME, TYPE_CHAR, @@ -643,37 +642,6 @@ struct StringVal : public AnyVal { size_t buf2_len); }; -struct DecimalVal : public AnyVal { - int8_t int_len; - int8_t frac_len; - bool sign; - int32_t buffer[9] = {0}; - - // Default value is zero - DecimalVal() : int_len(0), frac_len(0), sign(false) { - // Do nothing here - } - - static DecimalVal null() { - DecimalVal result; - result.is_null = true; - return result; - } - - void set_to_zero() { - memset(buffer, 0, sizeof(int32_t) * 9); - int_len = 0; - frac_len = 0; - sign = 0; - } - - void set_to_abs_value() { sign = false; } - - bool operator==(const DecimalVal& other) const; - - bool operator!=(const DecimalVal& other) const { return !(*this == other); } -}; - struct DecimalV2Val : public AnyVal { __int128 val; @@ -762,7 +730,6 @@ using doris_udf::LargeIntVal; using doris_udf::FloatVal; using doris_udf::DoubleVal; using doris_udf::StringVal; -using doris_udf::DecimalVal; using doris_udf::DecimalV2Val; using doris_udf::DateTimeVal; using doris_udf::HllVal; diff --git a/be/src/util/arrow/row_batch.cpp b/be/src/util/arrow/row_batch.cpp index 2bc4c78a2d..012b842a08 100644 --- a/be/src/util/arrow/row_batch.cpp +++ b/be/src/util/arrow/row_batch.cpp @@ -73,7 +73,6 @@ Status convert_to_arrow_type(const TypeDescriptor& type, std::shared_ptr(cell_ptr); - std::string decimal_str = decimal_val->to_string(); - ARROW_RETURN_NOT_OK(builder.Append(std::move(decimal_str))); - break; - } default: { LOG(WARNING) << "can't convert this type = " << primitive_type << "to arrow type"; return arrow::Status::TypeError("unsupported column type"); diff --git a/be/src/util/static_asserts.cpp b/be/src/util/static_asserts.cpp index f007ca9f52..eb50636e32 100644 --- a/be/src/util/static_asserts.cpp +++ b/be/src/util/static_asserts.cpp @@ -15,10 +15,7 @@ // specific language governing permissions and limitations // under the License. -#include - #include "runtime/datetime_value.h" -#include "runtime/decimal_value.h" #include "runtime/string_value.h" namespace doris { @@ -27,12 +24,11 @@ namespace doris { // at compile time. If these asserts fail, the compile will fail. class UnusedClass { private: - BOOST_STATIC_ASSERT(sizeof(StringValue) == 16); - BOOST_STATIC_ASSERT(offsetof(StringValue, len) == 8); + static_assert(sizeof(StringValue) == 16); + static_assert(offsetof(StringValue, len) == 8); // Datetime value - BOOST_STATIC_ASSERT(sizeof(DateTimeValue) == 16); - // BOOST_STATIC_ASSERT(offsetof(DateTimeValue, _year) == 8); - BOOST_STATIC_ASSERT(sizeof(DecimalValue) == 40); + static_assert(sizeof(DateTimeValue) == 16); + // static_assert(offsetof(DateTimeValue, _year) == 8); }; } // namespace doris diff --git a/be/src/util/symbols_util.cpp b/be/src/util/symbols_util.cpp index 879b145072..7461c689fc 100644 --- a/be/src/util/symbols_util.cpp +++ b/be/src/util/symbols_util.cpp @@ -160,9 +160,6 @@ static void append_any_val_type(int namespace_id, const TypeDescriptor& type, case TYPE_DATETIME: append_mangled_token("DateTimeVal", s); break; - case TYPE_DECIMAL: - append_mangled_token("DecimalVal", s); - break; case TYPE_DECIMALV2: append_mangled_token("DecimalV2Val", s); break; diff --git a/be/src/util/topn_counter.h b/be/src/util/topn_counter.h index f8dc584dc9..be6bd9c54a 100644 --- a/be/src/util/topn_counter.h +++ b/be/src/util/topn_counter.h @@ -23,7 +23,6 @@ #include "common/logging.h" #include "runtime/datetime_value.h" -#include "runtime/decimal_value.h" #include "runtime/decimalv2_value.h" #include "runtime/large_int_value.h" #include "udf/udf.h" @@ -40,20 +39,14 @@ public: Counter(const std::string& item, uint64_t count) : _item(item), _count(count) {} - uint64_t get_count() const { - return _count; - } + uint64_t get_count() const { return _count; } - const std::string& get_item() const { - return _item; - } + const std::string& get_item() const { return _item; } - void add_count(uint64_t count) { - _count += count; - } + void add_count(uint64_t count) { _count += count; } - bool operator == (const Counter& other) { - if(_item.compare(other._item) != 0) { + bool operator==(const Counter& other) { + if (_item.compare(other._item) != 0) { return false; } if (_count != other._count) { @@ -67,21 +60,26 @@ private: uint64_t _count; }; - // Refer to TopNCounter.java in https://github.com/apache/kylin // Based on the Space-Saving algorithm and the Stream-Summary data structure as described in: // Efficient Computation of Frequent and Top-k Elements in Data Streams by Metwally, Agrawal, and Abbadi class TopNCounter { public: - TopNCounter(uint32_t space_expand_rate = DEFAULT_SPACE_EXPAND_RATE) : - _top_num(0), _space_expand_rate(space_expand_rate), _capacity(0), _ordered(false), - _counter_map(new std::unordered_map(_capacity)), - _counter_vec(new std::vector(_capacity)){} + TopNCounter(uint32_t space_expand_rate = DEFAULT_SPACE_EXPAND_RATE) + : _top_num(0), + _space_expand_rate(space_expand_rate), + _capacity(0), + _ordered(false), + _counter_map(new std::unordered_map(_capacity)), + _counter_vec(new std::vector(_capacity)) {} - TopNCounter(const Slice& src) : - _top_num(0), _space_expand_rate(0), _capacity(0), _ordered(false), - _counter_map(new std::unordered_map(_capacity)), - _counter_vec(new std::vector(_capacity)) { + TopNCounter(const Slice& src) + : _top_num(0), + _space_expand_rate(0), + _capacity(0), + _ordered(false), + _counter_map(new std::unordered_map(_capacity)), + _counter_vec(new std::vector(_capacity)) { bool res = deserialize(src); DCHECK(res); } @@ -118,7 +116,7 @@ public: add_item_numeric(item, incrementCount); } void add_item(const StringVal& item, uint64_t incrementCount) { - add_item(std::string((char*) item.ptr, item.len), incrementCount); + add_item(std::string((char*)item.ptr, item.len), incrementCount); } void add_item(const DateTimeVal& item, uint64_t incrementCount) { char str[MAX_DTVALUE_STR_LEN]; @@ -128,9 +126,6 @@ public: void add_item(const LargeIntVal& item, uint64_t incrementCount) { add_item(LargeIntValue::to_string(item.val), incrementCount); } - void add_item(const DecimalVal& item, uint64_t incrementCount) { - add_item(DecimalValue::from_decimal_val(item).to_string(), incrementCount); - } void add_item(const DecimalV2Val& item, uint64_t incrementCount) { add_item(DecimalV2Value::from_decimal_val(item).to_string(), incrementCount); } @@ -169,14 +164,12 @@ private: std::vector* _counter_vec; }; -class TopNComparator -{ +class TopNComparator { public: - bool operator () (const Counter& s1, const Counter& s2) - { + bool operator()(const Counter& s1, const Counter& s2) { return s1.get_count() > s2.get_count(); } }; -} +} // namespace doris #endif //DORIS_BE_SRC_UTI_TOPN_COUNTER_H diff --git a/be/test/exec/csv_scan_node_test.cpp b/be/test/exec/csv_scan_node_test.cpp index 8841ab2df1..000b135be1 100644 --- a/be/test/exec/csv_scan_node_test.cpp +++ b/be/test/exec/csv_scan_node_test.cpp @@ -122,7 +122,7 @@ void CsvScanNodeTest::init_desc_tbl() { { TSlotDescriptor t_slot_desc; t_slot_desc.__set_id(i); - TTypeDesc ttype = gen_type_desc(TPrimitiveType::DECIMAL); + TTypeDesc ttype = gen_type_desc(TPrimitiveType::DECIMALV2); ttype.types[0].scalar_type.__set_precision(10); ttype.types[0].scalar_type.__set_scale(5); t_slot_desc.__set_slotType(ttype); @@ -135,7 +135,7 @@ void CsvScanNodeTest::init_desc_tbl() { t_slot_desc.__set_colName("decimal_column"); slot_descs.push_back(t_slot_desc); - offset += sizeof(DecimalValue); + offset += sizeof(DecimalValueV2); } ++i; // date_column @@ -207,7 +207,7 @@ void CsvScanNodeTest::init_desc_tbl() { } { TColumnType column_type; - column_type.__set_type(TPrimitiveType::DECIMAL); + column_type.__set_type(TPrimitiveType::DECIMALV2); column_type.__set_precision(10); column_type.__set_scale(5); column_type_map["decimal_column"] = column_type; diff --git a/be/test/exec/orc_scanner_test.cpp b/be/test/exec/orc_scanner_test.cpp index dbfcc18d83..daf9bb8da5 100644 --- a/be/test/exec/orc_scanner_test.cpp +++ b/be/test/exec/orc_scanner_test.cpp @@ -29,7 +29,7 @@ #include "exec/broker_scan_node.h" #include "exec/local_file_reader.h" #include "exprs/cast_functions.h" -#include "exprs/decimal_operators.h" +#include "exprs/decimalv2_operators.h" #include "gen_cpp/Descriptors_types.h" #include "gen_cpp/PlanNodes_types.h" #include "runtime/descriptors.h" @@ -51,7 +51,7 @@ public: UserFunctionCache::instance()->init( "./be/test/runtime/test_data/user_function_cache/normal"); CastFunctions::init(); - DecimalOperators::init(); + DecimalV2Operators::init(); } protected: @@ -406,7 +406,8 @@ TEST_F(OrcScannerTest, normal) { rangeDesc.file_type = TFileType::FILE_LOCAL; ranges.push_back(rangeDesc); - ORCScanner scanner(&_runtime_state, _profile, params, ranges, _addresses, _pre_filter, &_counter); + ORCScanner scanner(&_runtime_state, _profile, params, ranges, _addresses, _pre_filter, + &_counter); ASSERT_TRUE(scanner.open().ok()); auto tracker = std::make_shared(); @@ -529,7 +530,8 @@ TEST_F(OrcScannerTest, normal2) { rangeDesc.file_type = TFileType::FILE_LOCAL; ranges.push_back(rangeDesc); - ORCScanner scanner(&_runtime_state, _profile, params, ranges, _addresses, _pre_filter, &_counter); + ORCScanner scanner(&_runtime_state, _profile, params, ranges, _addresses, _pre_filter, + &_counter); ASSERT_TRUE(scanner.open().ok()); auto tracker = std::make_shared(); @@ -562,7 +564,7 @@ TEST_F(OrcScannerTest, normal3) { TTypeNode node; node.__set_type(TTypeNodeType::SCALAR); TScalarType scalar_type; - scalar_type.__set_type(TPrimitiveType::DECIMAL); + scalar_type.__set_type(TPrimitiveType::DECIMALV2); scalar_type.__set_precision(64); scalar_type.__set_scale(64); node.__set_scalar_type(scalar_type); @@ -608,14 +610,14 @@ TEST_F(OrcScannerTest, normal3) { cast_expr.__set_num_children(1); cast_expr.__set_output_scale(-1); cast_expr.__isset.fn = true; - cast_expr.fn.name.function_name = "casttodecimal"; + cast_expr.fn.name.function_name = "casttodecimalv2"; cast_expr.fn.binary_type = TFunctionBinaryType::BUILTIN; cast_expr.fn.arg_types.push_back(varchar_type); cast_expr.fn.ret_type = decimal_type; cast_expr.fn.has_var_args = false; - cast_expr.fn.__set_signature("cast_to_decimal_val(VARCHAR(*))"); + cast_expr.fn.__set_signature("cast_to_decimalv2_val(VARCHAR(*))"); cast_expr.fn.__isset.scalar_fn = true; - cast_expr.fn.scalar_fn.symbol = "doris::DecimalOperators::cast_to_decimal_val"; + cast_expr.fn.scalar_fn.symbol = "doris::DecimalV2Operators::cast_to_decimalv2_val"; TExprNode slot_ref; slot_ref.node_type = TExprNodeType::SLOT_REF; @@ -738,14 +740,14 @@ TEST_F(OrcScannerTest, normal3) { cast_expr.__set_num_children(1); cast_expr.__set_output_scale(-1); cast_expr.__isset.fn = true; - cast_expr.fn.name.function_name = "casttodecimal"; + cast_expr.fn.name.function_name = "casttodecimalv2"; cast_expr.fn.binary_type = TFunctionBinaryType::BUILTIN; cast_expr.fn.arg_types.push_back(varchar_type); cast_expr.fn.ret_type = decimal_type; cast_expr.fn.has_var_args = false; - cast_expr.fn.__set_signature("cast_to_decimal_val(VARCHAR(*))"); + cast_expr.fn.__set_signature("cast_to_decimalv2_val(VARCHAR(*))"); cast_expr.fn.__isset.scalar_fn = true; - cast_expr.fn.scalar_fn.symbol = "doris::DecimalOperators::cast_to_decimal_val"; + cast_expr.fn.scalar_fn.symbol = "doris::DecimalV2Operators::cast_to_decimalv2_val"; TExprNode slot_ref; slot_ref.node_type = TExprNodeType::SLOT_REF; @@ -878,7 +880,8 @@ TEST_F(OrcScannerTest, normal3) { rangeDesc.file_type = TFileType::FILE_LOCAL; ranges.push_back(rangeDesc); - ORCScanner scanner(&_runtime_state, _profile, params, ranges, _addresses, _pre_filter, &_counter); + ORCScanner scanner(&_runtime_state, _profile, params, ranges, _addresses, _pre_filter, + &_counter); ASSERT_TRUE(scanner.open().ok()); auto tracker = std::make_shared(); @@ -888,7 +891,7 @@ TEST_F(OrcScannerTest, normal3) { bool eof = false; ASSERT_TRUE(scanner.get_next(tuple, &tuple_pool, &eof).ok()); ASSERT_EQ(Tuple::to_string(tuple, *_desc_tbl->get_tuple_descriptor(1)), - "(0.123456789 1.12 -1.1234500000 0.12345 0.000 1 2020-01-14 14:12:19 2020-02-10 " + "(0.123456789 1.12 -1.12345 0.12345 0 1 2020-01-14 14:12:19 2020-02-10 " "-0.0014)"); scanner.close(); } diff --git a/be/test/exec/tablet_sink_test.cpp b/be/test/exec/tablet_sink_test.cpp index e976b5c3a1..b4ec5deb85 100644 --- a/be/test/exec/tablet_sink_test.cpp +++ b/be/test/exec/tablet_sink_test.cpp @@ -23,7 +23,7 @@ #include "gen_cpp/HeartbeatService_types.h" #include "gen_cpp/internal_service.pb.h" #include "runtime/bufferpool/reservation_tracker.h" -#include "runtime/decimal_value.h" +#include "runtime/decimalv2_value.h" #include "runtime/descriptor_helper.h" #include "runtime/exec_env.h" #include "runtime/result_queue_mgr.h" @@ -936,8 +936,8 @@ TEST_F(OlapTableSinkTest, decimal) { memset(tuple, 0, tuple_desc->byte_size()); *reinterpret_cast(tuple->get_slot(4)) = 12; - DecimalValue* dec_val = reinterpret_cast(tuple->get_slot(16)); - *dec_val = DecimalValue(std::string("12.3")); + DecimalV2Value* dec_val = reinterpret_cast(tuple->get_slot(16)); + *dec_val = DecimalV2Value(std::string("12.3")); batch.commit_last_row(); } // 13, 123.123456789 @@ -947,8 +947,8 @@ TEST_F(OlapTableSinkTest, decimal) { memset(tuple, 0, tuple_desc->byte_size()); *reinterpret_cast(tuple->get_slot(4)) = 13; - DecimalValue* dec_val = reinterpret_cast(tuple->get_slot(16)); - *dec_val = DecimalValue(std::string("123.123456789")); + DecimalV2Value* dec_val = reinterpret_cast(tuple->get_slot(16)); + *dec_val = DecimalV2Value(std::string("123.123456789")); batch.commit_last_row(); } @@ -959,8 +959,8 @@ TEST_F(OlapTableSinkTest, decimal) { memset(tuple, 0, tuple_desc->byte_size()); *reinterpret_cast(tuple->get_slot(4)) = 14; - DecimalValue* dec_val = reinterpret_cast(tuple->get_slot(16)); - *dec_val = DecimalValue(std::string("123456789123.1234")); + DecimalV2Value* dec_val = reinterpret_cast(tuple->get_slot(16)); + *dec_val = DecimalV2Value(std::string("123456789123.1234")); batch.commit_last_row(); } diff --git a/be/test/exprs/string_functions_test.cpp b/be/test/exprs/string_functions_test.cpp index c0fd49f630..f9d75345c4 100644 --- a/be/test/exprs/string_functions_test.cpp +++ b/be/test/exprs/string_functions_test.cpp @@ -23,9 +23,9 @@ #include #include "exprs/anyval_util.h" +#include "test_util/test_util.h" #include "testutil/function_utils.h" #include "util/logging.h" -#include "test_util/test_util.h" namespace doris { @@ -109,27 +109,6 @@ TEST_F(StringFunctionsTest, money_format_double) { delete context; } -TEST_F(StringFunctionsTest, money_format_decimal) { - doris_udf::FunctionContext* context = new doris_udf::FunctionContext(); - - DecimalValue dv1(std::string("3333333333.2222222222")); - DecimalVal value1; - dv1.to_decimal_val(&value1); - - StringVal result = StringFunctions::money_format(context, value1); - StringVal expected = AnyValUtil::from_string_temp(context, std::string("3,333,333,333.22")); - ASSERT_EQ(expected, result); - - DecimalValue dv2(std::string("-7407407406790123456.71604938271975308642")); - DecimalVal value2; - dv2.to_decimal_val(&value2); - - result = StringFunctions::money_format(context, value2); - expected = AnyValUtil::from_string_temp(context, std::string("-7,407,407,406,790,123,456.72")); - ASSERT_EQ(expected, result); - delete context; -} - TEST_F(StringFunctionsTest, money_format_decimal_v2) { doris_udf::FunctionContext* context = new doris_udf::FunctionContext(); @@ -291,7 +270,7 @@ TEST_F(StringFunctionsTest, null_or_empty) { TEST_F(StringFunctionsTest, substring) { doris_udf::FunctionContext* context = new doris_udf::FunctionContext(); - + ASSERT_EQ(AnyValUtil::from_string_temp(context, std::string("")), StringFunctions::substring(context, StringVal("hello word"), 0, 5)); diff --git a/be/test/olap/delete_handler_test.cpp b/be/test/olap/delete_handler_test.cpp index e78e835109..98823cc594 100644 --- a/be/test/olap/delete_handler_test.cpp +++ b/be/test/olap/delete_handler_test.cpp @@ -115,7 +115,7 @@ void set_default_create_tablet_request(TCreateTabletReq* request) { TColumn k9; k9.column_name = "k9"; k9.__set_is_key(true); - k9.column_type.type = TPrimitiveType::DECIMAL; + k9.column_type.type = TPrimitiveType::DECIMALV2; k9.column_type.__set_precision(6); k9.column_type.__set_scale(3); request->tablet_schema.columns.push_back(k9); @@ -196,7 +196,7 @@ void set_create_duplicate_tablet_request(TCreateTabletReq* request) { TColumn k9; k9.column_name = "k9"; k9.__set_is_key(true); - k9.column_type.type = TPrimitiveType::DECIMAL; + k9.column_type.type = TPrimitiveType::DECIMALV2; k9.column_type.__set_precision(6); k9.column_type.__set_scale(3); request->tablet_schema.columns.push_back(k9); diff --git a/be/test/olap/delta_writer_test.cpp b/be/test/olap/delta_writer_test.cpp index 60ff0b7aa6..a0573b5697 100644 --- a/be/test/olap/delta_writer_test.cpp +++ b/be/test/olap/delta_writer_test.cpp @@ -148,7 +148,7 @@ void create_tablet_request(int64_t tablet_id, int32_t schema_hash, TCreateTablet TColumn k10; k10.column_name = "k10"; k10.__set_is_key(true); - k10.column_type.type = TPrimitiveType::DECIMAL; + k10.column_type.type = TPrimitiveType::DECIMALV2; k10.column_type.__set_precision(6); k10.column_type.__set_scale(3); request->tablet_schema.columns.push_back(k10); @@ -221,7 +221,7 @@ void create_tablet_request(int64_t tablet_id, int32_t schema_hash, TCreateTablet TColumn v10; v10.column_name = "v10"; v10.__set_is_key(false); - v10.column_type.type = TPrimitiveType::DECIMAL; + v10.column_type.type = TPrimitiveType::DECIMALV2; v10.column_type.__set_precision(6); v10.column_type.__set_scale(3); v10.__set_aggregation_type(TAggregationType::SUM); @@ -438,8 +438,8 @@ TEST_F(TestDeltaWriter, write) { memcpy(var_ptr->ptr, "abcde", 5); var_ptr->len = 5; - DecimalValue decimal_value(1.1); - *(DecimalValue*)(tuple->get_slot(slots[9]->tuple_offset())) = decimal_value; + DecimalV2Value decimal_value(1.1); + *(DecimalV2Value*)(tuple->get_slot(slots[9]->tuple_offset())) = decimal_value; *(int8_t*)(tuple->get_slot(slots[10]->tuple_offset())) = -127; *(int16_t*)(tuple->get_slot(slots[11]->tuple_offset())) = -32767; @@ -463,8 +463,8 @@ TEST_F(TestDeltaWriter, write) { memcpy(var_ptr->ptr, "abcde", 5); var_ptr->len = 5; - DecimalValue val_decimal(1.1); - *(DecimalValue*)(tuple->get_slot(slots[19]->tuple_offset())) = val_decimal; + DecimalV2Value val_decimal(1.1); + *(DecimalV2Value*)(tuple->get_slot(slots[19]->tuple_offset())) = val_decimal; res = delta_writer->write(tuple); ASSERT_EQ(OLAP_SUCCESS, res); diff --git a/be/test/runtime/CMakeLists.txt b/be/test/runtime/CMakeLists.txt index 6c7e5aca6a..90087d2055 100644 --- a/be/test/runtime/CMakeLists.txt +++ b/be/test/runtime/CMakeLists.txt @@ -29,7 +29,6 @@ ADD_BE_TEST(string_buffer_test) #ADD_BE_TEST(data_stream_test) #ADD_BE_TEST(parallel_executor_test) ADD_BE_TEST(datetime_value_test) -ADD_BE_TEST(decimal_value_test) ADD_BE_TEST(decimalv2_value_test) ADD_BE_TEST(large_int_value_test) ADD_BE_TEST(string_value_test) diff --git a/be/test/runtime/decimal_value_test.cpp b/be/test/runtime/decimal_value_test.cpp index 8d6ee7d227..3d2c6f9c13 100644 --- a/be/test/runtime/decimal_value_test.cpp +++ b/be/test/runtime/decimal_value_test.cpp @@ -15,13 +15,12 @@ // specific language governing permissions and limitations // under the License. -#include "runtime/decimal_value.h" - #include #include #include +#include "runtime/decimalv2_value.h" #include "util/logging.h" namespace doris { diff --git a/be/test/util/arrow/arrow_work_flow_test.cpp b/be/test/util/arrow/arrow_work_flow_test.cpp index e45133e8ea..b237f211db 100644 --- a/be/test/util/arrow/arrow_work_flow_test.cpp +++ b/be/test/util/arrow/arrow_work_flow_test.cpp @@ -159,26 +159,6 @@ void ArrowWorkFlowTest::init_desc_tbl() { offset += sizeof(DateTimeValue); } ++i; - // decimal_column - { - TSlotDescriptor t_slot_desc; - t_slot_desc.__set_id(i); - TTypeDesc ttype = gen_type_desc(TPrimitiveType::DECIMAL); - ttype.types[0].scalar_type.__set_precision(10); - ttype.types[0].scalar_type.__set_scale(5); - t_slot_desc.__set_slotType(ttype); - t_slot_desc.__set_columnPos(i); - t_slot_desc.__set_byteOffset(offset); - t_slot_desc.__set_nullIndicatorByte(0); - t_slot_desc.__set_nullIndicatorBit(-1); - t_slot_desc.__set_slotIdx(i); - t_slot_desc.__set_isMaterialized(true); - t_slot_desc.__set_colName("decimal_column"); - - slot_descs.push_back(t_slot_desc); - offset += sizeof(DecimalValue); - } - ++i; // decimalv2_column { TSlotDescriptor t_slot_desc; @@ -278,13 +258,6 @@ void ArrowWorkFlowTest::init_desc_tbl() { column_type.__set_type(TPrimitiveType::DATE); column_type_map["date_column"] = column_type; } - { - TColumnType column_type; - column_type.__set_type(TPrimitiveType::DECIMAL); - column_type.__set_precision(10); - column_type.__set_scale(5); - column_type_map["decimal_column"] = column_type; - } { TColumnType column_type; column_type.__set_type(TPrimitiveType::DECIMALV2); @@ -308,7 +281,6 @@ void ArrowWorkFlowTest::init_desc_tbl() { std::vector columns; columns.push_back("int_column"); columns.push_back("date_column"); - columns.push_back("decimal_column"); columns.push_back("decimalv2_column"); columns.push_back("fix_len_string_column"); columns.push_back("largeint_column"); @@ -350,7 +322,7 @@ TEST_F(ArrowWorkFlowTest, NormalUse) { &record_batch); ASSERT_TRUE(status.ok()); ASSERT_EQ(6, record_batch->num_rows()); - ASSERT_EQ(6, record_batch->num_columns()); + ASSERT_EQ(5, record_batch->num_columns()); std::string result; status = serialize_record_batch(*record_batch, &result); ASSERT_TRUE(status.ok()); diff --git a/be/test/util/test_data/csv_data b/be/test/util/test_data/csv_data index 9dc9dfad8d..f292619632 100644 --- a/be/test/util/test_data/csv_data +++ b/be/test/util/test_data/csv_data @@ -1,6 +1,6 @@ -112345,2015-04-20,-12345.67891,24453.325,abc,9223372036854775807 -65536,2015-04-20,12345.67891,3.141,abcde,9223372036854775807 -45678,2015-04-20,.12345,-0.123,ab,-9223372036854775807 -200,2015-04-20,-12345.,-654.654,abcde,123456 -68987,2015-04-20,-12345,0.666,a,11011920 -189,2015-04-20,2,100.001,abcd,-11011907 +112345,2015-04-20,24453.325,abc,9223372036854775807 +65536,2015-04-20,3.141,abcde,9223372036854775807 +45678,2015-04-20,-0.123,ab,-9223372036854775807 +200,2015-04-20,-654.654,abcde,123456 +68987,2015-04-20,0.666,a,11011920 +189,2015-04-20,100.001,abcd,-11011907 diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AggregateInfoBase.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AggregateInfoBase.java index 9102c57d99..91dafce7e6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AggregateInfoBase.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AggregateInfoBase.java @@ -165,7 +165,7 @@ public abstract class AggregateInfoBase { if (!intermediateType.isWildcardDecimal()) { slotDesc.setType(intermediateType); } else { - Preconditions.checkState(expr.getType().isDecimal() || expr.getType().isDecimalV2()); + Preconditions.checkState(expr.getType().isDecimalV2()); } } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java index d3c977a7ea..b02eb0cb00 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ArithmeticExpr.java @@ -106,10 +106,6 @@ public class ArithmeticExpr extends Expr { Operator.DIVIDE.getName(), Lists.newArrayList(Type.DOUBLE, Type.DOUBLE), Type.DOUBLE)); - functionSet.addBuiltin(ScalarFunction.createBuiltinOperator( - Operator.DIVIDE.getName(), - Lists.newArrayList(Type.DECIMAL, Type.DECIMAL), - Type.DECIMAL)); functionSet.addBuiltin(ScalarFunction.createBuiltinOperator( Operator.DIVIDE.getName(), Lists.newArrayList(Type.DECIMALV2, Type.DECIMALV2), @@ -167,7 +163,7 @@ public class ArithmeticExpr extends Expr { @Override protected void toThrift(TExprNode msg) { msg.node_type = TExprNodeType.ARITHMETIC_EXPR; - if (!type.isDecimal() && !type.isDecimalV2()) { + if (!type.isDecimalV2()) { msg.setOpcode(op.getOpcode()); msg.setOutputColumn(outputColumn); } @@ -203,8 +199,6 @@ public class ArithmeticExpr extends Expr { return Type.DOUBLE; } else if (pt1 == PrimitiveType.DECIMALV2 || pt2 == PrimitiveType.DECIMALV2) { return Type.DECIMALV2; - } else if (pt1 == PrimitiveType.DECIMAL || pt2 == PrimitiveType.DECIMAL) { - return Type.DECIMAL; } else if (pt1 == PrimitiveType.LARGEINT || pt2 == PrimitiveType.LARGEINT) { return Type.LARGEINT; } else { diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java index f399334401..9a98ac5fbb 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java @@ -308,10 +308,6 @@ public class BinaryPredicate extends Predicate implements Writable { && (t2 == PrimitiveType.BIGINT || t2 == PrimitiveType.DECIMALV2)) { return Type.DECIMALV2; } - if ((t1 == PrimitiveType.BIGINT || t1 == PrimitiveType.DECIMAL) - && (t2 == PrimitiveType.BIGINT || t2 == PrimitiveType.DECIMAL)) { - return Type.DECIMAL; - } if ((t1 == PrimitiveType.BIGINT || t1 == PrimitiveType.LARGEINT) && (t2 == PrimitiveType.BIGINT || t2 == PrimitiveType.LARGEINT)) { return Type.LARGEINT; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java index e298a0cfca..dfdc4b0178 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CastExpr.java @@ -102,7 +102,7 @@ public class CastExpr extends Expr { } // Disable casting from boolean to decimal or datetime or date if (fromType.isBoolean() && - (toType.equals(Type.DECIMAL) || toType.equals(Type.DECIMALV2) || + (toType.equals(Type.DECIMALV2) || toType.equals(Type.DATETIME) || toType.equals(Type.DATE))) { continue; } @@ -111,9 +111,7 @@ public class CastExpr extends Expr { continue; } String beClass = toType.isDecimalV2() || fromType.isDecimalV2() ? "DecimalV2Operators" : "CastFunctions"; - if (toType.isDecimal() || fromType.isDecimal()) { - beClass = "DecimalOperators"; - } else if (fromType.isTime()) { + if (fromType.isTime()) { beClass = "TimeOperators"; } String typeName = Function.getUdfTypeName(toType.getPrimitiveType()); @@ -284,9 +282,10 @@ public class CastExpr extends Expr { return new IntLiteral(value.getLongValue(), type); } else if (type.isLargeIntType()) { return new LargeIntLiteral(value.getStringValue()); - } else if (type.isDecimal() || type.isDecimalV2()) { + } else if (type.isDecimalV2()) { return new DecimalLiteral(value.getStringValue()); } else if (type.isFloatingPointType()) { + return new FloatLiteral(value.getDoubleValue(), type); } else if (type.isStringType()) { return new StringLiteral(value.getStringValue()); diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java index bd493fa4c6..fc455db174 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ColumnDef.java @@ -250,7 +250,6 @@ public class ColumnDef { case DOUBLE: FloatLiteral doubleLiteral = new FloatLiteral(defaultValue); break; - case DECIMAL: case DECIMALV2: DecimalLiteral decimalLiteral = new DecimalLiteral(defaultValue); decimalLiteral.checkPrecisionAndScale(scalarType.getScalarPrecision(), scalarType.getScalarScale()); diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableAsSelectStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableAsSelectStmt.java index 90e563b716..a5769ffb87 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableAsSelectStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/CreateTableAsSelectStmt.java @@ -58,7 +58,7 @@ public class CreateTableAsSelectStmt extends StatementBase { // TODO(zc): support char, varchar and decimal for (Expr expr : tmpStmt.getResultExprs()) { - if (expr.getType().isDecimal() || expr.getType().isDecimalV2() || expr.getType().isStringType()) { + if (expr.getType().isDecimalV2() || expr.getType().isStringType()) { ErrorReport.reportAnalysisException(ErrorCode.ERR_UNSUPPORTED_TYPE_IN_CTAS, expr.getType()); } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/DecimalLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/DecimalLiteral.java index 91ce58603b..d64ea00ed2 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DecimalLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DecimalLiteral.java @@ -130,7 +130,6 @@ public class DecimalLiteral extends LiteralExpr { buffer.order(ByteOrder.LITTLE_ENDIAN); buffer.putLong(value.longValue()); break; - case DECIMAL: case DECIMALV2: buffer = ByteBuffer.allocate(12); buffer.order(ByteOrder.LITTLE_ENDIAN); @@ -234,7 +233,7 @@ public class DecimalLiteral extends LiteralExpr { @Override protected Expr uncheckedCastTo(Type targetType) throws AnalysisException { - if (targetType.isDecimal() || targetType.isDecimalV2()) { + if (targetType.isDecimalV2()) { return this; } else if (targetType.isFloatingPointType()) { return new FloatLiteral(value.doubleValue(), targetType); diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ExpressionFunctions.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ExpressionFunctions.java index 1232dcab66..dbea8a0b9b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ExpressionFunctions.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ExpressionFunctions.java @@ -222,7 +222,7 @@ public enum ExpressionFunctions { exprs = new IntLiteral[args.size()]; } else if (argType.isDateType()) { exprs = new DateLiteral[args.size()]; - } else if (argType.isDecimal()) { + } else if (argType.isDecimalV2()) { exprs = new DecimalLiteral[args.size()]; } else if (argType.isFloatingPointType()) { exprs = new FloatLiteral[args.size()]; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java index dc630f22a3..0b70f12454 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/FloatLiteral.java @@ -157,7 +157,7 @@ public class FloatLiteral extends LiteralExpr { @Override protected Expr uncheckedCastTo(Type targetType) throws AnalysisException { - if (!(targetType.isFloatingPointType() || targetType.isDecimal() || targetType.isDecimalV2())) { + if (!(targetType.isFloatingPointType() || targetType.isDecimalV2())) { return super.uncheckedCastTo(targetType); } if (targetType.isFloatingPointType()) { @@ -167,7 +167,7 @@ public class FloatLiteral extends LiteralExpr { return floatLiteral; } return this; - } else if (targetType.isDecimal() || targetType.isDecimalV2()) { + } else if (targetType.isDecimalV2()) { return new DecimalLiteral(new BigDecimal(value)); } return this; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/IndexDef.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/IndexDef.java index e2a0042d03..d19ff11b28 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/IndexDef.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/IndexDef.java @@ -127,7 +127,7 @@ public class IndexDef { if (indexType == IndexType.BITMAP) { String indexColName = column.getName(); PrimitiveType colType = column.getDataType(); - if (!(colType.isDateType() || colType.isDecimalType() || colType.isFixedPointType() || + if (!(colType.isDateType() || colType.isDecimalV2Type() || colType.isFixedPointType() || colType.isStringType() || colType == PrimitiveType.BOOLEAN)) { throw new AnalysisException(colType + " is not supported in bitmap index. " + "invalid column: " + indexColName); diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/IntLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/IntLiteral.java index 67f0482a92..64b3973c24 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/IntLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/IntLiteral.java @@ -307,7 +307,7 @@ public class IntLiteral extends LiteralExpr { } } else if (targetType.isFloatingPointType()) { return new FloatLiteral(new Double(value), targetType); - } else if (targetType.isDecimal() || targetType.isDecimalV2()) { + } else if (targetType.isDecimalV2()) { return new DecimalLiteral(new BigDecimal(value)); } return this; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/LargeIntLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/LargeIntLiteral.java index db01e01877..3e0b2413b5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/LargeIntLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/LargeIntLiteral.java @@ -191,7 +191,7 @@ public class LargeIntLiteral extends LiteralExpr { protected Expr uncheckedCastTo(Type targetType) throws AnalysisException { if (targetType.isFloatingPointType()) { return new FloatLiteral(new Double(value.doubleValue()), targetType); - } else if (targetType.isDecimal() || targetType.isDecimalV2()) { + } else if (targetType.isDecimalV2()) { return new DecimalLiteral(new BigDecimal(value)); } else if (targetType.isNumericType()) { try { diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/LiteralExpr.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/LiteralExpr.java index 370c4d4056..f6ab8f669e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/LiteralExpr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/LiteralExpr.java @@ -66,7 +66,6 @@ public abstract class LiteralExpr extends Expr implements Comparablebuilder() .put(Type.BOOLEAN, "14offset_fn_initIN9doris_udf10BooleanValEEEvPNS2_15FunctionContextEPT_") - .put(Type.DECIMAL, - "14offset_fn_initIN9doris_udf10DecimalValEEEvPNS2_15FunctionContextEPT_") .put(Type.DECIMALV2, "14offset_fn_initIN9doris_udf12DecimalV2ValEEEvPNS2_15FunctionContextEPT_") .put(Type.TINYINT, @@ -486,8 +477,6 @@ public class FunctionSet { ImmutableMap.builder() .put(Type.BOOLEAN, "16offset_fn_updateIN9doris_udf10BooleanValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValES8_PS6_") - .put(Type.DECIMAL, - "16offset_fn_updateIN9doris_udf10DecimalValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValES8_PS6_") .put(Type.DECIMALV2, "16offset_fn_updateIN9doris_udf12DecimalV2ValEEEvPNS2_15FunctionContextERKT_RKNS2_9BigIntValES8_PS6_") .put(Type.TINYINT, @@ -523,8 +512,6 @@ public class FunctionSet { ImmutableMap.builder() .put(Type.BOOLEAN, "15last_val_updateIN9doris_udf10BooleanValEEEvPNS2_15FunctionContextERKT_PS6_") - .put(Type.DECIMAL, - "15last_val_updateIN9doris_udf10DecimalValEEEvPNS2_15FunctionContextERKT_PS6_") .put(Type.DECIMALV2, "15last_val_updateIN9doris_udf12DecimalV2ValEEEvPNS2_15FunctionContextERKT_PS6_") .put(Type.TINYINT, @@ -556,9 +543,6 @@ public class FunctionSet { .put(Type.BOOLEAN, "24first_val_rewrite_updateIN9doris_udf10BooleanValEEEvPNS2_15" + "FunctionContextERKT_RKNS2_9BigIntValEPS6_") - .put(Type.DECIMAL, - "24first_val_rewrite_updateIN9doris_udf10DecimalValEEEvPNS2_15" - + "FunctionContextERKT_RKNS2_9BigIntValEPS6_") .put(Type.DECIMALV2, "24first_val_rewrite_updateIN9doris_udf12DecimalV2ValEEEvPNS2_15" + "FunctionContextERKT_RKNS2_9BigIntValEPS6_") @@ -598,8 +582,6 @@ public class FunctionSet { ImmutableMap.builder() .put(Type.BOOLEAN, "15last_val_removeIN9doris_udf10BooleanValEEEvPNS2_15FunctionContextERKT_PS6_") - .put(Type.DECIMAL, - "15last_val_removeIN9doris_udf10DecimalValEEEvPNS2_15FunctionContextERKT_PS6_") .put(Type.DECIMALV2, "15last_val_removeIN9doris_udf12DecimalV2ValEEEvPNS2_15FunctionContextERKT_PS6_") .put(Type.TINYINT, @@ -630,8 +612,6 @@ public class FunctionSet { ImmutableMap.builder() .put(Type.BOOLEAN, "16first_val_updateIN9doris_udf10BooleanValEEEvPNS2_15FunctionContextERKT_PS6_") - .put(Type.DECIMAL, - "16first_val_updateIN9doris_udf10DecimalValEEEvPNS2_15FunctionContextERKT_PS6_") .put(Type.DECIMALV2, "16first_val_updateIN9doris_udf12DecimalV2ValEEEvPNS2_15FunctionContextERKT_PS6_") .put(Type.TINYINT, @@ -841,8 +821,6 @@ public class FunctionSet { "_ZN5doris13TopNFunctions11topn_updateIN9doris_udf11DateTimeValEEEvPNS2_15FunctionContextERKT_RKNS2_6IntValEPNS2_9StringValE") .put(Type.DATETIME, "_ZN5doris13TopNFunctions11topn_updateIN9doris_udf11DateTimeValEEEvPNS2_15FunctionContextERKT_RKNS2_6IntValEPNS2_9StringValE") - .put(Type.DECIMAL, - "_ZN5doris13TopNFunctions11topn_updateIN9doris_udf10DecimalValEEEvPNS2_15FunctionContextERKT_RKNS2_6IntValEPNS2_9StringValE") .put(Type.DECIMALV2, "_ZN5doris13TopNFunctions11topn_updateIN9doris_udf12DecimalV2ValEEEvPNS2_15FunctionContextERKT_RKNS2_6IntValEPNS2_9StringValE") .put(Type.LARGEINT, @@ -873,8 +851,6 @@ public class FunctionSet { "_ZN5doris13TopNFunctions11topn_updateIN9doris_udf11DateTimeValEEEvPNS2_15FunctionContextERKT_RKNS2_6IntValESB_PNS2_9StringValE") .put(Type.DATETIME, "_ZN5doris13TopNFunctions11topn_updateIN9doris_udf11DateTimeValEEEvPNS2_15FunctionContextERKT_RKNS2_6IntValESB_PNS2_9StringValE") - .put(Type.DECIMAL, - "_ZN5doris13TopNFunctions11topn_updateIN9doris_udf10DecimalValEEEvPNS2_15FunctionContextERKT_RKNS2_6IntValESB_PNS2_9StringValE") .put(Type.DECIMALV2, "_ZN5doris13TopNFunctions11topn_updateIN9doris_udf12DecimalV2ValEEEvPNS2_15FunctionContextERKT_RKNS2_6IntValESB_PNS2_9StringValE") .put(Type.LARGEINT, @@ -1090,18 +1066,6 @@ public class FunctionSet { null, prefix + "28count_distinct_date_finalizeEPN9doris_udf15FunctionContextERKNS1_9StringValE", false, true, true)); - } else if (t.equals(Type.DECIMAL)) { - addBuiltin(AggregateFunction.createBuiltin("multi_distinct_count", Lists.newArrayList(t), - Type.BIGINT, - Type.VARCHAR, - prefix + "34count_or_sum_distinct_decimal_initEPN9doris_udf15FunctionContextEPNS1_9StringValE", - prefix + "36count_or_sum_distinct_decimal_updateEPN9doris_udf15FunctionContextERNS1_10DecimalValEPNS1_9StringValE", - prefix + "35count_or_sum_distinct_decimal_mergeEPN9doris_udf15FunctionContextERNS1_9StringValEPS4_", - prefix + "39count_or_sum_distinct_decimal_serializeEPN9doris_udf15FunctionContextERKNS1_9StringValE", - null, - null, - prefix + "31count_distinct_decimal_finalizeEPN9doris_udf15FunctionContextERKNS1_9StringValE", - false, true, true)); } else if (t.equals(Type.DECIMALV2)) { addBuiltin(AggregateFunction.createBuiltin("multi_distinct_count", Lists.newArrayList(t), Type.BIGINT, @@ -1129,18 +1093,6 @@ public class FunctionSet { null, prefix + MULTI_DISTINCT_SUM_FINALIZE_SYMBOL.get(t), false, true, true)); - } else if (t.equals(Type.DECIMAL)) { - addBuiltin(AggregateFunction.createBuiltin("multi_distinct_sum", Lists.newArrayList(t), - MULTI_DISTINCT_SUM_RETURN_TYPE.get(t), - Type.VARCHAR, - prefix + "34count_or_sum_distinct_decimal_initEPN9doris_udf15FunctionContextEPNS1_9StringValE", - prefix + "36count_or_sum_distinct_decimal_updateEPN9doris_udf15FunctionContextERNS1_10DecimalValEPNS1_9StringValE", - prefix + "35count_or_sum_distinct_decimal_mergeEPN9doris_udf15FunctionContextERNS1_9StringValEPS4_", - prefix + "39count_or_sum_distinct_decimal_serializeEPN9doris_udf15FunctionContextERKNS1_9StringValE", - null, - null, - prefix + "29sum_distinct_decimal_finalizeEPN9doris_udf15FunctionContextERKNS1_9StringValE", - false, true, true)); } else if (t.equals(Type.DECIMALV2)) { addBuiltin(AggregateFunction.createBuiltin("multi_distinct_sum", Lists.newArrayList(t), MULTI_DISTINCT_SUM_RETURN_TYPE.get(t), @@ -1355,13 +1307,6 @@ public class FunctionSet { null, null, prefix + "10sum_removeIN9doris_udf9DoubleValES3_EEvPNS2_15FunctionContextERKT_PT0_", null, false, true, false)); - addBuiltin(AggregateFunction.createBuiltin(name, - Lists.newArrayList(Type.DECIMAL), Type.DECIMAL, Type.DECIMAL, initNull, - prefix + "3sumIN9doris_udf10DecimalValES3_EEvPNS2_15FunctionContextERKT_PT0_", - prefix + "3sumIN9doris_udf10DecimalValES3_EEvPNS2_15FunctionContextERKT_PT0_", - null, null, - prefix + "10sum_removeIN9doris_udf10DecimalValES3_EEvPNS2_15FunctionContextERKT_PT0_", - null, false, true, false)); addBuiltin(AggregateFunction.createBuiltin(name, Lists.newArrayList(Type.DECIMALV2), Type.DECIMALV2, Type.DECIMALV2, initNull, prefix + "3sumIN9doris_udf12DecimalV2ValES3_EEvPNS2_15FunctionContextERKT_PT0_", @@ -1450,16 +1395,6 @@ public class FunctionSet { prefix + "10avg_removeIN9doris_udf9DoubleValEEEvPNS2_15FunctionContextERKT_PNS2_9StringValE", prefix + "12avg_finalizeEPN9doris_udf15FunctionContextERKNS1_9StringValE", false, true, false)); - addBuiltin(AggregateFunction.createBuiltin("avg", - Lists.newArrayList(Type.DECIMAL), Type.DECIMAL, Type.VARCHAR, - prefix + "16decimal_avg_initEPN9doris_udf15FunctionContextEPNS1_9StringValE", - prefix + "18decimal_avg_updateEPN9doris_udf15FunctionContextERKNS1_10DecimalValEPNS1_9StringValE", - prefix + "17decimal_avg_mergeEPN9doris_udf15FunctionContextERKNS1_9StringValEPS4_", - stringValSerializeOrFinalize, - prefix + "21decimal_avg_get_valueEPN9doris_udf15FunctionContextERKNS1_9StringValE", - prefix + "18decimal_avg_removeEPN9doris_udf15FunctionContextERKNS1_10DecimalValEPNS1_9StringValE", - prefix + "20decimal_avg_finalizeEPN9doris_udf15FunctionContextERKNS1_9StringValE", - false, true, false)); addBuiltin(AggregateFunction.createBuiltin("avg", Lists.newArrayList(Type.DECIMALV2), Type.DECIMALV2, Type.VARCHAR, prefix + "18decimalv2_avg_initEPN9doris_udf15FunctionContextEPNS1_9StringValE", diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/PrimitiveType.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/PrimitiveType.java index 40f994e40f..3357f61076 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/PrimitiveType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/PrimitiveType.java @@ -48,7 +48,6 @@ public enum PrimitiveType { // Aligning to 8 bytes so 16 total. VARCHAR("VARCHAR", 16, TPrimitiveType.VARCHAR), - DECIMAL("DECIMAL", 40, TPrimitiveType.DECIMAL), DECIMALV2("DECIMALV2", 16, TPrimitiveType.DECIMALV2), HLL("HLL", 16, TPrimitiveType.HLL), @@ -78,7 +77,6 @@ public enum PrimitiveType { builder.put(NULL_TYPE, DOUBLE); builder.put(NULL_TYPE, DATE); builder.put(NULL_TYPE, DATETIME); - builder.put(NULL_TYPE, DECIMAL); builder.put(NULL_TYPE, DECIMALV2); builder.put(NULL_TYPE, CHAR); builder.put(NULL_TYPE, VARCHAR); @@ -95,7 +93,6 @@ public enum PrimitiveType { builder.put(BOOLEAN, DOUBLE); builder.put(BOOLEAN, DATE); builder.put(BOOLEAN, DATETIME); - builder.put(BOOLEAN, DECIMAL); builder.put(BOOLEAN, DECIMALV2); builder.put(BOOLEAN, VARCHAR); // Tinyint @@ -109,7 +106,6 @@ public enum PrimitiveType { builder.put(TINYINT, DOUBLE); builder.put(TINYINT, DATE); builder.put(TINYINT, DATETIME); - builder.put(TINYINT, DECIMAL); builder.put(TINYINT, DECIMALV2); builder.put(TINYINT, VARCHAR); // Smallint @@ -123,7 +119,6 @@ public enum PrimitiveType { builder.put(SMALLINT, DOUBLE); builder.put(SMALLINT, DATE); builder.put(SMALLINT, DATETIME); - builder.put(SMALLINT, DECIMAL); builder.put(SMALLINT, DECIMALV2); builder.put(SMALLINT, VARCHAR); // Int @@ -137,7 +132,6 @@ public enum PrimitiveType { builder.put(INT, DOUBLE); builder.put(INT, DATE); builder.put(INT, DATETIME); - builder.put(INT, DECIMAL); builder.put(INT, DECIMALV2); builder.put(INT, VARCHAR); // Bigint @@ -151,7 +145,6 @@ public enum PrimitiveType { builder.put(BIGINT, DOUBLE); builder.put(BIGINT, DATE); builder.put(BIGINT, DATETIME); - builder.put(BIGINT, DECIMAL); builder.put(BIGINT, DECIMALV2); builder.put(BIGINT, VARCHAR); // Largeint @@ -165,7 +158,6 @@ public enum PrimitiveType { builder.put(LARGEINT, DOUBLE); builder.put(LARGEINT, DATE); builder.put(LARGEINT, DATETIME); - builder.put(LARGEINT, DECIMAL); builder.put(LARGEINT, DECIMALV2); builder.put(LARGEINT, VARCHAR); // Float @@ -179,7 +171,6 @@ public enum PrimitiveType { builder.put(FLOAT, DOUBLE); builder.put(FLOAT, DATE); builder.put(FLOAT, DATETIME); - builder.put(FLOAT, DECIMAL); builder.put(FLOAT, DECIMALV2); builder.put(FLOAT, VARCHAR); // Double @@ -193,7 +184,6 @@ public enum PrimitiveType { builder.put(DOUBLE, DOUBLE); builder.put(DOUBLE, DATE); builder.put(DOUBLE, DATETIME); - builder.put(DOUBLE, DECIMAL); builder.put(DOUBLE, DECIMALV2); builder.put(DOUBLE, VARCHAR); // Date @@ -207,7 +197,6 @@ public enum PrimitiveType { builder.put(DATE, DOUBLE); builder.put(DATE, DATE); builder.put(DATE, DATETIME); - builder.put(DATE, DECIMAL); builder.put(DATE, DECIMALV2); builder.put(DATE, VARCHAR); // Datetime @@ -221,7 +210,6 @@ public enum PrimitiveType { builder.put(DATETIME, DOUBLE); builder.put(DATETIME, DATE); builder.put(DATETIME, DATETIME); - builder.put(DATETIME, DECIMAL); builder.put(DATETIME, DECIMALV2); builder.put(DATETIME, VARCHAR); // Char @@ -238,23 +226,11 @@ public enum PrimitiveType { builder.put(VARCHAR, DOUBLE); builder.put(VARCHAR, DATE); builder.put(VARCHAR, DATETIME); - builder.put(VARCHAR, DECIMAL); builder.put(VARCHAR, DECIMALV2); builder.put(VARCHAR, VARCHAR); builder.put(VARCHAR, HLL); builder.put(VARCHAR, BITMAP); - // Decimal - builder.put(DECIMAL, BOOLEAN); - builder.put(DECIMAL, TINYINT); - builder.put(DECIMAL, SMALLINT); - builder.put(DECIMAL, INT); - builder.put(DECIMAL, BIGINT); - builder.put(DECIMAL, LARGEINT); - builder.put(DECIMAL, FLOAT); - builder.put(DECIMAL, DOUBLE); - builder.put(DECIMAL, DECIMAL); - builder.put(DECIMAL, DECIMALV2); - builder.put(DECIMAL, VARCHAR); + // DecimalV2 builder.put(DECIMALV2, BOOLEAN); builder.put(DECIMALV2, TINYINT); @@ -264,7 +240,6 @@ public enum PrimitiveType { builder.put(DECIMALV2, LARGEINT); builder.put(DECIMALV2, FLOAT); builder.put(DECIMALV2, DOUBLE); - builder.put(DECIMALV2, DECIMAL); builder.put(DECIMALV2, DECIMALV2); builder.put(DECIMALV2, VARCHAR); @@ -303,7 +278,6 @@ public enum PrimitiveType { numericTypes.add(LARGEINT); numericTypes.add(FLOAT); numericTypes.add(DOUBLE); - numericTypes.add(DECIMAL); numericTypes.add(DECIMALV2); supportedTypes = Lists.newArrayList(); @@ -322,7 +296,6 @@ public enum PrimitiveType { supportedTypes.add(DATE); supportedTypes.add(DATETIME); supportedTypes.add(TIME); - supportedTypes.add(DECIMAL); supportedTypes.add(DECIMALV2); supportedTypes.add(BITMAP); } @@ -374,7 +347,6 @@ public enum PrimitiveType { compatibilityMatrix[NULL_TYPE.ordinal()][DATETIME.ordinal()] = DATETIME; compatibilityMatrix[NULL_TYPE.ordinal()][CHAR.ordinal()] = CHAR; compatibilityMatrix[NULL_TYPE.ordinal()][VARCHAR.ordinal()] = VARCHAR; - compatibilityMatrix[NULL_TYPE.ordinal()][DECIMAL.ordinal()] = DECIMAL; compatibilityMatrix[NULL_TYPE.ordinal()][DECIMALV2.ordinal()] = DECIMALV2; compatibilityMatrix[NULL_TYPE.ordinal()][TIME.ordinal()] = TIME; compatibilityMatrix[NULL_TYPE.ordinal()][BITMAP.ordinal()] = BITMAP; @@ -391,7 +363,6 @@ public enum PrimitiveType { compatibilityMatrix[BOOLEAN.ordinal()][DATETIME.ordinal()] = INVALID_TYPE; compatibilityMatrix[BOOLEAN.ordinal()][CHAR.ordinal()] = INVALID_TYPE; compatibilityMatrix[BOOLEAN.ordinal()][VARCHAR.ordinal()] = INVALID_TYPE; - compatibilityMatrix[BOOLEAN.ordinal()][DECIMAL.ordinal()] = DECIMAL; compatibilityMatrix[BOOLEAN.ordinal()][DECIMALV2.ordinal()] = DECIMALV2; compatibilityMatrix[BOOLEAN.ordinal()][TIME.ordinal()] = TIME; @@ -406,7 +377,6 @@ public enum PrimitiveType { compatibilityMatrix[TINYINT.ordinal()][DATETIME.ordinal()] = INVALID_TYPE; compatibilityMatrix[TINYINT.ordinal()][CHAR.ordinal()] = INVALID_TYPE; compatibilityMatrix[TINYINT.ordinal()][VARCHAR.ordinal()] = INVALID_TYPE; - compatibilityMatrix[TINYINT.ordinal()][DECIMAL.ordinal()] = DECIMAL; compatibilityMatrix[TINYINT.ordinal()][DECIMALV2.ordinal()] = DECIMALV2; compatibilityMatrix[TINYINT.ordinal()][TIME.ordinal()] = TIME; @@ -420,7 +390,6 @@ public enum PrimitiveType { compatibilityMatrix[SMALLINT.ordinal()][DATETIME.ordinal()] = INVALID_TYPE; compatibilityMatrix[SMALLINT.ordinal()][CHAR.ordinal()] = INVALID_TYPE; compatibilityMatrix[SMALLINT.ordinal()][VARCHAR.ordinal()] = INVALID_TYPE; - compatibilityMatrix[SMALLINT.ordinal()][DECIMAL.ordinal()] = DECIMAL; compatibilityMatrix[SMALLINT.ordinal()][DECIMALV2.ordinal()] = DECIMALV2; compatibilityMatrix[SMALLINT.ordinal()][TIME.ordinal()] = TIME; @@ -433,7 +402,6 @@ public enum PrimitiveType { compatibilityMatrix[INT.ordinal()][DATETIME.ordinal()] = INVALID_TYPE; compatibilityMatrix[INT.ordinal()][CHAR.ordinal()] = INVALID_TYPE; compatibilityMatrix[INT.ordinal()][VARCHAR.ordinal()] = INVALID_TYPE; - compatibilityMatrix[INT.ordinal()][DECIMAL.ordinal()] = DECIMAL; compatibilityMatrix[INT.ordinal()][DECIMALV2.ordinal()] = DECIMALV2; compatibilityMatrix[INT.ordinal()][TIME.ordinal()] = TIME; @@ -445,7 +413,6 @@ public enum PrimitiveType { compatibilityMatrix[BIGINT.ordinal()][DATETIME.ordinal()] = INVALID_TYPE; compatibilityMatrix[BIGINT.ordinal()][CHAR.ordinal()] = INVALID_TYPE; compatibilityMatrix[BIGINT.ordinal()][VARCHAR.ordinal()] = INVALID_TYPE; - compatibilityMatrix[BIGINT.ordinal()][DECIMAL.ordinal()] = DECIMAL; compatibilityMatrix[BIGINT.ordinal()][DECIMALV2.ordinal()] = DECIMALV2; compatibilityMatrix[BIGINT.ordinal()][TIME.ordinal()] = TIME; @@ -456,7 +423,6 @@ public enum PrimitiveType { compatibilityMatrix[LARGEINT.ordinal()][DATETIME.ordinal()] = INVALID_TYPE; compatibilityMatrix[LARGEINT.ordinal()][CHAR.ordinal()] = INVALID_TYPE; compatibilityMatrix[LARGEINT.ordinal()][VARCHAR.ordinal()] = INVALID_TYPE; - compatibilityMatrix[LARGEINT.ordinal()][DECIMAL.ordinal()] = DECIMAL; compatibilityMatrix[LARGEINT.ordinal()][DECIMALV2.ordinal()] = DECIMALV2; compatibilityMatrix[LARGEINT.ordinal()][TIME.ordinal()] = TIME; @@ -466,7 +432,6 @@ public enum PrimitiveType { compatibilityMatrix[FLOAT.ordinal()][DATETIME.ordinal()] = INVALID_TYPE; compatibilityMatrix[FLOAT.ordinal()][CHAR.ordinal()] = INVALID_TYPE; compatibilityMatrix[FLOAT.ordinal()][VARCHAR.ordinal()] = INVALID_TYPE; - compatibilityMatrix[FLOAT.ordinal()][DECIMAL.ordinal()] = DECIMAL; compatibilityMatrix[FLOAT.ordinal()][DECIMALV2.ordinal()] = DECIMALV2; compatibilityMatrix[FLOAT.ordinal()][TIME.ordinal()] = TIME; @@ -475,7 +440,6 @@ public enum PrimitiveType { compatibilityMatrix[DOUBLE.ordinal()][DATETIME.ordinal()] = INVALID_TYPE; compatibilityMatrix[DOUBLE.ordinal()][CHAR.ordinal()] = INVALID_TYPE; compatibilityMatrix[DOUBLE.ordinal()][VARCHAR.ordinal()] = INVALID_TYPE; - compatibilityMatrix[DOUBLE.ordinal()][DECIMAL.ordinal()] = DECIMAL; compatibilityMatrix[DOUBLE.ordinal()][DECIMALV2.ordinal()] = DECIMALV2; compatibilityMatrix[DOUBLE.ordinal()][TIME.ordinal()] = TIME; @@ -483,31 +447,25 @@ public enum PrimitiveType { compatibilityMatrix[DATE.ordinal()][DATETIME.ordinal()] = DATETIME; compatibilityMatrix[DATE.ordinal()][CHAR.ordinal()] = INVALID_TYPE; compatibilityMatrix[DATE.ordinal()][VARCHAR.ordinal()] = INVALID_TYPE; - compatibilityMatrix[DATE.ordinal()][DECIMAL.ordinal()] = INVALID_TYPE; compatibilityMatrix[DATE.ordinal()][DECIMALV2.ordinal()] = INVALID_TYPE; compatibilityMatrix[DATE.ordinal()][TIME.ordinal()] = INVALID_TYPE; compatibilityMatrix[DATETIME.ordinal()][DATETIME.ordinal()] = DATETIME; compatibilityMatrix[DATETIME.ordinal()][CHAR.ordinal()] = INVALID_TYPE; compatibilityMatrix[DATETIME.ordinal()][VARCHAR.ordinal()] = INVALID_TYPE; - compatibilityMatrix[DATETIME.ordinal()][DECIMAL.ordinal()] = INVALID_TYPE; compatibilityMatrix[DATETIME.ordinal()][DECIMALV2.ordinal()] = INVALID_TYPE; compatibilityMatrix[DATETIME.ordinal()][TIME.ordinal()] = INVALID_TYPE; compatibilityMatrix[CHAR.ordinal()][CHAR.ordinal()] = CHAR; compatibilityMatrix[CHAR.ordinal()][VARCHAR.ordinal()] = VARCHAR; - compatibilityMatrix[CHAR.ordinal()][DECIMAL.ordinal()] = INVALID_TYPE; compatibilityMatrix[CHAR.ordinal()][DECIMALV2.ordinal()] = INVALID_TYPE; compatibilityMatrix[CHAR.ordinal()][TIME.ordinal()] = INVALID_TYPE; compatibilityMatrix[VARCHAR.ordinal()][VARCHAR.ordinal()] = VARCHAR; - compatibilityMatrix[VARCHAR.ordinal()][DECIMAL.ordinal()] = INVALID_TYPE; compatibilityMatrix[VARCHAR.ordinal()][DECIMALV2.ordinal()] = INVALID_TYPE; compatibilityMatrix[VARCHAR.ordinal()][TIME.ordinal()] = INVALID_TYPE; - compatibilityMatrix[DECIMAL.ordinal()][DECIMAL.ordinal()] = DECIMAL; compatibilityMatrix[DECIMALV2.ordinal()][DECIMALV2.ordinal()] = DECIMALV2; - compatibilityMatrix[DECIMALV2.ordinal()][DECIMAL.ordinal()] = DECIMALV2; compatibilityMatrix[DECIMALV2.ordinal()][TIME.ordinal()] = INVALID_TYPE; compatibilityMatrix[HLL.ordinal()][HLL.ordinal()] = HLL; @@ -597,7 +555,7 @@ public enum PrimitiveType { } public static int getMaxSlotSize() { - return DECIMAL.slotSize; + return DECIMALV2.slotSize; } /** @@ -650,16 +608,13 @@ public enum PrimitiveType { return this == FLOAT || this == DOUBLE; } - public boolean isDecimalType() { - return this == DECIMAL; - } public boolean isDecimalV2Type() { return this == DECIMALV2; } public boolean isNumericType() { - return isFixedPointType() || isFloatingPointType() || isDecimalType() || isDecimalV2Type(); + return isFixedPointType() || isFloatingPointType() || isDecimalV2Type(); } public boolean isValid() { @@ -715,7 +670,6 @@ public enum PrimitiveType { return MysqlColType.MYSQL_TYPE_DATETIME; } } - case DECIMAL: case DECIMALV2: return MysqlColType.MYSQL_TYPE_NEWDECIMAL; default: @@ -734,7 +688,6 @@ public enum PrimitiveType { case CHAR: // char index size is length return -1; - case DECIMAL: case DECIMALV2: return DECIMAL_INDEX_LEN; default: diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarFunction.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarFunction.java index 38162a069e..b00febfc06 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarFunction.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarFunction.java @@ -173,10 +173,6 @@ public class ScalarFunction extends Function { case DATETIME: beFn += "_datetime_val"; break; - case DECIMAL: - beFn += "_decimal_val"; - usesDecimal = true; - break; case DECIMALV2: beFn += "_decimalv2_val"; usesDecimalV2 = true; diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarType.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarType.java index 532dfa3caa..d137361457 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/ScalarType.java @@ -92,8 +92,6 @@ public class ScalarType extends Type { return createCharType(len); case VARCHAR: return createVarcharType(len); - case DECIMAL: - return createDecimalType(precision, scale); case DECIMALV2: return createDecimalV2Type(precision, scale); default: @@ -135,8 +133,6 @@ public class ScalarType extends Type { return DATETIME; case TIME: return TIME; - case DECIMAL: - return (ScalarType) createDecimalType(); case DECIMALV2: return DEFAULT_DECIMALV2; case LARGEINT: @@ -183,7 +179,6 @@ public class ScalarType extends Type { case "TIME": return TIME; case "DECIMAL": - return (ScalarType) createDecimalType(); case "DECIMALV2": return (ScalarType) createDecimalV2Type(); case "LARGEINT": @@ -207,31 +202,14 @@ public class ScalarType extends Type { return type; } - public static ScalarType createDecimalType() { - return DEFAULT_DECIMAL; - } - public static ScalarType createDecimalV2Type() { return DEFAULT_DECIMALV2; } - public static ScalarType createDecimalType(int precision) { - return createDecimalType(precision, DEFAULT_SCALE); - } - public static ScalarType createDecimalV2Type(int precision) { return createDecimalV2Type(precision, DEFAULT_SCALE); } - public static ScalarType createDecimalType(int precision, int scale) { - // Preconditions.checkState(precision >= 0); // Enforced by parser - // Preconditions.checkState(scale >= 0); // Enforced by parser. - ScalarType type = new ScalarType(PrimitiveType.DECIMAL); - type.precision = precision; - type.scale = scale; - return type; - } - public static ScalarType createDecimalV2Type(int precision, int scale) { // Preconditions.checkState(precision >= 0); // Enforced by parser // Preconditions.checkState(scale >= 0); // Enforced by parser. @@ -241,16 +219,6 @@ public class ScalarType extends Type { return type; } - // Identical to createDecimalType except that higher precisions are truncated - // to the max storable precision. The BE will report overflow in these cases - // (think of this as adding ints to BIGINT but BIGINT can still overflow). - public static ScalarType createDecimalTypeInternal(int precision, int scale) { - ScalarType type = new ScalarType(PrimitiveType.DECIMAL); - type.precision = Math.min(precision, MAX_PRECISION); - type.scale = Math.min(type.precision, scale); - return type; - } - public static ScalarType createDecimalV2TypeInternal(int precision, int scale) { ScalarType type = new ScalarType(PrimitiveType.DECIMALV2); type.precision = Math.min(precision, MAX_PRECISION); @@ -289,11 +257,6 @@ public class ScalarType extends Type { return "CHAR(*)"; } return "CHAR(" + len + ")"; - } else if (type == PrimitiveType.DECIMAL) { - if (isWildcardDecimal()) { - return "DECIMAL(*,*)"; - } - return "DECIMAL(" + precision + "," + scale + ")"; } else if (type == PrimitiveType.DECIMALV2) { if (isWildcardDecimal()) { return "DECIMAL(*,*)"; @@ -318,9 +281,6 @@ public class ScalarType extends Type { case VARCHAR: stringBuilder.append("varchar").append("(").append(len).append(")"); break; - case DECIMAL: - stringBuilder.append("decimal").append("(").append(precision).append(", ").append(scale).append(")"); - break; case DECIMALV2: stringBuilder.append("decimal").append("(").append(precision).append(", ").append(scale).append(")"); break; @@ -371,7 +331,6 @@ public class ScalarType extends Type { node.setScalarType(scalarType); break; } - case DECIMAL: case DECIMALV2: { node.setType(TTypeNodeType.SCALAR); TScalarType scalarType = new TScalarType(); @@ -400,12 +359,12 @@ public class ScalarType extends Type { } public int decimalPrecision() { - Preconditions.checkState(type == PrimitiveType.DECIMAL || type == PrimitiveType.DECIMALV2); + Preconditions.checkState(type == PrimitiveType.DECIMALV2); return precision; } public int decimalScale() { - Preconditions.checkState(type == PrimitiveType.DECIMAL || type == PrimitiveType.DECIMALV2); + Preconditions.checkState(type == PrimitiveType.DECIMALV2); return scale; } @@ -423,7 +382,7 @@ public class ScalarType extends Type { @Override public boolean isWildcardDecimal() { - return (type == PrimitiveType.DECIMAL || type == PrimitiveType.DECIMALV2) + return (type == PrimitiveType.DECIMALV2) && precision == -1 && scale == -1; } @@ -437,18 +396,6 @@ public class ScalarType extends Type { return type == PrimitiveType.CHAR && len == -1; } - /** - * Returns true if this type is a fully specified (not wild card) decimal. - */ - @Override - public boolean isFullySpecifiedDecimal() { - if (!isDecimal() && !isDecimalV2()) return false; - if (isWildcardDecimal()) return false; - if (precision <= 0 || precision > MAX_PRECISION) return false; - if (scale < 0 || scale > precision) return false; - return true; - } - @Override public boolean isFixedLengthType() { return type == PrimitiveType.BOOLEAN || type == PrimitiveType.TINYINT @@ -456,7 +403,7 @@ public class ScalarType extends Type { || type == PrimitiveType.BIGINT || type == PrimitiveType.FLOAT || type == PrimitiveType.DOUBLE || type == PrimitiveType.DATE || type == PrimitiveType.DATETIME || type == PrimitiveType.DECIMALV2 - || type == PrimitiveType.CHAR || type == PrimitiveType.DECIMAL; + || type == PrimitiveType.CHAR; } @Override @@ -513,13 +460,10 @@ public class ScalarType extends Type { if (type == PrimitiveType.HLL && scalarType.isStringType()) { return true; } - if ((isDecimal() || isDecimalV2()) && scalarType.isWildcardDecimal()) { + if (isDecimalV2() && scalarType.isWildcardDecimal()) { Preconditions.checkState(!isWildcardDecimal()); return true; } - if (isDecimal() && scalarType.isDecimal()) { - return true; - } if (isDecimalV2() && scalarType.isDecimalV2()) { return true; } @@ -541,7 +485,7 @@ public class ScalarType extends Type { if (type == PrimitiveType.VARCHAR) { return len == other.len; } - if (type == PrimitiveType.DECIMAL || type == PrimitiveType.DECIMALV2) { + if ( type == PrimitiveType.DECIMALV2) { return precision == other.precision && scale == other.scale; } return true; @@ -555,8 +499,6 @@ public class ScalarType extends Type { return ScalarType.DOUBLE; } else if (isNull()) { return ScalarType.NULL; - } else if (isDecimal()) { - return createDecimalTypeInternal(MAX_PRECISION, scale); } else if (isDecimalV2()) { return createDecimalV2TypeInternal(MAX_PRECISION, scale); } else if (isLargeIntType()) { @@ -570,8 +512,6 @@ public class ScalarType extends Type { Preconditions.checkState(isNumericType() || isNull()); if (type == PrimitiveType.DOUBLE || type == PrimitiveType.BIGINT || isNull()) { return this; - } else if (type == PrimitiveType.DECIMAL) { - return createDecimalTypeInternal(MAX_PRECISION, scale); } else if (type == PrimitiveType.DECIMALV2) { return createDecimalV2TypeInternal(MAX_PRECISION, scale); } @@ -586,17 +526,16 @@ public class ScalarType extends Type { switch (type) { case NULL_TYPE: return Type.NULL; - case DECIMAL: case DECIMALV2: return this; case TINYINT: - return createDecimalType(3); + return createDecimalV2Type(3); case SMALLINT: - return createDecimalType(5); + return createDecimalV2Type(5); case INT: - return createDecimalType(10); + return createDecimalV2Type(10); case BIGINT: - return createDecimalType(19); + return createDecimalV2Type(19); case FLOAT: return createDecimalV2TypeInternal(MAX_PRECISION, 9); case DOUBLE: @@ -613,8 +552,8 @@ public class ScalarType extends Type { * the decimal point must be greater or equal. */ public boolean isSupertypeOf(ScalarType o) { - Preconditions.checkState(isDecimal() || isDecimalV2()); - Preconditions.checkState(o.isDecimal() || o.isDecimalV2()); + Preconditions.checkState(isDecimalV2()); + Preconditions.checkState(o.isDecimalV2()); if (isWildcardDecimal()) { return true; } @@ -658,8 +597,8 @@ public class ScalarType extends Type { return createVarcharType(Math.max(t1.len, t2.len)); } - if ((t1.isDecimal() || t1.isDecimalV2()) && t2.isDate() - || t1.isDate() && (t2.isDecimal() || t2.isDecimalV2())) { + if (t1.isDecimalV2() && t2.isDate() + || t1.isDate() && t2.isDecimalV2()) { return INVALID; } @@ -667,40 +606,6 @@ public class ScalarType extends Type { return DECIMALV2; } - if (t1.isDecimal() || t2.isDecimal()) { - return DECIMAL; -// // The case of decimal and float/double must be handled carefully. There are two -// // modes: strict and non-strict. In non-strict mode, we convert to the floating -// // point type, since it can contain a larger range of values than any decimal (but -// // has lower precision in some parts of its range), so it is generally better. -// // In strict mode, we avoid conversion in either direction because there are also -// // decimal values (e.g. 0.1) that cannot be exactly represented in binary -// // floating point. -// // TODO: it might make sense to promote to double in many cases, but this would -// // require more work elsewhere to avoid breaking things, e.g. inserting decimal -// // literals into float columns. -// if (t1.isFloatingPointType()) return strict ? INVALID : t1; -// if (t2.isFloatingPointType()) return strict ? INVALID : t2; -// -// // Allow casts between decimal and numeric types by converting -// // numeric types to the containing decimal type. -// ScalarType t1Decimal = t1.getMinResolutionDecimal(); -// ScalarType t2Decimal = t2.getMinResolutionDecimal(); -// if (t1Decimal.isInvalid() || t2Decimal.isInvalid()) return Type.INVALID; -// Preconditions.checkState(t1Decimal.isDecimal()); -// Preconditions.checkState(t2Decimal.isDecimal()); -// -// if (t1Decimal.equals(t2Decimal)) { -// Preconditions.checkState(!(t1.isDecimal() && t2.isDecimal())); -// // The containing decimal type for a non-decimal type is always an exclusive -// // upper bound, therefore the decimal has higher precision. -// return t1Decimal; -// } -// if (t1Decimal.isSupertypeOf(t2Decimal)) return t1; -// if (t2Decimal.isSupertypeOf(t1Decimal)) return t2; -// return TypesUtil.getDecimalAssignmentCompatibleType(t1Decimal, t2Decimal); - } - PrimitiveType smallerType = (t1.type.ordinal() < t2.type.ordinal() ? t1.type : t2.type); PrimitiveType largerType = @@ -751,8 +656,6 @@ public class ScalarType extends Type { return 12; case DATE: return 3; - case DECIMAL: - return 40; case CHAR: case VARCHAR: return len; @@ -772,7 +675,7 @@ public class ScalarType extends Type { if (type == PrimitiveType.CHAR || type == PrimitiveType.VARCHAR || type == PrimitiveType.HLL) { thrift.setLen(len); } - if (type == PrimitiveType.DECIMAL || type == PrimitiveType.DECIMALV2) { + if (type == PrimitiveType.DECIMALV2) { thrift.setPrecision(precision); thrift.setScale(scale); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Type.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Type.java index f059fa67f8..7eaa872cee 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Type.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Type.java @@ -65,13 +65,9 @@ public abstract class Type { public static final ScalarType DATE = new ScalarType(PrimitiveType.DATE); public static final ScalarType DATETIME = new ScalarType(PrimitiveType.DATETIME); public static final ScalarType TIME = new ScalarType(PrimitiveType.TIME); - public static final ScalarType DEFAULT_DECIMAL = (ScalarType) - ScalarType.createDecimalType(ScalarType.DEFAULT_PRECISION, - ScalarType.DEFAULT_SCALE); public static final ScalarType DEFAULT_DECIMALV2 = (ScalarType) ScalarType.createDecimalV2Type(ScalarType.DEFAULT_PRECISION, ScalarType.DEFAULT_SCALE); - public static final ScalarType DECIMAL = DEFAULT_DECIMAL; public static final ScalarType DECIMALV2 = DEFAULT_DECIMALV2; // (ScalarType) ScalarType.createDecimalTypeInternal(-1, -1); public static final ScalarType DEFAULT_VARCHAR = ScalarType.createVarcharType(-1); @@ -100,7 +96,6 @@ public abstract class Type { numericTypes.add(LARGEINT); numericTypes.add(FLOAT); numericTypes.add(DOUBLE); - numericTypes.add(DECIMAL); numericTypes.add(DECIMALV2); supportedTypes = Lists.newArrayList(); @@ -119,7 +114,6 @@ public abstract class Type { supportedTypes.add(CHAR); supportedTypes.add(DATE); supportedTypes.add(DATETIME); - supportedTypes.add(DECIMAL); supportedTypes.add(DECIMALV2); supportedTypes.add(TIME); } @@ -173,16 +167,10 @@ public abstract class Type { return isScalarType(PrimitiveType.BOOLEAN); } - public boolean isDecimal() { - return isScalarType(PrimitiveType.DECIMAL); - } - public boolean isDecimalV2() { return isScalarType(PrimitiveType.DECIMALV2); } - public boolean isDecimalOrNull() { return isDecimal() || isNull(); } - public boolean isFullySpecifiedDecimal() { return false; } public boolean isWildcardDecimal() { return false; } public boolean isWildcardVarchar() { return false; } public boolean isWildcardChar() { return false; } @@ -250,7 +238,7 @@ public abstract class Type { } public boolean isNumericType() { - return isFixedPointType() || isFloatingPointType() || isDecimal() || isDecimalV2(); + return isFixedPointType() || isFloatingPointType() || isDecimalV2(); } public boolean isNativeType() { @@ -471,8 +459,6 @@ public abstract class Type { return Type.DATETIME; case TIME: return Type.TIME; - case DECIMAL: - return Type.DECIMAL; case DECIMALV2: return Type.DECIMALV2; case CHAR: @@ -527,11 +513,6 @@ public abstract class Type { type = ScalarType.createVarcharType(scalarType.getLen()); } else if (scalarType.getType() == TPrimitiveType.HLL) { type = ScalarType.createHllType(); - } else if (scalarType.getType() == TPrimitiveType.DECIMAL) { - Preconditions.checkState(scalarType.isSetPrecision() - && scalarType.isSetPrecision()); - type = ScalarType.createDecimalType(scalarType.getPrecision(), - scalarType.getScale()); } else if (scalarType.getType() == TPrimitiveType.DECIMALV2) { Preconditions.checkState(scalarType.isSetPrecision() && scalarType.isSetPrecision()); @@ -636,7 +617,6 @@ public abstract class Type { return 7; case DOUBLE: return 15; - case DECIMAL: case DECIMALV2: return t.decimalPrecision(); default: @@ -664,7 +644,6 @@ public abstract class Type { return 7; case DOUBLE: return 15; - case DECIMAL: case DECIMALV2: return t.decimalScale(); default: @@ -694,7 +673,6 @@ public abstract class Type { case BIGINT: case FLOAT: case DOUBLE: - case DECIMAL: case DECIMALV2: return 10; default: @@ -766,7 +744,6 @@ public abstract class Type { compatibilityMatrix[TINYINT.ordinal()][DATETIME.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[TINYINT.ordinal()][CHAR.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[TINYINT.ordinal()][VARCHAR.ordinal()] = PrimitiveType.INVALID_TYPE; - compatibilityMatrix[TINYINT.ordinal()][DECIMAL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[TINYINT.ordinal()][DECIMALV2.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[TINYINT.ordinal()][HLL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[TINYINT.ordinal()][TIME.ordinal()] = PrimitiveType.DOUBLE; @@ -783,7 +760,6 @@ public abstract class Type { compatibilityMatrix[SMALLINT.ordinal()][DATETIME.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[SMALLINT.ordinal()][CHAR.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[SMALLINT.ordinal()][VARCHAR.ordinal()] = PrimitiveType.INVALID_TYPE; - compatibilityMatrix[SMALLINT.ordinal()][DECIMAL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[SMALLINT.ordinal()][DECIMALV2.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[SMALLINT.ordinal()][HLL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[SMALLINT.ordinal()][TIME.ordinal()] = PrimitiveType.DOUBLE; @@ -803,7 +779,6 @@ public abstract class Type { compatibilityMatrix[INT.ordinal()][DATETIME.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[INT.ordinal()][CHAR.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[INT.ordinal()][VARCHAR.ordinal()] = PrimitiveType.INVALID_TYPE; - compatibilityMatrix[INT.ordinal()][DECIMAL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[INT.ordinal()][DECIMALV2.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[INT.ordinal()][HLL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[INT.ordinal()][TIME.ordinal()] = PrimitiveType.DOUBLE; @@ -824,7 +799,6 @@ public abstract class Type { compatibilityMatrix[BIGINT.ordinal()][DATETIME.ordinal()] = PrimitiveType.BIGINT; compatibilityMatrix[BIGINT.ordinal()][CHAR.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[BIGINT.ordinal()][VARCHAR.ordinal()] = PrimitiveType.INVALID_TYPE; - compatibilityMatrix[BIGINT.ordinal()][DECIMAL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[BIGINT.ordinal()][DECIMALV2.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[BIGINT.ordinal()][HLL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[BIGINT.ordinal()][TIME.ordinal()] = PrimitiveType.DOUBLE; @@ -837,7 +811,6 @@ public abstract class Type { compatibilityMatrix[LARGEINT.ordinal()][DATETIME.ordinal()] = PrimitiveType.LARGEINT; compatibilityMatrix[LARGEINT.ordinal()][CHAR.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[LARGEINT.ordinal()][VARCHAR.ordinal()] = PrimitiveType.INVALID_TYPE; - compatibilityMatrix[LARGEINT.ordinal()][DECIMAL.ordinal()] = PrimitiveType.DECIMAL; compatibilityMatrix[LARGEINT.ordinal()][DECIMALV2.ordinal()] = PrimitiveType.DECIMALV2; compatibilityMatrix[LARGEINT.ordinal()][HLL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[LARGEINT.ordinal()][TIME.ordinal()] = PrimitiveType.DOUBLE; @@ -849,7 +822,6 @@ public abstract class Type { compatibilityMatrix[FLOAT.ordinal()][DATETIME.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[FLOAT.ordinal()][CHAR.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[FLOAT.ordinal()][VARCHAR.ordinal()] = PrimitiveType.INVALID_TYPE; - compatibilityMatrix[FLOAT.ordinal()][DECIMAL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[FLOAT.ordinal()][DECIMALV2.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[FLOAT.ordinal()][HLL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[FLOAT.ordinal()][TIME.ordinal()] = PrimitiveType.DOUBLE; @@ -860,7 +832,6 @@ public abstract class Type { compatibilityMatrix[DOUBLE.ordinal()][DATETIME.ordinal()] = PrimitiveType.DOUBLE ; compatibilityMatrix[DOUBLE.ordinal()][CHAR.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[DOUBLE.ordinal()][VARCHAR.ordinal()] = PrimitiveType.INVALID_TYPE; - compatibilityMatrix[DOUBLE.ordinal()][DECIMAL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[DOUBLE.ordinal()][DECIMALV2.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[DOUBLE.ordinal()][HLL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[DOUBLE.ordinal()][TIME.ordinal()] = PrimitiveType.DOUBLE; @@ -870,7 +841,6 @@ public abstract class Type { compatibilityMatrix[DATE.ordinal()][DATETIME.ordinal()] = PrimitiveType.DATETIME; compatibilityMatrix[DATE.ordinal()][CHAR.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[DATE.ordinal()][VARCHAR.ordinal()] = PrimitiveType.INVALID_TYPE; - compatibilityMatrix[DATE.ordinal()][DECIMAL.ordinal()] = PrimitiveType.DECIMAL; compatibilityMatrix[DATE.ordinal()][DECIMALV2.ordinal()] = PrimitiveType.DECIMALV2; compatibilityMatrix[DATE.ordinal()][HLL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[DATE.ordinal()][TIME.ordinal()] = PrimitiveType.INVALID_TYPE; @@ -879,7 +849,6 @@ public abstract class Type { // DATETIME compatibilityMatrix[DATETIME.ordinal()][CHAR.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[DATETIME.ordinal()][VARCHAR.ordinal()] = PrimitiveType.INVALID_TYPE; - compatibilityMatrix[DATETIME.ordinal()][DECIMAL.ordinal()] = PrimitiveType.DECIMAL; compatibilityMatrix[DATETIME.ordinal()][DECIMALV2.ordinal()] = PrimitiveType.DECIMALV2; compatibilityMatrix[DATETIME.ordinal()][HLL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[DATETIME.ordinal()][TIME.ordinal()] = PrimitiveType.INVALID_TYPE; @@ -888,25 +857,17 @@ public abstract class Type { // We can convert some but not all string values to timestamps. // CHAR compatibilityMatrix[CHAR.ordinal()][VARCHAR.ordinal()] = PrimitiveType.VARCHAR; - compatibilityMatrix[CHAR.ordinal()][DECIMAL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[CHAR.ordinal()][DECIMALV2.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[CHAR.ordinal()][HLL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[CHAR.ordinal()][TIME.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[CHAR.ordinal()][BITMAP.ordinal()] = PrimitiveType.INVALID_TYPE; // VARCHAR - compatibilityMatrix[VARCHAR.ordinal()][DECIMAL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[VARCHAR.ordinal()][DECIMALV2.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[VARCHAR.ordinal()][HLL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[VARCHAR.ordinal()][TIME.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[VARCHAR.ordinal()][BITMAP.ordinal()] = PrimitiveType.INVALID_TYPE; - // DECIMAL - compatibilityMatrix[DECIMAL.ordinal()][DECIMALV2.ordinal()] = PrimitiveType.DECIMALV2; - compatibilityMatrix[DECIMAL.ordinal()][HLL.ordinal()] = PrimitiveType.INVALID_TYPE; - compatibilityMatrix[DECIMAL.ordinal()][TIME.ordinal()] = PrimitiveType.INVALID_TYPE; - compatibilityMatrix[DECIMAL.ordinal()][BITMAP.ordinal()] = PrimitiveType.INVALID_TYPE; - // DECIMALV2 compatibilityMatrix[DECIMALV2.ordinal()][HLL.ordinal()] = PrimitiveType.INVALID_TYPE; compatibilityMatrix[DECIMALV2.ordinal()][TIME.ordinal()] = PrimitiveType.INVALID_TYPE; @@ -929,7 +890,6 @@ public abstract class Type { if (t1 == PrimitiveType.INVALID_TYPE || t2 == PrimitiveType.INVALID_TYPE) continue; if (t1 == PrimitiveType.NULL_TYPE || t2 == PrimitiveType.NULL_TYPE) continue; - if (t1 == PrimitiveType.DECIMAL || t2 == PrimitiveType.DECIMAL) continue; if (t1 == PrimitiveType.DECIMALV2 || t2 == PrimitiveType.DECIMALV2) continue; if (t1 == PrimitiveType.TIME || t2 == PrimitiveType.TIME) continue; Preconditions.checkNotNull(compatibilityMatrix[i][j]); @@ -959,8 +919,6 @@ public abstract class Type { case HLL: case BITMAP: return VARCHAR; - case DECIMAL: - return DECIMAL; case DECIMALV2: return DECIMALV2; default: @@ -990,12 +948,6 @@ public abstract class Type { if (t1ResultType == PrimitiveType.BIGINT && t2ResultType == PrimitiveType.BIGINT) { return getAssignmentCompatibleType(t1, t2, false); } - if ((t1ResultType == PrimitiveType.BIGINT - || t1ResultType == PrimitiveType.DECIMAL) - && (t2ResultType == PrimitiveType.BIGINT - || t2ResultType == PrimitiveType.DECIMAL)) { - return Type.DECIMAL; - } if ((t1ResultType == PrimitiveType.BIGINT || t1ResultType == PrimitiveType.DECIMALV2) && (t2ResultType == PrimitiveType.BIGINT @@ -1051,8 +1003,6 @@ public abstract class Type { case VARCHAR: case HLL: return Type.DOUBLE; - case DECIMAL: - return Type.DECIMAL; case DECIMALV2: return Type.DECIMALV2; default: diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java b/fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java index 3cb2aa61a1..6551829b05 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java +++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java @@ -68,7 +68,6 @@ public class Util { TYPE_STRING_MAP.put(PrimitiveType.DATETIME, "datetime"); TYPE_STRING_MAP.put(PrimitiveType.CHAR, "char(%d)"); TYPE_STRING_MAP.put(PrimitiveType.VARCHAR, "varchar(%d)"); - TYPE_STRING_MAP.put(PrimitiveType.DECIMAL, "decimal(%d,%d)"); TYPE_STRING_MAP.put(PrimitiveType.DECIMALV2, "decimal(%d,%d)"); TYPE_STRING_MAP.put(PrimitiveType.HLL, "varchar(%d)"); TYPE_STRING_MAP.put(PrimitiveType.BOOLEAN, "bool"); diff --git a/fe/fe-core/src/main/java/org/apache/doris/http/rest/TableSchemaAction.java b/fe/fe-core/src/main/java/org/apache/doris/http/rest/TableSchemaAction.java index ae8bbe623a..c986870698 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/http/rest/TableSchemaAction.java +++ b/fe/fe-core/src/main/java/org/apache/doris/http/rest/TableSchemaAction.java @@ -101,7 +101,7 @@ public class TableSchemaAction extends RestBaseAction { Map baseInfo = new HashMap<>(2); Type colType = column.getOriginType(); PrimitiveType primitiveType = colType.getPrimitiveType(); - if (primitiveType == PrimitiveType.DECIMALV2 || primitiveType == PrimitiveType.DECIMAL) { + if (primitiveType == PrimitiveType.DECIMALV2) { ScalarType scalarType = (ScalarType) colType; baseInfo.put("precision", scalarType.getPrecision() + ""); baseInfo.put("scale", scalarType.getScalarScale() + ""); diff --git a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/TableSchemaAction.java b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/TableSchemaAction.java index a68abdb439..a776fce96b 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/TableSchemaAction.java +++ b/fe/fe-core/src/main/java/org/apache/doris/httpv2/rest/TableSchemaAction.java @@ -81,7 +81,7 @@ public class TableSchemaAction extends RestBaseController { Map baseInfo = new HashMap<>(2); Type colType = column.getOriginType(); PrimitiveType primitiveType = colType.getPrimitiveType(); - if (primitiveType == PrimitiveType.DECIMALV2 || primitiveType == PrimitiveType.DECIMAL) { + if (primitiveType == PrimitiveType.DECIMALV2) { ScalarType scalarType = (ScalarType) colType; baseInfo.put("precision", scalarType.getPrecision() + ""); baseInfo.put("scale", scalarType.getScalarScale() + ""); diff --git a/fe/fe-core/src/main/java/org/apache/doris/load/loadv2/SparkLoadPendingTask.java b/fe/fe-core/src/main/java/org/apache/doris/load/loadv2/SparkLoadPendingTask.java index 5f4bd82484..6b3e6408a5 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/load/loadv2/SparkLoadPendingTask.java +++ b/fe/fe-core/src/main/java/org/apache/doris/load/loadv2/SparkLoadPendingTask.java @@ -320,7 +320,7 @@ public class SparkLoadPendingTask extends LoadTask { // decimal precision scale int precision = 0; int scale = 0; - if (type.isDecimalType() || type.isDecimalV2Type()) { + if (type.isDecimalV2Type()) { precision = column.getPrecision(); scale = column.getScale(); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/planner/Planner.java b/fe/fe-core/src/main/java/org/apache/doris/planner/Planner.java index 6f66cdc0e1..fa7a101f59 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/planner/Planner.java +++ b/fe/fe-core/src/main/java/org/apache/doris/planner/Planner.java @@ -90,13 +90,11 @@ public class Planner { for (Expr expr : outputExprs) { List slotList = Lists.newArrayList(); expr.getIds(null, slotList); - if (PrimitiveType.DECIMAL != expr.getType().getPrimitiveType() && - PrimitiveType.DECIMALV2 != expr.getType().getPrimitiveType()) { + if (PrimitiveType.DECIMALV2 != expr.getType().getPrimitiveType()) { continue; } - if (PrimitiveType.DECIMAL != slotDesc.getType().getPrimitiveType() && - PrimitiveType.DECIMALV2 != slotDesc.getType().getPrimitiveType()) { + if (PrimitiveType.DECIMALV2 != slotDesc.getType().getPrimitiveType()) { continue; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/cache/PartitionRange.java b/fe/fe-core/src/main/java/org/apache/doris/qe/cache/PartitionRange.java index 15a2c8f501..073ffd7501 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/cache/PartitionRange.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/cache/PartitionRange.java @@ -171,7 +171,6 @@ public class PartitionRange { case DATETIME: case FLOAT: case DOUBLE: - case DECIMAL: case DECIMALV2: case CHAR: case VARCHAR: diff --git a/fe/fe-core/src/main/java/org/apache/doris/task/HadoopLoadPendingTask.java b/fe/fe-core/src/main/java/org/apache/doris/task/HadoopLoadPendingTask.java index 309815ae8a..7f5fc54831 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/task/HadoopLoadPendingTask.java +++ b/fe/fe-core/src/main/java/org/apache/doris/task/HadoopLoadPendingTask.java @@ -552,9 +552,6 @@ public class HadoopLoadPendingTask extends LoadPendingTask { case BITMAP: columnType = "BITMAP"; break; - case DECIMAL: - columnType = "DECIMAL"; - break; case DECIMALV2: columnType = "DECIMAL"; break; @@ -584,7 +581,7 @@ public class HadoopLoadPendingTask extends LoadPendingTask { } // decimal precision scale - if (type == PrimitiveType.DECIMAL || type == PrimitiveType.DECIMALV2) { + if (type == PrimitiveType.DECIMALV2) { dppColumn.put("precision", column.getPrecision()); dppColumn.put("scale", column.getScale()); } diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/DecimalLiteralTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/DecimalLiteralTest.java index 3faf0b6245..af153dcda8 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/DecimalLiteralTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/DecimalLiteralTest.java @@ -34,7 +34,7 @@ public class DecimalLiteralTest { BigDecimal decimal = new BigDecimal("-123456789123456789.123456789"); DecimalLiteral literal = new DecimalLiteral(decimal); - ByteBuffer buffer = literal.getHashValue(PrimitiveType.DECIMAL); + ByteBuffer buffer = literal.getHashValue(PrimitiveType.DECIMALV2); long longValue = buffer.getLong(); int fracValue = buffer.getInt(); System.out.println("long: " + longValue); @@ -44,7 +44,6 @@ public class DecimalLiteralTest { // if DecimalLiteral need to cast to Decimal and Decimalv2, need to cast // to themselves - Assert.assertEquals(literal, literal.uncheckedCastTo(Type.DECIMAL)); Assert.assertEquals(literal, literal.uncheckedCastTo(Type.DECIMALV2)); Assert.assertEquals(1, literal.compareLiteral(new NullLiteral())); diff --git a/fe/fe-core/src/test/java/org/apache/doris/backup/CatalogMocker.java b/fe/fe-core/src/test/java/org/apache/doris/backup/CatalogMocker.java index d184f22ac8..da9166c17a 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/backup/CatalogMocker.java +++ b/fe/fe-core/src/test/java/org/apache/doris/backup/CatalogMocker.java @@ -153,7 +153,7 @@ public class CatalogMocker { Column k5 = new Column("k5", ScalarType.createType(PrimitiveType.LARGEINT), true, null, "", "key5"); Column k6 = new Column("k6", ScalarType.createType(PrimitiveType.DATE), true, null, "", "key6"); Column k7 = new Column("k7", ScalarType.createType(PrimitiveType.DATETIME), true, null, "", "key7"); - Column k8 = new Column("k8", ScalarType.createDecimalType(10, 3), true, null, "", "key8"); + Column k8 = new Column("k8", ScalarType.createDecimalV2Type(10, 3), true, null, "", "key8"); k1.setIsKey(true); k2.setIsKey(true); k3.setIsKey(true); diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/ColumnTypeTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/ColumnTypeTest.java index b141597313..623a672222 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/ColumnTypeTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/ColumnTypeTest.java @@ -96,7 +96,7 @@ public class ColumnTypeTest { TypeDef type = TypeDef.createDecimal(12, 5); type.analyze(null); Assert.assertEquals("decimal(12, 5)", type.toString()); - Assert.assertEquals(PrimitiveType.DECIMAL, type.getType().getPrimitiveType()); + Assert.assertEquals(PrimitiveType.DECIMALV2, type.getType().getPrimitiveType()); Assert.assertEquals(12, ((ScalarType) type.getType()).getScalarPrecision()); Assert.assertEquals(5, ((ScalarType) type.getType()).getScalarScale()); @@ -146,7 +146,7 @@ public class ColumnTypeTest { ScalarType type2 = ScalarType.createType(PrimitiveType.BIGINT); ColumnType.write(dos, type2); - ScalarType type3 = ScalarType.createDecimalType(1, 1); + ScalarType type3 = ScalarType.createDecimalV2Type(1, 1); ColumnType.write(dos, type3); ScalarType type4 = ScalarType.createDecimalV2Type(1, 1); diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/FunctionSetTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/FunctionSetTest.java index e1b6e68eb6..2301a12e50 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/FunctionSetTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/FunctionSetTest.java @@ -35,12 +35,12 @@ public class FunctionSetTest { @Test public void testGetLagFunction() { - Type[] argTypes1 = {ScalarType.DECIMAL, ScalarType.TINYINT, ScalarType.TINYINT}; + Type[] argTypes1 = {ScalarType.DECIMALV2, ScalarType.TINYINT, ScalarType.TINYINT}; Function lagDesc1 = new Function(new FunctionName("lag"), argTypes1, (Type) ScalarType.INVALID, false); Function newFunction = functionSet.getFunction(lagDesc1, Function.CompareMode.IS_SUPERTYPE_OF); Type[] newArgTypes = newFunction.getArgs(); Assert.assertTrue(newArgTypes[0].matchesType(newArgTypes[2])); - Assert.assertTrue(newArgTypes[0].matchesType(ScalarType.DECIMAL)); + Assert.assertTrue(newArgTypes[0].matchesType(ScalarType.DECIMALV2)); Type[] argTypes2 = {ScalarType.VARCHAR, ScalarType.TINYINT, ScalarType.TINYINT}; Function lagDesc2 = new Function(new FunctionName("lag"), argTypes2, (Type) ScalarType.INVALID, false); diff --git a/gensrc/script/doris_builtins_functions.py b/gensrc/script/doris_builtins_functions.py index 009c40e7eb..3ce5056872 100755 --- a/gensrc/script/doris_builtins_functions.py +++ b/gensrc/script/doris_builtins_functions.py @@ -403,8 +403,6 @@ visible_functions = [ '_ZN5doris13MathFunctions3absEPN9doris_udf15FunctionContextERKNS1_6IntValE'], [['abs'], 'SMALLINT', ['TINYINT'], '_ZN5doris13MathFunctions3absEPN9doris_udf15FunctionContextERKNS1_10TinyIntValE'], - [['abs'], 'DECIMAL', ['DECIMAL'], - '_ZN5doris13MathFunctions3absEPN9doris_udf15FunctionContextERKNS1_10DecimalValE'], [['abs'], 'DECIMALV2', ['DECIMALV2'], '_ZN5doris13MathFunctions3absEPN9doris_udf15FunctionContextERKNS1_12DecimalV2ValE'], @@ -508,9 +506,6 @@ visible_functions = [ [['mod'], 'LARGEINT', ['LARGEINT', 'LARGEINT'], '_ZN5doris9Operators31mod_large_int_val_large_int_valEPN9doris_udf' '15FunctionContextERKNS1_11LargeIntValES6_'], - [['mod'], 'DECIMAL', ['DECIMAL', 'DECIMAL'], - '_ZN5doris16DecimalOperators27mod_decimal_val_decimal_valEPN9doris_udf' - '15FunctionContextERKNS1_10DecimalValES6_'], [['mod'], 'DECIMALV2', ['DECIMALV2', 'DECIMALV2'], '_ZN5doris18DecimalV2Operators31mod_decimalv2_val_decimalv2_valEPN9doris_udf' '15FunctionContextERKNS1_12DecimalV2ValES6_'], @@ -525,9 +520,6 @@ visible_functions = [ [['positive'], 'DOUBLE', ['DOUBLE'], '_ZN5doris13MathFunctions15positive_doubleEPN9doris_udf' '15FunctionContextERKNS1_9DoubleValE'], - [['positive'], 'DECIMAL', ['DECIMAL'], - '_ZN5doris13MathFunctions16positive_decimalEPN9doris_udf' - '15FunctionContextERKNS1_10DecimalValE'], [['positive'], 'DECIMALV2', ['DECIMALV2'], '_ZN5doris13MathFunctions16positive_decimalEPN9doris_udf' '15FunctionContextERKNS1_12DecimalV2ValE'], @@ -537,9 +529,6 @@ visible_functions = [ [['negative'], 'DOUBLE', ['DOUBLE'], '_ZN5doris13MathFunctions15negative_doubleEPN9doris_udf' '15FunctionContextERKNS1_9DoubleValE'], - [['negative'], 'DECIMAL', ['DECIMAL'], - '_ZN5doris13MathFunctions16negative_decimalEPN9doris_udf' - '15FunctionContextERKNS1_10DecimalValE'], [['negative'], 'DECIMALV2', ['DECIMALV2'], '_ZN5doris13MathFunctions16negative_decimalEPN9doris_udf' '15FunctionContextERKNS1_12DecimalV2ValE'], @@ -560,8 +549,6 @@ visible_functions = [ '_ZN5doris13MathFunctions5leastEPN9doris_udf15FunctionContextEiPKNS1_9DoubleValE'], [['least'], 'DATETIME', ['DATETIME', '...'], '_ZN5doris13MathFunctions5leastEPN9doris_udf15FunctionContextEiPKNS1_11DateTimeValE'], - [['least'], 'DECIMAL', ['DECIMAL', '...'], - '_ZN5doris13MathFunctions5leastEPN9doris_udf15FunctionContextEiPKNS1_10DecimalValE'], [['least'], 'DECIMALV2', ['DECIMALV2', '...'], '_ZN5doris13MathFunctions5leastEPN9doris_udf15FunctionContextEiPKNS1_12DecimalV2ValE'], [['least'], 'VARCHAR', ['VARCHAR', '...'], @@ -581,8 +568,6 @@ visible_functions = [ '_ZN5doris13MathFunctions8greatestEPN9doris_udf15FunctionContextEiPKNS1_8FloatValE'], [['greatest'], 'DOUBLE', ['DOUBLE', '...'], '_ZN5doris13MathFunctions8greatestEPN9doris_udf15FunctionContextEiPKNS1_9DoubleValE'], - [['greatest'], 'DECIMAL', ['DECIMAL', '...'], - '_ZN5doris13MathFunctions8greatestEPN9doris_udf15FunctionContextEiPKNS1_10DecimalValE'], [['greatest'], 'DECIMALV2', ['DECIMALV2', '...'], '_ZN5doris13MathFunctions8greatestEPN9doris_udf15FunctionContextEiPKNS1_12DecimalV2ValE'], [['greatest'], 'DATETIME', ['DATETIME', '...'], @@ -603,7 +588,6 @@ visible_functions = [ [['if'], 'DOUBLE', ['BOOLEAN', 'DOUBLE', 'DOUBLE'], ''], [['if'], 'DATETIME', ['BOOLEAN', 'DATETIME', 'DATETIME'], ''], [['if'], 'DATE', ['BOOLEAN', 'DATE', 'DATE'], ''], - [['if'], 'DECIMAL', ['BOOLEAN', 'DECIMAL', 'DECIMAL'], ''], [['if'], 'DECIMALV2', ['BOOLEAN', 'DECIMALV2', 'DECIMALV2'], ''], [['if'], 'BITMAP', ['BOOLEAN', 'BITMAP', 'BITMAP'], ''], # The priority of varchar should be lower than decimal in IS_SUPERTYPE_OF mode. @@ -619,7 +603,6 @@ visible_functions = [ [['nullif'], 'DOUBLE', ['DOUBLE', 'DOUBLE'], ''], [['nullif'], 'DATETIME', ['DATETIME', 'DATETIME'], ''], [['nullif'], 'DATE', ['DATE', 'DATE'], ''], - [['nullif'], 'DECIMAL', ['DECIMAL', 'DECIMAL'], ''], [['nullif'], 'DECIMALV2', ['DECIMALV2', 'DECIMALV2'], ''], # The priority of varchar should be lower than decimal in IS_SUPERTYPE_OF mode. [['nullif'], 'VARCHAR', ['VARCHAR', 'VARCHAR'], ''], @@ -636,7 +619,6 @@ visible_functions = [ [['ifnull'], 'DATETIME', ['DATETIME', 'DATETIME'], ''], [['ifnull'], 'DATETIME', ['DATE', 'DATETIME'], ''], [['ifnull'], 'DATETIME', ['DATETIME', 'DATE'], ''], - [['ifnull'], 'DECIMAL', ['DECIMAL', 'DECIMAL'], ''], [['ifnull'], 'DECIMALV2', ['DECIMALV2', 'DECIMALV2'], ''], [['ifnull'], 'BITMAP', ['BITMAP', 'BITMAP'], ''], # The priority of varchar should be lower than decimal in IS_SUPERTYPE_OF mode. @@ -652,7 +634,6 @@ visible_functions = [ [['coalesce'], 'DOUBLE', ['DOUBLE', '...'], ''], [['coalesce'], 'DATETIME', ['DATETIME', '...'], ''], [['coalesce'], 'DATE', ['DATE', '...'], ''], - [['coalesce'], 'DECIMAL', ['DECIMAL', '...'], ''], [['coalesce'], 'DECIMALV2', ['DECIMALV2', '...'], ''], [['coalesce'], 'BITMAP', ['BITMAP', '...'], ''], # The priority of varchar should be lower than decimal in IS_SUPERTYPE_OF mode. @@ -763,8 +744,6 @@ visible_functions = [ '_ZN5doris15StringFunctions12money_formatEPN9doris_udf15FunctionContextERKNS1_11LargeIntValE'], [['money_format'], 'VARCHAR', ['DOUBLE'], '_ZN5doris15StringFunctions12money_formatEPN9doris_udf15FunctionContextERKNS1_9DoubleValE'], - [['money_format'], 'VARCHAR', ['DECIMAL'], - '_ZN5doris15StringFunctions12money_formatEPN9doris_udf15FunctionContextERKNS1_10DecimalValE'], [['money_format'], 'VARCHAR', ['DECIMALV2'], '_ZN5doris15StringFunctions12money_formatEPN9doris_udf15FunctionContextERKNS1_12DecimalV2ValE'], [['split_part'], 'VARCHAR', ['VARCHAR', 'VARCHAR', 'INT'], diff --git a/gensrc/thrift/Types.thrift b/gensrc/thrift/Types.thrift index 544e29bfc5..ee2dc87ee7 100644 --- a/gensrc/thrift/Types.thrift +++ b/gensrc/thrift/Types.thrift @@ -66,7 +66,7 @@ enum TPrimitiveType { DATE, DATETIME, BINARY, - DECIMAL, + DECIMAL_DEPRACTED, // not used now, only for place holder // CHAR(n). Currently only supported in UDAs CHAR, LARGEINT,