Skip to content

result_format: data parser & builder #8748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ydb/core/kqp/provider/yql_kikimr_results.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <ydb/library/uuid/uuid.h>

#include <ydb/library/yql/parser/pg_wrapper/interface/type_desc.h>
#include <ydb/library/yql/providers/common/codec/yql_codec_results.h>
#include <ydb/library/yql/public/result_format/yql_codec_results.h>
#include <ydb/library/yql/public/decimal/yql_decimal.h>

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

void WriteValueToYson(const TStringStream& stream, NCommon::TYsonResultWriter& writer, const NKikimrMiniKQL::TType& type,
void WriteValueToYson(const TStringStream& stream, NResult::TYsonResultWriter& writer, const NKikimrMiniKQL::TType& type,
const NKikimrMiniKQL::TValue& value, const TVector<TString>* fieldsOrder,
const IDataProvider::TFillSettings& fillSettings, bool& truncated, bool firstLevel = false)
{
Expand Down Expand Up @@ -333,7 +333,7 @@ void KikimrResultToYson(const TStringStream& stream, NYson::TYsonWriter& writer,
const TVector<TString>& columnHints, const IDataProvider::TFillSettings& fillSettings, bool& truncated)
{
truncated = false;
NCommon::TYsonResultWriter resultWriter(writer);
NResult::TYsonResultWriter resultWriter(writer);
WriteValueToYson(stream, resultWriter, result.GetType(), result.GetValue(), columnHints.empty() ? nullptr : &columnHints,
fillSettings, truncated, true);
}
Expand Down
4 changes: 2 additions & 2 deletions ydb/library/yql/parser/pg_wrapper/comp_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ constexpr auto PG_ERROR = ERROR;
#include <ydb/library/yql/public/udf/arrow/block_builder.cpp>
#include <ydb/library/yql/parser/pg_catalog/catalog.h>
#include <ydb/library/yql/providers/common/codec/yql_codec_buf.h>
#include <ydb/library/yql/providers/common/codec/yql_codec_results.h>
#include <ydb/library/yql/public/result_format/yql_codec_results.h>
#include <ydb/library/yql/public/udf/udf_value_builder.h>
#include <ydb/library/yql/utils/fp_bits.h>
#include <library/cpp/yson/detail.h>
Expand Down Expand Up @@ -3699,7 +3699,7 @@ void WriteYsonValueInTableFormatPg(TOutputBuf& buf, TPgType* type, const NUdf::T
}
}

void WriteYsonValuePg(TYsonResultWriter& writer, const NUdf::TUnboxedValuePod& value, TPgType* type,
void WriteYsonValuePg(NResult::TYsonResultWriter& writer, const NUdf::TUnboxedValuePod& value, TPgType* type,
const TVector<ui32>* structPositions) {
if (!value) {
writer.OnNull();
Expand Down
7 changes: 5 additions & 2 deletions ydb/library/yql/parser/pg_wrapper/interface/codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ class TPgType;
} // NKikimr

namespace NYql {
namespace NResult {
class TYsonResultWriter;
}

namespace NCommon {

class TInputBuf;
class TOutputBuf;
class TYsonResultWriter;

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

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

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

void WriteYsonValueInTableFormatPg(TOutputBuf& buf, NKikimr::NMiniKQL::TPgType* type, const NKikimr::NUdf::TUnboxedValuePod& value, bool topLevel);
Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/parser/pg_wrapper/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ PEERDIR(
ydb/library/yql/public/udf
ydb/library/yql/utils
ydb/library/yql/public/decimal
ydb/library/yql/public/result_format
ydb/library/binary_json
ydb/library/dynumber
ydb/library/uuid
Expand Down
1 change: 0 additions & 1 deletion ydb/library/yql/providers/common/codec/ut/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ ENDIF()

SRCS(
yql_json_codec_ut.cpp
yql_restricted_yson_ut.cpp
)

PEERDIR(
Expand Down
5 changes: 1 addition & 4 deletions ydb/library/yql/providers/common/codec/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ SRCS(
yql_codec.h
yql_codec_buf.cpp
yql_codec_buf.h
yql_codec_results.cpp
yql_codec_results.h
yql_restricted_yson.cpp
yql_restricted_yson.h
yql_codec_type_flags.cpp
yql_codec_type_flags.h
yql_json_codec.cpp
Expand All @@ -18,6 +14,7 @@ PEERDIR(
ydb/library/yql/minikql/computation
ydb/library/yql/parser/pg_wrapper/interface
ydb/library/yql/providers/common/mkql
ydb/library/yql/public/result_format
library/cpp/yson/node
library/cpp/yson
library/cpp/json
Expand Down
13 changes: 6 additions & 7 deletions ydb/library/yql/providers/common/codec/yql_codec.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
#include "yql_codec.h"
#include "yql_restricted_yson.h"
#include "yql_codec_type_flags.h"

#include <ydb/library/yql/core/yql_expr_type_annotation.h>

#include <ydb/library/yql/public/decimal/yql_decimal.h>
#include <ydb/library/yql/public/decimal/yql_decimal_serialize.h>
#include <ydb/library/yql/minikql/mkql_node_cast.h>
#include <ydb/library/yql/minikql/mkql_string_util.h>
#include <ydb/library/yql/minikql/mkql_type_builder.h>
#include <ydb/library/yql/minikql/computation/mkql_computation_node_pack.h>
#include <ydb/library/yql/public/result_format/yql_restricted_yson.h>

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

void WriteYsonValueImpl(TYsonResultWriter& writer, const NUdf::TUnboxedValuePod& value, TType* type,
void WriteYsonValueImpl(NResult::TYsonResultWriter& writer, const NUdf::TUnboxedValuePod& value, TType* type,
const TVector<ui32>* structPositions) {
// Result format
switch (type->GetKind()) {
Expand Down Expand Up @@ -107,7 +106,7 @@ void WriteYsonValueImpl(TYsonResultWriter& writer, const NUdf::TUnboxedValuePod&
return;
}
case NUdf::EDataSlot::Yson:
EncodeRestrictedYson(writer, value.AsStringRef());
NResult::EncodeRestrictedYson(writer, value.AsStringRef());
return;
case NUdf::EDataSlot::Date:
writer.OnUint64Scalar(value.Get<ui16>());
Expand Down Expand Up @@ -263,7 +262,7 @@ void WriteYsonValueImpl(TYsonResultWriter& writer, const NUdf::TUnboxedValuePod&
void WriteYsonValue(NYson::TYsonConsumerBase& writer, const NUdf::TUnboxedValuePod& value, TType* type,
const TVector<ui32>* structPositions)
{
TYsonResultWriter resultWriter(writer);
NResult::TYsonResultWriter resultWriter(writer);
WriteYsonValueImpl(resultWriter, value, type, structPositions);
}

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

TString decodedYson = DecodeRestrictedYson(TStringBuf(yson.data(), yson.size()), NYson::EYsonFormat::Text);
TString decodedYson = NResult::DecodeRestrictedYson(TStringBuf(yson.data(), yson.size()), NYson::EYsonFormat::Text);
return NUdf::TUnboxedValue(MakeString(NUdf::TStringRef(decodedYson)));
}

Expand Down Expand Up @@ -1436,7 +1435,7 @@ NUdf::TUnboxedValue ReadYsonValue(TType* type, ui64 nativeYtTypeFlags,
}

auto nextString = ReadNextString(cmd, buf);
YQL_ENSURE(nextString == TYsonResultWriter::VoidString, "Expected Void");
YQL_ENSURE(nextString == NResult::TYsonResultWriter::VoidString, "Expected Void");
return NUdf::TUnboxedValuePod::Void();
}

Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/providers/yt/codec/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ PEERDIR(
ydb/library/yql/minikql
ydb/library/yql/public/udf
ydb/library/yql/utils
ydb/library/yql/public/result_format
ydb/library/yql/providers/common/codec
ydb/library/yql/providers/common/schema/mkql
ydb/library/yql/providers/common/schema/parser
Expand Down
4 changes: 2 additions & 2 deletions ydb/library/yql/providers/yt/codec/yt_codec_io.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "yt_codec_io.h"

#include <ydb/library/yql/providers/common/codec/yql_restricted_yson.h>
#include <ydb/library/yql/public/result_format/yql_restricted_yson.h>
#include <ydb/library/yql/providers/common/codec/yql_codec_type_flags.h>
#include <ydb/library/yql/providers/common/codec/yql_codec.h>
#include <ydb/library/yql/providers/yt/common/yql_names.h>
Expand Down Expand Up @@ -2225,7 +2225,7 @@ void DecodeToYson(TMkqlIOCache& specsCache, size_t tableIndex, const NYT::TNode&
}
if (res.GetType() != NYT::TNode::Undefined) {
if (dataType->GetKind() == TType::EKind::Data && static_cast<TDataType*>(dataType)->GetSchemeType() == NUdf::TDataType<NUdf::TYson>::Id) {
items[field->StructIndex] = NCommon::EncodeRestrictedYson(res, NYT::NYson::EYsonFormat::Binary);
items[field->StructIndex] = NResult::EncodeRestrictedYson(res, NYT::NYson::EYsonFormat::Binary);
} else {
items[field->StructIndex] = NYT::NodeToYsonString(res, NYT::NYson::EYsonFormat::Binary);
}
Expand Down
7 changes: 5 additions & 2 deletions ydb/library/yql/public/result_format/ut/ya.make
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
UNITTEST_FOR(ydb/library/yql/public/result_format)

SRCS(
yql_result_format_ut.cpp
yql_result_format_response_ut.cpp
yql_result_format_type_ut.cpp
yql_result_format_data_ut.cpp
yql_restricted_yson_ut.cpp
)

PEERDIR(
library/cpp/yson/node
library/cpp/string_utils/base64
)

END()

Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ TString Normalize(const TString& yson) {
Y_UNIT_TEST_SUITE(TRestrictedYson) {
void RunTest(const NYT::TNode& node, const TString& expectedNodeStr, const TString& expectedEncodedStr) {
UNIT_ASSERT_VALUES_EQUAL(FormatNode(node), expectedNodeStr);
TString encoded = NCommon::EncodeRestrictedYson(node, NYson::EYsonFormat::Text);
TString encoded = NResult::EncodeRestrictedYson(node, NYson::EYsonFormat::Text);
UNIT_ASSERT_VALUES_EQUAL(Normalize(encoded), expectedEncodedStr);
TString decoded = NCommon::DecodeRestrictedYson(TStringBuf(encoded), NYson::EYsonFormat::Text);
TString decoded = NResult::DecodeRestrictedYson(TStringBuf(encoded), NYson::EYsonFormat::Text);
UNIT_ASSERT_VALUES_EQUAL(FormatNode(node), Normalize(decoded));
}

Expand Down
Loading
Loading