10#include <library/cpp/type_info/type_info.h>
11#include <library/cpp/yson/node/node.h>
13#include <util/generic/guid.h>
14#include <util/generic/map.h>
15#include <util/generic/maybe.h>
16#include <util/generic/ptr.h>
17#include <util/generic/vector.h>
19#include <google/protobuf/message.h>
21#include <initializer_list>
29#define FLUENT_FIELD(type, name) \
31 TSelf& name(const type& value) \
34 return static_cast<TSelf&>(*this); \
38#define FLUENT_FIELD_ENCAPSULATED(type, name) \
42 TSelf& name(const type& value) & \
45 return static_cast<TSelf&>(*this); \
47 TSelf name(const type& value) && \
50 return static_cast<TSelf&>(*this); \
52 const type& name() const & \
62#define FLUENT_FIELD_OPTION(type, name) \
63 TMaybe<type> name##_; \
64 TSelf& name(const type& value) \
67 return static_cast<TSelf&>(*this); \
71#define FLUENT_FIELD_OPTION_ENCAPSULATED(type, name) \
73 TMaybe<type> name##_; \
75 TSelf& name(const type& value) & \
78 return static_cast<TSelf&>(*this); \
80 TSelf name(const type& value) && \
83 return static_cast<TSelf&>(*this); \
85 TSelf& Reset##name() & \
87 name##_ = Nothing(); \
88 return static_cast<TSelf&>(*this); \
90 TSelf Reset##name() && \
92 name##_ = Nothing(); \
93 return static_cast<TSelf&>(*this); \
95 const TMaybe<type>& name() const& \
99 TMaybe<type> name() && \
105#define FLUENT_FIELD_DEFAULT(type, name, defaultValue) \
106 type name##_ = defaultValue; \
107 TSelf& name(const type& value) \
110 return static_cast<TSelf&>(*this); \
114#define FLUENT_FIELD_DEFAULT_ENCAPSULATED(type, name, defaultValue) \
116 type name##_ = defaultValue; \
118 TSelf& name(const type& value) & \
121 return static_cast<TSelf&>(*this); \
123 TSelf name(const type& value) && \
126 return static_cast<TSelf&>(*this); \
128 const type& name() const & \
138#define FLUENT_VECTOR_FIELD(type, name) \
139 TVector<type> name##s_; \
140 TSelf& Add##name(const type& value) \
142 name##s_.push_back(value); \
143 return static_cast<TSelf&>(*this);\
145 TSelf& name##s(TVector<type> values) \
147 name##s_ = std::move(values); \
148 return static_cast<TSelf&>(*this);\
152#define FLUENT_OPTIONAL_VECTOR_FIELD_ENCAPSULATED(type, name) \
154 TMaybe<TVector<type>> name##s_; \
156 const TMaybe<TVector<type>>& name##s() const & { \
159 TMaybe<TVector<type>>& name##s() & { \
162 TMaybe<TVector<type>> name##s() && { \
163 return std::move(name##s_); \
165 TSelf& Add##name(const type& value) & \
167 if (name##s_.Empty()) { \
168 name##s_.ConstructInPlace(); \
170 name##s_->push_back(value); \
171 return static_cast<TSelf&>(*this);\
173 TSelf Add##name(const type& value) && \
175 if (name##s_.Empty()) { \
176 name##s_.ConstructInPlace(); \
178 name##s_->push_back(value); \
179 return static_cast<TSelf&&>(*this);\
181 TSelf& name##s(TVector<type> values) & \
183 name##s_ = std::move(values); \
184 return static_cast<TSelf&>(*this);\
186 TSelf name##s(TVector<type> values) && \
188 name##s_ = std::move(values); \
189 return static_cast<TSelf&&>(*this);\
191 TSelf& name##s(TNothing) & \
193 name##s_ = Nothing(); \
194 return static_cast<TSelf&>(*this);\
196 TSelf name##s(TNothing) && \
198 name##s_ = Nothing(); \
199 return static_cast<TSelf&&>(*this);\
201 TSelf& Reset##name##s() & \
203 name##s_ = Nothing(); \
204 return static_cast<TSelf&>(*this);\
206 TSelf Reset##name##s() && \
208 name##s_ = Nothing(); \
209 return static_cast<TSelf&&>(*this);\
213#define FLUENT_VECTOR_FIELD_ENCAPSULATED(type, name) \
215 TVector<type> name##s_; \
217 TSelf& Add##name(const type& value) & \
219 name##s_.push_back(value); \
220 return static_cast<TSelf&>(*this);\
222 TSelf Add##name(const type& value) && \
224 name##s_.push_back(value); \
225 return static_cast<TSelf&>(*this);\
227 TSelf& name##s(TVector<type> value) & \
229 name##s_ = std::move(value); \
230 return static_cast<TSelf&>(*this);\
232 TSelf name##s(TVector<type> value) && \
234 name##s_ = std::move(value); \
235 return static_cast<TSelf&>(*this);\
237 const TVector<type>& name##s() const & \
241 TVector<type> name##s() && \
247#define FLUENT_MAP_FIELD(keytype, valuetype, name) \
248 TMap<keytype,valuetype> name##_; \
249 TSelf& Add##name(const keytype& key, const valuetype& value) \
251 name##_.emplace(key, value); \
252 return static_cast<TSelf&>(*this);\
278template <
class T,
class TDerived>
282 using TSelf = std::conditional_t<std::is_void_v<TDerived>,
TOneOrMany, TDerived>;
292 Parts_.assign(il.begin(), il.end());
296 template <
class U,
class... TArgs>
297 requires std::is_convertible_v<U, T>
300 Add(arg, std::forward<TArgs>(args)...);
321 template <
class U,
class... TArgs>
322 requires std::is_convertible_v<U, T>
323 TSelf&
Add(U&& part, TArgs&&... args) &
325 Parts_.push_back(std::forward<U>(part));
326 if constexpr (
sizeof...(args) > 0) {
327 [[maybe_unused]]
int dummy[
sizeof...(args)] = {(
Parts_.push_back(std::forward<TArgs>(args)), 0) ... };
329 return static_cast<TSelf&
>(*this);
332 template <
class U,
class... TArgs>
333 requires std::is_convertible_v<U, T>
334 TSelf
Add(U&& part, TArgs&&... args) &&
336 return std::move(
Add(std::forward<U>(part), std::forward<TArgs>(args)...));
459 EC_REED_SOLOMON_6_3_ATTR ,
461 EC_ISA_LRC_12_2_2_ATTR ,
462 EC_ISA_REED_SOLOMON_6_3_ATTR ,
463 EC_ISA_REED_SOLOMON_3_3_ATTR ,
474 SM_UNVERSIONED_UPDATE ,
540 bool operator==(
const TStringBuf rhsName)
const;
541 bool operator==(
const TString& rhsName)
const;
545 operator TString()
const;
546 operator TStringBuf()
const;
547 operator std::string()
const;
549 Y_SAVELOAD_DEFINE(Name_, SortOrder_);
557 :
public TOneOrMany<TSortColumn, TSortColumns>
587 operator TColumnNames()
const;
640 FLUENT_FIELD_ENCAPSULATED(TString, Name);
657 NTi::TTypePtr TypeV3()
const;
711 friend void Deserialize(
TColumnSchema& columnSchema,
const TNode& node);
712 NTi::TTypePtr TypeV3_;
713 TMaybe<TNode> RawTypeV3_;
757 FLUENT_FIELD_OPTION_ENCAPSULATED(TString, StableName);
841 friend void Deserialize(
TTableSchema& tableSchema,
const TNode& node);
848void PrintTo(
const TTableSchema& schema, std::ostream* out);
852 const ::google::protobuf::Descriptor& messageDescriptor,
854 bool keepFieldsWithoutExtension =
true);
857template <
class TProtoType,
typename = std::enable_if_t<std::is_base_of_v<::google::protobuf::Message, TProtoType>>>
860 bool keepFieldsWithoutExtension =
true)
863 std::is_base_of_v<::google::protobuf::Message, TProtoType>,
864 "Template argument must be derived from ::google::protobuf::Message");
867 *TProtoType::descriptor(),
869 keepFieldsWithoutExtension);
937 FLUENT_FIELD_DEFAULT_ENCAPSULATED(TKey, Key, TKey{});
966 FLUENT_FIELD_OPTION(TKey,
Key);
1061 Ranges_.ConstructInPlace();
1063 Ranges_->push_back(std::move(range));
1086 TMaybe<TVector<TReadRange>>& MutableRanges()
1097 if (Ranges_.Defined()) {
1098 return TArrayRef(Ranges_->data(), Ranges_->size());
1104 TArrayRef<const TReadRange> GetRangesView()
const
1106 if (Ranges_.Defined()) {
1107 return TArrayRef(Ranges_->data(), Ranges_->size());
1119 return Ranges_.GetRef()[i];
1124 return Ranges_.GetRef()[i];
1135 FLUENT_FIELD_OPTION(
bool, Teleport);
1136 FLUENT_FIELD_OPTION(
bool, Primary);
1137 FLUENT_FIELD_OPTION(
bool, Foreign);
1138 FLUENT_FIELD_OPTION(i64, RowCountLimit);
1140 FLUENT_FIELD_OPTION(TString, FileName);
1201 using TRenameColumnsDescriptor = THashMap<TString, TString>;
1230 TMaybe<TVector<TReadRange>> Ranges_;
1237template <
typename TProtoType>
1240 static_assert(std::is_base_of_v<::google::protobuf::Message, TProtoType>,
"TProtoType must be Protobuf message");
1242 auto schemedPath = path;
1243 if (!schemedPath.Schema_) {
1254template <
typename TRowType>
1257 if constexpr (std::is_base_of_v<::google::protobuf::Message, TRowType>) {
1333 FLUENT_FIELD_DEFAULT(i64, Begin, 0);
1336 FLUENT_FIELD_OPTION(i64,
End);
Single column description.
Definition common.h:618
const TMaybe< TNode > & RawTypeV3() const
Raw yson representation of column type.
TColumnSchema()
Construct empty column schemas.
TColumnSchema & Type(EValueType type) &
Functions to work with type in old manner.
FLUENT_FIELD_OPTION_ENCAPSULATED(TString, Aggregate)
Aggregating function name.
TColumnSchema & Type(EValueType type, bool required) &
Set type in old-style manner.
FLUENT_FIELD_OPTION_ENCAPSULATED(TString, Lock)
Lock group name.
FLUENT_FIELD_OPTION_ENCAPSULATED(TString, Group)
Storage group name.
FLUENT_FIELD_OPTION_ENCAPSULATED(ESortOrder, SortOrder)
Column sort order.
TColumnSchema & Type(const NTi::TTypePtr &type) &
Set and get column type.
bool Required() const
Column requiredness.
TColumnSchema(const TColumnSchema &)=default
Copy and move constructors are default.
FLUENT_FIELD_OPTION_ENCAPSULATED(TString, Expression)
Expression defining column value.
Single deleted description.
Definition common.h:735
TDeletedColumnSchema(const TDeletedColumnSchema &)=default
Copy and move constructors are default.
TDeletedColumnSchema()=default
Construct empty removed column schemas.
Table key column description.
Definition common.h:494
FLUENT_FIELD_ENCAPSULATED(TString, Name)
Column name.
TSortColumn(TStringBuf name={}, ESortOrder sortOrder=ESortOrder::SO_ASCENDING)
Construct object from name and sort order.
TNode ToNode() const
Convert sort to yson representation as YT API expects it.
const TSortColumn & EnsureAscending() const
Check that sort order is ascending, throw exception otherwise.
FLUENT_FIELD_DEFAULT_ENCAPSULATED(ESortOrder, SortOrder, ESortOrder::SO_ASCENDING)
Sort order.
bool operator==(const TSortColumn &rhs) const =default
Comparison is default and checks both name and sort order.
TSortColumn & operator=(TStringBuf name)
Assign object from column name, and set sort order to ascending.
List of TSortColumn.
Definition common.h:558
const TSortColumns & EnsureAscending() const
Make sure that all columns are of ascending sort order.
TSortColumns(const TVector< TString > &names)
Construct list of ascending sort order columns by their names.
TVector< TString > GetNames() const
Get list of column names.
TSortColumns()
Construct empty list.
Description of table schema.
Definition common.h:771
TTableSchema & AddColumn(const TString &name, EValueType type) &
Add optional column of specified type.
TTableSchema AddColumn(const TString &name, const NTi::TTypePtr &type) &&
Add column.
TTableSchema & AddColumn(const TString &name, const NTi::TTypePtr &type) &
Add column.
FLUENT_FIELD_DEFAULT_ENCAPSULATED(bool, Strict, true)
Strictness of the schema.
TTableSchema AddColumn(const TString &name, const NTi::TTypePtr &type, ESortOrder sortOrder) &&
Add column.
TTableSchema SortBy(const TSortColumns &columns) &&
Make table schema sorted by specified columns.
FLUENT_VECTOR_FIELD_ENCAPSULATED(TDeletedColumnSchema, DeletedColumn)
Deleted column schema.
TTableSchema & SortBy(const TSortColumns &columns) &
Make table schema sorted by specified columns.
FLUENT_FIELD_DEFAULT_ENCAPSULATED(bool, UniqueKeys, false)
Whether keys are unique.
static NYT::TTableSchema FromNode(const TNode &node)
Parse schema from yson node.
FLUENT_VECTOR_FIELD_ENCAPSULATED(TColumnSchema, Column)
Column schema.
TVector< TColumnSchema > & MutableColumns()
Get modifiable column list.
bool Empty() const
Check if schema has any described column.
TTableSchema & AddColumn(const TString &name, const NTi::TTypePtr &type, ESortOrder sortOrder) &
Add column.
TNode ToNode() const
Get yson description of table schema.
TTableSchema AddColumn(const TString &name, EValueType type) &&
Add optional column of specified type.
TTableSchema & AddColumn(const TString &name, EValueType type, ESortOrder sortOrder) &
Add optional column of specified type.
TTableSchema AddColumn(const TString &name, EValueType type, ESortOrder sortOrder) &&
Add optional column of specified type.
Main namespace of YT client.
Definition abortable_stream.h:7
EMasterReadKind
Enumeration for specifying how reading from master is performed.
Definition common.h:1416
@ Leader
Reading from leader.
Definition common.h:1422
@ Follower
Reading from master follower (default).
Definition common.h:1425
EErasureCodecAttr
Value of "erasure_codec" attribute.
Definition common.h:456
bool operator==(const TColumnSchema &lhs, const TColumnSchema &rhs)
Equality check checks all fields of column schema.
TRichYPath MaybeWithSchema(const TRichYPath &path, const TSortColumns &sortBy=TSortColumns())
Create copy of NYT::TRichYPath with schema derived from TRowType if possible.
Definition common.h:1255
TRichYPath WithSchema(const TRichYPath &path, const TSortColumns &sortBy=TSortColumns())
Definition common.h:1238
ESchemaModificationAttr
Value of "schema_modification" attribute.
Definition common.h:472
const TVector< TReadRange > & GetRangesCompat(const TRichYPath &path)
Get the list of ranges related to path in compatibility mode.
EOptimizeForAttr
Value of "optimize_for" attribute.
Definition common.h:443
@ OF_SCAN_ATTR
Optimize for scan.
Definition common.h:445
@ OF_LOOKUP_ATTR
Optimize for lookup.
Definition common.h:448
ERelation
Enumeration describing comparison operation used in key bound.
Definition common.h:895
@ Less
Relation "less".
Definition common.h:901
@ GreaterOrEqual
Relation "greater or equal".
Definition common.h:922
@ Greater
Relation "greater".
Definition common.h:915
@ LessOrEqual
Relation "less or equal".
Definition common.h:908
TTableSchema CreateTableSchema(const ::google::protobuf::Descriptor &messageDescriptor, const TSortColumns &sortColumns=TSortColumns(), bool keepFieldsWithoutExtension=true)
Create table schema by protobuf message descriptor.
bool IsTrivial(const TReadLimit &readLimit)
Check if none of the fields of NYT::TReadLimit is set.
EValueType NodeTypeToValueType(TNode::EType nodeType)
Convert yson node type to table schema type.
ESortOrder
Sort order.
Definition common.h:431
@ SO_DESCENDING
Descending sort order.
Definition common.h:435
@ SO_ASCENDING
Ascending sort order.
Definition common.h:433
NTi::TTypePtr ToTypeV3(EValueType type, bool required)
Helper function to create new style type from old style one.
EValueType
Type of the value that can occur in YT table.
Definition common.h:352
@ VT_UINT16
Uint16, unsigned integer of 16 bits.
Definition common.h:380
@ VT_INTERVAL
Interval, difference between two timestamps (signed).
Definition common.h:399
@ VT_UINT64
Uint64, unsigned integer of 64 bits.
Definition common.h:357
@ VT_ANY
Any, arbitrary yson document.
Definition common.h:368
@ VT_DOUBLE
Double, floating point number of double precision (64 bits).
Definition common.h:360
@ VT_NULL
Null, absence of value (almost never used in schemas).
Definition common.h:388
@ VT_DATE
Date, number of days since Unix epoch (unsigned).
Definition common.h:393
@ VT_UINT32
Uint32, unsigned integer of 32 bits.
Definition common.h:382
@ VT_INT64
Int64, signed integer of 64 bits.
Definition common.h:354
@ VT_DATETIME
Datetime, number of seconds since Unix epoch (unsigned).
Definition common.h:395
@ VT_BOOLEAN
Boolean, true or false.
Definition common.h:362
@ VT_JSON
Json, sequence of bytes that is valid json.
Definition common.h:404
@ VT_TIMESTAMP
Timestamp, number of milliseconds since Unix epoch (unsigned).
Definition common.h:397
@ VT_VOID
Void, absence of value (almost never used in schemas) the difference between null,...
Definition common.h:390
@ VT_UINT8
Uint8, unsigned integer of 8 bits.
Definition common.h:378
@ VT_FLOAT
Float, floating point number (32 bits).
Definition common.h:402
@ VT_INT8
Int8, signed integer of 8 bits.
Definition common.h:371
@ VT_UTF8
Utf8, byte sequence that is valid utf8.
Definition common.h:385
@ VT_INT16
Int16, signed integer of 16 bits.
Definition common.h:373
@ VT_STRING
String, arbitrary byte sequence.
Definition common.h:365
@ VT_INT32
Int32, signed integer of 32 bits.
Definition common.h:375
List of attributes to retrieve in operations like NYT::ICypressClient::Get.
Definition common.h:1389
FLUENT_VECTOR_FIELD(TString, Attribute)
List of attributes.
Description of a file partition.
Definition common.h:1341
TString Cookie
Partition cookie that can be passed to NYT::IClientBase::CreateFilePartitionReader.
Definition common.h:1343
i64 Length
Partition length in bytes.
Definition common.h:1346
File partitions from GetFilePartitions command.
Definition common.h:1351
TVector< TFilePartition > Partitions
Partitions are listed in the order of the requested ranges, one per range.
Definition common.h:1353
Byte range of a file, offsets are uncompressed bytes.
Definition common.h:1328
TSelf & End(i64)
If missing, the range extends to the end of file.
Key with relation specifying interval of keys in lower or upper limit of NYT::TReadRange.
Definition common.h:930
Description of a partition.
Definition common.h:1299
TMaybe< TString > Cookie
Partition cookie that can be passed to NYT::IClientBase::CreatePartitionReader.
Definition common.h:1314
TStatistics AggregateStatistics
Aggregate statistics of all the table ranges in the partition.
Definition common.h:1311
TVector< TRichYPath > TableRanges
Ranges of input tables for this partition.
Definition common.h:1308
Table partitions from GetTablePartitions command.
Definition common.h:1319
TVector< TMultiTablePartition > Partitions
Disjoint partitions into which the input tables were divided.
Definition common.h:1321
TOneOrMany()=default
Initialize with empty sequence.
TOneOrMany(U &&arg, TArgs &&... args)
Put arguments to sequence.
Definition common.h:298
TSelf & Add(U &&part, TArgs &&... args) &
Add all arguments to sequence.
Definition common.h:323
TOneOrMany(TVector< T > args)
Initialize from vector.
Definition common.h:304
TVector< T > Parts_
Content of sequence.
Definition common.h:341
bool operator==(const TOneOrMany &rhs) const
Order is defined the same way as in TVector.
Definition common.h:309
Description of the read limit.
Definition common.h:951
TSelf & Offset(i64)
File offset.
TSelf & Key(TKey)
Table key.
TSelf & TabletIndex(i64)
Tablet index.
TSelf & RowIndex(i64)
Row index.
TSelf & KeyBound(TKeyBound)
KeyBound specifies table key and whether to include it.
Range of a table or a file.
Definition common.h:995
static TReadRange FromKeys(const TKey &lowerKeyInclusive, const TKey &upperKeyExclusive)
Create read range from keys.
Definition common.h:1022
TSelf & UpperLimit(TReadLimit)
Lower limit of the range.
TSelf & Exact(TReadLimit)
Exact key or row index.
TSelf & LowerLimit(TReadLimit)
Lower limit of the range.
static TReadRange FromRowIndices(i64 lowerLimit, i64 upperLimit)
Create read range from row indexes.
Definition common.h:1014
Path with additional attributes.
Definition common.h:1040
TSelf & Schema(TTableSchema)
Specifies table schema that will be set on the path.
TSelf & PartiallySorted(bool)
TSelf & OptimizeFor(EOptimizeForAttr)
Specifies optimize_for attribute that will be set on the path.
TSelf & Format(TNode)
Specify format to use when loading table.
TSelf & SortedBy(TSortColumns)
Specifies that path is expected to be sorted by these columns.
const TReadRange & GetRange(ssize_t i) const
Definition common.h:1117
TSelf & CompressionCodec(TString)
Specifies compression codec that will be set on the path.
TArrayRef< TReadRange > MutableRangesView()
Definition common.h:1095
TSelf & Path(TYPath)
Path itself.
TSelf & Cluster(TString)
Specifies cluster for the YPath.
TSelf & Columns(TColumnNames)
Specifies columns that should be read.
TSelf & RenameColumns(TRenameColumnsDescriptor)
Specifies columnar mapping which will be applied to columns before transfer to job.
TSelf & TransactionId(TTransactionId)
Specify transaction that should be used to access this path.
TSelf & Executable(bool)
Specifies that this path points to executable file.
TSelf & Timestamp(i64)
Timestamp of dynamic table.
TRichYPath(const char *path)
Create path from string.
Definition common.h:1220
TSelf & OriginalPath(TYPath)
Specifies original path to be shown in Web UI.
TSelf & InputQuery(TString)
Specifies input_query for the path.
TSelf & ErasureCodec(EErasureCodecAttr)
Specifies erasure codec that will be set on the path.
TSelf & Create(bool)
Wether to create operation output path.
TSelf & Append(bool)
Specifies that path should be appended not overwritten.
TRichYPath & AddRange(TReadRange range)
Add range to read.
Definition common.h:1058
const TMaybe< TVector< TReadRange > > & GetRanges() const
Definition common.h:1081
TRichYPath()
Create empty path with no attributes.
Definition common.h:1213
TSelf & BypassArtifactCache(bool)
Do not put file used in operation into node cache.
TSelf & SchemaModification(ESchemaModificationAttr)
Specifies schema modification that will be set on the path.
Statistics about table columns.
Definition common.h:1281
TMaybe< i64 > TimestampTotalWeight
Timestamps total weight (only for dynamic tables).
Definition common.h:1292
i64 LegacyChunksDataWeight
Total weight of all old chunks that don't keep columnar statistics.
Definition common.h:1289
THashMap< TString, ui64 > ColumnEstimatedUniqueCounts
Estimated number of unique elements for each column.
Definition common.h:1286
THashMap< TString, i64 > ColumnDataWeight
Total data weight for all chunks for each of requested columns.
Definition common.h:1283
Contains information about tablet.
Definition common.h:1363
ui64 BarrierTimestamp
Tablet cell barrier timestamp, which lags behind the current timestamp.
Definition common.h:1382
i64 TrimmedRowCount
Contains the number of front rows that are trimmed and are not guaranteed to be accessible.
Definition common.h:1374
i64 TotalRowCount
Indicates the total number of rows added to the tablet (including trimmed ones).
Definition common.h:1368