def test_prettyprint_repeated_single(self): schema = [ BigQueryTestSchemaField('c1', 'string', 'c1', None, False, False, False), BigQueryTestSchemaField('c2', 'integer', 'c2', None, False, True, True), ] table = [ { 'c1': 'a', 'c2': [1] }, { 'c1': 'b', 'c2': [2] }, { 'c1': 'c', 'c2': [3] }, ] expected = ''' c1 c2 a 1 b 2 c 3 ''' flat = flatten_table(table, schema) self.assertMultiLineEqual(table_prettyprint(flat), expected.strip())
def test_prettyprint_flat(self): schema = [ BigQueryTestSchemaField('c1', 'string', 'c1', None, False, False, False), BigQueryTestSchemaField('c2', 'integer', 'c2', None, False, False, False), ] table = [ { 'c1': 'foo', 'c2': 123 }, { 'c1': 'bar', 'c2': 456 }, ] expected = ''' c1 c2 foo 123 bar 456 ''' flat = flatten_table(table, schema) self.assertEquals(table_prettyprint(flat), expected.strip())
def test_prettyprint_repeated_nested(self): schema = [ BigQueryTestSchemaField('c1', 'record', 'c1', [ BigQueryTestSchemaField('a', 'integer', 'c1.a', None, False, True, True), BigQueryTestSchemaField('b', 'integer', 'c1.b', None, False, False, False), ], False, True, True), BigQueryTestSchemaField('c2', 'integer', 'c2', None, False, False, False), ] table = [ { 'c1': [{ 'a': [1, 2], 'b': 100 }, { 'a': [4], 'b': 200 }], 'c2': 0 }, { 'c1': [{ 'a': [3], 'b': 200 }], 'c2': 5 }, { 'c1': [{ 'a': [], 'b': 300 }, { 'a': [1, 2], 'b': 10 }], 'c2': 10 }, ] expected = ''' c1.a c1.b c2 1 100 0 2 4 200 3 200 5 300 10 1 10 2 ''' flat = flatten_table(table, schema) self.assertMultiLineEqual(table_prettyprint(flat), expected.strip())
def test_prettyprint_records_flat(self): schema = [ BigQueryTestSchemaField('c1', 'record', 'c1', [ BigQueryTestSchemaField('a', 'string', 'c1.a', None, False, False, False), BigQueryTestSchemaField('b', 'string', 'c1.b', None, False, False, False), ], False, False, False), BigQueryTestSchemaField('c2', 'integer', 'c2', None, False, False, False), ] table = [ { 'c1': { 'a': 'foo', 'b': 'bar' }, 'c2': 123 }, { 'c1': { 'a': 'baz', 'b': 'qux' }, 'c2': 456 }, ] expected = ''' c1.a c1.b c2 foo bar 123 baz qux 456 ''' flat = flatten_table(table, schema) self.assertMultiLineEqual(table_prettyprint(flat), expected.strip())
def test_table_prettyprint_complex(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), ] table = [ { 'c1': 'foo', 'c2': [{ 'x': [{ 'xx': 1 }], 'y': 'a' }] }, { 'c1': 'bar', 'c2': [{ 'y': 'b' }, { 'y': 'z' }] }, { 'c1': 'baz', 'c2': [{ 'x': [{ 'xx': 3 }, { 'xx': 4 }], 'y': 'b' }, { 'x': [{ 'xx': 5 }], 'y': 'd' }] }, ] expected = ''' c1 c2.x.xx c2.y foo 1 a bar b z baz 3 b 4 5 d''' flat = flatten_table(table, schema) self.assertEquals(table_prettyprint(flat), expected.lstrip())