Skip to content

Commit efdd4c7

Browse files
authored
Typed pg descriptor (#8913)
Strong typing of pg_wrapper functions 1. Add NKikimr::NScheme::ITypeDesc 2. Add NKikimr::NPg::ITypeDesc 3. They are casted using reinterpret_cast in ydb/core/scheme_types/scheme_type_info.h
1 parent 4620ab7 commit efdd4c7

File tree

66 files changed

+290
-244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+290
-244
lines changed

ydb/core/engine/minikql/minikql_engine_host.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ NUdf::TUnboxedValue GetCellValue(const TCell& cell, NScheme::TTypeInfo type) {
10871087
}
10881088

10891089
if (type.GetTypeId() == NScheme::NTypeIds::Pg) {
1090-
return NYql::NCommon::PgValueFromNativeBinary(cell.AsBuf(), NPg::PgTypeIdFromTypeDesc(type.GetTypeDesc()));
1090+
return NYql::NCommon::PgValueFromNativeBinary(cell.AsBuf(), NPg::PgTypeIdFromTypeDesc(type.GetPgTypeDesc()));
10911091
}
10921092

10931093
Y_DEBUG_ABORT("Unsupported type: %" PRIu16, type.GetTypeId());

ydb/core/engine/mkql_keys.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ TCell MakeCell(NScheme::TTypeInfo type, const NUdf::TUnboxedValuePod& value,
275275
NYql::NUdf::TStringRef ref;
276276
bool isPg = (type.GetTypeId() == NScheme::NTypeIds::Pg);
277277
if (isPg) {
278-
auto typeDesc = type.GetTypeDesc();
278+
auto typeDesc = type.GetPgTypeDesc();
279279
if (typmod != -1 && NPg::TypeDescNeedsCoercion(typeDesc)) {
280280
TMaybe<TString> err;
281281
binary = NYql::NCommon::PgValueCoerce(value, NPg::PgTypeIdFromTypeDesc(typeDesc), typmod, &err);

ydb/core/engine/mkql_proto.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ bool CellsFromTuple(const NKikimrMiniKQL::TType* tupleType,
192192
if (v.HasBytes()) {
193193
c = TCell(v.GetBytes().data(), v.GetBytes().size());
194194
} else if (v.HasText()) {
195-
auto typeDesc = types[i].GetTypeDesc();
195+
auto typeDesc = types[i].GetPgTypeDesc();
196196
auto convert = NPg::PgNativeBinaryFromNativeText(v.GetText(), NPg::PgTypeIdFromTypeDesc(typeDesc));
197197
if (convert.Error) {
198198
CHECK_OR_RETURN_ERROR(false, Sprintf("Cannot parse value of type Pg: %s in tuple at position %" PRIu32, convert.Error->data(), i));
@@ -329,7 +329,7 @@ bool CellToValue(NScheme::TTypeInfo type, const TCell& c, NKikimrMiniKQL::TValue
329329
break;
330330

331331
case NScheme::NTypeIds::Pg: {
332-
auto convert = NPg::PgNativeTextFromNativeBinary(c.AsBuf(), type.GetTypeDesc());
332+
auto convert = NPg::PgNativeTextFromNativeBinary(c.AsBuf(), type.GetPgTypeDesc());
333333
if (convert.Error) {
334334
errStr = *convert.Error;
335335
return false;

ydb/core/formats/arrow/switch/switch_type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ template <typename TFunc>
177177
break; // Deprecated types
178178

179179
case NScheme::NTypeIds::Pg:
180-
switch (NPg::PgTypeIdFromTypeDesc(typeInfo.GetTypeDesc())) {
180+
switch (NPg::PgTypeIdFromTypeDesc(typeInfo.GetPgTypeDesc())) {
181181
case INT2OID:
182182
return callback(TTypeWrapper<arrow::Int16Type>());
183183
case INT4OID:

ydb/core/grpc_services/rpc_kh_describe.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ class TKikhouseDescribeTableRPC : public TActorBootstrapped<TKikhouseDescribeTab
179179
auto& typeInfo = col.second.PType;
180180
auto* item = colMeta->mutable_type();
181181
if (typeInfo.GetTypeId() == NScheme::NTypeIds::Pg) {
182-
auto* typeDesc = typeInfo.GetTypeDesc();
182+
auto typeDesc = typeInfo.GetPgTypeDesc();
183183
auto* pg = item->mutable_pg_type();
184184
pg->set_type_name(NPg::PgTypeNameFromTypeDesc(typeDesc));
185185
pg->set_oid(NPg::PgTypeIdFromTypeDesc(typeDesc));

ydb/core/grpc_services/rpc_object_storage.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ bool CellFromTuple(NScheme::TTypeInfo type,
116116
if (tupleValue.Hasbytes_value()) {
117117
c = TCell(tupleValue.Getbytes_value().data(), tupleValue.Getbytes_value().size());
118118
} else if (tupleValue.Hastext_value()) {
119-
auto typeDesc = type.GetTypeDesc();
119+
auto typeDesc = type.GetPgTypeDesc();
120120
auto convert = NPg::PgNativeBinaryFromNativeText(tupleValue.Gettext_value(), NPg::PgTypeIdFromTypeDesc(typeDesc));
121121
if (convert.Error) {
122122
CHECK_OR_RETURN_ERROR(false, Sprintf("Cannot parse value of type Pg: %s in tuple at position %" PRIu32, convert.Error->data(), position));
@@ -815,7 +815,7 @@ class TObjectStorageListingRequestGrpc : public TActorBootstrapped<TObjectStorag
815815

816816
void FillResultRows(Ydb::ResultSet &resultSet, TVector<TSysTables::TTableColumnInfo> &columns, TVector<TSerializedCellVec> resultRows) {
817817
const auto getPgTypeFromColMeta = [](const auto &colMeta) {
818-
return NYdb::TPgType(NPg::PgTypeNameFromTypeDesc(colMeta.PType.GetTypeDesc()),
818+
return NYdb::TPgType(NPg::PgTypeNameFromTypeDesc(colMeta.PType.GetPgTypeDesc()),
819819
colMeta.PTypeMod);
820820
};
821821

@@ -846,7 +846,7 @@ class TObjectStorageListingRequestGrpc : public TActorBootstrapped<TObjectStorag
846846
const auto& cell = row.GetCells()[i];
847847
vb.AddMember(colMeta.Name);
848848
if (colMeta.PType.GetTypeId() == NScheme::NTypeIds::Pg) {
849-
const NPg::TConvertResult& pgResult = NPg::PgNativeTextFromNativeBinary(cell.AsBuf(), colMeta.PType.GetTypeDesc());
849+
const NPg::TConvertResult& pgResult = NPg::PgNativeTextFromNativeBinary(cell.AsBuf(), colMeta.PType.GetPgTypeDesc());
850850
if (pgResult.Error) {
851851
LOG_DEBUG_S(TlsActivationContext->AsActorContext(), NKikimrServices::RPC_REQUEST, "PgNativeTextFromNativeBinary error " << *pgResult.Error);
852852
}

ydb/core/grpc_services/rpc_read_rows.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class TReadRowsRPC : public TActorBootstrapped<TReadRowsRPC> {
164164
}
165165
} else if (typeInProto.has_pg_type()) {
166166
const auto& typeName = typeInProto.pg_type().type_name();
167-
auto* typeDesc = NPg::TypeDescFromPgTypeName(typeName);
167+
auto typeDesc = NPg::TypeDescFromPgTypeName(typeName);
168168
if (!typeDesc) {
169169
errorMessage = Sprintf("Unknown pg type for column %s: %s",
170170
name.c_str(), typeName.c_str());
@@ -567,7 +567,7 @@ class TReadRowsRPC : public TActorBootstrapped<TReadRowsRPC> {
567567
auto& ioStats = stats.ReadIOStat;
568568

569569
const auto getPgTypeFromColMeta = [](const auto &colMeta) {
570-
return NYdb::TPgType(NPg::PgTypeNameFromTypeDesc(colMeta.Type.GetTypeDesc()),
570+
return NYdb::TPgType(NPg::PgTypeNameFromTypeDesc(colMeta.Type.GetPgTypeDesc()),
571571
colMeta.PTypeMod);
572572
};
573573

@@ -604,7 +604,7 @@ class TReadRowsRPC : public TActorBootstrapped<TReadRowsRPC> {
604604
vb.AddMember(colMeta.Name);
605605
if (colMeta.Type.GetTypeId() == NScheme::NTypeIds::Pg)
606606
{
607-
const NPg::TConvertResult& pgResult = NPg::PgNativeTextFromNativeBinary(cell.AsBuf(), colMeta.Type.GetTypeDesc());
607+
const NPg::TConvertResult& pgResult = NPg::PgNativeTextFromNativeBinary(cell.AsBuf(), colMeta.Type.GetPgTypeDesc());
608608
if (pgResult.Error) {
609609
LOG_DEBUG_S(TlsActivationContext->AsActorContext(), NKikimrServices::RPC_REQUEST, "PgNativeTextFromNativeBinary error " << *pgResult.Error);
610610
}

ydb/core/io_formats/cell_maker/cell_maker.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,23 +108,23 @@ namespace {
108108
}
109109

110110
template <typename T>
111-
bool TryParse(TStringBuf value, T& result, TString& err, void* parseParam) {
111+
bool TryParse(TStringBuf value, T& result, TString& err, const NScheme::TTypeInfo& typeInfo) {
112112
Y_UNUSED(value);
113113
Y_UNUSED(result);
114114
Y_UNUSED(err);
115-
Y_UNUSED(parseParam);
116-
Y_ABORT("TryParse with parseParam is unimplemented");
115+
Y_UNUSED(typeInfo);
116+
Y_ABORT("TryParse with typeInfo is unimplemented");
117117
}
118118

119-
template <>
120-
bool TryParse(TStringBuf value, NPg::TConvertResult& result, TString& err, void* typeDesc) {
119+
template<>
120+
bool TryParse<NPg::TConvertResult>(TStringBuf value, NPg::TConvertResult& result, TString& err, const NScheme::TTypeInfo& typeInfo) {
121121
TString unescaped;
122122
if (!CheckedUnescape(value, unescaped)) {
123123
err = MakeError<NPg::TConvertResult>();
124124
return false;
125125
}
126126

127-
result = NPg::PgNativeBinaryFromNativeText(unescaped, typeDesc);
127+
result = NPg::PgNativeBinaryFromNativeText(unescaped, typeInfo.GetPgTypeDesc());
128128
if (result.Error) {
129129
err = *result.Error;
130130
return false;
@@ -233,9 +233,9 @@ namespace {
233233
return Conv(c, v, pool, conv);
234234
}
235235

236-
static bool Make(TCell& c, TStringBuf v, TMemoryPool& pool, TString& err, TConverter<T, TStringBuf> conv, void* parseParam) {
236+
static bool Make(TCell& c, TStringBuf v, TMemoryPool& pool, TString& err, TConverter<T, TStringBuf> conv, const NScheme::TTypeInfo& typeInfo) {
237237
T t;
238-
if (!TryParse<T>(v, t, err, parseParam)) {
238+
if (!TryParse(v, t, err, typeInfo)) {
239239
return false;
240240
}
241241

@@ -266,12 +266,12 @@ namespace {
266266

267267
} // anonymous
268268

269-
bool MakeCell(TCell& cell, TStringBuf value, NScheme::TTypeInfo type, TMemoryPool& pool, TString& err) {
269+
bool MakeCell(TCell& cell, TStringBuf value, const NScheme::TTypeInfo& typeInfo, TMemoryPool& pool, TString& err) {
270270
if (value == "null") {
271271
return true;
272272
}
273273

274-
switch (type.GetTypeId()) {
274+
switch (typeInfo.GetTypeId()) {
275275
case NScheme::NTypeIds::Bool:
276276
return TCellMaker<bool>::Make(cell, value, pool, err);
277277
case NScheme::NTypeIds::Int8:
@@ -322,21 +322,21 @@ bool MakeCell(TCell& cell, TStringBuf value, NScheme::TTypeInfo type, TMemoryPoo
322322
case NScheme::NTypeIds::Decimal:
323323
return TCellMaker<NYql::NDecimal::TInt128, std::pair<ui64, ui64>>::Make(cell, value, pool, err, &Int128ToPair);
324324
case NScheme::NTypeIds::Pg:
325-
return TCellMaker<NPg::TConvertResult, TStringBuf>::Make(cell, value, pool, err, &PgToStringBuf, type.GetTypeDesc());
325+
return TCellMaker<NPg::TConvertResult, TStringBuf>::Make(cell, value, pool, err, &PgToStringBuf, typeInfo);
326326
case NScheme::NTypeIds::Uuid:
327327
return TCellMaker<TUuidHolder, TStringBuf>::Make(cell, value, pool, err, &UuidToStringBuf);
328328
default:
329329
return false;
330330
}
331331
}
332332

333-
bool MakeCell(TCell& cell, const NJson::TJsonValue& value, NScheme::TTypeInfo type, TMemoryPool& pool, TString& err) {
333+
bool MakeCell(TCell& cell, const NJson::TJsonValue& value, const NScheme::TTypeInfo& typeInfo, TMemoryPool& pool, TString& err) {
334334
if (value.IsNull()) {
335335
return true;
336336
}
337337

338338
try {
339-
switch (type.GetTypeId()) {
339+
switch (typeInfo.GetTypeId()) {
340340
case NScheme::NTypeIds::Bool:
341341
return TCellMaker<bool>::MakeDirect(cell, value.GetBooleanSafe(), pool, err);
342342
case NScheme::NTypeIds::Int8:
@@ -403,12 +403,12 @@ bool MakeCell(TCell& cell, const NJson::TJsonValue& value, NScheme::TTypeInfo ty
403403
}
404404
}
405405

406-
bool CheckCellValue(const TCell& cell, NScheme::TTypeInfo type) {
406+
bool CheckCellValue(const TCell& cell, const NScheme::TTypeInfo& typeInfo) {
407407
if (cell.IsNull()) {
408408
return true;
409409
}
410410

411-
switch (type.GetTypeId()) {
411+
switch (typeInfo.GetTypeId()) {
412412
case NScheme::NTypeIds::Bool:
413413
case NScheme::NTypeIds::Int8:
414414
case NScheme::NTypeIds::Uint8:

ydb/core/io_formats/cell_maker/cell_maker.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
namespace NKikimr::NFormats {
1313

14-
bool MakeCell(TCell& cell, TStringBuf value, NScheme::TTypeInfo type, TMemoryPool& pool, TString& err);
15-
bool MakeCell(TCell& cell, const NJson::TJsonValue& value, NScheme::TTypeInfo type, TMemoryPool& pool, TString& err);
16-
bool CheckCellValue(const TCell& cell, NScheme::TTypeInfo type);
14+
bool MakeCell(TCell& cell, TStringBuf value, const NScheme::TTypeInfo& typeInfo, TMemoryPool& pool, TString& err);
15+
bool MakeCell(TCell& cell, const NJson::TJsonValue& value, const NScheme::TTypeInfo& typeInfo, TMemoryPool& pool, TString& err);
16+
bool CheckCellValue(const TCell& cell, const NScheme::TTypeInfo& typeInfo);
1717

1818
}

ydb/core/kqp/common/kqp_types.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace NKikimr::NScheme {
88
void ProtoMiniKQLTypeFromTypeInfo(NKikimrMiniKQL::TType* type, const TTypeInfo typeInfo) {
99
if (typeInfo.GetTypeId() == NTypeIds::Pg) {
1010
type->SetKind(NKikimrMiniKQL::Pg);
11-
type->MutablePg()->Setoid(NPg::PgTypeIdFromTypeDesc(typeInfo.GetTypeDesc()));
11+
type->MutablePg()->Setoid(NPg::PgTypeIdFromTypeDesc(typeInfo.GetPgTypeDesc()));
1212
} else {
1313
type->SetKind(NKikimrMiniKQL::Data);
1414
type->MutableData()->SetScheme(typeInfo.GetTypeId());
@@ -28,7 +28,7 @@ TTypeInfo TypeInfoFromProtoMiniKQLType(const NKikimrMiniKQL::TType& type) {
2828

2929
const NMiniKQL::TType* MiniKQLTypeFromTypeInfo(const TTypeInfo typeInfo, const NMiniKQL::TTypeEnvironment& env) {
3030
if (typeInfo.GetTypeId() == NTypeIds::Pg) {
31-
return NMiniKQL::TPgType::Create(NPg::PgTypeIdFromTypeDesc(typeInfo.GetTypeDesc()), env);
31+
return NMiniKQL::TPgType::Create(NPg::PgTypeIdFromTypeDesc(typeInfo.GetPgTypeDesc()), env);
3232
} else {
3333
return NMiniKQL::TDataType::Create((NUdf::TDataTypeId)typeInfo.GetTypeId(), env);
3434
}

0 commit comments

Comments
 (0)