00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef KUDU_CLIENT_SCHEMA_H
00019 #define KUDU_CLIENT_SCHEMA_H
00020
00021 #include <string>
00022 #include <vector>
00023
00024 #include "kudu/client/value.h"
00025 #include "kudu/util/kudu_export.h"
00026
00027 namespace kudu {
00028
00029 class ColumnSchema;
00030 class KuduPartialRow;
00031 class Schema;
00032 class TestWorkload;
00033
00034 namespace tools {
00035 class RemoteKsckMaster;
00036 class ReplicaDumper;
00037 }
00038
00039 namespace client {
00040
00041 namespace internal {
00042 class GetTableSchemaRpc;
00043 class LookupRpc;
00044 class MetaCacheEntry;
00045 class WriteRpc;
00046 }
00047
00048 class KuduClient;
00049 class KuduSchema;
00050 class KuduSchemaBuilder;
00051 class KuduWriteOperation;
00052
00054 class KUDU_EXPORT KuduColumnStorageAttributes {
00055 public:
00057 enum EncodingType {
00058 AUTO_ENCODING = 0,
00059 PLAIN_ENCODING = 1,
00060 PREFIX_ENCODING = 2,
00061 GROUP_VARINT = 3,
00062 RLE = 4,
00063 DICT_ENCODING = 5,
00064 BIT_SHUFFLE = 6
00065 };
00066
00068 enum CompressionType {
00069 DEFAULT_COMPRESSION = 0,
00070 NO_COMPRESSION = 1,
00071 SNAPPY = 2,
00072 LZ4 = 3,
00073 ZLIB = 4,
00074 };
00075
00076
00088 KuduColumnStorageAttributes(EncodingType encoding = AUTO_ENCODING,
00089 CompressionType compression = DEFAULT_COMPRESSION,
00090 int32_t block_size = 0)
00091 : encoding_(encoding),
00092 compression_(compression),
00093 block_size_(block_size) {
00094 }
00095
00097 const EncodingType encoding() const {
00098 return encoding_;
00099 }
00100
00102 const CompressionType compression() const {
00103 return compression_;
00104 }
00105
00107 std::string ToString() const;
00108
00109 private:
00110 EncodingType encoding_;
00111 CompressionType compression_;
00112 int32_t block_size_;
00113 };
00114
00116 class KUDU_EXPORT KuduColumnSchema {
00117 public:
00119 enum DataType {
00120 INT8 = 0,
00121 INT16 = 1,
00122 INT32 = 2,
00123 INT64 = 3,
00124 STRING = 4,
00125 BOOL = 5,
00126 FLOAT = 6,
00127 DOUBLE = 7,
00128 BINARY = 8,
00129 UNIXTIME_MICROS = 9,
00130 TIMESTAMP = UNIXTIME_MICROS
00131 };
00132
00136 static std::string DataTypeToString(DataType type);
00137
00154 KuduColumnSchema(const std::string &name,
00155 DataType type,
00156 bool is_nullable = false,
00157 const void* default_value = NULL,
00158 KuduColumnStorageAttributes attributes = KuduColumnStorageAttributes());
00159
00164 KuduColumnSchema(const KuduColumnSchema& other);
00165 ~KuduColumnSchema();
00166
00172 KuduColumnSchema& operator=(const KuduColumnSchema& other);
00173
00178 void CopyFrom(const KuduColumnSchema& other);
00179
00185 bool Equals(const KuduColumnSchema& other) const;
00186
00193 const std::string& name() const;
00194
00196 DataType type() const;
00197
00199 bool is_nullable() const;
00201
00202 private:
00203 friend class KuduColumnSpec;
00204 friend class KuduSchema;
00205 friend class KuduSchemaBuilder;
00206
00207
00208 friend class KuduTableAlterer;
00209
00210 KuduColumnSchema();
00211
00212
00213 ColumnSchema* col_;
00214 };
00215
00224 class KUDU_EXPORT KuduColumnSpec {
00225 public:
00237 KuduColumnSpec* Default(KuduValue* value);
00238
00244 KuduColumnSpec* Compression(KuduColumnStorageAttributes::CompressionType compression);
00245
00253 KuduColumnSpec* Encoding(KuduColumnStorageAttributes::EncodingType encoding);
00254
00274 KuduColumnSpec* BlockSize(int32_t block_size);
00275
00288 KuduColumnSpec* PrimaryKey();
00289
00295 KuduColumnSpec* NotNull();
00296
00302 KuduColumnSpec* Nullable();
00303
00311 KuduColumnSpec* Type(KuduColumnSchema::DataType type);
00313
00323 KuduColumnSpec* RemoveDefault();
00324
00330 KuduColumnSpec* RenameTo(const std::string& new_name);
00332
00333 private:
00334 class KUDU_NO_EXPORT Data;
00335 friend class KuduSchemaBuilder;
00336 friend class KuduTableAlterer;
00337
00338
00339
00340 ~KuduColumnSpec();
00341
00342 explicit KuduColumnSpec(const std::string& col_name);
00343
00344 Status ToColumnSchema(KuduColumnSchema* col) const;
00345
00346
00347 Data* data_;
00348 };
00349
00371 class KUDU_EXPORT KuduSchemaBuilder {
00372 public:
00373 KuduSchemaBuilder();
00374 ~KuduSchemaBuilder();
00375
00382 KuduColumnSpec* AddColumn(const std::string& name);
00383
00391 KuduSchemaBuilder* SetPrimaryKey(const std::vector<std::string>& key_col_names);
00392
00402 Status Build(KuduSchema* schema);
00403
00404 private:
00405 class KUDU_NO_EXPORT Data;
00406
00407 Data* data_;
00408 };
00409
00411 class KUDU_EXPORT KuduSchema {
00412 public:
00413 KuduSchema();
00414
00419 KuduSchema(const KuduSchema& other);
00420 ~KuduSchema();
00421
00428 KuduSchema& operator=(const KuduSchema& other);
00429 void CopyFrom(const KuduSchema& other);
00431
00441 Status Reset(const std::vector<KuduColumnSchema>& columns, int key_columns)
00442 WARN_UNUSED_RESULT;
00443
00450 bool Equals(const KuduSchema& other) const;
00451
00455 KuduColumnSchema Column(size_t idx) const;
00456
00458 size_t num_columns() const;
00459
00468 void GetPrimaryKeyColumnIndexes(std::vector<int>* indexes) const;
00469
00477 KuduPartialRow* NewRow() const;
00478
00479 private:
00480 friend class KuduClient;
00481 friend class KuduScanner;
00482 friend class KuduScanToken;
00483 friend class KuduScanTokenBuilder;
00484 friend class KuduSchemaBuilder;
00485 friend class KuduTable;
00486 friend class KuduTableCreator;
00487 friend class KuduWriteOperation;
00488 friend class ScanConfiguration;
00489 friend class internal::GetTableSchemaRpc;
00490 friend class internal::LookupRpc;
00491 friend class internal::MetaCacheEntry;
00492 friend class internal::WriteRpc;
00493 friend class tools::RemoteKsckMaster;
00494 friend class tools::ReplicaDumper;
00495
00496 friend KuduSchema KuduSchemaFromSchema(const Schema& schema);
00497
00498
00499
00500 explicit KuduSchema(const Schema& schema);
00501
00502
00503
00504 size_t num_key_columns() const;
00505
00506
00507 Schema* schema_;
00508 };
00509
00510 }
00511 }
00512 #endif // KUDU_CLIENT_SCHEMA_H