query: Add facilities for printing query request

This commit is contained in:
Tomasz Grabiec
2015-03-19 21:29:24 +01:00
parent bdbd5547e3
commit ebfc1ffb20
4 changed files with 98 additions and 0 deletions

View File

@@ -305,6 +305,7 @@ urchin_core = (['database.cc',
'dht/i_partitioner.cc',
'dht/murmur3_partitioner.cc',
'unimplemented.cc',
'query.cc',
]
+ [Antlr3Grammar('cql3/Cql.g')]
+ [Thrift('interface/cassandra.thrift', 'Cassandra')]

15
keys.hh
View File

@@ -281,3 +281,18 @@ public:
return from_exploded(s, prefix.components());
}
};
static inline
std::ostream& operator<<(std::ostream& out, const partition_key& pk) {
return out << "pk{" << to_hex(pk) << "}";
}
static inline
std::ostream& operator<<(std::ostream& out, const clustering_key& ck) {
return out << "ck{" << to_hex(ck) << "}";
}
static inline
std::ostream& operator<<(std::ostream& out, const clustering_key_prefix& ckp) {
return out << "ckp{" << to_hex(ckp) << "}";
}

39
query.cc Normal file
View File

@@ -0,0 +1,39 @@
/*
* Copyright (C) 2015 Cloudius Systems, Ltd.
*/
#include "query.hh"
namespace query {
template <typename T>
sstring join(const std::vector<T>& v, sstring sep) {
std::ostringstream oss;
size_t left = v.size();
for (auto&& item : v) {
oss << item;
if (--left) {
oss << ", ";
}
}
return oss.str();
}
std::ostream& operator<<(std::ostream& out, const partition_slice& ps) {
return out << "{"
<< "regular_cols=[" << join(ps.regular_columns, ", ") << "]"
<< ", static_cols=[" << join(ps.static_columns, ", ") << "]"
<< ", rows=[" << join(ps.row_ranges, ", ") << "]"
<< "}";
}
std::ostream& operator<<(std::ostream& out, const read_command& r) {
return out << "read_command{"
<< "ks=" << r.keyspace
<< ", cf=" << r.column_family
<< ", pks=[" << join(r.partition_ranges, ", ") << "]"
<< ", slice=" << r.slice << ""
<< ", limit=" << r.row_limit << "}";
}
}

View File

@@ -73,8 +73,50 @@ public:
const T& end_value() const {
return _end->value();
}
const optional<bound>& start() const {
return _start;
}
const optional<bound>& end() const {
return _end;
}
template<typename U>
friend std::ostream& operator<<(std::ostream& out, const range<U>& r);
};
template<typename U>
std::ostream& operator<<(std::ostream& out, const range<U>& r) {
if (r.is_singular()) {
return out << "==" << r.start_value();
}
if (!r.start()) {
out << "(-inf, ";
} else {
if (r.start()->is_inclusive()) {
out << "[";
} else {
out << "(";
}
out << r.start()->value() << ", ";
}
if (!r.end()) {
out << "+inf)";
} else {
out << r.end()->value();
if (r.end()->is_inclusive()) {
out << "]";
} else {
out << ")";
}
}
return out;
}
using partition_range = range<partition_key>;
using clustering_range = range<clustering_key_prefix>;
@@ -142,6 +184,7 @@ public:
, slice(std::move(slice))
, row_limit(row_limit)
{ }
friend std::ostream& operator<<(std::ostream& out, const read_command& r);
};
}