Skip to content

Commit

Permalink
Enable Timestamp64/Interval64 as PK. (ydb-platform#3581)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tony-Romanov authored Apr 9, 2024
1 parent c869403 commit 692b467
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
39 changes: 39 additions & 0 deletions ydb/core/kqp/ut/scheme/kqp_scheme_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5587,6 +5587,45 @@ Y_UNIT_TEST_SUITE(KqpOlapScheme) {
testHelper.ReadData("SELECT * FROM `/Root/ColumnTableTest` WHERE id=1", "[[1;[123];[-456]]]");
testHelper.ReadData("SELECT * FROM `/Root/ColumnTableTest` WHERE id=2", "[[2;[-789];#]]");
}

Y_UNIT_TEST(UseTimestamp64AsPrimaryKey) {
TKikimrSettings runnerSettings;
runnerSettings.WithSampleTables = false;
TTestHelper testHelper(runnerSettings);

TVector<TTestHelper::TColumnSchema> schema = {
TTestHelper::TColumnSchema().SetName("timestamp").SetType(NScheme::NTypeIds::Timestamp64).SetNullable(false),
TTestHelper::TColumnSchema().SetName("interval").SetType(NScheme::NTypeIds::Interval64)
};

Tests::NCommon::TLoggerInit(testHelper.GetKikimr()).Initialize();
TTestHelper::TColumnTable testTable;

testTable.SetName("/Root/ColumnTableTest").SetPrimaryKey({"timestamp"}).SetSharding({"timestamp"}).SetSchema(schema);
testHelper.CreateTable(testTable);

{
TTestHelper::TUpdatesBuilder tableInserter(testTable.GetArrowSchema(schema));
tableInserter.AddRow().Add(-7000000).Add(3000001);
tableInserter.AddRow().Add(-3000000).Add(-1000002);
tableInserter.AddRow().Add(0).AddNull();
tableInserter.AddRow().Add(4000000).Add(-2000003);
tableInserter.AddRow().Add(9000000).Add(5000004);
testHelper.BulkUpsert(testTable, tableInserter);
}

testHelper.ReadData("SELECT * FROM `/Root/ColumnTableTest` WHERE `timestamp` = Timestamp64('1970-01-01T00:00:00Z')", "[[#;0]]");
testHelper.ReadData("SELECT * FROM `/Root/ColumnTableTest` WHERE `timestamp` < Timestamp64('1970-01-01T00:00:00Z')",
"[[[3000001];-7000000];[[-1000002];-3000000]]");
testHelper.ReadData("SELECT * FROM `/Root/ColumnTableTest` WHERE `timestamp` > Timestamp64('1970-01-01T00:00:00Z')",
"[[[-2000003];4000000];[[5000004];9000000]]");
testHelper.ReadData("SELECT * FROM `/Root/ColumnTableTest` WHERE `timestamp` <= Timestamp64('1970-01-01T00:00:00Z')",
"[[[3000001];-7000000];[[-1000002];-3000000];[#;0]]");
testHelper.ReadData("SELECT * FROM `/Root/ColumnTableTest` WHERE `timestamp` >= Timestamp64('1970-01-01T00:00:00Z')",
"[[#;0];[[-2000003];4000000];[[5000004];9000000]]");
testHelper.ReadData("SELECT * FROM `/Root/ColumnTableTest` WHERE `timestamp` != Timestamp64('1970-01-01T00:00:00Z')",
"[[[3000001];-7000000];[[-1000002];-3000000];[[-2000003];4000000];[[5000004];9000000]]");
}
/*
Y_UNIT_TEST(AddColumnOnSchemeChange) {
TKikimrSettings runnerSettings;
Expand Down
2 changes: 2 additions & 0 deletions ydb/core/tx/schemeshard/olap/columns/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ namespace NKikimr::NSchemeShard {
case NYql::NProto::Date:
case NYql::NProto::Datetime:
case NYql::NProto::Timestamp:
case NYql::NProto::Timestamp64:
case NYql::NProto::Interval64:
return true;
case NYql::NProto::Interval:
case NYql::NProto::Decimal:
Expand Down

0 comments on commit 692b467

Please sign in to comment.