@@ -2325,6 +2325,52 @@ def test_request_data_with_options(self):
23252325 tableId = self .table ,
23262326 body = expected_body )
23272327
2328+ def test_insert_id_key_with_nested_column (self ):
2329+ """Ensure that dot separated insert_id_key properly extracted with nested column value."""
2330+ rows = [
2331+ {'nested' : {'col' : 'nested_col1' }, 'val' : 1 },
2332+ {'nested' : {'col' : 'nested_col2' }, 'val' : 2 },
2333+ ]
2334+ expected_body = self .data .copy ()
2335+ expected_body ['rows' ] = [
2336+ {'insertId' : 'nested_col1' , 'json' : {'nested' : {'col' : 'nested_col1' }, 'val' : 1 }},
2337+ {'insertId' : 'nested_col2' , 'json' : {'nested' : {'col' : 'nested_col2' }, 'val' : 2 }},
2338+ ]
2339+
2340+ self .client .push_rows (self .dataset , self .table , rows ,
2341+ insert_id_key = 'nested.col' )
2342+ self .mock_table_data .insertAll .assert_called_with (
2343+ projectId = self .project ,
2344+ datasetId = self .dataset ,
2345+ tableId = self .table ,
2346+ body = expected_body )
2347+
2348+ expected_body = self .data .copy ()
2349+ expected_body ['rows' ] = [
2350+ {'insertId' : 1 , 'json' : {'nested' : {'col' : 'nested_col1' }, 'val' : 1 }},
2351+ {'insertId' : 2 , 'json' : {'nested' : {'col' : 'nested_col2' }, 'val' : 2 }},
2352+ ]
2353+ self .client .push_rows (self .dataset , self .table , rows ,
2354+ insert_id_key = 'val' )
2355+ self .mock_table_data .insertAll .assert_called_with (
2356+ projectId = self .project ,
2357+ datasetId = self .dataset ,
2358+ tableId = self .table ,
2359+ body = expected_body )
2360+
2361+ expected_body = self .data .copy ()
2362+ expected_body ['rows' ] = [
2363+ {'json' : {'nested' : {'col' : 'nested_col1' }, 'val' : 1 }},
2364+ {'json' : {'nested' : {'col' : 'nested_col2' }, 'val' : 2 }},
2365+ ]
2366+ self .client .push_rows (self .dataset , self .table , rows ,
2367+ insert_id_key = 'no_such.column' )
2368+ self .mock_table_data .insertAll .assert_called_with (
2369+ projectId = self .project ,
2370+ datasetId = self .dataset ,
2371+ tableId = self .table ,
2372+ body = expected_body )
2373+
23282374
23292375class TestGetAllTables (unittest .TestCase ):
23302376
0 commit comments