def test_update_record_recursive_deep_repeated_new(self): schema = [ BigQueryTestSchemaField('c1', 'string', 'c1', None, False, False, False), BigQueryTestSchemaField('c2', 'record', 'c2', [ BigQueryTestSchemaField('x', 'record', 'c2.x', [ BigQueryTestSchemaField('xx', 'integer', 'c2.x.xx', None, False, False, True), ], False, True, True), BigQueryTestSchemaField('y', 'string', 'c2.y', None, False, False, True), ], False, True, True), ] record = {'c1': 'foo', 'c2': [{'x': [{'xx': 1}], 'y': 'bar'}]} row = {'c2.x.xx': 2, 'c2.y': 'baz'} update_record(schema, row, record) self.assertEquals( record, { 'c1': 'foo', 'c2': [{ 'x': [{ 'xx': 1 }], 'y': 'bar' }, { 'x': [{ 'xx': 2 }], 'y': 'baz' }] })
def test_update_record_repeated_multiple(self): schema = [ BigQueryTestSchemaField('c1', 'string', 'c1', None, False, False, False), BigQueryTestSchemaField('c2', 'integer', 'c2', None, False, True, True), ] record = {'c1': 'foo', 'c2': [123]} row = {'c2': 456} update_record(schema, row, record) self.assertEquals(record, {'c1': 'foo', 'c2': [123, 456]})
def test_update_record_flat_empty(self): schema = [ BigQueryTestSchemaField('c1', 'string', 'c1', None, False, False, False), BigQueryTestSchemaField('c2', 'integer', 'c2', None, False, False, False), ] record = {} row = {'c1': 'foo', 'c2': 123} update_record(schema, row, record) self.assertEquals(record, {'c1': 'foo', 'c2': 123})
def test_update_record_recursive(self): schema = [ BigQueryTestSchemaField('c1', 'string', 'c1', None, False, False, False), BigQueryTestSchemaField('c2', 'record', 'c2', [ BigQueryTestSchemaField('x', 'integer', 'c2.x', None, False, False, False), BigQueryTestSchemaField('y', 'integer', 'c2.y', None, False, False, False), ], False, False, False), ] record = {} row = {'c1': 'foo', 'c2.x': 123, 'c2.y': 456} update_record(schema, row, record) self.assertEquals(record, {'c1': 'foo', 'c2': {'x': 123, 'y': 456}})
def test_update_record_recursive_repeated_multiple(self): schema = [ BigQueryTestSchemaField('c1', 'string', 'c1', None, False, False, False), BigQueryTestSchemaField('c2', 'record', 'c2', [ BigQueryTestSchemaField('x', 'integer', 'c2.x', None, False, False, False), BigQueryTestSchemaField('y', 'integer', 'c2.y', None, False, True, True), ], False, False, False), ] record = {'c1': 'foo', 'c2': {'x': 123, 'y': [456]}} row = {'c2.y': 789} update_record(schema, row, record) self.assertEquals(record, { 'c1': 'foo', 'c2': { 'x': 123, 'y': [456, 789] } })
def test_update_record_deep_nested_nullable(self): schema = [ BigQueryTestSchemaField('repository', 'record', 'repository', [ BigQueryTestSchemaField('name', 'string', 'repository.name', None, True, False, False), ], True, False, True), BigQueryTestSchemaField('payload', 'record', 'payload', [ BigQueryTestSchemaField('pages', 'record', 'payload.pages', [ BigQueryTestSchemaField('title', 'string', 'payload.pages.title', None, True, False, True), ], False, True, True), ], True, False, False), ] record = { 'repository': { 'name': 'foo' }, 'payload': { 'pages': [{ 'title': 'foo1' }] } } row = {'payload.pages.title': 'foo2'} update_record(schema, row, record) self.assertEquals( record, { 'repository': { 'name': 'foo' }, 'payload': { 'pages': [{ 'title': 'foo1' }, { 'title': 'foo2' }] } })