Skip to content

Commit

Permalink
Use Decimal(22, 9) as Primary Key in Olap (ydb-platform#4716)
Browse files Browse the repository at this point in the history
  • Loading branch information
iddqdex authored and MrLolthe1st committed May 28, 2024
1 parent d81ced1 commit 89f739a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 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 @@ -6664,7 +6664,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 @@ -6690,6 +6690,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 @@ -6699,6 +6723,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.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ NKikimr::TConclusionStatus TSchemaTransactionOperator::ValidateTableSchema(const
//NTypeIds::Float,
//NTypeIds::Double,
NTypeIds::String,
NTypeIds::Utf8
NTypeIds::Utf8,
NTypeIds::Decimal
};
if (!schema.HasEngine() ||
schema.GetEngine() != NKikimrSchemeOp::EColumnTableEngine::COLUMN_ENGINE_REPLACING_TIMESERIES) {
Expand Down
1 change: 1 addition & 0 deletions ydb/core/tx/schemeshard/olap/columns/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ namespace NKikimr::NSchemeShard {
case NYql::NProto::Datetime64:
case NYql::NProto::Timestamp64:
case NYql::NProto::Interval64:
case NYql::NProto::Decimal:
return true;
default:
return false;
Expand Down

0 comments on commit 89f739a

Please sign in to comment.