Skip to content

Commit ce6c4c6

Browse files
committed
Merge branch 'rightlib' into mergelibs-yurchuk-manual
2 parents f438674 + caec531 commit ce6c4c6

File tree

6 files changed

+95
-30
lines changed

6 files changed

+95
-30
lines changed

build/mapping.conf.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,12 +901,15 @@
901901
"7324461836": "https://devtools-registry.s3.yandex.net/7324461836",
902902
"7193803465": "https://devtools-registry.s3.yandex.net/7193803465",
903903
"7324464594": "https://devtools-registry.s3.yandex.net/7324464594",
904+
"7458707245": "https://devtools-registry.s3.yandex.net/7458707245",
904905
"7414146467": "https://devtools-registry.s3.yandex.net/7414146467",
905906
"7442753753": "https://devtools-registry.s3.yandex.net/7442753753",
906907
"7406675906": "https://devtools-registry.s3.yandex.net/7406675906",
907908
"7442782962": "https://devtools-registry.s3.yandex.net/7442782962",
908909
"7406663741": "https://devtools-registry.s3.yandex.net/7406663741",
910+
"7458616985": "https://devtools-registry.s3.yandex.net/7458616985",
909911
"7406665335": "https://devtools-registry.s3.yandex.net/7406665335",
912+
"7458630270": "https://devtools-registry.s3.yandex.net/7458630270",
910913
"7193800506": "https://devtools-registry.s3.yandex.net/7193800506",
911914
"7324461714": "https://devtools-registry.s3.yandex.net/7324461714",
912915
"7193813071": "https://devtools-registry.s3.yandex.net/7193813071",
@@ -1929,12 +1932,15 @@
19291932
"7324461836": "none-none-none-service_resources/TASKLET_EXECUTABLE/backup/0541e185-8261-4b07-9149-257f03a9c8ae/yfm-docs.tar",
19301933
"7193803465": "none-none-none-service_resources/TASKLET_EXECUTABLE/backup/17df2ad2-24bc-49e8-8909-b58685dac393/yfm-docs.tar",
19311934
"7324464594": "none-none-none-service_resources/TASKLET_EXECUTABLE/backup/32cc8c74-decd-44a8-bc8c-f8f0d7edfffe/yfm-docs.tar",
1935+
"7458707245": "none-none-none-service_resources/TASKLET_EXECUTABLE/backup/4e7df89f-3762-4eba-ba73-562ccaeae548/yfm-docs.tar",
19321936
"7414146467": "none-none-none-service_resources/TASKLET_EXECUTABLE/backup/66167d72-07fa-444c-8493-dea0a39d034e/yfm-docs.tar",
19331937
"7442753753": "none-none-none-service_resources/TASKLET_EXECUTABLE/backup/68e622e9-832b-4a30-81c5-a38c80bb0776/yfm-docs.tar",
19341938
"7406675906": "none-none-none-service_resources/TASKLET_EXECUTABLE/backup/6bba4fa0-ac5e-4a8a-89df-ce9e09573567/yfm-docs.tar",
19351939
"7442782962": "none-none-none-service_resources/TASKLET_EXECUTABLE/backup/6c14a83e-0f36-4397-92ae-c7f2fc1c69ce/yfm-docs.tar",
19361940
"7406663741": "none-none-none-service_resources/TASKLET_EXECUTABLE/backup/6f3d31a2-e730-48d5-92b4-024148b5768a/yfm-docs.tar",
1941+
"7458616985": "none-none-none-service_resources/TASKLET_EXECUTABLE/backup/85261fb1-0e04-4e8d-b1d5-7042725f1345/yfm-docs.tar",
19371942
"7406665335": "none-none-none-service_resources/TASKLET_EXECUTABLE/backup/895e2cbd-d4a8-4a5c-9cf5-5666e796f17a/yfm-docs.tar",
1943+
"7458630270": "none-none-none-service_resources/TASKLET_EXECUTABLE/backup/8bb29ea7-2952-4e33-b716-e6d188b5ded9/yfm-docs.tar",
19381944
"7193800506": "none-none-none-service_resources/TASKLET_EXECUTABLE/backup/9be8ed55-d7f8-4029-a7fd-fbfa072b896f/yfm-docs.tar",
19391945
"7324461714": "none-none-none-service_resources/TASKLET_EXECUTABLE/backup/b3543418-58d4-4e1c-b2be-43b55b035e91/yfm-docs.tar",
19401946
"7193813071": "none-none-none-service_resources/TASKLET_EXECUTABLE/backup/b6531a79-b803-4672-a9e9-f9f348009f5f/yfm-docs.tar",

