Beispiel #1
0
    def test_load_json_with_repeated_records(self):
        record_json = json.dumps({
            'rr': [
                {
                    'inner_non_repeated': 'x',
                    'inner_repeated': ['a', 'b', 'c'],
                },
                {
                    'inner_non_repeated': 'y',
                    'inner_repeated': ['d', 'e'],
                },
            ],
            'r': {
                'inner_repeated': ['l', 'm', 'n'],
            },
        })

        tq = tinyquery.TinyQuery()
        tq.load_table_from_newline_delimited_json(
            'test_table',
            json.dumps(self.record_schema['fields']),
            [record_json])
        self.assertIn('test_table', tq.tables_by_name)
        table = tq.tables_by_name['test_table']
        self.assertEqual(table.columns['rr.inner_non_repeated'].values[0],
                         ['x', 'y'])
        self.assertEqual(table.columns['rr.inner_repeated'].values[0],
                         ['a', 'b', 'c', 'd', 'e'])
        self.assertEqual(table.columns['r.inner_repeated'].values[0],
                         ['l', 'm', 'n'])
Beispiel #2
0
 def test_load_json_with_null_records(self):
     record_json = json.dumps({
         'i': 1,
         'r': {
             's': 'hello!',
             'r2': None,
         },
     })
     tq = tinyquery.TinyQuery()
     tq.load_table_from_newline_delimited_json(
         'test_table',
         json.dumps(self.record_schema['fields']),
         [record_json])
     self.assertIn('test_table', tq.tables_by_name)
     table = tq.tables_by_name['test_table']
     self.assertIn('r.r2.d2', table.columns)
     self.assertIn(None, table.columns['r.r2.d2'].values)
Beispiel #3
0
 def setUp(self):
     self.tq = tinyquery.TinyQuery()
     self.tq.load_table_or_view(
         tinyquery.Table(
             'test_table', 5,
             collections.OrderedDict([
                 ('val1', context.Column(tq_types.INT, [4, 1, 8, 1, 2])),
                 ('val2', context.Column(tq_types.INT, [8, 2, 4, 1, 6]))
             ])))
     self.tq.load_table_or_view(
         tinyquery.Table(
             'test_table_2', 2,
             collections.OrderedDict([
                 ('val3', context.Column(tq_types.INT, [3, 8])),
                 ('val2', context.Column(tq_types.INT, [2, 7])),
             ])))
     self.tq.load_table_or_view(
         tinyquery.Table(
             'test_table_3', 5,
             collections.OrderedDict([
                 ('foo', context.Column(tq_types.INT, [1, 2, 4, 5, 1])),
                 ('bar', context.Column(tq_types.INT, [2, 7, 3, 1, 1])),
             ])))
     self.tq.load_table_or_view(
         tinyquery.Table(
             'null_table', 4,
             collections.OrderedDict([
                 ('foo', context.Column(tq_types.INT, [1, None, None, 5])),
             ])))
     self.tq.load_table_or_view(
         tinyquery.Table(
             'string_table', 2,
             collections.OrderedDict([
                 ('str', context.Column(tq_types.STRING,
                                        ['hello', 'world'])),
             ])))
     self.tq.load_table_or_view(
         tinyquery.Table(
             'empty_table', 0,
             collections.OrderedDict([
                 ('foo', context.Column(tq_types.INT, [])),
             ])))
 def setUp(self):
     self.tinyquery = tinyquery.TinyQuery()
     self.tq_service = api_client.TinyQueryApiClient(self.tinyquery)