def inner(table_name: str, repo: Dolt) -> DoltTableUpdate: if branch and branch != repo.log(): repo.checkout(branch) query_commit = commit_ref or list(repo.log().keys())[0] table = get_table_metadata(repo.engine, table_name) from_commit, to_commit = get_from_commit_to_commit(repo, query_commit) pks_to_drop = get_dropped_pks(repo.engine, table, from_commit, to_commit) result = _read_from_dolt_history(repo.engine, table, query_commit) return pks_to_drop, result
def _test_dolt_table_reader_helper(repo: Dolt, table: Table, build_table_reader: Callable[[str], Callable[[str, Dolt], DoltTableUpdate]], get_expected: Callable[[int], Tuple[List[dict], List[dict]]]): commits = list(repo.log().keys()) update_to_commit = { FIRST_UPDATE: commits[4], SECOND_UPDATE: commits[3], THIRD_UPDATE: commits[2], FOURTH_UPDATE: commits[1], FIFTH_UPDATE: commits[0] } for update_num, commit in update_to_commit.items(): logger.info('comparison for commit/update_num {}/{}'.format(commit, update_num)) dropped_pks, dolt_data = build_table_reader(commit)(str(table.name), repo) expected_dropped_pks, expected_data = get_expected(update_num) assert expected_dropped_pks == dropped_pks assert_rows_equal(expected_data, list(dolt_data))
def get_from_commit_to_commit(repo: Dolt, commit_ref: str = None) -> Tuple[str, str]: """ Given a repo and commit it returns the commit and its parent, if no commit is provided the head and the parent of head are returned. :param repo: :param commit_ref: :return: """ commits = list(repo.log().keys()) commit_ref_index = None if not commit_ref: commit_ref_index = 0 else: for i, commit in enumerate(commits): if commit == commit_ref: commit_ref_index = i break assert commit_ref_index is not None, 'commit_ref not found in commit index' return commits[commit_ref_index + 1], commits[commit_ref_index]