0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ThriftHelper.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; either version 3
9  * of the 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 Hypertable. If not, see <http://www.gnu.org/licenses/>
18  */
19 
20 #include <Common/Compat.h>
21 
22 #include "ThriftHelper.h"
23 
24 #include <Common/TimeInline.h>
25 
26 #include <iostream>
27 
28 namespace Hypertable { namespace ThriftGen {
29 
30 std::ostream &operator<<(std::ostream &out, const CellAsArray &cell) {
31  size_t len = cell.size();
32 
33  out <<"CellAsArray(";
34 
35  if (len > 0)
36  out <<" row='"<< cell[0] <<"'";
37 
38  if (len > 1)
39  out <<" cf='"<< cell[1] <<"'";
40 
41  if (len > 2)
42  out <<" cq='"<< cell[2] <<"'";
43 
44  if (len > 3)
45  out <<" value='"<< cell[3] <<"'";
46 
47  if (len > 4)
48  out << " timestamp="<< cell[4];
49 
50  if (len > 5)
51  out <<" revision="<< cell[5];
52 
53  if (len > 6)
54  out << " flag="<< cell[6];
55 
56  return out <<")";
57 }
58 
59 // must be synced with AUTO_ASSIGN in Hypertable/Lib/KeySpec.h
60 const int64_t AUTO_ASSIGN = INT64_MIN + 2;
61 
62 Cell
63 make_cell(const char *row, const char *cf, const char *cq,
64  const std::string &value, int64_t ts, int64_t rev,
65  KeyFlag::type flag) {
66  Cell cell;
67 
68  cell.key.row = row;
69  cell.key.column_family = cf;
70  cell.key.timestamp = ts;
71  cell.key.revision = rev;
72  cell.key.flag = flag;
73  cell.key.__isset.row = cell.key.__isset.column_family = cell.key.__isset.timestamp
74  = cell.key.__isset.revision = cell.key.__isset.flag = true;
75 
76  if (cq) {
77  cell.key.column_qualifier = cq;
78  cell.key.__isset.column_qualifier = true;
79  }
80  if (value.size()) {
81  cell.value = value;
82  cell.__isset.value = true;
83  }
84  return cell;
85 }
86 
87 Cell
88 make_cell(const char *row, const char *cf, const char *cq,
89  const std::string &value, const char *ts, const char *rev,
90  KeyFlag::type flag) {
91  int64_t revn = rev ? atoll(rev) : AUTO_ASSIGN;
92 
93  if (ts)
94  return make_cell(row, cf, cq, value, parse_ts(ts), revn, flag);
95  else
96  return make_cell(row, cf, cq, value, AUTO_ASSIGN, revn, flag);
97 }
98 
99 }} // namespace Hypertable::Thrift
100 
const int64_t AUTO_ASSIGN
Definition: ThriftHelper.cc:60
const char * column_qualifier
Definition: Cell.h:68
uint64_t revision
Definition: Cell.h:70
Compatibility Macros for C/C++.
std::ostream & operator<<(std::ostream &out, const CellAsArray &cell)
Definition: ThriftHelper.cc:30
Cell make_cell(const char *row, const char *cf, const char *cq, const std::string &value, int64_t ts, int64_t rev, KeyFlag::type flag)
Definition: ThriftHelper.cc:63
int64_t parse_ts(const char *ts)
Inline function which parses a string with a timestamp in localtime and returns a 64bit nanosecond ti...
Definition: TimeInline.h:64
Hypertable definitions
An inline helper function to parse timestamps in YYYY-mm-dd[ HH:MM[:SS[.SS|:NS]]] format...
const char * column_family
Definition: Cell.h:67
uint8_t flag
Definition: Cell.h:73
Encapsulates decomposed key and value.
Definition: Cell.h:32
const uint8_t * value
Definition: Cell.h:71
int64_t timestamp
Definition: Cell.h:69