library/python/testing/yatest_common/yatest/common/canonical.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414

1515
def _copy(src, dst, universal_lines=False):
1616
if universal_lines:
17-
with open(dst, "wb") as f:
17+
with open(dst, "wb") as f_dst:
1818
mode = "rbU" if six.PY2 else "rb"
19-
for line in open(src, mode):
20-
f.write(line)
19+
with open(src, mode) as f_src:
20+
for line in f_src:
21+
f_dst.write(line)
2122
return
2223
shutil.copy(src, dst)
2324

yql/essentials/core/yql_expr_optimize.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "yql_expr_type_annotation.h"
55

66
#include <yql/essentials/utils/log/log.h>
7+
#include <yql/essentials/utils/log/profile.h>
78

89
namespace NYql {
910

@@ -343,7 +344,7 @@ namespace {
343344
}
344345
}
345346

346-
void VisitExprLambdasLastInternal(const TExprNode::TPtr& node,
347+
void VisitExprLambdasLastInternal(const TExprNode::TPtr& node,
347348
const TExprVisitPtrFunc& preLambdaFunc,
348349
const TExprVisitPtrFunc& postLambdaFunc,
349350
TNodeSet& visitedNodes)
@@ -357,9 +358,9 @@ namespace {
357358
VisitExprLambdasLastInternal(child, preLambdaFunc, postLambdaFunc, visitedNodes);
358359
}
359360
}
360-
361+
361362
preLambdaFunc(node);
362-
363+
363364
for (auto child : node->Children()) {
364365
if (child->IsLambda()) {
365366
VisitExprLambdasLastInternal(child, preLambdaFunc, postLambdaFunc, visitedNodes);
@@ -536,7 +537,7 @@ IGraphTransformer::TStatus ExpandApply(const TExprNode::TPtr& input, TExprNode::
536537
if (ctx.Step.IsDone(TExprStep::ExpandApplyForLambdas))
537538
return IGraphTransformer::TStatus::Ok;
538539

539-
YQL_CLOG(DEBUG, Core) << "Start ExpandApply";
540+
YQL_PROFILE_SCOPE(DEBUG, "ExpandApply");
540541
TOptimizeExprSettings settings(nullptr);
541542
auto ret = OptimizeExpr(input, output, [&](const TExprNode::TPtr& node, bool& changed, TExprContext& ctx) -> TExprNode::TPtr {
542543
if (node->Content() == "WithOptionalArgs") {
@@ -858,7 +859,6 @@ IGraphTransformer::TStatus ExpandApply(const TExprNode::TPtr& input, TExprNode::
858859
ctx.Step.Done(TExprStep::ExpandApplyForLambdas);
859860
}
860861

861-
YQL_CLOG(DEBUG, Core) << "Finish ExpandApply";
862862
return ret;
863863
}
864864

@@ -910,7 +910,7 @@ void VisitExpr(const TExprNode& root, const TExprVisitRefFunc& preFunc, const TE
910910
void VisitExpr(const TExprNode::TPtr& root, const TExprVisitPtrFunc& func, TNodeSet& visitedNodes) {
911911
VisitExprInternal(root, func, {}, visitedNodes);
912912
}
913-
913+
914914
void VisitExprLambdasLast(const TExprNode::TPtr& root, const TExprVisitPtrFunc& preLambdaFunc, const TExprVisitPtrFunc& postLambdaFunc)
915915
{
916916
TNodeSet visitedNodes;

yt/yt/library/decimal/decimal.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,10 +891,28 @@ TStringBuf TDecimal::WriteBinary256(int precision, TValue256 value, char* buffer
891891
CheckDecimalIntBits<TValue256>(precision);
892892
YT_VERIFY(bufferLength >= resultLength);
893893

894-
DecimalIntegerToBinaryUnchecked(std::move(value), buffer);
894+
DecimalIntegerToBinaryUnchecked(value, buffer);
895895
return TStringBuf{buffer, sizeof(TValue256)};
896896
}
897897

898+
TStringBuf TDecimal::WriteBinary256Variadic(int precision, TValue256 value, char* buffer, size_t bufferLength)
899+
{
900+
const size_t resultLength = GetValueBinarySize(precision);
901+
switch (resultLength) {
902+
case 4:
903+
return WriteBinary32(precision, *reinterpret_cast<i32*>(value.Parts.data()), buffer, bufferLength);
904+
case 8:
905+
return WriteBinary64(precision, *reinterpret_cast<i64*>(value.Parts.data()), buffer, bufferLength);
906+
case 16:
907+
return WriteBinary128(precision, *reinterpret_cast<TValue128*>(value.Parts.data()), buffer, bufferLength);
908+
case 32:
909+
return WriteBinary256(precision, value, buffer, bufferLength);
910+
default:
911+
THROW_ERROR_EXCEPTION("Invalid precision %v", precision);
912+
}
913+
}
914+
915+
898916
template <typename T>
899917
Y_FORCE_INLINE void CheckBufferLength(int precision, size_t bufferLength)
900918
{

yt/yt/library/decimal/decimal.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class TDecimal
2424
};
2525
static_assert(sizeof(TValue128) == 2 * sizeof(ui64));
2626

27+
//! Lower-endian representation of 256-bit decimal value.
2728
struct TValue256
2829
{
2930
std::array<ui32, 8> Parts;
@@ -64,6 +65,8 @@ class TDecimal
6465

6566
// Writes either 32-bit, 64-bit or 128-bit binary value depending on precision, provided a TValue128.
6667
static TStringBuf WriteBinary128Variadic(int precision, TValue128 value, char* buffer, size_t bufferLength);
68+
// Writes either 32-bit, 64-bit, 128-bit or 256-bit binary value depending on precision, provided a TValue256.
69+
static TStringBuf WriteBinary256Variadic(int precision, TValue256 value, char* buffer, size_t bufferLength);
6770

6871
static i32 ParseBinary32(int precision, TStringBuf buffer);
6972
static i64 ParseBinary64(int precision, TStringBuf buffer);

yt/yt/library/formats/arrow_parser.cpp

Lines changed: 57 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@ void ThrowOnError(const arrow::Status& status)
4040
}
4141
}
4242

43+
template <class TUnderlyingValueType>
44+
TStringBuf SerializeDecimalBinary(const TStringBuf& value, int precision, char* buffer, size_t bufferLength)
45+
{
46+
// NB: Arrow wire representation of Decimal128 is little-endian and (obviously) 128 bit,
47+
// while YT in-memory representation of Decimal is big-endian, variadic-length of either 32 bit, 64 bit or 128 bit,
48+
// and MSB-flipped to ensure lexical sorting order.
49+
// Representation of Decimal256 is similar, but the upper limit for a length is 256 bit.
50+
TUnderlyingValueType decimalValue;
51+
YT_VERIFY(value.size() == sizeof(decimalValue));
52+
std::memcpy(&decimalValue, value.data(), value.size());
53+
54+
TStringBuf decimalBinary;
55+
if constexpr (std::is_same_v<TUnderlyingValueType, TDecimal::TValue128>) {
56+
decimalBinary = TDecimal::WriteBinary128Variadic(precision, decimalValue, buffer, bufferLength);
57+
} else if constexpr (std::is_same_v<TUnderlyingValueType, TDecimal::TValue256>) {
58+
decimalBinary = TDecimal::WriteBinary256Variadic(precision, decimalValue, buffer, bufferLength);
59+
} else {
60+
static_assert(std::is_same_v<TUnderlyingValueType, TDecimal::TValue256>, "Unexpected decimal type");
61+
}
62+
return decimalBinary;
63+
}
64+
4365
////////////////////////////////////////////////////////////////////////////////
4466

4567
class TArraySimpleVisitor
@@ -291,28 +313,12 @@ class TArraySimpleVisitor
291313
}
292314

293315
template <class TUnderlyingValueType>
294-
TUnversionedValue MakeDecimalBinaryValue(const TStringBuf& value, i64 columnId, int precision)
316+
TUnversionedValue MakeDecimalBinaryValue(const TStringBuf& arrowValue, i64 columnId, int precision)
295317
{
296-
// NB: Arrow wire representation of Decimal128 is little-endian and (obviously) 128 bit,
297-
// while YT in-memory representation of Decimal is big-endian, variadic-length of either 32 bit, 64 bit or 128 bit,
298-
// and MSB-flipped to ensure lexical sorting order.
299-
// Representation of Decimal256 is similar, but only 256 bits.
300-
TUnderlyingValueType decimalValue;
301-
YT_VERIFY(value.size() == sizeof(decimalValue));
302-
std::memcpy(&decimalValue, value.data(), value.size());
303-
304-
const auto maxByteCount = sizeof(decimalValue);
318+
const auto maxByteCount = sizeof(TUnderlyingValueType);
305319
char* buffer = BufferForStringLikeValues_->Preallocate(maxByteCount);
306-
TStringBuf decimalBinary;
307-
if constexpr (std::is_same_v<TUnderlyingValueType, TDecimal::TValue128>) {
308-
decimalBinary = TDecimal::WriteBinary128Variadic(precision, decimalValue, buffer, maxByteCount);
309-
} else if constexpr (std::is_same_v<TUnderlyingValueType, TDecimal::TValue256>) {
310-
decimalBinary = TDecimal::WriteBinary256(precision, decimalValue, buffer, maxByteCount);
311-
} else {
312-
static_assert(std::is_same_v<TUnderlyingValueType, TDecimal::TValue256>, "Unexpected decimal type");
313-
}
320+
auto decimalBinary = SerializeDecimalBinary<TUnderlyingValueType>(arrowValue, precision, buffer, maxByteCount);
314321
BufferForStringLikeValues_->Advance(decimalBinary.size());
315-
316322
return MakeUnversionedStringValue(decimalBinary, columnId);
317323
}
318324
};
@@ -456,6 +462,20 @@ class TArrayCompositeVisitor
456462
return ParseStruct();
457463
}
458464

465+
arrow::Status Visit(const arrow::Decimal128Type& type) override
466+
{
467+
return ParseStringLikeArray<arrow::Decimal128Array>([&] (const TStringBuf& value) {
468+
WriteDecimalBinary<TDecimal::TValue128>(value, type.precision());
469+
});
470+
}
471+
472+
arrow::Status Visit(const arrow::Decimal256Type& type) override
473+
{
474+
return ParseStringLikeArray<arrow::Decimal256Array>([&] (const TStringBuf& value) {
475+
WriteDecimalBinary<TDecimal::TValue256>(value, type.precision());
476+
});
477+
}
478+
459479
private:
460480
const int RowIndex_;
461481

@@ -505,13 +525,21 @@ class TArrayCompositeVisitor
505525

506526
template <typename ArrayType>
507527
arrow::Status ParseStringLikeArray()
528+
{
529+
return ParseStringLikeArray<ArrayType>([&] (const TStringBuf& value) {
530+
Writer_->WriteBinaryString(value);
531+
});
532+
}
533+
534+
template <typename ArrayType>
535+
arrow::Status ParseStringLikeArray(auto writeStringValue)
508536
{
509537
auto array = std::static_pointer_cast<ArrayType>(Array_);
510538
if (array->IsNull(RowIndex_)) {
511539
Writer_->WriteEntity();
512540
} else {
513541
auto element = array->GetView(RowIndex_);
514-
Writer_->WriteBinaryString(TStringBuf(element.data(), element.size()));
542+
writeStringValue(TStringBuf(element.data(), element.size()));
515543
}
516544
return arrow::Status::OK();
517545
}
@@ -610,6 +638,15 @@ class TArrayCompositeVisitor
610638
}
611639
return arrow::Status::OK();
612640
}
641+
642+
template <class TUnderlyingType>
643+
void WriteDecimalBinary(TStringBuf arrowValue, int precision)
644+
{
645+
const auto maxByteCount = sizeof(TUnderlyingType);
646+
char buffer[maxByteCount];
647+
auto decimalBinary = SerializeDecimalBinary<TUnderlyingType>(arrowValue, precision, buffer, maxByteCount);
648+
Writer_->WriteBinaryString(decimalBinary);
649+
}
613650
};
614651

615652
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)