diff --git a/cql3/Cql.g b/cql3/Cql.g index bad935ef0e..622783b0a6 100644 --- a/cql3/Cql.g +++ b/cql3/Cql.g @@ -153,44 +153,39 @@ using operations_type = std::vectorsyntax_error(*this, msg); } - std::map convert_property_map(shared_ptr map) { - throw std::runtime_error("not implemented"); -#if 0 - if (map == null || map.entries == null || map.entries.isEmpty()) - return Collections.emptyMap(); - - Map res = new HashMap(map.entries.size()); - - for (Pair entry : map.entries) - { + std::unordered_map convert_property_map(shared_ptr map) { + if (!map || map->entries.empty()) { + return std::unordered_map{}; + } + std::unordered_map res{map->entries.size()}; + for (auto&& entry : map->entries) { // Because the parser tries to be smart and recover on error (to // allow displaying more than one error I suppose), we have null // entries in there. Just skip those, a proper error will be thrown in the end. - if (entry.left == null || entry.right == null) - break; - - if (!(entry.left instanceof Constants.Literal)) - { - String msg = "Invalid property name: " + entry.left; - if (entry.left instanceof AbstractMarker.Raw) - msg += " (bind variables are not supported in DDL queries)"; - addRecognitionError(msg); + if (!entry.first || !entry.second) { break; } - if (!(entry.right instanceof Constants.Literal)) - { - String msg = "Invalid property value: " + entry.right + " for property: " + entry.left; - if (entry.right instanceof AbstractMarker.Raw) + auto left = dynamic_pointer_cast(entry.first); + if (!left) { + sstring msg = "Invalid property name: " + entry.first->to_string(); + if (dynamic_pointer_cast(entry.first)) { msg += " (bind variables are not supported in DDL queries)"; - addRecognitionError(msg); + } + add_recognition_error(msg); break; } - - res.put(((Constants.Literal)entry.left).getRawText(), ((Constants.Literal)entry.right).getRawText()); + auto right = dynamic_pointer_cast(entry.second); + if (!right) { + sstring msg = "Invalid property value: " + entry.first->to_string() + " for property: " + entry.second->to_string(); + if (dynamic_pointer_cast(entry.second)) { + msg += " (bind variables are not supported in DDL queries)"; + } + add_recognition_error(msg); + break; + } + res.emplace(left->get_raw_text(), right->get_raw_text()); } - return res; -#endif } void add_raw_update(std::vector,::shared_ptr>>& operations,