Skip to content

Commit

Permalink
Use Decimal(22, 9) as Primary Key in Olap (ydb-platform#4716) (cherry…
Browse files Browse the repository at this point in the history
…-pick from ccdedf8)
  • Loading branch information
iddqdex committed May 21, 2024
1 parent 3a5da67 commit 6991785
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
3 changes: 0 additions & 3 deletions ydb/core/formats/arrow/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ static bool ConvertData(TCell& cell, const NScheme::TTypeInfo& colType, TMemoryP
cell = TCell(saved.data(), saved.size());
break;
}
case NScheme::NTypeIds::Decimal:
errorMessage = "Decimal conversion is not supported yet";
return false;
default:
break;
}
Expand Down
33 changes: 32 additions & 1 deletion ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5881,7 +5881,7 @@ Y_UNIT_TEST_SUITE(KqpOlapTypes) {
};

TTestHelper::TColumnTable testTable;
testTable.SetName("/Root/ColumnTableTest").SetPrimaryKey({"id"}).SetSharding({"id"}).SetSchema(schema);
testTable.SetName("/Root/ColumnTableTest").SetPrimaryKey({"id", "dec"}).SetSharding({"id", "dec"}).SetSchema(schema);
testHelper.CreateTable(testTable);

{
Expand All @@ -5907,6 +5907,30 @@ Y_UNIT_TEST_SUITE(KqpOlapTypes) {
.AddMember("id").Int64(5)
.AddMember("dec").Decimal(TString("-nan"))
.EndStruct();
builder.AddListItem().BeginStruct()
.AddMember("id").Int64(6)
.AddMember("dec").Decimal(TString("1.1"))
.EndStruct();
builder.AddListItem().BeginStruct()
.AddMember("id").Int64(7)
.AddMember("dec").Decimal(TString("12.1"))
.EndStruct();
builder.AddListItem().BeginStruct()
.AddMember("id").Int64(8)
.AddMember("dec").Decimal(TString("inf"))
.EndStruct();
builder.AddListItem().BeginStruct()
.AddMember("id").Int64(9)
.AddMember("dec").Decimal(TString("-inf"))
.EndStruct();
builder.AddListItem().BeginStruct()
.AddMember("id").Int64(10)
.AddMember("dec").Decimal(TString("2.1"))
.EndStruct();
builder.AddListItem().BeginStruct()
.AddMember("id").Int64(11)
.AddMember("dec").Decimal(TString("15.1"))
.EndStruct();
builder.EndList();
const auto result = testHelper.GetKikimr().GetTableClient().BulkUpsert(testTable.GetName(), builder.Build()).GetValueSync();
UNIT_ASSERT_C(result.IsSuccess() , result.GetIssues().ToString());
Expand All @@ -5916,6 +5940,13 @@ Y_UNIT_TEST_SUITE(KqpOlapTypes) {
testHelper.ReadData("SELECT dec FROM `/Root/ColumnTableTest` WHERE id=3", "[[\"-inf\"]]");
testHelper.ReadData("SELECT dec FROM `/Root/ColumnTableTest` WHERE id=4", "[[\"nan\"]]");
testHelper.ReadData("SELECT dec FROM `/Root/ColumnTableTest` WHERE id=5", "[[\"-nan\"]]");
testHelper.ReadData("SELECT id FROM `/Root/ColumnTableTest` WHERE dec=CAST(\"10.1\" As Decimal(22,9))", "[[1]]");
testHelper.ReadData("SELECT id FROM `/Root/ColumnTableTest` WHERE dec=CAST(\"inf\" As Decimal(22,9)) ORDER BY id", "[[2];[8]]");
testHelper.ReadData("SELECT id FROM `/Root/ColumnTableTest` WHERE dec=CAST(\"-inf\" As Decimal(22,9)) ORDER BY id", "[[3];[9]]");
// Nan cannot by find.
testHelper.ReadData("SELECT id FROM `/Root/ColumnTableTest` WHERE dec=CAST(\"nan\" As Decimal(22,9))", "[]");
testHelper.ReadData("SELECT id FROM `/Root/ColumnTableTest` WHERE dec=CAST(\"-nan\" As Decimal(22,9))", "[]");
testHelper.ReadData("SELECT dec FROM `/Root/ColumnTableTest` WHERE id > 5 ORDER BY dec", "[[\"-inf\"];[\"1.1\"];[\"2.1\"];[\"12.1\"];[\"15.1\"];[\"inf\"]]");
}

Y_UNIT_TEST(TimestampCmpErr) {
Expand Down
3 changes: 2 additions & 1 deletion ydb/core/tx/columnshard/transactions/operators/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ namespace NKikimr::NColumnShard {
//NTypeIds::Float,
//NTypeIds::Double,
NTypeIds::String,
NTypeIds::Utf8
NTypeIds::Utf8,
NTypeIds::Decimal
};

if (!schema.HasEngine() ||
Expand Down
2 changes: 1 addition & 1 deletion ydb/core/tx/schemeshard/olap/columns/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ namespace NKikimr::NSchemeShard {
case NYql::NProto::Date:
case NYql::NProto::Datetime:
case NYql::NProto::Timestamp:
case NYql::NProto::Decimal:
return true;
case NYql::NProto::Interval:
case NYql::NProto::Decimal:
case NYql::NProto::DyNumber:
case NYql::NProto::Yson:
case NYql::NProto::Json:
Expand Down

0 comments on commit 6991785

Please sign in to comment.