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 
89  EncodingType encoding = AUTO_ENCODING,
90  CompressionType compression = DEFAULT_COMPRESSION,
91  int32_t block_size = 0)
92  ATTRIBUTE_DEPRECATED("this constructor will be private in a future release")
93  : encoding_(encoding),
94  compression_(compression),
95  block_size_(block_size) {
96  }
97 
99  const EncodingType encoding() const {
100  return encoding_;
101  }
102 
104  const CompressionType compression() const {
105  return compression_;
106  }
107 
109  std::string ToString() const;
110 
111  private:
112  EncodingType encoding_;
113  CompressionType compression_;
114  int32_t block_size_;
115 };
116 
118 class KUDU_EXPORT KuduColumnSchema {
119  public:
121  enum DataType {
122  INT8 = 0,
123  INT16 = 1,
124  INT32 = 2,
125  INT64 = 3,
126  STRING = 4,
127  BOOL = 5,
128  FLOAT = 6,
129  DOUBLE = 7,
130  BINARY = 8,
131  UNIXTIME_MICROS = 9,
132  TIMESTAMP = UNIXTIME_MICROS
133  };
134 
138  static std::string DataTypeToString(DataType type);
139 
156  KuduColumnSchema(const std::string &name,
157  DataType type,
158  bool is_nullable = false,
159  const void* default_value = NULL,
161  ATTRIBUTE_DEPRECATED("use KuduSchemaBuilder instead");
162 
167  KuduColumnSchema(const KuduColumnSchema& other);
168  ~KuduColumnSchema();
169 
175  KuduColumnSchema& operator=(const KuduColumnSchema& other);
176 
181  void CopyFrom(const KuduColumnSchema& other);
182 
188  bool Equals(const KuduColumnSchema& other) const;
189 
196  const std::string& name() const;
197 
199  DataType type() const;
200 
202  bool is_nullable() const;
204 
205  private:
206  friend class KuduColumnSpec;
207  friend class KuduSchema;
208  friend class KuduSchemaBuilder;
209  // KuduTableAlterer::Data needs to be a friend. Friending the parent class
210  // is transitive to nested classes. See http://tiny.cloudera.com/jwtui
211  friend class KuduTableAlterer;
212 
214 
215  // Owned.
216  ColumnSchema* col_;
217 };
218 
227 class KUDU_EXPORT KuduColumnSpec {
228  public:
240  KuduColumnSpec* Default(KuduValue* value);
241 
247  KuduColumnSpec* Compression(KuduColumnStorageAttributes::CompressionType compression);
248 
256  KuduColumnSpec* Encoding(KuduColumnStorageAttributes::EncodingType encoding);
257 
277  KuduColumnSpec* BlockSize(int32_t block_size);
278 
291  KuduColumnSpec* PrimaryKey();
292 
298  KuduColumnSpec* NotNull();
299 
305  KuduColumnSpec* Nullable();
306 
314  KuduColumnSpec* Type(KuduColumnSchema::DataType type);
316 
326  KuduColumnSpec* RemoveDefault();
327 
333  KuduColumnSpec* RenameTo(const std::string& new_name);
335 
336  private:
337  class KUDU_NO_EXPORT Data;
338  friend class KuduSchemaBuilder;
339  friend class KuduTableAlterer;
340 
341  // This class should always be owned and deleted by one of its friends,
342  // not the user.
343  ~KuduColumnSpec();
344 
345  explicit KuduColumnSpec(const std::string& col_name);
346 
347  Status ToColumnSchema(KuduColumnSchema* col) const;
348 
349  // Owned.
350  Data* data_;
351 };
352 
374 class KUDU_EXPORT KuduSchemaBuilder {
375  public:
378 
385  KuduColumnSpec* AddColumn(const std::string& name);
386 
394  KuduSchemaBuilder* SetPrimaryKey(const std::vector<std::string>& key_col_names);
395 
405  Status Build(KuduSchema* schema);
406 
407  private:
408  class KUDU_NO_EXPORT Data;
409  // Owned.
410  Data* data_;
411 };
412 
414 class KUDU_EXPORT KuduSchema {
415  public:
416  KuduSchema();
417 
422  KuduSchema(const KuduSchema& other);
423  ~KuduSchema();
424 
431  KuduSchema& operator=(const KuduSchema& other);
432  void CopyFrom(const KuduSchema& other);
434 
444  Status Reset(const std::vector<KuduColumnSchema>& columns, int key_columns)
445  ATTRIBUTE_DEPRECATED("this method will be removed in a future release")
446  WARN_UNUSED_RESULT;
447 
454  bool Equals(const KuduSchema& other) const;
455 
459  KuduColumnSchema Column(size_t idx) const;
460 
462  size_t num_columns() const;
463 
472  void GetPrimaryKeyColumnIndexes(std::vector<int>* indexes) const;
473 
481  KuduPartialRow* NewRow() const;
482 
483  private:
484  friend class KuduClient;
485  friend class KuduScanner;
486  friend class KuduScanToken;
487  friend class KuduScanTokenBuilder;
488  friend class KuduSchemaBuilder;
489  friend class KuduTable;
490  friend class KuduTableCreator;
491  friend class KuduWriteOperation;
492  friend class ScanConfiguration;
493  friend class internal::GetTableSchemaRpc;
494  friend class internal::LookupRpc;
495  friend class internal::MetaCacheEntry;
496  friend class internal::WriteRpc;
497  friend class tools::RemoteKsckMaster;
498  friend class tools::ReplicaDumper;
499 
500  friend KuduSchema KuduSchemaFromSchema(const Schema& schema);
501 
502 
503  // For use by kudu tests.
504  explicit KuduSchema(const Schema& schema);
505 
506  // Private since we don't want users to rely on the first N columns
507  // being the keys.
508  size_t num_key_columns() const;
509 
510  // Owned.
511  Schema* schema_;
512 };
513 
514 } // namespace client
515 } // namespace kudu
516 #endif // KUDU_CLIENT_SCHEMA_H
A representation of a table's schema.
Definition: schema.h:414
A representation of an operation's outcome.
Definition: status.h:116
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:227
Representation of the column schema.
Definition: schema.h:118
const EncodingType encoding() const
Definition: schema.h:99
Builds scan tokens for a table.
Definition: client.h:1978
Alters an existing table based on the provided steps.
Definition: client.h:918
KuduColumnStorageAttributes(EncodingType encoding=AUTO_ENCODING, CompressionType compression=DEFAULT_COMPRESSION, int32_t block_size=0) ATTRIBUTE_DEPRECATED("this const ructor will be private in a future release")
Definition: schema.h:88
A handle for a connection to a cluster.
Definition: client.h:235
A representation of a table on a particular cluster.
Definition: client.h:787
This class is a representation of a single scan.
Definition: client.h:1548
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:374
DataType
Supported data types for columns.
Definition: schema.h:121
A scan descriptor limited to a single physical contiguous location.
Definition: client.h:1918
A helper class to create a new table with the desired options.
Definition: client.h:571
const CompressionType compression() const
Definition: schema.h:104
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