feat: add json type proto (#188)

* feat: add type extension for json type

* refactor: use a extension type

* refactor: as enum
This commit is contained in:
Yohan Wal
2024-09-09 16:14:58 +08:00
committed by GitHub
parent 157cfdb527
commit 973f49cde8
5 changed files with 611 additions and 103 deletions
+78 -28
View File
@@ -299,7 +299,7 @@ PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORIT
} // namespace v1
} // namespace greptime
static ::_pb::Metadata file_level_metadata_greptime_2fv1_2fcommon_2eproto[20];
static const ::_pb::EnumDescriptor* file_level_enum_descriptors_greptime_2fv1_2fcommon_2eproto[2];
static const ::_pb::EnumDescriptor* file_level_enum_descriptors_greptime_2fv1_2fcommon_2eproto[3];
static constexpr ::_pb::ServiceDescriptor const** file_level_service_descriptors_greptime_2fv1_2fcommon_2eproto = nullptr;
const uint32_t TableStruct_greptime_2fv1_2fcommon_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {
@@ -447,6 +447,7 @@ const uint32_t TableStruct_greptime_2fv1_2fcommon_2eproto::offsets[] PROTOBUF_SE
~0u, // no _weak_field_map_
~0u, // no _inlined_string_donated_
::_pbi::kInvalidFieldOffsetTag,
::_pbi::kInvalidFieldOffsetTag,
PROTOBUF_FIELD_OFFSET(::greptime::v1::ColumnDataTypeExtension, _impl_.type_ext_),
~0u, // no _has_bits_
PROTOBUF_FIELD_OFFSET(::greptime::v1::DecimalTypeExtension, _internal_metadata_),
@@ -492,9 +493,9 @@ static const ::_pbi::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protode
{ 120, -1, -1, sizeof(::greptime::v1::IntervalMonthDayNano)},
{ 129, -1, -1, sizeof(::greptime::v1::Decimal128)},
{ 137, -1, -1, sizeof(::greptime::v1::ColumnDataTypeExtension)},
{ 145, -1, -1, sizeof(::greptime::v1::DecimalTypeExtension)},
{ 153, 161, -1, sizeof(::greptime::v1::ColumnOptions_OptionsEntry_DoNotUse)},
{ 163, -1, -1, sizeof(::greptime::v1::ColumnOptions)},
{ 146, -1, -1, sizeof(::greptime::v1::DecimalTypeExtension)},
{ 154, 162, -1, sizeof(::greptime::v1::ColumnOptions_OptionsEntry_DoNotUse)},
{ 164, -1, -1, sizeof(::greptime::v1::ColumnOptions)},
};
static const ::_pb::Message* const file_default_instances[] = {
@@ -550,33 +551,35 @@ const char descriptor_table_protodef_greptime_2fv1_2fcommon_2eproto[] PROTOBUF_S
"2\024.greptime.v1.Metrics\"I\n\024IntervalMonthD"
"ayNano\022\016\n\006months\030\001 \001(\005\022\014\n\004days\030\002 \001(\005\022\023\n\013"
"nanoseconds\030\003 \001(\003\"$\n\nDecimal128\022\n\n\002hi\030\001 "
"\001(\003\022\n\n\002lo\030\002 \001(\003\"`\n\027ColumnDataTypeExtensi"
"on\0229\n\014decimal_type\030\001 \001(\0132!.greptime.v1.D"
"ecimalTypeExtensionH\000B\n\n\010type_ext\"8\n\024Dec"
"imalTypeExtension\022\021\n\tprecision\030\001 \001(\005\022\r\n\005"
"scale\030\002 \001(\005\"y\n\rColumnOptions\0228\n\007options\030"
"\001 \003(\0132\'.greptime.v1.ColumnOptions.Option"
"sEntry\032.\n\014OptionsEntry\022\013\n\003key\030\001 \001(\t\022\r\n\005v"
"alue\030\002 \001(\t:\0028\001*1\n\014SemanticType\022\007\n\003TAG\020\000\022"
"\t\n\005FIELD\020\001\022\r\n\tTIMESTAMP\020\002*\326\003\n\016ColumnData"
"Type\022\013\n\007BOOLEAN\020\000\022\010\n\004INT8\020\001\022\t\n\005INT16\020\002\022\t"
"\n\005INT32\020\003\022\t\n\005INT64\020\004\022\t\n\005UINT8\020\005\022\n\n\006UINT1"
"6\020\006\022\n\n\006UINT32\020\007\022\n\n\006UINT64\020\010\022\013\n\007FLOAT32\020\t"
"\022\013\n\007FLOAT64\020\n\022\n\n\006BINARY\020\013\022\n\n\006STRING\020\014\022\010\n"
"\004DATE\020\r\022\014\n\010DATETIME\020\016\022\024\n\020TIMESTAMP_SECON"
"D\020\017\022\031\n\025TIMESTAMP_MILLISECOND\020\020\022\031\n\025TIMEST"
"AMP_MICROSECOND\020\021\022\030\n\024TIMESTAMP_NANOSECON"
"D\020\022\022\017\n\013TIME_SECOND\020\023\022\024\n\020TIME_MILLISECOND"
"\020\024\022\024\n\020TIME_MICROSECOND\020\025\022\023\n\017TIME_NANOSEC"
"OND\020\026\022\027\n\023INTERVAL_YEAR_MONTH\020\027\022\025\n\021INTERV"
"AL_DAY_TIME\020\030\022\033\n\027INTERVAL_MONTH_DAY_NANO"
"\020\031\022\016\n\nDECIMAL128\020\036BO\n\016io.greptime.v1B\006Co"
"mmonZ5github.com/GreptimeTeam/greptime-p"
"roto/go/greptime/v1b\006proto3"
"\001(\003\022\n\n\002lo\030\002 \001(\003\"\225\001\n\027ColumnDataTypeExtens"
"ion\0229\n\014decimal_type\030\001 \001(\0132!.greptime.v1."
"DecimalTypeExtensionH\000\0223\n\tjson_type\030\002 \001("
"\0162\036.greptime.v1.JsonTypeExtensionH\000B\n\n\010t"
"ype_ext\"8\n\024DecimalTypeExtension\022\021\n\tpreci"
"sion\030\001 \001(\005\022\r\n\005scale\030\002 \001(\005\"y\n\rColumnOptio"
"ns\0228\n\007options\030\001 \003(\0132\'.greptime.v1.Column"
"Options.OptionsEntry\032.\n\014OptionsEntry\022\013\n\003"
"key\030\001 \001(\t\022\r\n\005value\030\002 \001(\t:\0028\001*1\n\014Semantic"
"Type\022\007\n\003TAG\020\000\022\t\n\005FIELD\020\001\022\r\n\tTIMESTAMP\020\002*"
"\326\003\n\016ColumnDataType\022\013\n\007BOOLEAN\020\000\022\010\n\004INT8\020"
"\001\022\t\n\005INT16\020\002\022\t\n\005INT32\020\003\022\t\n\005INT64\020\004\022\t\n\005UI"
"NT8\020\005\022\n\n\006UINT16\020\006\022\n\n\006UINT32\020\007\022\n\n\006UINT64\020"
"\010\022\013\n\007FLOAT32\020\t\022\013\n\007FLOAT64\020\n\022\n\n\006BINARY\020\013\022"
"\n\n\006STRING\020\014\022\010\n\004DATE\020\r\022\014\n\010DATETIME\020\016\022\024\n\020T"
"IMESTAMP_SECOND\020\017\022\031\n\025TIMESTAMP_MILLISECO"
"ND\020\020\022\031\n\025TIMESTAMP_MICROSECOND\020\021\022\030\n\024TIMES"
"TAMP_NANOSECOND\020\022\022\017\n\013TIME_SECOND\020\023\022\024\n\020TI"
"ME_MILLISECOND\020\024\022\024\n\020TIME_MICROSECOND\020\025\022\023"
"\n\017TIME_NANOSECOND\020\026\022\027\n\023INTERVAL_YEAR_MON"
"TH\020\027\022\025\n\021INTERVAL_DAY_TIME\020\030\022\033\n\027INTERVAL_"
"MONTH_DAY_NANO\020\031\022\016\n\nDECIMAL128\020\036*$\n\021Json"
"TypeExtension\022\017\n\013JSON_BINARY\020\000BO\n\016io.gre"
"ptime.v1B\006CommonZ5github.com/GreptimeTea"
"m/greptime-proto/go/greptime/v1b\006proto3"
;
static ::_pbi::once_flag descriptor_table_greptime_2fv1_2fcommon_2eproto_once;
const ::_pbi::DescriptorTable descriptor_table_greptime_2fv1_2fcommon_2eproto = {
false, false, 2067, descriptor_table_protodef_greptime_2fv1_2fcommon_2eproto,
false, false, 2159, descriptor_table_protodef_greptime_2fv1_2fcommon_2eproto,
"greptime/v1/common.proto",
&descriptor_table_greptime_2fv1_2fcommon_2eproto_once, nullptr, 0, 20,
schemas, file_default_instances, TableStruct_greptime_2fv1_2fcommon_2eproto::offsets,
@@ -645,6 +648,19 @@ bool ColumnDataType_IsValid(int value) {
}
}
const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* JsonTypeExtension_descriptor() {
::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&descriptor_table_greptime_2fv1_2fcommon_2eproto);
return file_level_enum_descriptors_greptime_2fv1_2fcommon_2eproto[2];
}
bool JsonTypeExtension_IsValid(int value) {
switch (value) {
case 0:
return true;
default:
return false;
}
}
// ===================================================================
@@ -4309,6 +4325,10 @@ ColumnDataTypeExtension::ColumnDataTypeExtension(const ColumnDataTypeExtension&
from._internal_decimal_type());
break;
}
case kJsonType: {
_this->_internal_set_json_type(from._internal_json_type());
break;
}
case TYPE_EXT_NOT_SET: {
break;
}
@@ -4357,6 +4377,10 @@ void ColumnDataTypeExtension::clear_type_ext() {
}
break;
}
case kJsonType: {
// No need to clear
break;
}
case TYPE_EXT_NOT_SET: {
break;
}
@@ -4389,6 +4413,15 @@ const char* ColumnDataTypeExtension::_InternalParse(const char* ptr, ::_pbi::Par
} else
goto handle_unusual;
continue;
// .greptime.v1.JsonTypeExtension json_type = 2;
case 2:
if (PROTOBUF_PREDICT_TRUE(static_cast<uint8_t>(tag) == 16)) {
uint64_t val = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr);
CHK_(ptr);
_internal_set_json_type(static_cast<::greptime::v1::JsonTypeExtension>(val));
} else
goto handle_unusual;
continue;
default:
goto handle_unusual;
} // switch
@@ -4425,6 +4458,13 @@ uint8_t* ColumnDataTypeExtension::_InternalSerialize(
_Internal::decimal_type(this).GetCachedSize(), target, stream);
}
// .greptime.v1.JsonTypeExtension json_type = 2;
if (_internal_has_json_type()) {
target = stream->EnsureSpace(target);
target = ::_pbi::WireFormatLite::WriteEnumToArray(
2, this->_internal_json_type(), target);
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray(
_internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream);
@@ -4449,6 +4489,12 @@ size_t ColumnDataTypeExtension::ByteSizeLong() const {
*_impl_.type_ext_.decimal_type_);
break;
}
// .greptime.v1.JsonTypeExtension json_type = 2;
case kJsonType: {
total_size += 1 +
::_pbi::WireFormatLite::EnumSize(this->_internal_json_type());
break;
}
case TYPE_EXT_NOT_SET: {
break;
}
@@ -4477,6 +4523,10 @@ void ColumnDataTypeExtension::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg
from._internal_decimal_type());
break;
}
case kJsonType: {
_this->_internal_set_json_type(from._internal_json_type());
break;
}
case TYPE_EXT_NOT_SET: {
break;
}
+84
View File
@@ -213,6 +213,30 @@ inline bool ColumnDataType_Parse(
return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum<ColumnDataType>(
ColumnDataType_descriptor(), name, value);
}
enum JsonTypeExtension : int {
JSON_BINARY = 0,
JsonTypeExtension_INT_MIN_SENTINEL_DO_NOT_USE_ = std::numeric_limits<int32_t>::min(),
JsonTypeExtension_INT_MAX_SENTINEL_DO_NOT_USE_ = std::numeric_limits<int32_t>::max()
};
bool JsonTypeExtension_IsValid(int value);
constexpr JsonTypeExtension JsonTypeExtension_MIN = JSON_BINARY;
constexpr JsonTypeExtension JsonTypeExtension_MAX = JSON_BINARY;
constexpr int JsonTypeExtension_ARRAYSIZE = JsonTypeExtension_MAX + 1;
const ::PROTOBUF_NAMESPACE_ID::EnumDescriptor* JsonTypeExtension_descriptor();
template<typename T>
inline const std::string& JsonTypeExtension_Name(T enum_t_value) {
static_assert(::std::is_same<T, JsonTypeExtension>::value ||
::std::is_integral<T>::value,
"Incorrect type passed to function JsonTypeExtension_Name.");
return ::PROTOBUF_NAMESPACE_ID::internal::NameOfEnum(
JsonTypeExtension_descriptor(), enum_t_value);
}
inline bool JsonTypeExtension_Parse(
::PROTOBUF_NAMESPACE_ID::ConstStringParam name, JsonTypeExtension* value) {
return ::PROTOBUF_NAMESPACE_ID::internal::ParseNamedEnum<JsonTypeExtension>(
JsonTypeExtension_descriptor(), name, value);
}
// ===================================================================
class QueryContext_ExtensionsEntry_DoNotUse : public ::PROTOBUF_NAMESPACE_ID::internal::MapEntry<QueryContext_ExtensionsEntry_DoNotUse,
@@ -2764,6 +2788,7 @@ class ColumnDataTypeExtension final :
}
enum TypeExtCase {
kDecimalType = 1,
kJsonType = 2,
TYPE_EXT_NOT_SET = 0,
};
@@ -2846,6 +2871,7 @@ class ColumnDataTypeExtension final :
enum : int {
kDecimalTypeFieldNumber = 1,
kJsonTypeFieldNumber = 2,
};
// .greptime.v1.DecimalTypeExtension decimal_type = 1;
bool has_decimal_type() const;
@@ -2865,12 +2891,26 @@ class ColumnDataTypeExtension final :
::greptime::v1::DecimalTypeExtension* decimal_type);
::greptime::v1::DecimalTypeExtension* unsafe_arena_release_decimal_type();
// .greptime.v1.JsonTypeExtension json_type = 2;
bool has_json_type() const;
private:
bool _internal_has_json_type() const;
public:
void clear_json_type();
::greptime::v1::JsonTypeExtension json_type() const;
void set_json_type(::greptime::v1::JsonTypeExtension value);
private:
::greptime::v1::JsonTypeExtension _internal_json_type() const;
void _internal_set_json_type(::greptime::v1::JsonTypeExtension value);
public:
void clear_type_ext();
TypeExtCase type_ext_case() const;
// @@protoc_insertion_point(class_scope:greptime.v1.ColumnDataTypeExtension)
private:
class _Internal;
void set_has_decimal_type();
void set_has_json_type();
inline bool has_type_ext() const;
inline void clear_has_type_ext();
@@ -2883,6 +2923,7 @@ class ColumnDataTypeExtension final :
constexpr TypeExtUnion() : _constinit_{} {}
::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized _constinit_;
::greptime::v1::DecimalTypeExtension* decimal_type_;
int json_type_;
} type_ext_;
mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_;
uint32_t _oneof_case_[1];
@@ -4891,6 +4932,44 @@ inline ::greptime::v1::DecimalTypeExtension* ColumnDataTypeExtension::mutable_de
return _msg;
}
// .greptime.v1.JsonTypeExtension json_type = 2;
inline bool ColumnDataTypeExtension::_internal_has_json_type() const {
return type_ext_case() == kJsonType;
}
inline bool ColumnDataTypeExtension::has_json_type() const {
return _internal_has_json_type();
}
inline void ColumnDataTypeExtension::set_has_json_type() {
_impl_._oneof_case_[0] = kJsonType;
}
inline void ColumnDataTypeExtension::clear_json_type() {
if (_internal_has_json_type()) {
_impl_.type_ext_.json_type_ = 0;
clear_has_type_ext();
}
}
inline ::greptime::v1::JsonTypeExtension ColumnDataTypeExtension::_internal_json_type() const {
if (_internal_has_json_type()) {
return static_cast< ::greptime::v1::JsonTypeExtension >(_impl_.type_ext_.json_type_);
}
return static_cast< ::greptime::v1::JsonTypeExtension >(0);
}
inline ::greptime::v1::JsonTypeExtension ColumnDataTypeExtension::json_type() const {
// @@protoc_insertion_point(field_get:greptime.v1.ColumnDataTypeExtension.json_type)
return _internal_json_type();
}
inline void ColumnDataTypeExtension::_internal_set_json_type(::greptime::v1::JsonTypeExtension value) {
if (!_internal_has_json_type()) {
clear_type_ext();
set_has_json_type();
}
_impl_.type_ext_.json_type_ = value;
}
inline void ColumnDataTypeExtension::set_json_type(::greptime::v1::JsonTypeExtension value) {
_internal_set_json_type(value);
// @@protoc_insertion_point(field_set:greptime.v1.ColumnDataTypeExtension.json_type)
}
inline bool ColumnDataTypeExtension::has_type_ext() const {
return type_ext_case() != TYPE_EXT_NOT_SET;
}
@@ -5038,6 +5117,11 @@ template <>
inline const EnumDescriptor* GetEnumDescriptor< ::greptime::v1::ColumnDataType>() {
return ::greptime::v1::ColumnDataType_descriptor();
}
template <> struct is_proto_enum< ::greptime::v1::JsonTypeExtension> : ::std::true_type {};
template <>
inline const EnumDescriptor* GetEnumDescriptor< ::greptime::v1::JsonTypeExtension>() {
return ::greptime::v1::JsonTypeExtension_descriptor();
}
PROTOBUF_NAMESPACE_CLOSE