0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ColumnPredicate.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
22 #include <Common/Compat.h>
23 
24 #include "ColumnPredicate.h"
25 
26 #include <Common/Logger.h>
27 #include <Common/Serialization.h>
28 
29 using namespace Hypertable;
30 using namespace Hypertable::Lib;
31 using namespace std;
32 
34  return 1;
35 }
36 
38  return 4 + Serialization::encoded_length_vstr(column_family) +
39  Serialization::encoded_length_vstr(column_qualifier_len) +
41 }
42 
67 void ColumnPredicate::encode_internal(uint8_t **bufp) const {
68  Serialization::encode_vstr(bufp, column_family);
69  Serialization::encode_vstr(bufp, column_qualifier, column_qualifier_len);
70  Serialization::encode_vstr(bufp, value, value_len);
71  Serialization::encode_i32(bufp, operation);
72 }
73 
74 void ColumnPredicate::decode_internal(uint8_t version, const uint8_t **bufp,
75  size_t *remainp) {
76  HT_TRY("decoding column predicate",
77  column_family = Serialization::decode_vstr(bufp, remainp);
78  column_qualifier = Serialization::decode_vstr(bufp, remainp, &column_qualifier_len);
79  value = Serialization::decode_vstr(bufp, remainp, &value_len);
80  operation = Serialization::decode_i32(bufp, remainp));
81 }
82 
83 const string ColumnPredicate::render_hql() const {
84  bool exists = (operation & ColumnPredicate::VALUE_MATCH) == 0;
85  string hql;
86  hql.reserve(strlen(column_family) + column_qualifier_len + value_len + 16);
87  if (exists)
88  hql.append("Exists(");
89  hql.append(column_family);
90  if (column_qualifier_len) {
91  hql.append(":");
93  hql.append(column_qualifier);
94  else if (operation & ColumnPredicate::QUALIFIER_PREFIX_MATCH) {
95  hql.append(column_qualifier);
96  hql.append("*");
97  }
98  else if (operation & ColumnPredicate::QUALIFIER_REGEX_MATCH) {
99  hql.append("/");
100  hql.append(column_qualifier);
101  hql.append("/");
102  }
103  }
104  if (exists) {
105  hql.append(")");
106  return hql;
107  }
108  HT_ASSERT(value);
109  if (operation & ColumnPredicate::EXACT_MATCH)
110  hql.append(" = \"");
111  else if (operation & ColumnPredicate::PREFIX_MATCH)
112  hql.append(" =^ \"");
113  else if (operation & ColumnPredicate::REGEX_MATCH)
114  hql.append(" =~ /");
115  hql.append(value);
116  if (operation & ColumnPredicate::REGEX_MATCH)
117  hql.append("/");
118  else
119  hql.append("\"");
120  return hql;
121 }
122 
124 std::ostream &Hypertable::Lib::operator<<(std::ostream &os, const ColumnPredicate &cp) {
125  os << "{ColumnPredicate";
126  if (cp.column_family)
127  os << " column_family=" << cp.column_family;
128  if (cp.column_qualifier)
129  os << " column_qualifier=" << cp.column_qualifier << ",len=" << cp.column_qualifier_len;
130  if (cp.value)
131  os << " value=" << cp.value << ",len=" << cp.value_len;
132  os << " operation=" << cp.operation << "}";
133  return os;
134 }
char * decode_vstr(const uint8_t **bufp, size_t *remainp)
Decode a vstr (vint64, data, null).
void encode_internal(uint8_t **bufp) const override
Writes serialized representation of object to a buffer.
const string render_hql() const
Renders predicate as HQL.
STL namespace.
size_t encoded_length_vstr(size_t len)
Computes the encoded length of vstr (vint64, data, null)
uint32_t decode_i32(const uint8_t **bufp, size_t *remainp)
Decode a 32-bit integer in little-endian order.
#define HT_ASSERT(_e_)
Definition: Logger.h:396
ostream & operator<<(ostream &os, const CellInterval &ci)
Logging routines and macros.
void encode_i32(uint8_t **bufp, uint32_t val)
Encode a 32-bit integer in little-endian order.
Compatibility Macros for C/C++.
Functions to serialize/deserialize primitives to/from a memory buffer.
Represents a column predicate (e.g.
Hypertable library.
Definition: CellInterval.h:30
void decode_internal(uint8_t version, const uint8_t **bufp, size_t *remainp) override
Reads serialized representation of object from a buffer.
void encode_vstr(uint8_t **bufp, const void *buf, size_t len)
Encode a buffer as variable length string (vint64, data, null)
Hypertable definitions
uint8_t encoding_version() const override
Returns encoding version.
size_t encoded_length_internal() const override
Returns internal serialized length.
#define HT_TRY(_s_, _code_)
Definition: Error.h:517