@@ -17,82 +17,152 @@ describe('useDefaultOrderBy', () => {
1717
1818 describe ( 'optimizeOrderBy function' , ( ) => {
1919 describe ( 'should handle' , ( ) => {
20- const mockSource = {
21- timestampValueExpression : 'Timestamp' ,
22- } ;
23-
2420 const testCases = [
2521 {
26- input : undefined ,
22+ sortingKey : undefined ,
2723 expected : 'Timestamp DESC' ,
2824 } ,
2925 {
30- input : '' ,
26+ sortingKey : '' ,
3127 expected : 'Timestamp DESC' ,
3228 } ,
3329 {
3430 // Traces Table
35- input : 'ServiceName, SpanName, toDateTime(Timestamp)' ,
31+ sortingKey : 'ServiceName, SpanName, toDateTime(Timestamp)' ,
3632 expected : 'Timestamp DESC' ,
3733 } ,
3834 {
3935 // Optimized Traces Table
40- input :
36+ sortingKey :
4137 'toStartOfHour(Timestamp), ServiceName, SpanName, toDateTime(Timestamp)' ,
4238 expected : '(toStartOfHour(Timestamp), toDateTime(Timestamp)) DESC' ,
4339 } ,
4440 {
4541 // Unsupported for now as it's not a great sort key, want to just
4642 // use default behavior for this
47- input : 'toDateTime(Timestamp), ServiceName, SpanName, Timestamp' ,
43+ sortingKey : 'toDateTime(Timestamp), ServiceName, SpanName, Timestamp' ,
4844 expected : 'Timestamp DESC' ,
4945 } ,
5046 {
5147 // Unsupported prefix sort key
52- input : 'toDateTime(Timestamp), ServiceName, SpanName' ,
48+ sortingKey : 'toDateTime(Timestamp), ServiceName, SpanName' ,
5349 expected : 'Timestamp DESC' ,
5450 } ,
5551 {
5652 // Inverted sort key order, we should not try to optimize this
57- input :
53+ sortingKey :
5854 'ServiceName, toDateTime(Timestamp), SeverityText, toStartOfHour(Timestamp)' ,
5955 expected : 'Timestamp DESC' ,
6056 } ,
6157 {
62- input : 'toStartOfHour(Timestamp), other_column, Timestamp' ,
58+ sortingKey : 'toStartOfHour(Timestamp), other_column, Timestamp' ,
6359 expected : '(toStartOfHour(Timestamp), Timestamp) DESC' ,
6460 } ,
6561 {
66- input : 'Timestamp, other_column' ,
62+ sortingKey : 'Timestamp, other_column' ,
6763 expected : 'Timestamp DESC' ,
6864 } ,
6965 {
70- input : 'user_id, toStartOfHour(Timestamp), status, Timestamp' ,
66+ sortingKey : 'user_id, toStartOfHour(Timestamp), status, Timestamp' ,
7167 expected : '(toStartOfHour(Timestamp), Timestamp) DESC' ,
7268 } ,
7369 {
74- input :
70+ sortingKey :
7571 'toStartOfMinute(Timestamp), user_id, status, toUnixTimestamp(Timestamp)' ,
7672 expected :
7773 '(toStartOfMinute(Timestamp), toUnixTimestamp(Timestamp)) DESC' ,
7874 } ,
7975 {
8076 // test variation of toUnixTimestamp
81- input :
77+ sortingKey :
8278 'toStartOfMinute(Timestamp), user_id, status, toUnixTimestamp64Nano(Timestamp)' ,
8379 expected :
8480 '(toStartOfMinute(Timestamp), toUnixTimestamp64Nano(Timestamp)) DESC' ,
8581 } ,
8682 {
87- input :
83+ sortingKey :
8884 'toUnixTimestamp(toStartOfMinute(Timestamp)), user_id, status, Timestamp' ,
8985 expected :
9086 '(toUnixTimestamp(toStartOfMinute(Timestamp)), Timestamp) DESC' ,
9187 } ,
88+ {
89+ sortingKey : 'Timestamp' ,
90+ displayedTimestampValueExpression : 'Timestamp64' ,
91+ expected : '(Timestamp, Timestamp64) DESC' ,
92+ } ,
93+ {
94+ sortingKey : 'Timestamp' ,
95+ displayedTimestampValueExpression : 'Timestamp64 ' ,
96+ expected : '(Timestamp, Timestamp64) DESC' ,
97+ } ,
98+ {
99+ sortingKey : 'Timestamp' ,
100+ displayedTimestampValueExpression : 'Timestamp' ,
101+ expected : 'Timestamp DESC' ,
102+ } ,
103+ {
104+ sortingKey : 'Timestamp' ,
105+ displayedTimestampValueExpression : '' ,
106+ expected : 'Timestamp DESC' ,
107+ } ,
108+ {
109+ sortingKey : 'Timestamp, ServiceName, Timestamp64' ,
110+ displayedTimestampValueExpression : 'Timestamp64' ,
111+ expected : '(Timestamp, Timestamp64) DESC' ,
112+ } ,
113+ {
114+ sortingKey :
115+ 'toStartOfMinute(Timestamp), Timestamp, ServiceName, Timestamp64' ,
116+ displayedTimestampValueExpression : 'Timestamp64' ,
117+ expected : '(toStartOfMinute(Timestamp), Timestamp, Timestamp64) DESC' ,
118+ } ,
119+ {
120+ sortingKey :
121+ 'toStartOfMinute(Timestamp), Timestamp64, ServiceName, Timestamp' ,
122+ displayedTimestampValueExpression : 'Timestamp64' ,
123+ expected : '(toStartOfMinute(Timestamp), Timestamp64, Timestamp) DESC' ,
124+ } ,
125+ {
126+ sortingKey : 'SomeOtherTimeColumn' ,
127+ displayedTimestampValueExpression : 'Timestamp64' ,
128+ expected : '(Timestamp, Timestamp64) DESC' ,
129+ } ,
130+ {
131+ sortingKey : '' ,
132+ displayedTimestampValueExpression : 'Timestamp64' ,
133+ expected : '(Timestamp, Timestamp64) DESC' ,
134+ } ,
135+ {
136+ sortingKey : 'ServiceName, TimestampTime, Timestamp' ,
137+ timestampValueExpression : 'TimestampTime, Timestamp' ,
138+ displayedTimestampValueExpression : 'Timestamp' ,
139+ expected : '(TimestampTime, Timestamp) DESC' ,
140+ } ,
141+ {
142+ sortingKey : 'ServiceName, TimestampTime, Timestamp' ,
143+ timestampValueExpression : 'Timestamp, TimestampTime' ,
144+ displayedTimestampValueExpression : 'Timestamp' ,
145+ expected : 'Timestamp DESC' ,
146+ } ,
147+ {
148+ sortingKey : '' ,
149+ timestampValueExpression : 'Timestamp, TimestampTime' ,
150+ displayedTimestampValueExpression : '' ,
151+ expected : 'Timestamp DESC' ,
152+ } ,
92153 ] ;
93154 for ( const testCase of testCases ) {
94- it ( `${ testCase . input } ` , ( ) => {
95- const mockTableMetadata = { sorting_key : testCase . input } ;
155+ it ( `${ testCase . sortingKey } ` , ( ) => {
156+ const mockSource = {
157+ timestampValueExpression :
158+ testCase . timestampValueExpression || 'Timestamp' ,
159+ displayedTimestampValueExpression :
160+ testCase . displayedTimestampValueExpression ,
161+ } ;
162+
163+ const mockTableMetadata = {
164+ sorting_key : testCase . sortingKey ,
165+ } ;
96166
97167 jest . spyOn ( sourceModule , 'useSource' ) . mockReturnValue ( {
98168 data : mockSource ,
0 commit comments