Skip to content

Commit 74f17ab

Browse files
authored
Partition at decimal keys (#10696)
1 parent 799414a commit 74f17ab

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

ydb/core/engine/mkql_proto.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,19 @@ bool CellsFromTuple(const NKikimrMiniKQL::TType* tupleType,
223223
}
224224
break;
225225
}
226+
case NScheme::NTypeIds::Decimal:
227+
{
228+
if (v.HasLow128() && v.HasHi128()) {
229+
NYql::NDecimal::TInt128 int128 = NYql::NDecimal::FromProto(v);
230+
auto &data = memoryOwner.emplace_back();
231+
data.resize(sizeof(NYql::NDecimal::TInt128));
232+
std::memcpy(data.Detach(), &int128, sizeof(NYql::NDecimal::TInt128));
233+
c = TCell(data);
234+
} else {
235+
CHECK_OR_RETURN_ERROR(false, Sprintf("Cannot parse value of type Decimal in tuple at position %" PRIu32, i));
236+
}
237+
break;
238+
}
226239
default:
227240
CHECK_OR_RETURN_ERROR(false, Sprintf("Unsupported typeId %" PRIu16 " at index %" PRIu32, typeId, i));
228241
break;

ydb/core/grpc_services/rpc_object_storage.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,19 @@ bool CellFromTuple(NScheme::TTypeInfo type,
144144
}
145145
break;
146146
}
147+
case NScheme::NTypeIds::Decimal:
148+
{
149+
if (tupleValue.Haslow_128()) {
150+
NYql::NDecimal::TInt128 int128 = NYql::NDecimal::FromHalfs(tupleValue.Getlow_128(), tupleValue.Gethigh_128());
151+
auto &data = memoryOwner.emplace_back();
152+
data.resize(sizeof(NYql::NDecimal::TInt128));
153+
std::memcpy(data.Detach(), &int128, sizeof(NYql::NDecimal::TInt128));
154+
c = TCell(data);
155+
} else {
156+
CHECK_OR_RETURN_ERROR(false, Sprintf("Cannot parse value of type Decimal in tuple at position %" PRIu32, position));
157+
}
158+
break;
159+
}
147160
default:
148161
CHECK_OR_RETURN_ERROR(false, Sprintf("Unsupported typeId %" PRIu16 " at index %" PRIu32, typeId, position));
149162
break;

ydb/core/kqp/ut/scan/kqp_scan_ut.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,36 @@ Y_UNIT_TEST_SUITE(KqpScan) {
237237
.BeginTuple().AddElement().BeginOptional().Decimal(TDecimalValue("1.5", 22, 9)).EndOptional().EndTuple()
238238
.Build());
239239

240-
auto ret = session.CreateTable("/Root/DecimalTest",
240+
auto ret = session.CreateTable("/Root/DecimalTest",
241241
TTableBuilder()
242242
.AddNullableColumn("Key", TDecimalType(22, 9))
243243
.AddNullableColumn("Key35", TDecimalType(35, 10))
244244
.AddNullableColumn("Value", TDecimalType(22, 9))
245245
.AddNullableColumn("Value35", TDecimalType(35, 10))
246246
.SetPrimaryKeyColumns({"Key", "Key35"})
247-
// .SetPartitionAtKeys(partitions) // Error at split boundary 0: Unsupported typeId 4865 at index 0
247+
.SetPartitionAtKeys(partitions)
248248
.Build()).GetValueSync();
249249
UNIT_ASSERT_C(ret.IsSuccess(), ret.GetIssues().ToString());
250250

251+
{
252+
auto describeResult = session.DescribeTable("/Root/DecimalTest" , TDescribeTableSettings().WithKeyShardBoundary(true)).ExtractValueSync();
253+
UNIT_ASSERT_VALUES_EQUAL(describeResult.GetStatus(), NYdb::EStatus::SUCCESS);
254+
const NYdb::NTable::TTableDescription& tableDescription = describeResult.GetTableDescription();
255+
const TVector<NYdb::NTable::TKeyRange>& keyRanges = tableDescription.GetKeyRanges();
256+
const TVector<NYdb::NTable::TTableColumn>& columns = tableDescription.GetTableColumns();
257+
UNIT_ASSERT_VALUES_EQUAL(columns.size(), 4);
258+
UNIT_ASSERT_STRINGS_EQUAL(columns[0].Type.ToString(), "Decimal(22,9)?");
259+
UNIT_ASSERT_STRINGS_EQUAL(columns[1].Type.ToString(), "Decimal(35,10)?");
260+
auto extractValue = [](const TValue& val) {
261+
auto parser = TValueParser(val);
262+
parser.OpenTuple();
263+
UNIT_ASSERT(parser.TryNextElement());
264+
return parser.GetOptionalDecimal()->ToString();
265+
};
266+
UNIT_ASSERT_VALUES_EQUAL(keyRanges.size(), 2);
267+
UNIT_ASSERT_STRINGS_EQUAL(extractValue(keyRanges[0].To()->GetValue()), "1.5");
268+
}
269+
251270
auto params = TParamsBuilder().AddParam("$in").BeginList()
252271
.AddListItem().BeginStruct()
253272
.AddMember("Key").Decimal(TDecimalValue("1.0", 22, 9))

0 commit comments

Comments
 (0)