@@ -2,7 +2,7 @@ import { screen } from '@testing-library/react';
22import userEvent from '@testing-library/user-event' ;
33
44import {
5- appendSelectWithPrimaryAndPartitionKey ,
5+ appendSelectWithAdditionalKeys ,
66 RawLogTable ,
77} from '@/components/DBRowTable' ;
88import { RowWhereResult } from '@/hooks/useRowWhere' ;
@@ -145,9 +145,9 @@ describe('RawLogTable', () => {
145145 } ) ;
146146} ) ;
147147
148- describe ( 'appendSelectWithPrimaryAndPartitionKey ' , ( ) => {
148+ describe ( 'appendSelectWithAdditionalKeys ' , ( ) => {
149149 it ( 'should extract columns from partition key with nested function call' , ( ) => {
150- const result = appendSelectWithPrimaryAndPartitionKey (
150+ const result = appendSelectWithAdditionalKeys (
151151 'col1, col2' ,
152152 'id, created_at' ,
153153 ' toStartOfInterval(timestamp, toIntervalDay(3))' ,
@@ -159,15 +159,15 @@ describe('appendSelectWithPrimaryAndPartitionKey', () => {
159159 } ) ;
160160
161161 it ( 'should extract no columns from empty primary key and partition key' , ( ) => {
162- const result = appendSelectWithPrimaryAndPartitionKey ( 'col1, col2' , '' , '' ) ;
162+ const result = appendSelectWithAdditionalKeys ( 'col1, col2' , '' , '' , [ ] ) ;
163163 expect ( result ) . toEqual ( {
164164 additionalKeysLength : 0 ,
165165 select : 'col1,col2' ,
166166 } ) ;
167167 } ) ;
168168
169169 it ( 'should extract columns from complex primary key' , ( ) => {
170- const result = appendSelectWithPrimaryAndPartitionKey (
170+ const result = appendSelectWithAdditionalKeys (
171171 'col1, col2' ,
172172 'id, timestamp, toStartOfInterval(timestamp2, toIntervalDay(3))' ,
173173 "toStartOfInterval(timestamp, toIntervalDay(3)), date_diff('DAY', col3, col4), now(), toDate(col5 + INTERVAL 1 DAY)" ,
@@ -179,7 +179,7 @@ describe('appendSelectWithPrimaryAndPartitionKey', () => {
179179 } ) ;
180180
181181 it ( 'should extract map columns' , ( ) => {
182- const result = appendSelectWithPrimaryAndPartitionKey (
182+ const result = appendSelectWithAdditionalKeys (
183183 'col1, col2' ,
184184 `map['key']` ,
185185 `map2['key'], map1['key3 ']` ,
@@ -191,7 +191,7 @@ describe('appendSelectWithPrimaryAndPartitionKey', () => {
191191 } ) ;
192192
193193 it ( 'should extract map columns' , ( ) => {
194- const result = appendSelectWithPrimaryAndPartitionKey (
194+ const result = appendSelectWithAdditionalKeys (
195195 'col1, col2' ,
196196 `` ,
197197 `map2['key.2']` ,
@@ -203,7 +203,7 @@ describe('appendSelectWithPrimaryAndPartitionKey', () => {
203203 } ) ;
204204
205205 it ( 'should extract array columns' , ( ) => {
206- const result = appendSelectWithPrimaryAndPartitionKey (
206+ const result = appendSelectWithAdditionalKeys (
207207 'col1, col2' ,
208208 `array[1]` ,
209209 `array[2], array[3]` ,
@@ -215,7 +215,7 @@ describe('appendSelectWithPrimaryAndPartitionKey', () => {
215215 } ) ;
216216
217217 it ( 'should extract json columns' , ( ) => {
218- const result = appendSelectWithPrimaryAndPartitionKey (
218+ const result = appendSelectWithAdditionalKeys (
219219 'col1, col2' ,
220220 `json.b` ,
221221 `json.a, json.b.c, toStartOfDay(timestamp, json_2.d)` ,
@@ -227,7 +227,7 @@ describe('appendSelectWithPrimaryAndPartitionKey', () => {
227227 } ) ;
228228
229229 it ( 'should extract json columns with type specifiers' , ( ) => {
230- const result = appendSelectWithPrimaryAndPartitionKey (
230+ const result = appendSelectWithAdditionalKeys (
231231 'col1, col2' ,
232232 `json.b.:Int64` ,
233233 `toStartOfDay(json.a.b.:DateTime)` ,
@@ -239,7 +239,7 @@ describe('appendSelectWithPrimaryAndPartitionKey', () => {
239239 } ) ;
240240
241241 it ( 'should skip json columns with hard-to-parse type specifiers' , ( ) => {
242- const result = appendSelectWithPrimaryAndPartitionKey (
242+ const result = appendSelectWithAdditionalKeys (
243243 'col1, col2' ,
244244 `json.b.:Array(String), col3` ,
245245 `` ,
@@ -251,7 +251,7 @@ describe('appendSelectWithPrimaryAndPartitionKey', () => {
251251 } ) ;
252252
253253 it ( 'should skip nested map references' , ( ) => {
254- const result = appendSelectWithPrimaryAndPartitionKey (
254+ const result = appendSelectWithAdditionalKeys (
255255 'col1, col2' ,
256256 `map['key']['key2'], col3` ,
257257 `` ,
@@ -261,4 +261,53 @@ describe('appendSelectWithPrimaryAndPartitionKey', () => {
261261 select : `col1,col2,col3` ,
262262 } ) ;
263263 } ) ;
264+
265+ it ( 'should append extraKeys to string select' , ( ) => {
266+ const result = appendSelectWithAdditionalKeys ( 'col1, col2' , 'id' , '' , [
267+ '__hdx_id' ,
268+ ] ) ;
269+ expect ( result ) . toEqual ( {
270+ additionalKeysLength : 2 ,
271+ select : 'col1,col2,id,__hdx_id' ,
272+ } ) ;
273+ } ) ;
274+
275+ it ( 'should not duplicate extraKeys already in select' , ( ) => {
276+ const result = appendSelectWithAdditionalKeys ( 'col1, __hdx_id' , 'id' , '' , [
277+ '__hdx_id' ,
278+ ] ) ;
279+ expect ( result ) . toEqual ( {
280+ additionalKeysLength : 1 ,
281+ select : 'col1,__hdx_id,id' ,
282+ } ) ;
283+ } ) ;
284+
285+ it ( 'should deduplicate extraKeys that overlap with primary/partition keys' , ( ) => {
286+ const result = appendSelectWithAdditionalKeys ( 'col1, col2' , 'id' , '' , [
287+ 'id' ,
288+ '__hdx_id' ,
289+ ] ) ;
290+ expect ( result ) . toEqual ( {
291+ additionalKeysLength : 2 ,
292+ select : 'col1,col2,id,__hdx_id' ,
293+ } ) ;
294+ } ) ;
295+
296+ it ( 'should append extraKeys to array-style select' , ( ) => {
297+ const result = appendSelectWithAdditionalKeys (
298+ [ { valueExpression : 'col1' } , { valueExpression : 'col2' } ] ,
299+ 'id' ,
300+ '' ,
301+ [ '__hdx_id' ] ,
302+ ) ;
303+ expect ( result ) . toEqual ( {
304+ additionalKeysLength : 2 ,
305+ select : [
306+ { valueExpression : 'col1' } ,
307+ { valueExpression : 'col2' } ,
308+ { valueExpression : 'id' } ,
309+ { valueExpression : '__hdx_id' } ,
310+ ] ,
311+ } ) ;
312+ } ) ;
264313} ) ;
0 commit comments