Kudu C++ client API
 All Classes Namespaces 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 TsAdminClient;
36 }
37 
38 namespace client {
39 
40 namespace internal {
41 class GetTableSchemaRpc;
42 class LookupRpc;
43 class MetaCacheEntry;
44 class WriteRpc;
45 } // namespace internal
46 
47 class KuduClient;
48 class KuduSchema;
49 class KuduSchemaBuilder;
50 class KuduWriteOperation;
51 
53 class KUDU_EXPORT KuduColumnStorageAttributes {
54  public:
56  enum EncodingType {
57  AUTO_ENCODING = 0,
58  PLAIN_ENCODING = 1,
59  PREFIX_ENCODING = 2,
60  GROUP_VARINT = 3,
61  RLE = 4,
62  DICT_ENCODING = 5,
63  BIT_SHUFFLE = 6
64  };
65 
68  DEFAULT_COMPRESSION = 0,
69  NO_COMPRESSION = 1,
70  SNAPPY = 2,
71  LZ4 = 3,
72  ZLIB = 4,
73  };
74 
75 
87  KuduColumnStorageAttributes(EncodingType encoding = AUTO_ENCODING,
88  CompressionType compression = DEFAULT_COMPRESSION,
89  int32_t block_size = 0)
90  : encoding_(encoding),
91  compression_(compression),
92  block_size_(block_size) {
93  }
94 
96  const EncodingType encoding() const {
97  return encoding_;
98  }
99 
101  const CompressionType compression() const {
102  return compression_;
103  }
104 
106  std::string ToString() const;
107 
108  private:
109  EncodingType encoding_;
110  CompressionType compression_;
111  int32_t block_size_;
112 };
113 
115 class KUDU_EXPORT KuduColumnSchema {
116  public:
118  enum DataType {
119  INT8 = 0,
120  INT16 = 1,
121  INT32 = 2,
122  INT64 = 3,
123  STRING = 4,
124  BOOL = 5,
125  FLOAT = 6,
126  DOUBLE = 7,
127  BINARY = 8,
128  TIMESTAMP = 9
129  };
130 
134  static std::string DataTypeToString(DataType type);
135 
152  KuduColumnSchema(const std::string &name,
153  DataType type,
154  bool is_nullable = false,
155  const void* default_value = NULL,
157 
162  KuduColumnSchema(const KuduColumnSchema& other);
163  ~KuduColumnSchema();
164 
170  KuduColumnSchema& operator=(const KuduColumnSchema& other);
171 
176  void CopyFrom(const KuduColumnSchema& other);
177 
183  bool Equals(const KuduColumnSchema& other) const;
184 
191  const std::string& name() const;
192 
194  DataType type() const;
195 
197  bool is_nullable() const;
199 
200  private:
201  friend class KuduColumnSpec;
202  friend class KuduSchema;
203  friend class KuduSchemaBuilder;
204  // KuduTableAlterer::Data needs to be a friend. Friending the parent class
205  // is transitive to nested classes. See http://tiny.cloudera.com/jwtui
206  friend class KuduTableAlterer;
207 
209 
210  // Owned.
211  ColumnSchema* col_;
212 };
213 
222 class KUDU_EXPORT KuduColumnSpec {
223  public:
235  KuduColumnSpec* Default(KuduValue* value);
236 
243 
252 
272  KuduColumnSpec* BlockSize(int32_t block_size);
273 
286  KuduColumnSpec* PrimaryKey();
287 
293  KuduColumnSpec* NotNull();
294 
300  KuduColumnSpec* Nullable();
301 
311 
321  KuduColumnSpec* RemoveDefault();
322 
328  KuduColumnSpec* RenameTo(const std::string& new_name);
330 
331  private:
332  class KUDU_NO_EXPORT Data;
333  friend class KuduSchemaBuilder;
334  friend class KuduTableAlterer;
335 
336  // This class should always be owned and deleted by one of its friends,
337  // not the user.
338  ~KuduColumnSpec();
339 
340  explicit KuduColumnSpec(const std::string& col_name);
341 
342  Status ToColumnSchema(KuduColumnSchema* col) const;
343 
344  // Owned.
345  Data* data_;
346 };
347 
369 class KUDU_EXPORT KuduSchemaBuilder {
370  public:
373 
380  KuduColumnSpec* AddColumn(const std::string& name);
381 
389  KuduSchemaBuilder* SetPrimaryKey(const std::vector<std::string>& key_col_names);
390 
400  Status Build(KuduSchema* schema);
401 
402  private:
403  class KUDU_NO_EXPORT Data;
404  // Owned.
405  Data* data_;
406 };
407 
409 class KUDU_EXPORT KuduSchema {
410  public:
411  KuduSchema();
412 
417  KuduSchema(const KuduSchema& other);
418  ~KuduSchema();
419 
426  KuduSchema& operator=(const KuduSchema& other);
427  void CopyFrom(const KuduSchema& other);
429 
439  Status Reset(const std::vector<KuduColumnSchema>& columns, int key_columns)
440  WARN_UNUSED_RESULT;
441 
448  bool Equals(const KuduSchema& other) const;
449 
453  KuduColumnSchema Column(size_t idx) const;
454 
456  size_t num_columns() const;
457 
466  void GetPrimaryKeyColumnIndexes(std::vector<int>* indexes) const;
467 
475  KuduPartialRow* NewRow() const;
476 
477  private:
478  friend class KuduClient;
479  friend class KuduScanner;
480  friend class KuduScanToken;
481  friend class KuduScanTokenBuilder;
482  friend class KuduSchemaBuilder;
483  friend class KuduTable;
484  friend class KuduTableCreator;
485  friend class KuduWriteOperation;
486  friend class ScanConfiguration;
487  friend class internal::GetTableSchemaRpc;
488  friend class internal::LookupRpc;
489  friend class internal::MetaCacheEntry;
490  friend class internal::WriteRpc;
491  friend class kudu::tools::TsAdminClient;
492 
493  friend KuduSchema KuduSchemaFromSchema(const Schema& schema);
494 
495 
496  // For use by kudu tests.
497  explicit KuduSchema(const Schema& schema);
498 
499  // Private since we don't want users to rely on the first N columns
500  // being the keys.
501  size_t num_key_columns() const;
502 
503  // Owned.
504  Schema* schema_;
505 };
506 
507 } // namespace client
508 } // namespace kudu
509 #endif // KUDU_CLIENT_SCHEMA_H
A representation of a table's schema.
Definition: schema.h:409
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:53
Builder API for specifying or altering a column within a table schema.
Definition: schema.h:222
Representation of the column schema.
Definition: schema.h:115
KuduColumnStorageAttributes(EncodingType encoding=AUTO_ENCODING, CompressionType compression=DEFAULT_COMPRESSION, int32_t block_size=0)
Definition: schema.h:87
const EncodingType encoding() const
Definition: schema.h:96
Builds scan tokens for a table.
Definition: client.h:1724
Alters an existing table based on the provided steps.
Definition: client.h:749
A handle for a connection to a cluster.
Definition: client.h:242
A representation of a table on a particular cluster.
Definition: client.h:648
This class is a representation of a single scan.
Definition: client.h:1299
A single-row write operation to be sent to a Kudu table.
Definition: write_op.h:55
CompressionType
Column compression types.
Definition: schema.h:67
Builder API for constructing a KuduSchema object.
Definition: schema.h:369
DataType
Supported data types for columns.
Definition: schema.h:118
A scan descriptor limited to a single physical contiguous location.
Definition: client.h:1657
A helper class to create a new table with the desired options.
Definition: client.h:433
const CompressionType compression() const
Definition: schema.h:101
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:56