@@ -32,25 +32,23 @@ func newTestServerWithCMV(t *testing.T, configs []CMVConfig) *server {
3232}
3333
3434func TestCMVTransformKey (t * testing.T ) {
35- // Mirrors the production CMV config: key_mapping [3,4,1,2,0] + append_source_key.
36- // SELECT SPLIT(_key,'#')[SAFE_OFFSET(3)] AS provider_id, ..., _key AS source_key
37- // ORDER BY provider_id, client_id, rev_ts, event_category, bitlink_id, source_key
38- // CMV key = provider_id#client_id#rev_ts#event_category#bitlink_id#<full_source_key>
35+ // key_mapping [3,4,1,2,0] + append_source_key:
36+ // CMV key = parts[3]#parts[4]#parts[1]#parts[2]#parts[0]#<full_source_key>
3937 inst := & cmvInstance {
4038 config : CMVConfig {
41- SourceTable : "attributions_conversion_events " ,
42- ViewID : "attributions_conversion_events_by_client " ,
39+ SourceTable : "events " ,
40+ ViewID : "events_by_account " ,
4341 KeySeparator : "#" ,
4442 KeyMapping : []int {3 , 4 , 1 , 2 , 0 },
4543 AppendSourceKey : true ,
4644 },
4745 }
4846
49- sourceKey := "bitlink123#9999999999#order#shopify#myshop.myshopify.com#01HWXYZ "
47+ sourceKey := "item-abc#9999999#type-x#region-a#account-42#src-01 "
5048 got := inst .transformKey (sourceKey )
51- // parts: [0]bitlink123 [1]9999999999 [2]order [3]shopify [4]myshop.myshopify.com [5]01HWXYZ
49+ // parts: [0]item-abc [1]9999999 [2]type-x [3]region-a [4]account-42 [5]src-01
5250 // mapped: parts[3]#parts[4]#parts[1]#parts[2]#parts[0] + full source key
53- want := "shopify#myshop.myshopify.com#9999999999#order#bitlink123#bitlink123#9999999999#order#shopify#myshop.myshopify.com#01HWXYZ "
51+ want := "region-a#account-42#9999999#type-x#item-abc#item-abc#9999999#type-x#region-a#account-42#src-01 "
5452 assert .Equal (t , want , got )
5553}
5654
@@ -264,11 +262,11 @@ func TestLoadCMVConfigs(t *testing.T) {
264262
265263 content := `[
266264 {
267- "source_table": "attributions_conversion_events ",
268- "view_id": "attributions_conversion_events_by_client ",
265+ "source_table": "events ",
266+ "view_id": "events_by_account ",
269267 "key_separator": "#",
270268 "key_mapping": [3, 4, 1, 2, 0],
271- "include_families": ["cr ", "d", "m "],
269+ "include_families": ["cf1 ", "cf2 "],
272270 "append_source_key": true
273271 }
274272 ]`
@@ -279,40 +277,38 @@ func TestLoadCMVConfigs(t *testing.T) {
279277 configs , err := LoadCMVConfigs (tmpFile .Name ())
280278 require .NoError (t , err )
281279 require .Len (t , configs , 1 )
282- assert .Equal (t , "attributions_conversion_events " , configs [0 ].SourceTable )
283- assert .Equal (t , "attributions_conversion_events_by_client " , configs [0 ].ViewID )
280+ assert .Equal (t , "events " , configs [0 ].SourceTable )
281+ assert .Equal (t , "events_by_account " , configs [0 ].ViewID )
284282 assert .Equal (t , "#" , configs [0 ].KeySeparator )
285283 assert .Equal (t , []int {3 , 4 , 1 , 2 , 0 }, configs [0 ].KeyMapping )
286- assert .Equal (t , []string {"cr " , "d" , "m " }, configs [0 ].IncludeFamilies )
284+ assert .Equal (t , []string {"cf1 " , "cf2 " }, configs [0 ].IncludeFamilies )
287285 assert .True (t , configs [0 ].AppendSourceKey )
288286}
289287
290288func TestParseCMVConfigFromSQL (t * testing.T ) {
291- // Mirrors the production Terraform CMV SQL exactly: no CAST, _key aliased as
292- // source_key, attribution_source_id is embedded in source_key not a separate component .
289+ // Standard Bigtable CMV SQL pattern: plain SPLIT ( no CAST) , _key aliased,
290+ // alias appears in ORDER BY to set AppendSourceKey = true .
293291 query := `SELECT
294- SPLIT(_key, '#')[SAFE_OFFSET(3)] AS provider_id,
295- SPLIT(_key, '#')[SAFE_OFFSET(4)] AS client_id,
296- SPLIT(_key, '#')[SAFE_OFFSET(1)] AS rev_ts,
297- SPLIT(_key, '#')[SAFE_OFFSET(2)] AS event_category,
298- SPLIT(_key, '#')[SAFE_OFFSET(0)] AS bitlink_id,
299- _key AS source_key,
300- cr AS cr,
301- d AS d,
302- m AS m
303- FROM ` + "`attributions_conversion_events`" + `
304- ORDER BY provider_id, client_id, rev_ts, event_category, bitlink_id, source_key`
305-
306- cfg , err := ParseCMVConfigFromSQL ("attributions_conversion_events_by_client" , query )
292+ SPLIT(_key, '#')[SAFE_OFFSET(3)] AS region,
293+ SPLIT(_key, '#')[SAFE_OFFSET(4)] AS account_id,
294+ SPLIT(_key, '#')[SAFE_OFFSET(1)] AS timestamp,
295+ SPLIT(_key, '#')[SAFE_OFFSET(2)] AS type,
296+ SPLIT(_key, '#')[SAFE_OFFSET(0)] AS item_id,
297+ _key AS src_key,
298+ cf1 AS cf1,
299+ cf2 AS cf2
300+ FROM ` + "`events`" + `
301+ ORDER BY region, account_id, timestamp, type, item_id, src_key`
302+
303+ cfg , err := ParseCMVConfigFromSQL ("events_by_account" , query )
307304 require .NoError (t , err )
308- assert .Equal (t , "attributions_conversion_events " , cfg .SourceTable )
309- assert .Equal (t , "attributions_conversion_events_by_client " , cfg .ViewID )
305+ assert .Equal (t , "events " , cfg .SourceTable )
306+ assert .Equal (t , "events_by_account " , cfg .ViewID )
310307 assert .Equal (t , "#" , cfg .KeySeparator )
311308 assert .Equal (t , []int {3 , 4 , 1 , 2 , 0 }, cfg .KeyMapping )
312309 assert .True (t , cfg .AppendSourceKey )
313- assert .Contains (t , cfg .IncludeFamilies , "cr" )
314- assert .Contains (t , cfg .IncludeFamilies , "d" )
315- assert .Contains (t , cfg .IncludeFamilies , "m" )
310+ assert .Contains (t , cfg .IncludeFamilies , "cf1" )
311+ assert .Contains (t , cfg .IncludeFamilies , "cf2" )
316312}
317313
318314func TestCMVDropRowRangePrefix (t * testing.T ) {
0 commit comments