Skip to content

Commit

Permalink
Partition at decimal keys
Browse files Browse the repository at this point in the history
  • Loading branch information
azevaykin committed Oct 22, 2024
1 parent 3fb6997 commit 3db358b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
9 changes: 9 additions & 0 deletions ydb/core/engine/mkql_proto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,15 @@ bool CellsFromTuple(const NKikimrMiniKQL::TType* tupleType,
}
break;
}
case NScheme::NTypeIds::Decimal:
{
if (v.HasLow128() && v.HasHi128()) {
c = TCell::Make<std::pair<ui64, ui64>>({v.GetLow128(), v.GetHi128()});
} 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
9 changes: 9 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,15 @@ bool CellFromTuple(NScheme::TTypeInfo type,
}
break;
}
case NScheme::NTypeIds::Decimal:
{
if (tupleValue.Haslow_128()) {
c = TCell::Make<std::pair<ui64, ui64>>({tupleValue.Getlow_128(), tupleValue.Gethigh_128()});
} 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

0 comments on commit 3db358b

Please sign in to comment.