From 1e52a954c421bcf23b053dace75125ac8bc0211c Mon Sep 17 00:00:00 2001 From: Sandeep Tamhankar Date: Wed, 18 Jan 2017 13:52:07 -0800 Subject: [PATCH 1/3] 356 - Map recognized custom types to built-in types --- src/result_response.cpp | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/result_response.cpp b/src/result_response.cpp index 4e5a5fec0..417a5f1f0 100644 --- a/src/result_response.cpp +++ b/src/result_response.cpp @@ -129,14 +129,7 @@ class DataTypeDecoder { default: if (value_type < CASS_VALUE_TYPE_LAST_ENTRY) { - if (data_type_cache_[value_type]) { - return data_type_cache_[value_type]; - } else { - DataType::Ptr data_type( - new DataType(static_cast(value_type))); - data_type_cache_[value_type] = data_type; - return data_type; - } + return decode_simple_type(value_type); } break; } @@ -148,6 +141,18 @@ class DataTypeDecoder { DataType::Ptr decode_custom() { StringRef class_name; buffer_ = decode_string(buffer_, &class_name); + +#define MAP_CUSTOM_TYPE(CUSTOM_TYPE, BUILTIN_TYPE) \ + if (class_name.to_string() == CUSTOM_TYPE) { \ + return decode_simple_type(BUILTIN_TYPE); \ + } + + MAP_CUSTOM_TYPE("org.apache.cassandra.db.marshal.ShortType", CASS_VALUE_TYPE_SMALL_INT); + MAP_CUSTOM_TYPE("org.apache.cassandra.db.marshal.ByteType", CASS_VALUE_TYPE_TINY_INT); + MAP_CUSTOM_TYPE("org.apache.cassandra.db.marshal.SimpleDateType", CASS_VALUE_TYPE_DATE); + MAP_CUSTOM_TYPE("org.apache.cassandra.db.marshal.TimeType", CASS_VALUE_TYPE_TIME); + + // If no mapping exists, return an actual custom type. return DataType::Ptr(new CustomType(class_name.to_string())); } @@ -160,6 +165,17 @@ class DataTypeDecoder { return DataType::Ptr(new CollectionType(collection_type, types, false)); } + DataType::Ptr decode_simple_type(uint16_t value_type) { + if (data_type_cache_[value_type]) { + return data_type_cache_[value_type]; + } else { + DataType::Ptr data_type( + new DataType(static_cast(value_type))); + data_type_cache_[value_type] = data_type; + return data_type; + } + } + DataType::Ptr decode_user_type() { StringRef keyspace; buffer_ = decode_string(buffer_, &keyspace); From 92431715e72fa65449a2fbfe2858186a5de136a2 Mon Sep 17 00:00:00 2001 From: Sandeep Tamhankar Date: Wed, 18 Jan 2017 15:40:36 -0800 Subject: [PATCH 2/3] 356 - Map recognized custom types to built-in types. --- src/result_response.cpp | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/result_response.cpp b/src/result_response.cpp index 417a5f1f0..939da21c6 100644 --- a/src/result_response.cpp +++ b/src/result_response.cpp @@ -104,7 +104,10 @@ namespace cass { class DataTypeDecoder { public: DataTypeDecoder(char* input) - : buffer_(input) { } + : buffer_(input) + { + native_types_.init_class_names(); + } char* buffer() const { return buffer_; } @@ -142,18 +145,12 @@ class DataTypeDecoder { StringRef class_name; buffer_ = decode_string(buffer_, &class_name); -#define MAP_CUSTOM_TYPE(CUSTOM_TYPE, BUILTIN_TYPE) \ - if (class_name.to_string() == CUSTOM_TYPE) { \ - return decode_simple_type(BUILTIN_TYPE); \ - } - - MAP_CUSTOM_TYPE("org.apache.cassandra.db.marshal.ShortType", CASS_VALUE_TYPE_SMALL_INT); - MAP_CUSTOM_TYPE("org.apache.cassandra.db.marshal.ByteType", CASS_VALUE_TYPE_TINY_INT); - MAP_CUSTOM_TYPE("org.apache.cassandra.db.marshal.SimpleDateType", CASS_VALUE_TYPE_DATE); - MAP_CUSTOM_TYPE("org.apache.cassandra.db.marshal.TimeType", CASS_VALUE_TYPE_TIME); - - // If no mapping exists, return an actual custom type. - return DataType::Ptr(new CustomType(class_name.to_string())); + const DataType::ConstPtr& type = native_types_.by_class_name(class_name.to_string()); + if (type == DataType::NIL) + // If no mapping exists, return an actual custom type. + return DataType::Ptr(new CustomType(class_name.to_string())); + else + return type->copy(); } DataType::Ptr decode_collection(CassValueType collection_type) { @@ -211,6 +208,7 @@ class DataTypeDecoder { private: char* buffer_; + NativeDataTypes native_types_; DataType::Ptr data_type_cache_[CASS_VALUE_TYPE_LAST_ENTRY]; }; From af209bc0df613b69de76b105eb92cca7aef16a47 Mon Sep 17 00:00:00 2001 From: Sandeep Tamhankar Date: Wed, 18 Jan 2017 16:05:00 -0800 Subject: [PATCH 3/3] 356 - Map recognized custom types to builtin types. * Minor cleanup. --- src/result_response.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/result_response.cpp b/src/result_response.cpp index 939da21c6..2e8aa2750 100644 --- a/src/result_response.cpp +++ b/src/result_response.cpp @@ -104,10 +104,9 @@ namespace cass { class DataTypeDecoder { public: DataTypeDecoder(char* input) - : buffer_(input) - { - native_types_.init_class_names(); - } + : buffer_(input) { + native_types_.init_class_names(); + } char* buffer() const { return buffer_; } @@ -153,15 +152,6 @@ class DataTypeDecoder { return type->copy(); } - DataType::Ptr decode_collection(CassValueType collection_type) { - DataType::Vec types; - types.push_back(decode()); - if (collection_type == CASS_VALUE_TYPE_MAP) { - types.push_back(decode()); - } - return DataType::Ptr(new CollectionType(collection_type, types, false)); - } - DataType::Ptr decode_simple_type(uint16_t value_type) { if (data_type_cache_[value_type]) { return data_type_cache_[value_type]; @@ -173,6 +163,15 @@ class DataTypeDecoder { } } + DataType::Ptr decode_collection(CassValueType collection_type) { + DataType::Vec types; + types.push_back(decode()); + if (collection_type == CASS_VALUE_TYPE_MAP) { + types.push_back(decode()); + } + return DataType::Ptr(new CollectionType(collection_type, types, false)); + } + DataType::Ptr decode_user_type() { StringRef keyspace; buffer_ = decode_string(buffer_, &keyspace); @@ -208,8 +207,8 @@ class DataTypeDecoder { private: char* buffer_; - NativeDataTypes native_types_; DataType::Ptr data_type_cache_[CASS_VALUE_TYPE_LAST_ENTRY]; + NativeDataTypes native_types_; }; bool ResultResponse::decode(int version, char* input, size_t size) {