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 KuduColumnStorageAttributes {
65  public:
67  enum EncodingType {
68  AUTO_ENCODING = 0,
69  PLAIN_ENCODING = 1,
70  PREFIX_ENCODING = 2,
71  RLE = 4,
72  DICT_ENCODING = 5,
73  BIT_SHUFFLE = 6,
74 
77  GROUP_VARINT = 3
78  };
79 
82  DEFAULT_COMPRESSION = 0,
83  NO_COMPRESSION = 1,
84  SNAPPY = 2,
85  LZ4 = 3,
86  ZLIB = 4,
87  };
88 
89 
102  EncodingType encoding = AUTO_ENCODING,
103  CompressionType compression = DEFAULT_COMPRESSION,
104  int32_t block_size = 0)
105  ATTRIBUTE_DEPRECATED("this constructor will be private in a future release")
106  : encoding_(encoding),
107  compression_(compression),
108  block_size_(block_size) {
109  }
110 
112  const EncodingType encoding() const {
113  return encoding_;
114  }
115 
117  const CompressionType compression() const {
118  return compression_;
119  }
120 
122  std::string ToString() const;
123 
124  private:
125  EncodingType encoding_;
126  CompressionType compression_;
127  int32_t block_size_;
128 };
129 
131 class KUDU_EXPORT KuduColumnSchema {
132  public:
134  enum DataType {
135  INT8 = 0,
136  INT16 = 1,
137  INT32 = 2,
138  INT64 = 3,
139  STRING = 4,
140  BOOL = 5,
141  FLOAT = 6,
142  DOUBLE = 7,
143  BINARY = 8,
144  UNIXTIME_MICROS = 9,
145  TIMESTAMP = UNIXTIME_MICROS
146  };
147 
151  static std::string DataTypeToString(DataType type);
152 
169  KuduColumnSchema(const std::string &name,
170  DataType type,
171  bool is_nullable = false,
172  const void* default_value = NULL,
174  ATTRIBUTE_DEPRECATED("use KuduSchemaBuilder instead");
175 
180  KuduColumnSchema(const KuduColumnSchema& other);
181  ~KuduColumnSchema();
182 
188  KuduColumnSchema& operator=(const KuduColumnSchema& other);
189 
194  void CopyFrom(const KuduColumnSchema& other);
195 
201  bool Equals(const KuduColumnSchema& other) const;
202 
209  const std::string& name() const;
210 
212  DataType type() const;
213 
215  bool is_nullable() const;
217 
218  private:
219  friend class KuduColumnSpec;
220  friend class KuduSchema;
221  friend class KuduSchemaBuilder;
222  // KuduTableAlterer::Data needs to be a friend. Friending the parent class
223  // is transitive to nested classes. See http://tiny.cloudera.com/jwtui
224  friend class KuduTableAlterer;
225 
227 
228  // Owned.
229  ColumnSchema* col_;
230 };
231 
240 class KUDU_EXPORT KuduColumnSpec {
241  public:
253  KuduColumnSpec* Default(KuduValue* value);
254 
260  KuduColumnSpec* Compression(KuduColumnStorageAttributes::CompressionType compression);
261 
269  KuduColumnSpec* Encoding(KuduColumnStorageAttributes::EncodingType encoding);
270 
290  KuduColumnSpec* BlockSize(int32_t block_size);
291 
304  KuduColumnSpec* PrimaryKey();
305 
311  KuduColumnSpec* NotNull();
312 
318  KuduColumnSpec* Nullable();
319 
327  KuduColumnSpec* Type(KuduColumnSchema::DataType type);
329 
339  KuduColumnSpec* RemoveDefault();
340 
346  KuduColumnSpec* RenameTo(const std::string& new_name);
348 
349  private:
350  class KUDU_NO_EXPORT Data;
351  friend class KuduSchemaBuilder;
352  friend class KuduTableAlterer;
353 
354  // This class should always be owned and deleted by one of its friends,
355  // not the user.
356  ~KuduColumnSpec();
357 
358  explicit KuduColumnSpec(const std::string& col_name);
359 
360  Status ToColumnSchema(KuduColumnSchema* col) const;
361 
362  Status ToColumnSchemaDelta(ColumnSchemaDelta* col_delta) const;
363 
364  Slice DefaultValueAsSlice() const;
365 
366  // Owned.
367  Data* data_;
368 };
369 
391 class KUDU_EXPORT KuduSchemaBuilder {
392  public:
395 
402  KuduColumnSpec* AddColumn(const std::string& name);
403 
411  KuduSchemaBuilder* SetPrimaryKey(const std::vector<std::string>& key_col_names);
412 
422  Status Build(KuduSchema* schema);
423 
424  private:
425  class KUDU_NO_EXPORT Data;
426  // Owned.
427  Data* data_;
428 };
429 
431 class KUDU_EXPORT KuduSchema {
432  public:
433  KuduSchema();
434 
439  KuduSchema(const KuduSchema& other);
440  ~KuduSchema();
441 
448  KuduSchema& operator=(const KuduSchema& other);
449  void CopyFrom(const KuduSchema& other);
451 
461  Status Reset(const std::vector<KuduColumnSchema>& columns, int key_columns)
462  ATTRIBUTE_DEPRECATED("this method will be removed in a future release")
463  WARN_UNUSED_RESULT;
464 
471  bool Equals(const KuduSchema& other) const;
472 
476  KuduColumnSchema Column(size_t idx) const;
477 
479  size_t num_columns() const;
480 
489  void GetPrimaryKeyColumnIndexes(std::vector<int>* indexes) const;
490 
498  KuduPartialRow* NewRow() const;
499 
500  private:
501  friend class ClientTest;
502  friend class KuduClient;
503  friend class KuduScanner;
504  friend class KuduScanToken;
505  friend class KuduScanTokenBuilder;
506  friend class KuduSchemaBuilder;
507  friend class KuduTable;
508  friend class KuduTableCreator;
509  friend class KuduWriteOperation;
510  friend class ScanConfiguration;
511  friend class internal::GetTableSchemaRpc;
512  friend class internal::LookupRpc;
513  friend class internal::MetaCacheEntry;
514  friend class internal::WriteRpc;
515  friend class tools::RemoteKsckMaster;
516  friend class tools::ReplicaDumper;
517 
518  friend KuduSchema KuduSchemaFromSchema(const Schema& schema);
519 
520 
521  // For use by kudu tests.
522  explicit KuduSchema(const Schema& schema);
523 
524  // Private since we don't want users to rely on the first N columns
525  // being the keys.
526  size_t num_key_columns() const;
527 
528  // Owned.
529  Schema* schema_;
530 };
531 
532 } // namespace client
533 } // namespace kudu
534 #endif // KUDU_CLIENT_SCHEMA_H
A representation of a table&#39;s schema.
Definition: schema.h:431
A representation of an operation&#39;s outcome.
Definition: status.h:135
A constant cell value with a specific type.
Definition: value.h:34
Representation of column storage attributes.
Definition: schema.h:64
Builder API for specifying or altering a column within a table schema.
Definition: schema.h:240
Representation of the column schema.
Definition: schema.h:131
const EncodingType encoding() const
Definition: schema.h:112
Builds scan tokens for a table.
Definition: client.h:2179
Alters an existing table based on the provided steps.
Definition: client.h:1024
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:101
A handle for a connection to a cluster.
Definition: client.h:295
A wrapper around externally allocated data.
Definition: slice.h:47
A representation of a table on a particular cluster.
Definition: client.h:868
This class is a representation of a single scan.
Definition: client.h:1701
A single-row write operation to be sent to a Kudu table.
Definition: write_op.h:65
CompressionType
Column compression types.
Definition: schema.h:81
Builder API for constructing a KuduSchema object.
Definition: schema.h:391
DataType
Supported data types for columns.
Definition: schema.h:134
A scan descriptor limited to a single physical contiguous location.
Definition: client.h:2119
A helper class to create a new table with the desired options.
Definition: client.h:652
A row which may only contain values for a subset of the columns.
Definition: partial_row.h:63
const CompressionType compression() const
Definition: schema.h:117
EncodingType
Column encoding types.
Definition: schema.h:67