Пример #1
0
def test_cache_no_columns():
    items_to_cache = set()
    cache = Cache(items_to_cache)

    data = [{'bla': 1, 'xyz': 2}, {'bla': 3, 'xyz': 4}]

    # Should not be cached
    cache.add('a', data)

    a_bla = cache.retrieve('a.bla')
    assert a_bla == []
Пример #2
0
def test_cache():
    items_to_cache = set((('a', 'bla'), ('a', 'foo'), ('b', 'foo')))
    cache = Cache(items_to_cache)

    data = [{'bla': 1, 'xyz': 2}, {'bla': 3, 'xyz': 4}]

    # Should be cached
    cache.add('a', data)

    # Should not be cached
    cache.add('b', data)

    a_bla = cache.retrieve('a.bla')
    assert a_bla == [1, 3]

    b_bla = cache.retrieve('b.bla')
    assert b_bla == []
Пример #3
0
    def _run_helper(self, sequence: Sequence[str],
                    deps: AbstractSet[Tuple[str, str]], seed: int,
                    num_rows: int) -> None:
        cache = Cache(deps)

        with DB(self.args.dsn) as dbconn:
            rand_gen = Random(seed=seed)
            for table_name in sequence:
                table = self.tables[table_name]

                rows_to_gen = Executor._get_num_rows_to_gen(
                    rand_gen, num_rows, table.scaler)

                logger.info(
                    f'Generating {rows_to_gen} rows (seed {seed}) for table { table_name }'
                )

                data = BaseObject.sample_from_source(rand_gen, rows_to_gen,
                                                     table.schema, cache)
                dbconn.ingest_table(table_name, table.schema, data)
                cache.add(table_name, data)