eldenmoon commented on code in PR #51766:
URL: https://github.com/apache/doris/pull/51766#discussion_r2153464444
##########
be/src/util/jsonb_writer.h:
##########
@@ -464,8 +544,14 @@ class JsonbWriterT {
OS_TYPE* getOutput() { return os_; }
JsonbDocument* getDocument() {
- return JsonbDocument::checkAndCreateDocument(getOutput()->getBuffer(),
- getOutput()->getSize());
+ JsonbDocument* doc = nullptr;
+ auto st =
JsonbDocument::checkAndCreateDocument(getOutput()->getBuffer(),
Review Comment:
use THROW_IF_ERROR
##########
be/src/vec/data_types/data_type_jsonb.cpp:
##########
@@ -70,6 +71,26 @@ Status DataTypeJsonb::from_string(ReadBuffer& rb, IColumn*
column) const {
return Status::OK();
}
+Field DataTypeJsonb::get_default() const {
+ std::string default_json = "null";
+ // convert default_json to binary
+ JsonBinaryValue jsonb_value;
+ THROW_IF_ERROR(jsonb_value.from_json_string(default_json));
Review Comment:
maybe this could be const static value to avoid from_json_string each time
call get_default ?
##########
be/src/util/jsonb_document.h:
##########
@@ -756,6 +791,95 @@ class JsonbIntVal : public JsonbValue {
}
};
+template <JsonbDecimalType T>
+class JsonbDecimalVal : public JsonbValue {
+public:
+ using NativeType = typename T::NativeType;
+ JsonbDecimalVal() = delete;
+
+ // get the decimal value
+ T val() const { return T(_value); }
+
+ uint32_t precision() const { return _precision; }
+ uint32_t scale() const { return _scale; }
+
+ // set the decimal value
+ bool setVal(const T& decimal, uint32_t precision, uint32_t scale) {
+ if (!isDecimal()) {
+ return false;
+ }
+
+ _precision = precision;
+ _scale = scale;
+ _value = decimal.value;
+ return true;
+ }
+
+private:
+ uint32_t _precision;
Review Comment:
is uint_8 enough for _precision and _scale?
##########
be/src/util/jsonb_utils.cpp:
##########
@@ -0,0 +1,97 @@
+// 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 "jsonb_utils.h"
+
+#include <cstdint>
+
+#include "common/status.h"
+#include "util/date_func.h"
+#include "util/string_parser.hpp"
+#include "vec/runtime/vdatetime_value.h"
+
+namespace doris {
+template <JsonbDecimalType T>
+void JsonbToJson::decimal_to_json(const T& value, const uint32_t precision,
const uint32_t scale) {
+ auto value_str = value.to_string(precision, scale);
+ if (config::enable_json_decimal_as_string) {
+ // If enable_json_decimal_as_string is true, we output decimal as
string
+ // to avoid precision loss.
+ os_.put('"');
+ os_.write(value_str.data(), value_str.size());
Review Comment:
why not just keep this branch ? string_to_float will lost precision, and
user maybe confused?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]