@@ -17,82 +17,157 @@ 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 : 'toStartOfMinute(Timestamp), user_id, status, Timestamp' , 
90+           timestampValueExpression : 'Timestamp, toStartOfMinute(Timestamp)' , 
91+           expected : '(toStartOfMinute(Timestamp), Timestamp) DESC' , 
92+         } , 
93+         { 
94+           sortingKey : 'Timestamp' , 
95+           displayedTimestampValueExpression : 'Timestamp64' , 
96+           expected : '(Timestamp, Timestamp64) DESC' , 
97+         } , 
98+         { 
99+           sortingKey : 'Timestamp' , 
100+           displayedTimestampValueExpression : 'Timestamp64 ' , 
101+           expected : '(Timestamp, Timestamp64) DESC' , 
102+         } , 
103+         { 
104+           sortingKey : 'Timestamp' , 
105+           displayedTimestampValueExpression : 'Timestamp' , 
106+           expected : 'Timestamp DESC' , 
107+         } , 
108+         { 
109+           sortingKey : 'Timestamp' , 
110+           displayedTimestampValueExpression : '' , 
111+           expected : 'Timestamp DESC' , 
112+         } , 
113+         { 
114+           sortingKey : 'Timestamp, ServiceName, Timestamp64' , 
115+           displayedTimestampValueExpression : 'Timestamp64' , 
116+           expected : '(Timestamp, Timestamp64) DESC' , 
117+         } , 
118+         { 
119+           sortingKey :
120+             'toStartOfMinute(Timestamp), Timestamp, ServiceName, Timestamp64' , 
121+           displayedTimestampValueExpression : 'Timestamp64' , 
122+           expected : '(toStartOfMinute(Timestamp), Timestamp, Timestamp64) DESC' , 
123+         } , 
124+         { 
125+           sortingKey :
126+             'toStartOfMinute(Timestamp), Timestamp64, ServiceName, Timestamp' , 
127+           displayedTimestampValueExpression : 'Timestamp64' , 
128+           expected : '(toStartOfMinute(Timestamp), Timestamp64, Timestamp) DESC' , 
129+         } , 
130+         { 
131+           sortingKey : 'SomeOtherTimeColumn' , 
132+           displayedTimestampValueExpression : 'Timestamp64' , 
133+           expected : '(Timestamp, Timestamp64) DESC' , 
134+         } , 
135+         { 
136+           sortingKey : '' , 
137+           displayedTimestampValueExpression : 'Timestamp64' , 
138+           expected : '(Timestamp, Timestamp64) DESC' , 
139+         } , 
140+         { 
141+           sortingKey : 'ServiceName, TimestampTime, Timestamp' , 
142+           timestampValueExpression : 'TimestampTime, Timestamp' , 
143+           displayedTimestampValueExpression : 'Timestamp' , 
144+           expected : '(TimestampTime, Timestamp) DESC' , 
145+         } , 
146+         { 
147+           sortingKey : 'ServiceName, TimestampTime, Timestamp' , 
148+           timestampValueExpression : 'Timestamp, TimestampTime' , 
149+           displayedTimestampValueExpression : 'Timestamp' , 
150+           expected : 'Timestamp DESC' , 
151+         } , 
152+         { 
153+           sortingKey : '' , 
154+           timestampValueExpression : 'Timestamp, TimestampTime' , 
155+           displayedTimestampValueExpression : '' , 
156+           expected : 'Timestamp DESC' , 
157+         } , 
92158      ] ; 
93159      for  ( const  testCase  of  testCases )  { 
94-         it ( `${ testCase . input }  ,  ( )  =>  { 
95-           const  mockTableMetadata  =  {  sorting_key : testCase . input  } ; 
160+         it ( `${ testCase . sortingKey }  ,  ( )  =>  { 
161+           const  mockSource  =  { 
162+             timestampValueExpression :
163+               testCase . timestampValueExpression  ||  'Timestamp' , 
164+             displayedTimestampValueExpression :
165+               testCase . displayedTimestampValueExpression , 
166+           } ; 
167+ 
168+           const  mockTableMetadata  =  { 
169+             sorting_key : testCase . sortingKey , 
170+           } ; 
96171
97172          jest . spyOn ( sourceModule ,  'useSource' ) . mockReturnValue ( { 
98173            data : mockSource , 
0 commit comments