Skip to content

Commit 85d1fd0

Browse files
authored
result_format: data parser & builder (#8748)
1 parent cba7316 commit 85d1fd0

30 files changed

+2401
-525
lines changed

ydb/core/kqp/provider/yql_kikimr_results.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include <ydb/library/uuid/uuid.h>
66

77
#include <ydb/library/yql/parser/pg_wrapper/interface/type_desc.h>
8-
#include <ydb/library/yql/providers/common/codec/yql_codec_results.h>
8+
#include <ydb/library/yql/public/result_format/yql_codec_results.h>
99
#include <ydb/library/yql/public/decimal/yql_decimal.h>
1010

1111
namespace NYql {
@@ -26,7 +26,7 @@ bool ResultsOverflow(ui64 rows, ui64 bytes, const IDataProvider::TFillSettings&
2626
return false;
2727
}
2828

29-
void WriteValueToYson(const TStringStream& stream, NCommon::TYsonResultWriter& writer, const NKikimrMiniKQL::TType& type,
29+
void WriteValueToYson(const TStringStream& stream, NResult::TYsonResultWriter& writer, const NKikimrMiniKQL::TType& type,
3030
const NKikimrMiniKQL::TValue& value, const TVector<TString>* fieldsOrder,
3131
const IDataProvider::TFillSettings& fillSettings, bool& truncated, bool firstLevel = false)
3232
{
@@ -333,7 +333,7 @@ void KikimrResultToYson(const TStringStream& stream, NYson::TYsonWriter& writer,
333333
const TVector<TString>& columnHints, const IDataProvider::TFillSettings& fillSettings, bool& truncated)
334334
{
335335
truncated = false;
336-
NCommon::TYsonResultWriter resultWriter(writer);
336+
NResult::TYsonResultWriter resultWriter(writer);
337337
WriteValueToYson(stream, resultWriter, result.GetType(), result.GetValue(), columnHints.empty() ? nullptr : &columnHints,
338338
fillSettings, truncated, true);
339339
}

ydb/library/yql/parser/pg_wrapper/comp_factory.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ constexpr auto PG_ERROR = ERROR;
8484
#include <ydb/library/yql/public/udf/arrow/block_builder.cpp>
8585
#include <ydb/library/yql/parser/pg_catalog/catalog.h>
8686
#include <ydb/library/yql/providers/common/codec/yql_codec_buf.h>
87-
#include <ydb/library/yql/providers/common/codec/yql_codec_results.h>
87+
#include <ydb/library/yql/public/result_format/yql_codec_results.h>
8888
#include <ydb/library/yql/public/udf/udf_value_builder.h>
8989
#include <ydb/library/yql/utils/fp_bits.h>
9090
#include <library/cpp/yson/detail.h>
@@ -3699,7 +3699,7 @@ void WriteYsonValueInTableFormatPg(TOutputBuf& buf, TPgType* type, const NUdf::T
36993699
}
37003700
}
37013701

3702-
void WriteYsonValuePg(TYsonResultWriter& writer, const NUdf::TUnboxedValuePod& value, TPgType* type,
3702+
void WriteYsonValuePg(NResult::TYsonResultWriter& writer, const NUdf::TUnboxedValuePod& value, TPgType* type,
37033703
const TVector<ui32>* structPositions) {
37043704
if (!value) {
37053705
writer.OnNull();

ydb/library/yql/parser/pg_wrapper/interface/codec.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ class TPgType;
1414
} // NKikimr
1515

1616
namespace NYql {
17+
namespace NResult {
18+
class TYsonResultWriter;
19+
}
20+
1721
namespace NCommon {
1822

1923
class TInputBuf;
2024
class TOutputBuf;
21-
class TYsonResultWriter;
2225

2326
TString PgValueToString(const NUdf::TUnboxedValuePod& value, ui32 pgTypeId);
2427
NUdf::TUnboxedValue PgValueFromString(const TStringBuf text, ui32 pgTypeId);
@@ -31,7 +34,7 @@ NUdf::TUnboxedValue PgValueFromNativeBinary(const TStringBuf binary, ui32 pgType
3134

3235
TString PgValueCoerce(const NUdf::TUnboxedValuePod& value, ui32 pgTypeId, i32 typMod, TMaybe<TString>* error);
3336

34-
void WriteYsonValuePg(TYsonResultWriter& writer, const NUdf::TUnboxedValuePod& value, NKikimr::NMiniKQL::TPgType* type,
37+
void WriteYsonValuePg(NResult::TYsonResultWriter& writer, const NUdf::TUnboxedValuePod& value, NKikimr::NMiniKQL::TPgType* type,
3538
const TVector<ui32>* structPositions);
3639

3740
void WriteYsonValueInTableFormatPg(TOutputBuf& buf, NKikimr::NMiniKQL::TPgType* type, const NKikimr::NUdf::TUnboxedValuePod& value, bool topLevel);

ydb/library/yql/parser/pg_wrapper/ya.make

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ PEERDIR(
8888
ydb/library/yql/public/udf
8989
ydb/library/yql/utils
9090
ydb/library/yql/public/decimal
91+
ydb/library/yql/public/result_format
9192
ydb/library/binary_json
9293
ydb/library/dynumber
9394
ydb/library/uuid

ydb/library/yql/providers/common/codec/ut/ya.make

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ ENDIF()
88

99
SRCS(
1010
yql_json_codec_ut.cpp
11-
yql_restricted_yson_ut.cpp
1211
)
1312

1413
PEERDIR(

ydb/library/yql/providers/common/codec/ya.make

+1-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ SRCS(
55
yql_codec.h
66
yql_codec_buf.cpp
77
yql_codec_buf.h
8-
yql_codec_results.cpp
9-
yql_codec_results.h
10-
yql_restricted_yson.cpp
11-
yql_restricted_yson.h
128
yql_codec_type_flags.cpp
139
yql_codec_type_flags.h
1410
yql_json_codec.cpp
@@ -18,6 +14,7 @@ PEERDIR(
1814
ydb/library/yql/minikql/computation
1915
ydb/library/yql/parser/pg_wrapper/interface
2016
ydb/library/yql/providers/common/mkql
17+
ydb/library/yql/public/result_format
2118
library/cpp/yson/node
2219
library/cpp/yson
2320
library/cpp/json

ydb/library/yql/providers/common/codec/yql_codec.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#include "yql_codec.h"
2-
#include "yql_restricted_yson.h"
32
#include "yql_codec_type_flags.h"
43

54
#include <ydb/library/yql/core/yql_expr_type_annotation.h>
6-
75
#include <ydb/library/yql/public/decimal/yql_decimal.h>
86
#include <ydb/library/yql/public/decimal/yql_decimal_serialize.h>
97
#include <ydb/library/yql/minikql/mkql_node_cast.h>
108
#include <ydb/library/yql/minikql/mkql_string_util.h>
119
#include <ydb/library/yql/minikql/mkql_type_builder.h>
1210
#include <ydb/library/yql/minikql/computation/mkql_computation_node_pack.h>
11+
#include <ydb/library/yql/public/result_format/yql_restricted_yson.h>
1312

1413
#include <ydb/library/yql/utils/yql_panic.h>
1514
#include <ydb/library/yql/utils/swap_bytes.h>
@@ -33,7 +32,7 @@ using namespace NKikimr;
3332
using namespace NKikimr::NMiniKQL;
3433
using namespace NYson::NDetail;
3534

36-
void WriteYsonValueImpl(TYsonResultWriter& writer, const NUdf::TUnboxedValuePod& value, TType* type,
35+
void WriteYsonValueImpl(NResult::TYsonResultWriter& writer, const NUdf::TUnboxedValuePod& value, TType* type,
3736
const TVector<ui32>* structPositions) {
3837
// Result format
3938
switch (type->GetKind()) {
@@ -107,7 +106,7 @@ void WriteYsonValueImpl(TYsonResultWriter& writer, const NUdf::TUnboxedValuePod&
107106
return;
108107
}
109108
case NUdf::EDataSlot::Yson:
110-
EncodeRestrictedYson(writer, value.AsStringRef());
109+
NResult::EncodeRestrictedYson(writer, value.AsStringRef());
111110
return;
112111
case NUdf::EDataSlot::Date:
113112
writer.OnUint64Scalar(value.Get<ui16>());
@@ -263,7 +262,7 @@ void WriteYsonValueImpl(TYsonResultWriter& writer, const NUdf::TUnboxedValuePod&
263262
void WriteYsonValue(NYson::TYsonConsumerBase& writer, const NUdf::TUnboxedValuePod& value, TType* type,
264263
const TVector<ui32>* structPositions)
265264
{
266-
TYsonResultWriter resultWriter(writer);
265+
NResult::TYsonResultWriter resultWriter(writer);
267266
WriteYsonValueImpl(resultWriter, value, type, structPositions);
268267
}
269268

@@ -1030,7 +1029,7 @@ NUdf::TUnboxedValue ReadYsonValue(TType* type, ui64 nativeYtTypeFlags,
10301029
return NUdf::TUnboxedValue(MakeString(NUdf::TStringRef(yson)));
10311030
}
10321031

1033-
TString decodedYson = DecodeRestrictedYson(TStringBuf(yson.data(), yson.size()), NYson::EYsonFormat::Text);
1032+
TString decodedYson = NResult::DecodeRestrictedYson(TStringBuf(yson.data(), yson.size()), NYson::EYsonFormat::Text);
10341033
return NUdf::TUnboxedValue(MakeString(NUdf::TStringRef(decodedYson)));
10351034
}
10361035

@@ -1436,7 +1435,7 @@ NUdf::TUnboxedValue ReadYsonValue(TType* type, ui64 nativeYtTypeFlags,
14361435
}
14371436

14381437
auto nextString = ReadNextString(cmd, buf);
1439-
YQL_ENSURE(nextString == TYsonResultWriter::VoidString, "Expected Void");
1438+
YQL_ENSURE(nextString == NResult::TYsonResultWriter::VoidString, "Expected Void");
14401439
return NUdf::TUnboxedValuePod::Void();
14411440
}
14421441

ydb/library/yql/providers/yt/codec/ya.make

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ PEERDIR(
1818
ydb/library/yql/minikql
1919
ydb/library/yql/public/udf
2020
ydb/library/yql/utils
21+
ydb/library/yql/public/result_format
2122
ydb/library/yql/providers/common/codec
2223
ydb/library/yql/providers/common/schema/mkql
2324
ydb/library/yql/providers/common/schema/parser

ydb/library/yql/providers/yt/codec/yt_codec_io.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "yt_codec_io.h"
22

3-
#include <ydb/library/yql/providers/common/codec/yql_restricted_yson.h>
3+
#include <ydb/library/yql/public/result_format/yql_restricted_yson.h>
44
#include <ydb/library/yql/providers/common/codec/yql_codec_type_flags.h>
55
#include <ydb/library/yql/providers/common/codec/yql_codec.h>
66
#include <ydb/library/yql/providers/yt/common/yql_names.h>
@@ -2225,7 +2225,7 @@ void DecodeToYson(TMkqlIOCache& specsCache, size_t tableIndex, const NYT::TNode&
22252225
}
22262226
if (res.GetType() != NYT::TNode::Undefined) {
22272227
if (dataType->GetKind() == TType::EKind::Data && static_cast<TDataType*>(dataType)->GetSchemeType() == NUdf::TDataType<NUdf::TYson>::Id) {
2228-
items[field->StructIndex] = NCommon::EncodeRestrictedYson(res, NYT::NYson::EYsonFormat::Binary);
2228+
items[field->StructIndex] = NResult::EncodeRestrictedYson(res, NYT::NYson::EYsonFormat::Binary);
22292229
} else {
22302230
items[field->StructIndex] = NYT::NodeToYsonString(res, NYT::NYson::EYsonFormat::Binary);
22312231
}

ydb/library/yql/public/result_format/ut/ya.make

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
UNITTEST_FOR(ydb/library/yql/public/result_format)
22

33
SRCS(
4-
yql_result_format_ut.cpp
4+
yql_result_format_response_ut.cpp
5+
yql_result_format_type_ut.cpp
6+
yql_result_format_data_ut.cpp
7+
yql_restricted_yson_ut.cpp
58
)
69

710
PEERDIR(
811
library/cpp/yson/node
12+
library/cpp/string_utils/base64
913
)
1014

1115
END()
12-

ydb/library/yql/providers/common/codec/yql_restricted_yson_ut.cpp renamed to ydb/library/yql/public/result_format/ut/yql_restricted_yson_ut.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ TString Normalize(const TString& yson) {
2727
Y_UNIT_TEST_SUITE(TRestrictedYson) {
2828
void RunTest(const NYT::TNode& node, const TString& expectedNodeStr, const TString& expectedEncodedStr) {
2929
UNIT_ASSERT_VALUES_EQUAL(FormatNode(node), expectedNodeStr);
30-
TString encoded = NCommon::EncodeRestrictedYson(node, NYson::EYsonFormat::Text);
30+
TString encoded = NResult::EncodeRestrictedYson(node, NYson::EYsonFormat::Text);
3131
UNIT_ASSERT_VALUES_EQUAL(Normalize(encoded), expectedEncodedStr);
32-
TString decoded = NCommon::DecodeRestrictedYson(TStringBuf(encoded), NYson::EYsonFormat::Text);
32+
TString decoded = NResult::DecodeRestrictedYson(TStringBuf(encoded), NYson::EYsonFormat::Text);
3333
UNIT_ASSERT_VALUES_EQUAL(FormatNode(node), Normalize(decoded));
3434
}
3535

0 commit comments

Comments
 (0)