From df02fc6b06fed5dc03b2e72bc8bb140b519da4bf Mon Sep 17 00:00:00 2001 From: Piotr Sarna Date: Sun, 5 Apr 2020 12:25:19 +0200 Subject: [PATCH] alternator: add fallback serialization for all types While most types (e.g. boolean) are not valid key types for alternator users, system tables derived from Scylla may still use this type for keys, e.g. system_auth.roles. Note that types which are not directly supported by alternator (e.g. double) will not be representable out-of-the-box - instead, they simply fall back to string, which is both human-readable and supported by alternator. --- alternator/serialization.cc | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/alternator/serialization.cc b/alternator/serialization.cc index d9050401a6..2a7b1a65ee 100644 --- a/alternator/serialization.cc +++ b/alternator/serialization.cc @@ -153,7 +153,9 @@ std::string type_to_string(data_type type) { }; auto it = types.find(type); if (it == types.end()) { - throw std::runtime_error(format("Unknown type {}", type->name())); + // fall back to string, in order to be able to present + // internal Scylla types in a human-readable way + return "S"; } return it->second; } @@ -205,8 +207,11 @@ rjson::value json_key_column_value(bytes_view cell, const column_definition& col auto s = to_json_string(*decimal_type, bytes(cell)); return rjson::from_string(s); } else { - // We shouldn't get here, we shouldn't see such key columns. - throw std::runtime_error(format("Unexpected key type: {}", column.type->name())); + // Support for arbitrary key types is useful for parsing values of virtual tables, + // which can involve any type supported by Scylla. + // In order to guarantee that the returned type is parsable by alternator clients, + // they are represented simply as strings. + return rjson::from_string(column.type->to_string(bytes(cell))); } }