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 // NOTE: using stdint.h instead of cstdint because this file is supposed
22 // to be processed by a compiler lacking C++11 support.
23 #include <stdint.h>
24 
25 #include <cstddef>
26 #include <string>
27 #include <vector>
28 
29 #ifdef KUDU_HEADERS_NO_STUBS
30 #include "kudu/gutil/port.h"
31 #else
32 #include "kudu/client/stubs.h"
33 #endif
34 
35 #include "kudu/util/kudu_export.h"
36 #include "kudu/util/status.h"
37 
38 namespace kudu {
39 
40 class ColumnSchema;
41 struct ColumnSchemaDelta;
42 class KuduPartialRow;
43 class Schema;
44 class Slice;
45 
46 namespace tools {
47 class RemoteKsckMaster;
48 class ReplicaDumper;
49 }
50 
51 namespace client {
52 
53 namespace internal {
54 class GetTableSchemaRpc;
55 class LookupRpc;
56 class MetaCacheEntry;
57 class WriteRpc;
58 } // namespace internal
59 
60 class KuduSchema;
61 class KuduValue;
62 
64 class KUDU_EXPORT KuduColumnTypeAttributes {
65  public:
67 
73 
80  KuduColumnTypeAttributes(int8_t precision, int8_t scale);
81 
83 
90  KuduColumnTypeAttributes& operator=(const KuduColumnTypeAttributes& other);
91  void CopyFrom(const KuduColumnTypeAttributes& other);
93 
95  int8_t precision() const;
96 
98  int8_t scale() const;
99 
100  private:
101  class KUDU_NO_EXPORT Data;
102  // Owned.
103  Data* data_;
104 };
105 
107 class KUDU_EXPORT KuduColumnStorageAttributes {
108  public:
111  AUTO_ENCODING = 0,
112  PLAIN_ENCODING = 1,
113  PREFIX_ENCODING = 2,
114  RLE = 4,
115  DICT_ENCODING = 5,
116  BIT_SHUFFLE = 6,
117 
120  GROUP_VARINT = 3
121  };
122 
125  DEFAULT_COMPRESSION = 0,
126  NO_COMPRESSION = 1,
127  SNAPPY = 2,
128  LZ4 = 3,
129  ZLIB = 4,
130  };
131 
132 
145  EncodingType encoding = AUTO_ENCODING,
146  CompressionType compression = DEFAULT_COMPRESSION,
147  int32_t block_size = 0)
148  ATTRIBUTE_DEPRECATED("this constructor will be private in a future release")
149  : encoding_(encoding),
150  compression_(compression),
151  block_size_(block_size) {
152  }
153 
155  const EncodingType encoding() const {
156  return encoding_;
157  }
158 
160  const CompressionType compression() const {
161  return compression_;
162  }
163 
165  std::string ToString() const;
166 
167  private:
168  EncodingType encoding_;
169  CompressionType compression_;
170  int32_t block_size_;
171 };
172 
174 class KUDU_EXPORT KuduColumnSchema {
175  public:
177  enum DataType {
178  INT8 = 0,
179  INT16 = 1,
180  INT32 = 2,
181  INT64 = 3,
182  STRING = 4,
183  BOOL = 5,
184  FLOAT = 6,
185  DOUBLE = 7,
186  BINARY = 8,
187  UNIXTIME_MICROS = 9,
188  DECIMAL = 10,
189  TIMESTAMP = UNIXTIME_MICROS
190  };
191 
195  static std::string DataTypeToString(DataType type);
196 
201  KuduColumnSchema(const KuduColumnSchema& other);
202  ~KuduColumnSchema();
203 
209  KuduColumnSchema& operator=(const KuduColumnSchema& other);
210 
215  void CopyFrom(const KuduColumnSchema& other);
216 
222  bool Equals(const KuduColumnSchema& other) const;
223 
230  const std::string& name() const;
231 
233  DataType type() const;
234 
236  bool is_nullable() const;
238 
240  KuduColumnTypeAttributes type_attributes() const;
241 
242  private:
243  friend class KuduColumnSpec;
244  friend class KuduSchema;
245  friend class KuduSchemaBuilder;
246  // KuduTableAlterer::Data needs to be a friend. Friending the parent class
247  // is transitive to nested classes. See http://tiny.cloudera.com/jwtui
248  friend class KuduTableAlterer;
249 
251 
253  KuduColumnSchema(const std::string &name,
254  DataType type,
255  bool is_nullable = false,
256  const void* default_value = NULL,
259 
260  // Owned.
261  ColumnSchema* col_;
262 };
263 
272 class KUDU_EXPORT KuduColumnSpec {
273  public:
285  KuduColumnSpec* Default(KuduValue* value);
286 
293 
302 
322  KuduColumnSpec* BlockSize(int32_t block_size);
323 
340  KuduColumnSpec* Precision(int8_t precision);
341 
355  KuduColumnSpec* Scale(int8_t scale);
357 
370  KuduColumnSpec* PrimaryKey();
371 
377  KuduColumnSpec* NotNull();
378 
384  KuduColumnSpec* Nullable();
385 
395 
405  KuduColumnSpec* RemoveDefault();
406 
412  KuduColumnSpec* RenameTo(const std::string& new_name);
414 
415  private:
416  class KUDU_NO_EXPORT Data;
417  friend class KuduSchemaBuilder;
418  friend class KuduTableAlterer;
419 
420  // This class should always be owned and deleted by one of its friends,
421  // not the user.
422  ~KuduColumnSpec();
423 
424  explicit KuduColumnSpec(const std::string& col_name);
425 
426  Status ToColumnSchema(KuduColumnSchema* col) const;
427 
428  Status ToColumnSchemaDelta(ColumnSchemaDelta* col_delta) const;
429 
430  Slice DefaultValueAsSlice() const;
431 
432  // Owned.
433  Data* data_;
434 };
435 
457 class KUDU_EXPORT KuduSchemaBuilder {
458  public:
461 
468  KuduColumnSpec* AddColumn(const std::string& name);
469 
477  KuduSchemaBuilder* SetPrimaryKey(const std::vector<std::string>& key_col_names);
478 
488  Status Build(KuduSchema* schema);
489 
490  private:
491  class KUDU_NO_EXPORT Data;
492  // Owned.
493  Data* data_;
494 };
495 
497 class KUDU_EXPORT KuduSchema {
498  public:
499  KuduSchema();
500 
505  KuduSchema(const KuduSchema& other);
506  ~KuduSchema();
507 
514  KuduSchema& operator=(const KuduSchema& other);
515  void CopyFrom(const KuduSchema& other);
517 
527  Status Reset(const std::vector<KuduColumnSchema>& columns, int key_columns)
528  ATTRIBUTE_DEPRECATED("this method will be removed in a future release")
529  WARN_UNUSED_RESULT;
530 
537  bool Equals(const KuduSchema& other) const;
538 
542  KuduColumnSchema Column(size_t idx) const;
543 
545  size_t num_columns() const;
546 
555  void GetPrimaryKeyColumnIndexes(std::vector<int>* indexes) const;
556 
564  KuduPartialRow* NewRow() const;
565 
566  private:
567  friend class ClientTest;
568  friend class KuduClient;
569  friend class KuduScanner;
570  friend class KuduScanToken;
571  friend class KuduScanTokenBuilder;
572  friend class KuduSchemaBuilder;
573  friend class KuduTable;
574  friend class KuduTableCreator;
575  friend class KuduWriteOperation;
576  friend class ScanConfiguration;
577  friend class internal::GetTableSchemaRpc;
578  friend class internal::LookupRpc;
579  friend class internal::MetaCacheEntry;
580  friend class internal::WriteRpc;
581  friend class tools::RemoteKsckMaster;
582  friend class tools::ReplicaDumper;
583 
584  friend KuduSchema KuduSchemaFromSchema(const Schema& schema);
585 
586 
587  // For use by kudu tests.
588  explicit KuduSchema(const Schema& schema);
589 
590  // Private since we don't want users to rely on the first N columns
591  // being the keys.
592  size_t num_key_columns() const;
593 
594  // Owned.
595  Schema* schema_;
596 };
597 
598 } // namespace client
599 } // namespace kudu
600 #endif // KUDU_CLIENT_SCHEMA_H
A representation of a table&#39;s schema.
Definition: schema.h:497
Representation of column type attributes.
Definition: schema.h:64
A representation of an operation&#39;s outcome.
Definition: status.h:145
A constant cell value with a specific type.
Definition: value.h:35
Representation of column storage attributes.
Definition: schema.h:107
Builder API for specifying or altering a column within a table schema.
Definition: schema.h:272
Representation of the column schema.
Definition: schema.h:174
const EncodingType encoding() const
Definition: schema.h:155
Builds scan tokens for a table.
Definition: client.h:2197
Alters an existing table based on the provided steps.
Definition: client.h:1029
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:144
A handle for a connection to a cluster.
Definition: client.h:298
A wrapper around externally allocated data.
Definition: slice.h:47
A representation of a table on a particular cluster.
Definition: client.h:873
This class is a representation of a single scan.
Definition: client.h:1706
A single-row write operation to be sent to a Kudu table.
Definition: write_op.h:65
CompressionType
Column compression types.
Definition: schema.h:124
Builder API for constructing a KuduSchema object.
Definition: schema.h:457
DataType
Supported data types for columns.
Definition: schema.h:177
A scan descriptor limited to a single physical contiguous location.
Definition: client.h:2137
A helper class to create a new table with the desired options.
Definition: client.h:657
A row which may only contain values for a subset of the columns.
Definition: partial_row.h:64
const CompressionType compression() const
Definition: schema.h:160
EncodingType
Column encoding types.
Definition: schema.h:110