@@ -29,6 +29,10 @@ void CreateSimpleDataTypes(TKikimrRunner& kikimr) {
2929 col_datetime Datetime,
3030 col_timestamp Timestamp,
3131 col_interval Interval,
32+ col_date32 Date32,
33+ col_datetime64 Datetime64,
34+ col_timestamp64 Timestamp64,
35+ col_interval64 Interval64,
3236 col_decimal Decimal(22, 9),
3337 col_decimal_35 Decimal(35, 10),
3438 PRIMARY KEY (col_uint64)
@@ -39,33 +43,61 @@ void CreateSimpleDataTypes(TKikimrRunner& kikimr) {
3943
4044 result = session.ExecuteDataQuery (R"(
4145 --!syntax_v1
42- REPLACE INTO `/Root/SimpleDataTypes` (col_bool, col_uint64, col_int32,
43- col_double, col_float, col_string, col_utf8, col_date, col_datetime,
44- col_timestamp, col_interval, col_decimal, col_decimal_35) VALUES
45- (NULL, NULL, -1, 1.0, 1.0f, "Value-001", "値-001",
46- Date("2021-01-01"), Datetime("2021-01-01T01:01:01Z"), Timestamp("2021-01-01T01:01:01.111111Z"),
47- Interval("P1DT1H1M1.111111S"), Decimal("1.11", 22, 9), Decimal("155555555555555", 35, 10)),
48- (false, 2u, NULL, NULL, 2.0f, "Value-002", "値-002",
49- Date("2021-02-02"), Datetime("2021-07-31T02:02:02Z"), Timestamp("2021-02-02T02:02:02.222222Z"),
50- Interval("P2DT2H2M2.222S"), Decimal("2.22", 22, 9), Decimal("255555555555555", 35, 10)),
51- (false, 101u, -101, 101.101, NULL, NULL, "値-101",
52- Date("2021-02-02"), Datetime("2021-05-31T10:10:10Z"), Timestamp("2021-10-10T10:10:10.101101Z"),
53- Interval("P101DT10H10M10.101101S"), Decimal("101.101", 22, 9), Decimal("355555555555555", 35, 10)),
54- (true, 102u, -102, 102.102, 102.0f, "Value-102", NULL,
55- Date("2021-12-12"), Datetime("2021-12-12T10:10:10Z"), Timestamp("2021-12-12T10:10:10.102102Z"),
56- Interval("P102DT10H10M10.102102S"), Decimal("102.102", 22, 9), Decimal("455555555555555", 35, 10)),
57- (false, 201u, -201, 201.201, 201.201f, "Value-201", "値-201",
58- NULL, NULL, Timestamp("2021-12-21T10:10:10.201201Z"),
59- Interval("P201DT10H10M10.201201S"), Decimal("201.201", 22, 9), Decimal("555555555555555", 35, 10)),
60- (true, 202u, -202, 202.202, 202.202f, "Value-202", "値-202",
61- Date("2021-12-22"), Datetime("2021-12-22T10:10:10Z"), NULL,
62- NULL, Decimal("202.202", 22, 9), Decimal("655555555555555", 35, 10)),
63- (true, 301u, -301, 301.301, 301.301f, "Value-301", "値-301",
64- Date("2021-05-31"), Datetime("2021-10-10T10:31:31Z"), Timestamp("2021-05-31T10:31:31.301301Z"),
65- Interval("P301DT10H10M10.301301S"), NULL, NULL),
66- (false, 302u, -302, 302.302, 302.302f, "Value-302", "値-302",
67- Date("2021-06-30"), Datetime("2021-05-31T10:32:32Z"), Timestamp("2021-06-30T10:32:32.302302Z"),
68- Interval("P302DT10H10M10.302302S"), Decimal("302.302", 22, 9), Decimal("755555555555555", 35, 10))
46+ REPLACE INTO `/Root/SimpleDataTypes` (
47+ col_bool, col_uint64, col_int32, col_double, col_float, col_string, col_utf8,
48+ col_date, col_datetime, col_timestamp, col_interval,
49+ col_date32, col_datetime64, col_timestamp64, col_interval64,
50+ col_decimal, col_decimal_35
51+ )
52+ VALUES
53+ (
54+ NULL, NULL, -1, 1.0, 1.0f, "Value-001", "値-001",
55+ Date("2021-01-01"), Datetime("2021-01-01T01:01:01Z"), Timestamp("2021-01-01T01:01:01.111111Z"), Interval("P1DT1H1M1.111111S"),
56+ Date32("2021-01-01"), Datetime64("2021-01-01T01:01:01Z"), Timestamp64("2021-01-01T01:01:01.111111Z"), Interval64("P1DT1H1M1.111111S"),
57+ Decimal("1.11", 22, 9), Decimal("155555555555555", 35, 10)
58+ ),
59+ (
60+ false, 2u, NULL, NULL, 2.0f, "Value-002", "値-002",
61+ Date("2021-02-02"), Datetime("2021-07-31T02:02:02Z"), Timestamp("2021-02-02T02:02:02.222222Z"), Interval("P2DT2H2M2.222S"),
62+ Date32("-2021-02-02"), Datetime64("-2021-02-02T02:02:02Z"), Timestamp64("-2021-02-02T02:02:02.222222Z"), Interval64("P2DT2H2M2.222S"),
63+ Decimal("2.22", 22, 9), Decimal("255555555555555", 35, 10)
64+ ),
65+ (
66+ false, 101u, -101, 101.101, NULL, NULL, "値-101",
67+ Date("2021-02-02"), Datetime("2021-05-31T10:10:10Z"), Timestamp("2021-10-10T10:10:10.101101Z"), Interval("P101DT10H10M10.101101S"),
68+ Date32("2021-02-02"), Datetime64("2021-02-02T10:10:10Z"), Timestamp64("2021-02-02T10:10:10.101101Z"), Interval64("P101DT10H10M10.101101S"),
69+ Decimal("101.101", 22, 9), Decimal("355555555555555", 35, 10)
70+ ),
71+ (
72+ true, 102u, -102, 102.102, 102.0f, "Value-102", NULL,
73+ Date("2021-12-12"), Datetime("2021-12-12T10:10:10Z"), Timestamp("2021-12-12T10:10:10.102102Z"), Interval("P102DT10H10M10.102102S"),
74+ Date32("2021-12-12"), Datetime64("2021-12-12T10:10:10Z"), Timestamp64("2021-12-12T10:10:10.102102Z"), Interval64("P102DT10H10M10.102102S"),
75+ Decimal("102.102", 22, 9), Decimal("455555555555555", 35, 10)
76+ ),
77+ (
78+ false, 201u, -201, 201.201, 201.201f, "Value-201", "値-201",
79+ NULL, NULL, Timestamp("2021-12-21T10:10:10.201201Z"), Interval("P201DT10H10M10.201201S"),
80+ Date32("2021-12-12"), Datetime64("2021-12-12T10:10:10Z"), Timestamp64("2021-12-12T10:10:10.102102Z"), Interval64("P102DT10H10M10.102102S"),
81+ Decimal("201.201", 22, 9), Decimal("555555555555555", 35, 10)
82+ ),
83+ (
84+ true, 202u, -202, 202.202, 202.202f, "Value-202", "値-202",
85+ Date("2021-12-22"), Datetime("2021-12-22T10:10:10Z"), NULL, NULL,
86+ Date32("2021-12-22"), NULL, NULL, Interval64("P202DT10H10M10.202202S"),
87+ Decimal("202.202", 22, 9), Decimal("655555555555555", 35, 10)
88+ ),
89+ (
90+ true, 301u, -301, 301.301, 301.301f, "Value-301", "値-301",
91+ Date("2021-05-31"), Datetime("2021-10-10T10:31:31Z"), Timestamp("2021-05-31T10:31:31.301301Z"), Interval("P301DT10H10M10.301301S"),
92+ Date32("-2021-05-31"), Datetime64("-2021-10-10T10:31:31Z"), Timestamp64("-2021-05-31T10:31:31.301301Z"), Interval64("P301DT10H10M10.301301S"),
93+ NULL, NULL
94+ ),
95+ (
96+ false, 302u, -302, 302.302, 302.302f, "Value-302", "値-302",
97+ Date("2021-06-30"), Datetime("2021-05-31T10:32:32Z"), Timestamp("2021-06-30T10:32:32.302302Z"), Interval("P302DT10H10M10.302302S"),
98+ Date32("2021-06-30"), Datetime64("2021-05-31T10:32:32Z"), Timestamp64("2021-06-30T10:32:32.302302Z"), Interval64("P302DT10H10M10.302302S"),
99+ Decimal("302.302", 22, 9), Decimal("755555555555555", 35, 10)
100+ );
69101 )" , TTxControl::BeginTx ().CommitTx ()).GetValueSync ();
70102
71103 UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
@@ -359,6 +391,118 @@ Y_UNIT_TEST_SUITE(KqpMergeCn) {
359391 [[180122222000];["P2DT2H2M2.222S"]]])" , StreamResultToYson (result));
360392 }
361393
394+ Y_UNIT_TEST (TopSortBy_Date32_Limit4) {
395+ TKikimrRunner kikimr;
396+ auto db = kikimr.GetTableClient ();
397+ CreateSimpleDataTypes (kikimr);
398+
399+ TString query = R"(
400+ SELECT col_date32, CAST(col_date32 AS String) FROM `/Root/SimpleDataTypes` ORDER BY col_date32 LIMIT 4
401+ )" ;
402+
403+ auto settings = TStreamExecScanQuerySettings ()
404+ .Explain (true );
405+
406+ auto result = db.StreamExecuteScanQuery (query, settings).GetValueSync ();
407+ UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
408+
409+ auto res = CollectStreamResult (result);
410+ CheckPlanForMergeCn (res.PlanJson , false , " TopSort" );
411+
412+ result = db.StreamExecuteScanQuery (query).GetValueSync ();
413+ UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
414+
415+ CompareYson (R"( [
416+ [[-1457286];["-2021-02-02"]];
417+ [[-1457167];["-2021-05-31"]];
418+ [[18628];["2021-01-01"]];
419+ [[18660];["2021-02-02"]]
420+ ])" , StreamResultToYson (result));
421+ }
422+
423+ Y_UNIT_TEST (TopSortByDesc_Datetime64_Limit3) {
424+ TKikimrRunner kikimr;
425+ auto db = kikimr.GetTableClient ();
426+ CreateSimpleDataTypes (kikimr);
427+
428+ TString query = R"(
429+ SELECT col_datetime64, CAST(col_datetime64 AS String) FROM `/Root/SimpleDataTypes` ORDER BY col_datetime64 DESC LIMIT 3
430+ )" ;
431+
432+ auto settings = TStreamExecScanQuerySettings ()
433+ .Explain (true );
434+
435+ auto result = db.StreamExecuteScanQuery (query, settings).GetValueSync ();
436+ UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
437+
438+ auto res = CollectStreamResult (result);
439+ CheckPlanForMergeCn (res.PlanJson , false , " TopSort" );
440+
441+ result = db.StreamExecuteScanQuery (query).GetValueSync ();
442+ UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
443+
444+ CompareYson (R"( [
445+ [[1639303810];["2021-12-12T10:10:10Z"]];
446+ [[1639303810];["2021-12-12T10:10:10Z"]];
447+ [[1622457152];["2021-05-31T10:32:32Z"]]
448+ ])" , StreamResultToYson (result));
449+ }
450+
451+ Y_UNIT_TEST (TopSortBy_Timestamp64_Limit2) {
452+ TKikimrRunner kikimr;
453+ auto db = kikimr.GetTableClient ();
454+ CreateSimpleDataTypes (kikimr);
455+
456+ TString query = R"(
457+ SELECT col_timestamp64, CAST(col_timestamp64 AS String) FROM `/Root/SimpleDataTypes` ORDER BY col_timestamp64 LIMIT 2
458+ )" ;
459+
460+ auto settings = TStreamExecScanQuerySettings ()
461+ .Explain (true );
462+
463+ auto result = db.StreamExecuteScanQuery (query, settings).GetValueSync ();
464+ UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
465+
466+ auto res = CollectStreamResult (result);
467+ CheckPlanForMergeCn (res.PlanJson , false , " TopSort" );
468+
469+ result = db.StreamExecuteScanQuery (query).GetValueSync ();
470+ UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
471+
472+ CompareYson (R"( [
473+ [#;#];
474+ [[-125909503077777778];["-2021-02-02T02:02:02.222222Z"]]
475+ ])" , StreamResultToYson (result));
476+ }
477+
478+ Y_UNIT_TEST (TopSortBy_Interval64_Limit3) {
479+ TKikimrRunner kikimr;
480+ auto db = kikimr.GetTableClient ();
481+ CreateSimpleDataTypes (kikimr);
482+
483+ TString query = R"(
484+ SELECT col_interval, CAST(col_interval AS String) FROM `/Root/SimpleDataTypes` ORDER BY col_interval LIMIT 3
485+ )" ;
486+
487+ auto settings = TStreamExecScanQuerySettings ()
488+ .Explain (true );
489+
490+ auto result = db.StreamExecuteScanQuery (query, settings).GetValueSync ();
491+ UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
492+
493+ auto res = CollectStreamResult (result);
494+ CheckPlanForMergeCn (res.PlanJson , false , " TopSort" );
495+
496+ result = db.StreamExecuteScanQuery (query).GetValueSync ();
497+ UNIT_ASSERT_C (result.IsSuccess (), result.GetIssues ().ToString ());
498+
499+ CompareYson (R"( [
500+ [#;#];
501+ [[90061111111];["P1DT1H1M1.111111S"]];
502+ [[180122222000];["P2DT2H2M2.222S"]]
503+ ])" , StreamResultToYson (result));
504+ }
505+
362506 Y_UNIT_TEST (TopSortBy_Decimal_Limit5) {
363507 TKikimrRunner kikimr;
364508 auto db = kikimr.GetTableClient ();
0 commit comments