Skip to content
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
13 changes: 13 additions & 0 deletions ydb/core/engine/mkql_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,19 @@ bool CellsFromTuple(const NKikimrMiniKQL::TType* tupleType,
}
break;
}
case NScheme::NTypeIds::Decimal:
{
if (v.HasLow128() && v.HasHi128()) {
NYql::NDecimal::TInt128 int128 = NYql::NDecimal::FromProto(v);
auto &data = memoryOwner.emplace_back();
data.resize(sizeof(NYql::NDecimal::TInt128));
std::memcpy(data.Detach(), &int128, sizeof(NYql::NDecimal::TInt128));
c = TCell(data);
} else {
CHECK_OR_RETURN_ERROR(false, Sprintf("Cannot parse value of type Decimal in tuple at position %" PRIu32, i));
}
break;
}
default:
CHECK_OR_RETURN_ERROR(false, Sprintf("Unsupported typeId %" PRIu16 " at index %" PRIu32, typeId, i));
break;
Expand Down
13 changes: 13 additions & 0 deletions ydb/core/grpc_services/rpc_object_storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,19 @@ bool CellFromTuple(NScheme::TTypeInfo type,
}
break;
}
case NScheme::NTypeIds::Decimal:
{
if (tupleValue.Haslow_128()) {
NYql::NDecimal::TInt128 int128 = NYql::NDecimal::FromHalfs(tupleValue.Getlow_128(), tupleValue.Gethigh_128());
auto &data = memoryOwner.emplace_back();
data.resize(sizeof(NYql::NDecimal::TInt128));
std::memcpy(data.Detach(), &int128, sizeof(NYql::NDecimal::TInt128));
c = TCell(data);
} else {
CHECK_OR_RETURN_ERROR(false, Sprintf("Cannot parse value of type Decimal in tuple at position %" PRIu32, position));
}
break;
}
default:
CHECK_OR_RETURN_ERROR(false, Sprintf("Unsupported typeId %" PRIu16 " at index %" PRIu32, typeId, position));
break;
Expand Down
25 changes: 22 additions & 3 deletions ydb/core/kqp/ut/scan/kqp_scan_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,36 @@ Y_UNIT_TEST_SUITE(KqpScan) {
.BeginTuple().AddElement().BeginOptional().Decimal(TDecimalValue("1.5", 22, 9)).EndOptional().EndTuple()
.Build());

auto ret = session.CreateTable("/Root/DecimalTest",
auto ret = session.CreateTable("/Root/DecimalTest",
TTableBuilder()
.AddNullableColumn("Key", TDecimalType(22, 9))
.AddNullableColumn("Key35", TDecimalType(35, 10))
.AddNullableColumn("Value", TDecimalType(22, 9))
.AddNullableColumn("Value35", TDecimalType(35, 10))
.SetPrimaryKeyColumns({"Key", "Key35"})
// .SetPartitionAtKeys(partitions) // Error at split boundary 0: Unsupported typeId 4865 at index 0
.SetPartitionAtKeys(partitions)
.Build()).GetValueSync();
UNIT_ASSERT_C(ret.IsSuccess(), ret.GetIssues().ToString());

{
auto describeResult = session.DescribeTable("/Root/DecimalTest" , TDescribeTableSettings().WithKeyShardBoundary(true)).ExtractValueSync();
UNIT_ASSERT_VALUES_EQUAL(describeResult.GetStatus(), NYdb::EStatus::SUCCESS);
const NYdb::NTable::TTableDescription& tableDescription = describeResult.GetTableDescription();
const TVector<NYdb::NTable::TKeyRange>& keyRanges = tableDescription.GetKeyRanges();
const TVector<NYdb::NTable::TTableColumn>& columns = tableDescription.GetTableColumns();
UNIT_ASSERT_VALUES_EQUAL(columns.size(), 4);
UNIT_ASSERT_STRINGS_EQUAL(columns[0].Type.ToString(), "Decimal(22,9)?");
UNIT_ASSERT_STRINGS_EQUAL(columns[1].Type.ToString(), "Decimal(35,10)?");
auto extractValue = [](const TValue& val) {
auto parser = TValueParser(val);
parser.OpenTuple();
UNIT_ASSERT(parser.TryNextElement());
return parser.GetOptionalDecimal()->ToString();
};
UNIT_ASSERT_VALUES_EQUAL(keyRanges.size(), 2);
UNIT_ASSERT_STRINGS_EQUAL(extractValue(keyRanges[0].To()->GetValue()), "1.5");
}

auto params = TParamsBuilder().AddParam("$in").BeginList()
.AddListItem().BeginStruct()
.AddMember("Key").Decimal(TDecimalValue("1.0", 22, 9))
Expand Down Expand Up @@ -282,7 +301,7 @@ Y_UNIT_TEST_SUITE(KqpScan) {
CompareYson(R"([
[["155555555555555"];["155555555555555.123456789"]];
[["255555555555555"];["255555555555555.987654321"]]
])", StreamResultToYson(it35));
])", StreamResultToYson(it35));
}

Y_UNIT_TEST(TaggedScalar) {
Expand Down
Loading