Kudu C++ client API
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
schema.h
1 //
2 // Licensed to the Apache Software Foundation (ASF) under one
3 // or more contributor license agreements. See the NOTICE file
4 // distributed with this work for additional information
5 // regarding copyright ownership. The ASF licenses this file
6 // to you under the Apache License, Version 2.0 (the
7 // "License"); you may not use this file except in compliance
8 // with the License. You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing,
13 // software distributed under the License is distributed on an
14 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 // KIND, either express or implied. See the License for the
16 // specific language governing permissions and limitations
17 // under the License.
18 #ifndef KUDU_CLIENT_SCHEMA_H
19 #define KUDU_CLIENT_SCHEMA_H
20 
21 #include <string>
22 #include <vector>
23 
24 #include "kudu/client/value.h"
25 #include "kudu/util/kudu_export.h"
26 
27 namespace kudu {
28 
29 class ColumnSchema;
30 class KuduPartialRow;
31 class Schema;
32 class TestWorkload;
33 
34 namespace tools {
35 class RemoteKsckMaster;
36 class ReplicaDumper;
37 }
38 
39 namespace client {
40 
41 namespace internal {
42 class GetTableSchemaRpc;
43 class LookupRpc;
44 class MetaCacheEntry;
45 class WriteRpc;
46 } // namespace internal
47 
48 class KuduClient;
49 class KuduSchema;
50 class KuduSchemaBuilder;
51 class KuduWriteOperation;
52 
54 class KUDU_EXPORT KuduColumnStorageAttributes {
55  public:
57  enum EncodingType {
58  AUTO_ENCODING = 0,
59  PLAIN_ENCODING = 1,
60  PREFIX_ENCODING = 2,
61  GROUP_VARINT = 3,
62  RLE = 4,
63  DICT_ENCODING = 5,
64  BIT_SHUFFLE = 6
65  };
66 
69  DEFAULT_COMPRESSION = 0,
70  NO_COMPRESSION = 1,
71  SNAPPY = 2,
72  LZ4 = 3,
73  ZLIB = 4,
74  };
75 
76 
88  KuduColumnStorageAttributes(EncodingType encoding = AUTO_ENCODING,
89  CompressionType compression = DEFAULT_COMPRESSION,
90  int32_t block_size = 0)
91  : encoding_(encoding),
92  compression_(compression),
93  block_size_(block_size) {
94  }
95 
97  const EncodingType encoding() const {
98  return encoding_;
99  }
100 
102  const CompressionType compression() const {
103  return compression_;
104  }
105 
107  std::string ToString() const;
108 
109  private:
110  EncodingType encoding_;
111  CompressionType compression_;
112  int32_t block_size_;
113 };
114 
116 class KUDU_EXPORT KuduColumnSchema {
117  public:
119  enum DataType {
120  INT8 = 0,
121  INT16 = 1,
122  INT32 = 2,
123  INT64 = 3,
124  STRING = 4,
125  BOOL = 5,
126  FLOAT = 6,
127  DOUBLE = 7,
128  BINARY = 8,
129  UNIXTIME_MICROS = 9,
130  TIMESTAMP = UNIXTIME_MICROS
131  };
132 
136  static std::string DataTypeToString(DataType type);
137 
154  KuduColumnSchema(const std::string &name,
155  DataType type,
156  bool is_nullable = false,
157  const void* default_value = NULL,
159 
164  KuduColumnSchema(const KuduColumnSchema& other);
165  ~KuduColumnSchema();
166 
172  KuduColumnSchema& operator=(const KuduColumnSchema& other);
173 
178  void CopyFrom(const KuduColumnSchema& other);
179 
185  bool Equals(const KuduColumnSchema& other) const;
186 
193  const std::string& name() const;
194 
196  DataType type() const;
197 
199  bool is_nullable() const;
201 
202  private:
203  friend class KuduColumnSpec;
204  friend class KuduSchema;
205  friend class KuduSchemaBuilder;
206  // KuduTableAlterer::Data needs to be a friend. Friending the parent class
207  // is transitive to nested classes. See http://tiny.cloudera.com/jwtui
208  friend class KuduTableAlterer;
209 
211 
212  // Owned.
213  ColumnSchema* col_;
214 };
215 
224 class KUDU_EXPORT KuduColumnSpec {
225  public:
237  KuduColumnSpec* Default(KuduValue* value);
238 
245 
254 
274  KuduColumnSpec* BlockSize(int32_t block_size);
275 
288  KuduColumnSpec* PrimaryKey();
289 
295  KuduColumnSpec* NotNull();
296 
302  KuduColumnSpec* Nullable();
303 
313 
323  KuduColumnSpec* RemoveDefault();
324 
330  KuduColumnSpec* RenameTo(const std::string& new_name);
332 
333  private:
334  class KUDU_NO_EXPORT Data;
335  friend class KuduSchemaBuilder;
336  friend class KuduTableAlterer;
337 
338  // This class should always be owned and deleted by one of its friends,
339  // not the user.
340  ~KuduColumnSpec();
341 
342  explicit KuduColumnSpec(const std::string& col_name);
343 
344  Status ToColumnSchema(KuduColumnSchema* col) const;
345 
346  // Owned.
347  Data* data_;
348 };
349 
371 class KUDU_EXPORT KuduSchemaBuilder {
372  public:
375 
382  KuduColumnSpec* AddColumn(const std::string& name);
383 
391  KuduSchemaBuilder* SetPrimaryKey(const std::vector<std::string>& key_col_names);
392 
402  Status Build(KuduSchema* schema);
403 
404  private:
405  class KUDU_NO_EXPORT Data;
406  // Owned.
407  Data* data_;
408 };
409 
411 class KUDU_EXPORT KuduSchema {
412  public:
413  KuduSchema();
414 
419  KuduSchema(const KuduSchema& other);
420  ~KuduSchema();
421 
428  KuduSchema& operator=(const KuduSchema& other);
429  void CopyFrom(const KuduSchema& other);
431 
441  Status Reset(const std::vector<KuduColumnSchema>& columns, int key_columns)
442  WARN_UNUSED_RESULT;
443 
450  bool Equals(const KuduSchema& other) const;
451 
455  KuduColumnSchema Column(size_t idx) const;
456 
458  size_t num_columns() const;
459 
468  void GetPrimaryKeyColumnIndexes(std::vector<int>* indexes) const;
469 
477  KuduPartialRow* NewRow() const;
478 
479  private:
480  friend class KuduClient;
481  friend class KuduScanner;
482  friend class KuduScanToken;
483  friend class KuduScanTokenBuilder;
484  friend class KuduSchemaBuilder;
485  friend class KuduTable;
486  friend class KuduTableCreator;
487  friend class KuduWriteOperation;
488  friend class ScanConfiguration;
489  friend class internal::GetTableSchemaRpc;
490  friend class internal::LookupRpc;
491  friend class internal::MetaCacheEntry;
492  friend class internal::WriteRpc;
493  friend class tools::RemoteKsckMaster;
494  friend class tools::ReplicaDumper;
495 
496  friend KuduSchema KuduSchemaFromSchema(const Schema& schema);
497 
498 
499  // For use by kudu tests.
500  explicit KuduSchema(const Schema& schema);
501 
502  // Private since we don't want users to rely on the first N columns
503  // being the keys.
504  size_t num_key_columns() const;
505 
506  // Owned.
507  Schema* schema_;
508 };
509 
510 } // namespace client
511 } // namespace kudu
512 #endif // KUDU_CLIENT_SCHEMA_H
A representation of a table's schema.
Definition: schema.h:411
A representation of an operation's outcome.
Definition: status.h:106
A constant cell value with a specific type.
Definition: value.h:33
Representation of column storage attributes.
Definition: schema.h:54
Builder API for specifying or altering a column within a table schema.
Definition: schema.h:224
Representation of the column schema.
Definition: schema.h:116
KuduColumnStorageAttributes(EncodingType encoding=AUTO_ENCODING, CompressionType compression=DEFAULT_COMPRESSION, int32_t block_size=0)
Definition: schema.h:88
const EncodingType encoding() const
Definition: schema.h:97
Builds scan tokens for a table.
Definition: client.h:1899
Alters an existing table based on the provided steps.
Definition: client.h:864
A handle for a connection to a cluster.
Definition: client.h:243
A representation of a table on a particular cluster.
Definition: client.h:759
This class is a representation of a single scan.
Definition: client.h:1481
A single-row write operation to be sent to a Kudu table.
Definition: write_op.h:55
CompressionType
Column compression types.
Definition: schema.h:68
Builder API for constructing a KuduSchema object.
Definition: schema.h:371
DataType
Supported data types for columns.
Definition: schema.h:119
A scan descriptor limited to a single physical contiguous location.
Definition: client.h:1839
A helper class to create a new table with the desired options.
Definition: client.h:544
const CompressionType compression() const
Definition: schema.h:102
A row which may only contain values for a subset of the columns.
Definition: partial_row.h:53
EncodingType
Column encoding types.
Definition: schema.h:57