Skip to content

Commit

Permalink
insert and select OK
Browse files Browse the repository at this point in the history
  • Loading branch information
jacktengg committed Oct 7, 2023
1 parent c96091c commit 8f58458
Show file tree
Hide file tree
Showing 41 changed files with 295 additions and 38 deletions.
12 changes: 12 additions & 0 deletions be/src/gutil/endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "gutil/int128.h"
#include "gutil/integral_types.h"
#include "gutil/port.h"
#include "vec/core/wide_integer.h"

inline uint64 gbswap_64(uint64 host_int) {
#if defined(__GNUC__) && defined(__x86_64__) && !defined(__APPLE__)
Expand All @@ -59,6 +60,11 @@ inline unsigned __int128 gbswap_128(unsigned __int128 host_int) {
(static_cast<unsigned __int128>(bswap_64(static_cast<uint64>(host_int))) << 64);
}

inline wide::UInt256 gbswap_256(wide::UInt256 host_int) {
wide::UInt256 result{gbswap_64(host_int.items[0]), gbswap_64(host_int.items[1]), gbswap_64(host_int.items[2]), gbswap_64(host_int.items[3])};
return result;
}

// Swap bytes of a 24-bit value.
inline uint32_t bswap_24(uint32_t x) {
return ((x & 0x0000ffULL) << 16) | ((x & 0x00ff00ULL)) | ((x & 0xff0000ULL) >> 16);
Expand Down Expand Up @@ -252,6 +258,9 @@ class BigEndian {
static unsigned __int128 FromHost128(unsigned __int128 x) { return gbswap_128(x); }
static unsigned __int128 ToHost128(unsigned __int128 x) { return gbswap_128(x); }

static wide::UInt256 FromHost256(wide::UInt256 x) { return gbswap_256(x); }
static wide::UInt256 ToHost256(wide::UInt256 x) { return gbswap_256(x); }

static bool IsLittleEndian() { return true; }

#elif defined IS_BIG_ENDIAN
Expand All @@ -271,6 +280,9 @@ class BigEndian {
static uint128 FromHost128(uint128 x) { return x; }
static uint128 ToHost128(uint128 x) { return x; }

static wide::UInt256 FromHost128(wide::UInt256 x) { return x; }
static wide::UInt256 ToHost128(wide::UInt256 x) { return x; }

static bool IsLittleEndian() { return false; }

#endif /* ENDIAN */
Expand Down
2 changes: 2 additions & 0 deletions be/src/olap/delete_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ bool DeleteHandler::is_condition_value_valid(const TabletColumn& column,
return valid_decimal(value_str, column.precision(), column.frac());
case FieldType::OLAP_FIELD_TYPE_DECIMAL128I:
return valid_decimal(value_str, column.precision(), column.frac());
case FieldType::OLAP_FIELD_TYPE_DECIMAL256:
return valid_decimal(value_str, column.precision(), column.frac());
case FieldType::OLAP_FIELD_TYPE_CHAR:
case FieldType::OLAP_FIELD_TYPE_VARCHAR:
return value_str.size() <= column.length();
Expand Down
4 changes: 4 additions & 0 deletions be/src/olap/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,8 @@ class FieldFactory {
[[fallthrough]];
case FieldType::OLAP_FIELD_TYPE_DECIMAL128I:
[[fallthrough]];
case FieldType::OLAP_FIELD_TYPE_DECIMAL256:
[[fallthrough]];
case FieldType::OLAP_FIELD_TYPE_DATETIMEV2: {
Field* field = new Field(column);
field->set_precision(column.precision());
Expand Down Expand Up @@ -647,6 +649,8 @@ class FieldFactory {
[[fallthrough]];
case FieldType::OLAP_FIELD_TYPE_DECIMAL128I:
[[fallthrough]];
case FieldType::OLAP_FIELD_TYPE_DECIMAL256:
[[fallthrough]];
case FieldType::OLAP_FIELD_TYPE_DATETIMEV2: {
Field* field = new Field(column);
field->set_precision(column.precision());
Expand Down
1 change: 1 addition & 0 deletions be/src/olap/key_coder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class KeyCoderResolver {
add_mapping<FieldType::OLAP_FIELD_TYPE_DECIMAL32>();
add_mapping<FieldType::OLAP_FIELD_TYPE_DECIMAL64>();
add_mapping<FieldType::OLAP_FIELD_TYPE_DECIMAL128I>();
add_mapping<FieldType::OLAP_FIELD_TYPE_DECIMAL256>();
}

template <FieldType field_type>
Expand Down
33 changes: 19 additions & 14 deletions be/src/olap/key_coder.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class KeyCoderTraits<
field_type,
typename std::enable_if<
std::is_integral<typename CppTypeTraits<field_type>::CppType>::value ||
field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256 ||
vectorized::IsDecimalNumber<typename CppTypeTraits<field_type>::CppType>>::type> {
public:
using CppType = typename CppTypeTraits<field_type>::CppType;
Expand All @@ -93,20 +94,24 @@ class KeyCoderTraits<
private:
// Swap value's endian from/to big endian
static UnsignedCppType swap_big_endian(UnsignedCppType val) {
switch (sizeof(UnsignedCppType)) {
case 1:
return val;
case 2:
return BigEndian::FromHost16(val);
case 4:
return BigEndian::FromHost32(val);
case 8:
return BigEndian::FromHost64(val);
case 16:
return BigEndian::FromHost128(val);
default:
LOG(FATAL) << "Invalid type to big endian, type=" << int(field_type)
<< ", size=" << sizeof(UnsignedCppType);
if constexpr (field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256) {
return BigEndian::FromHost256(val);
} else {
switch (sizeof(UnsignedCppType)) {
case 1:
return val;
case 2:
return BigEndian::FromHost16(val);
case 4:
return BigEndian::FromHost32(val);
case 8:
return BigEndian::FromHost64(val);
case 16:
return BigEndian::FromHost128(val);
default:
LOG(FATAL) << "Invalid type to big endian, type=" << int(field_type)
<< ", size=" << sizeof(UnsignedCppType);
}
}
}

Expand Down
1 change: 1 addition & 0 deletions be/src/olap/olap_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ constexpr bool field_is_numeric_type(const FieldType& field_type) {
field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL32 ||
field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL64 ||
field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL128I ||
field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256 ||
field_type == FieldType::OLAP_FIELD_TYPE_BOOL;
}

Expand Down
1 change: 1 addition & 0 deletions be/src/olap/rowset/segment_v2/bitshuffle_page.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ inline Status parse_bit_shuffle_header(const Slice& data, size_t& num_elements,
case 8:
case 12:
case 16:
case 32:
break;
default:
return Status::InternalError("invalid size_of_elem:{}", size_of_element);
Expand Down
4 changes: 4 additions & 0 deletions be/src/olap/rowset/segment_v2/encoding_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ EncodingInfoResolver::EncodingInfoResolver() {
_add_map<FieldType::OLAP_FIELD_TYPE_DECIMAL128I, PLAIN_ENCODING>();
_add_map<FieldType::OLAP_FIELD_TYPE_DECIMAL128I, BIT_SHUFFLE, true>();

_add_map<FieldType::OLAP_FIELD_TYPE_DECIMAL256, BIT_SHUFFLE>();
_add_map<FieldType::OLAP_FIELD_TYPE_DECIMAL256, PLAIN_ENCODING>();
_add_map<FieldType::OLAP_FIELD_TYPE_DECIMAL256, BIT_SHUFFLE, true>();

_add_map<FieldType::OLAP_FIELD_TYPE_HLL, PLAIN_ENCODING>();

_add_map<FieldType::OLAP_FIELD_TYPE_OBJECT, PLAIN_ENCODING>();
Expand Down
3 changes: 2 additions & 1 deletion be/src/olap/rowset/segment_v2/zone_map_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ Status ZoneMapIndexReader::_load(bool use_page_cache, bool kept_in_memory,
M(TYPE_STRING) \
M(TYPE_DECIMAL32) \
M(TYPE_DECIMAL64) \
M(TYPE_DECIMAL128I)
M(TYPE_DECIMAL128I) \
M(TYPE_DECIMAL256)

Status ZoneMapIndexWriter::create(Field* field, std::unique_ptr<ZoneMapIndexWriter>& res) {
switch (field->type()) {
Expand Down
3 changes: 3 additions & 0 deletions be/src/olap/schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,9 @@ vectorized::IColumn::MutablePtr Schema::get_predicate_column_ptr(const Field& fi
case FieldType::OLAP_FIELD_TYPE_DECIMAL128I:
ptr = doris::vectorized::PredicateColumnType<TYPE_DECIMAL128I>::create();
break;
case FieldType::OLAP_FIELD_TYPE_DECIMAL256:
ptr = doris::vectorized::PredicateColumnType<TYPE_DECIMAL256>::create();
break;
case FieldType::OLAP_FIELD_TYPE_ARRAY:
ptr = doris::vectorized::ColumnArray::create(
get_predicate_column_ptr(*field.get_sub_field(0), reader_type),
Expand Down
5 changes: 5 additions & 0 deletions be/src/olap/tablet_schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ FieldType TabletColumn::get_field_type_by_string(const std::string& type_str) {
type = FieldType::OLAP_FIELD_TYPE_DECIMAL64;
} else if (0 == upper_type_str.compare("DECIMAL128I")) {
type = FieldType::OLAP_FIELD_TYPE_DECIMAL128I;
} else if (0 == upper_type_str.compare("DECIMAL256")) {
type = FieldType::OLAP_FIELD_TYPE_DECIMAL256;
} else if (0 == upper_type_str.compare(0, 7, "DECIMAL")) {
type = FieldType::OLAP_FIELD_TYPE_DECIMAL;
} else if (0 == upper_type_str.compare(0, 7, "VARCHAR")) {
Expand Down Expand Up @@ -226,6 +228,9 @@ std::string TabletColumn::get_string_by_field_type(FieldType type) {
case FieldType::OLAP_FIELD_TYPE_DECIMAL128I:
return "DECIMAL128I";

case FieldType::OLAP_FIELD_TYPE_DECIMAL256:
return "DECIMAL256";

case FieldType::OLAP_FIELD_TYPE_VARCHAR:
return "VARCHAR";

Expand Down
1 change: 1 addition & 0 deletions be/src/olap/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const TypeInfo* get_scalar_type_info(FieldType field_type) {
get_scalar_type_info<FieldType::OLAP_FIELD_TYPE_JSONB>(),
get_scalar_type_info<FieldType::OLAP_FIELD_TYPE_VARIANT>(),
get_scalar_type_info<FieldType::OLAP_FIELD_TYPE_AGG_STATE>(),
get_scalar_type_info<FieldType::OLAP_FIELD_TYPE_DECIMAL256>(),
nullptr};
return field_type_array[int(field_type)];
}
Expand Down
30 changes: 30 additions & 0 deletions be/src/olap/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "util/string_parser.hpp"
#include "util/types.h"
#include "vec/common/arena.h"
#include "vec/core/wide_integer.h"
#include "vec/runtime/vdatetime_value.h"

namespace doris {
Expand Down Expand Up @@ -690,6 +691,11 @@ struct CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DECIMAL128I> {
using UnsignedCppType = uint128_t;
};
template <>
struct CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DECIMAL256> {
using CppType = Int256;
using UnsignedCppType = wide::UInt256;
};
template <>
struct CppTypeTraits<FieldType::OLAP_FIELD_TYPE_DATE> {
using CppType = uint24_t;
using UnsignedCppType = uint24_t;
Expand Down Expand Up @@ -1083,6 +1089,30 @@ struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_DECIMAL128I>
}
};

template <>
struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_DECIMAL256>
: public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_DECIMAL256> {
static Status from_string(void* buf, const std::string& scan_key, const int precision,
const int scale) {
StringParser::ParseResult result = StringParser::PARSE_SUCCESS;
auto value = StringParser::string_to_decimal<TYPE_DECIMAL256>(
scan_key.c_str(), scan_key.size(), 76, scale, &result);
if (result == StringParser::PARSE_FAILURE) {
return Status::Error<ErrorCode::INVALID_ARGUMENT>(
"FieldTypeTraits<OLAP_FIELD_TYPE_DECIMAL128I>::from_string meet PARSE_FAILURE");
}
*reinterpret_cast<Int256*>(buf) = value;
return Status::OK();
}
static std::string to_string(const void* src) {
return "";
// auto value = reinterpret_cast<const wide::Int256*>(src);
// fmt::memory_buffer buffer;
// fmt::format_to(buffer, "{}", *value);
// return std::string(buffer.data(), buffer.size());
}
};

template <>
struct FieldTypeTraits<FieldType::OLAP_FIELD_TYPE_DATE>
: public BaseFieldtypeTraits<FieldType::OLAP_FIELD_TYPE_DATE> {
Expand Down
1 change: 1 addition & 0 deletions be/src/olap/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ constexpr bool is_numeric_type(const FieldType& field_type) {
field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL32 ||
field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL64 ||
field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL128I ||
field_type == FieldType::OLAP_FIELD_TYPE_DECIMAL256 ||
field_type == FieldType::OLAP_FIELD_TYPE_BOOL;
}

Expand Down
3 changes: 3 additions & 0 deletions be/src/runtime/primitive_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ PrimitiveType thrift_to_type(TPrimitiveType::type ttype) {
case TPrimitiveType::DECIMAL128I:
return TYPE_DECIMAL128I;

case TPrimitiveType::DECIMAL256:
return TYPE_DECIMAL256;

case TPrimitiveType::CHAR:
return TYPE_CHAR;

Expand Down
3 changes: 2 additions & 1 deletion be/src/runtime/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ TypeDescriptor::TypeDescriptor(const std::vector<TTypeNode>& types, int* idx)
DCHECK(scalar_type.__isset.len);
len = scalar_type.len;
} else if (type == TYPE_DECIMALV2 || type == TYPE_DECIMAL32 || type == TYPE_DECIMAL64 ||
type == TYPE_DECIMAL128I || type == TYPE_DATETIMEV2 || type == TYPE_TIMEV2) {
type == TYPE_DECIMAL128I || type == TYPE_DECIMAL256 || type == TYPE_DATETIMEV2 ||
type == TYPE_TIMEV2) {
DCHECK(scalar_type.__isset.precision);
DCHECK(scalar_type.__isset.scale);
precision = scalar_type.precision;
Expand Down
10 changes: 9 additions & 1 deletion be/src/vec/core/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ class Field {
Bitmap = 27,
HyperLogLog = 28,
QuantileState = 29,
Decimal256 = 30,
Int256 = 30,
Decimal256 = 31,
};

static const int MIN_NON_POD = 16;
Expand Down Expand Up @@ -643,6 +644,9 @@ class Field {
case Types::Decimal128I:
f(field.template get<DecimalField<Decimal128I>>());
return;
case Types::Decimal256:
f(field.template get<DecimalField<Decimal256>>());
return;
case Types::VariantMap:
f(field.template get<VariantMap>());
return;
Expand Down Expand Up @@ -780,6 +784,10 @@ struct Field::TypeToEnum<Int128> {
static constexpr Types::Which value = Types::Int128;
};
template <>
struct Field::TypeToEnum<Int256> {
static constexpr Types::Which value = Types::Int256;
};
template <>
struct Field::TypeToEnum<Float64> {
static constexpr Types::Which value = Types::Float64;
};
Expand Down
28 changes: 25 additions & 3 deletions be/src/vec/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ enum class TypeIndex {
QuantileState = 42,
Time = 43,
AggState = 44,
Decimal256
Decimal256 = 45,
Int256
};

struct Consted {
Expand Down Expand Up @@ -281,10 +282,21 @@ struct TypeName<Int128> {
static const char* get() { return "Int128"; }
};
template <>
inline constexpr bool IsNumber<Int256> = true;
template <>
struct TypeName<Int256> {
static const char* get() { return "Int256"; }
};
template <>
struct TypeId<Int128> {
static constexpr const TypeIndex value = TypeIndex::Int128;
};

template <>
struct TypeId<Int256> {
static constexpr const TypeIndex value = TypeIndex::Int256;
};

using Date = Int64;
using DateTime = Int64;
using DateV2 = UInt32;
Expand Down Expand Up @@ -634,8 +646,11 @@ struct Decimal<Int256> {
constexpr auto precision =
std::is_same_v<T, Int32>
? BeConsts::MAX_DECIMAL32_PRECISION
: (std::is_same_v<T, Int64> ? BeConsts::MAX_DECIMAL64_PRECISION
: BeConsts::MAX_DECIMAL128_PRECISION);
: (std::is_same_v<T, Int64>
? BeConsts::MAX_DECIMAL64_PRECISION
: (std::is_same_v<T, Int128>
? BeConsts::MAX_DECIMAL128_PRECISION
: BeConsts::MAX_DECIMAL256_PRECISION));
return precision + 1 // Add a space for decimal place
+ 1 // Add a space for leading 0
+ 1; // Add a space for negative sign
Expand Down Expand Up @@ -895,6 +910,11 @@ constexpr bool IsDecimal128I = false;
template <>
inline constexpr bool IsDecimal128I<Decimal128I> = true;

template <typename T>
constexpr bool IsDecimal256 = false;
template <>
inline constexpr bool IsDecimal256<Decimal256> = true;

template <typename T>
constexpr bool IsDecimalV2 = IsDecimal128<T> && !IsDecimal128I<T>;

Expand Down Expand Up @@ -959,6 +979,8 @@ inline const char* getTypeName(TypeIndex idx) {
return TypeName<Int64>::get();
case TypeIndex::Int128:
return TypeName<Int128>::get();
case TypeIndex::Int256:
return TypeName<Int256>::get();
case TypeIndex::Float32:
return TypeName<Float32>::get();
case TypeIndex::Float64:
Expand Down
1 change: 1 addition & 0 deletions be/src/vec/core/wide_integer.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class integer {
};

using Int256 = integer<256, signed>;
using UInt256 = integer<256, unsigned>;

template <typename T>
static constexpr bool ArithmeticConcept() noexcept;
Expand Down
4 changes: 2 additions & 2 deletions be/src/vec/data_types/data_type_decimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,10 @@ bool DataTypeDecimal<T>::parse_from_string(const std::string& str, T* res) const

DataTypePtr create_decimal(UInt64 precision_value, UInt64 scale_value, bool use_v2) {
if (precision_value < min_decimal_precision() ||
precision_value > max_decimal_precision<Decimal128>()) {
precision_value > max_decimal_precision<Decimal256>()) {
throw doris::Exception(doris::ErrorCode::NOT_IMPLEMENTED_ERROR,
"Wrong precision {}, min: {}, max: {}", precision_value,
min_decimal_precision(), max_decimal_precision<Decimal128>());
min_decimal_precision(), max_decimal_precision<Decimal256>());
}

if (static_cast<UInt64>(scale_value) > precision_value) {
Expand Down
Loading

0 comments on commit 8f58458

Please sign in to comment.