Exemplo n.º 1
0
def test_log() -> None:
    """Test log and log filtering."""
    runner = CliRunner()
    result = _run(runner, ["--json", "log"])
    logs = simplejson.loads(result.output)
    assert len(logs) == 0
    refs = ReferenceSchema().loads(_run(
        runner, ["--json", "branch", "-l", "main"]).output,
                                   many=True)
    empty_hash = refs[0].hash_
    _run(
        runner,
        [
            "contents",
            "--set",
            "foo.bar",
            "--ref",
            "main",
            "-m",
            "test_message",
            "-c",
            empty_hash,
        ],
        input=ContentsSchema().dumps(IcebergTable("/a/b/c")),
    )
    result = _run(runner, ["--json", "contents", "foo.bar"])
    tables = ContentsSchema().loads(result.output, many=True)
    assert len(tables) == 1
    assert tables[0] == IcebergTable("/a/b/c")
    result = _run(runner, ["--json", "log"])
    logs = simplejson.loads(result.output)
    assert len(logs) == 1
    result = _run(runner, ["--json", "log", logs[0]["hash"]])
    logs = simplejson.loads(result.output)
    assert len(logs) == 1
    result = _run(runner, ["--json", "contents", "--list"])
    entries = EntrySchema().loads(result.output, many=True)
    assert len(entries) == 1
    _run(runner, [
        "--json", "contents", "--delete", "foo.bar", "--ref", "main", "-m",
        "delete_message", "-c", logs[0]["hash"]
    ])
    result = _run(runner, ["--json", "log"])
    logs = simplejson.loads(result.output)
    assert len(logs) == 2
    result = _run(
        runner,
        ["--json", "log", "{}..{}".format(logs[0]["hash"], logs[1]["hash"])])
    logs = simplejson.loads(result.output)
    assert len(logs) == 1
Exemplo n.º 2
0
def test_merge() -> None:
    """Test merge operation."""
    runner = CliRunner()
    _run(runner, ["branch", "dev"])
    refs = ReferenceSchema().loads(_run(runner, ["--json", "branch", "-l", "dev"]).output, many=True)
    empty_hash = next(i.hash_ for i in refs if i.name == "dev")
    _run(
        runner,
        [
            "contents",
            "--set",
            "foo.bar",
            "--ref",
            "dev",
            "-m",
            "test_message",
            "-c",
            empty_hash,
        ],
        input=ContentsSchema().dumps(IcebergTable("uuid", "/a/b/c")),
    )
    refs = ReferenceSchema().loads(_run(runner, ["--json", "branch", "-l", "main"]).output, many=True)
    main_hash = next(i.hash_ for i in refs if i.name == "main")
    _run(runner, ["merge", "dev", "-c", main_hash])
    result = _run(runner, ["--json", "branch"])
    branches = ReferenceSchema().loads(result.output, many=True)
    refs = {i.name: i.hash_ for i in branches}
    assert refs["main"] == refs["dev"]
    _run(runner, ["branch", "dev", "--delete"])
    result = _run(runner, ["--json", "log"])
    logs = simplejson.loads(result.output)
    _run(runner, ["--json", "contents", "--delete", "foo.bar", "--ref", "main", "-m", "delete_message", "-c", logs[0]["hash"]])
    _run(runner, ["branch", "main", "--delete"])
    _run(runner, ["branch", "main"])
Exemplo n.º 3
0
def test_log() -> None:
    """Test log and log filtering."""
    runner = CliRunner()
    result = _run(runner, ["--json", "log"])
    logs = simplejson.loads(result.output)
    assert len(logs) == 0
    refs = ReferenceSchema().loads(_run(
        runner, ["--json", "branch", "-l", "main"]).output,
                                   many=True)
    empty_hash = refs[0].hash_
    _run(
        runner,
        [
            "contents", "--set", "foo.bar", "--ref", "main", "-m",
            "test_message", "-c", empty_hash, "--author", "nessie_user1"
        ],
        input=ContentsSchema().dumps(IcebergTable("uuid", "/a/b/c")),
    )
    result = _run(runner, ["--json", "contents", "foo.bar"])
    tables = ContentsSchema().loads(result.output, many=True)
    assert len(tables) == 1
    assert tables[0] == IcebergTable("uuid", "/a/b/c")
    result = _run(runner, ["--json", "log"])
    logs = simplejson.loads(result.output)
    assert len(logs) == 1
    result = _run(runner, ["--json", "log", logs[0]["hash"]])
    logs = simplejson.loads(result.output)
    assert len(logs) == 1
    result = _run(runner, ["--json", "contents", "--list"])
    entries = EntrySchema().loads(result.output, many=True)
    assert len(entries) == 1
    _run(
        runner,
        [
            "--json",
            "contents",
            "--delete",
            "foo.bar",
            "--ref",
            "main",
            "-m",
            "delete_message",
            "-c",
            logs[0]["hash"],
            "--author",
            "nessie_user2",
        ],
    )
    result = _run(runner, ["--json", "log"])
    logs = simplejson.loads(result.output)
    assert len(logs) == 2
    result = _run(
        runner,
        ["--json", "log", "{}..{}".format(logs[0]["hash"], logs[1]["hash"])])
    logs = simplejson.loads(result.output)
    assert len(logs) == 1
    result = _run(runner, ["--json", "log"])
    logs = simplejson.loads(result.output)
    assert len(logs) == 2
    result = _run(runner, ["--json", "log", "--author", "nessie_user1"])
    logs = simplejson.loads(result.output)
    assert len(logs) == 1
    result = _run(runner, ["--json", "log", "--author", "nessie_user2"])
    logs = simplejson.loads(result.output)
    assert len(logs) == 1
    result = _run(runner, [
        "--json", "log", "--author", "nessie_user2", "--author", "nessie_user1"
    ])
    logs = simplejson.loads(result.output)
    assert len(logs) == 2
    # the committer is set on the server-side and is empty if we're not logged
    # in when performing a commit
    result = _run(runner, ["--json", "log", "--committer", ""])
    logs = simplejson.loads(result.output)
    assert len(logs) == 2
    result = _run(runner, [
        "--json", "log", "--query",
        "commit.author == 'nessie_user2' || commit.author == 'non_existing'"
    ])
    logs = simplejson.loads(result.output)
    assert len(logs) == 1
    result = _run(runner, [
        "--json", "log", "--after", "2001-01-01T00:00:00+00:00", "--before",
        "2999-12-30T23:00:00+00:00"
    ])
    logs = simplejson.loads(result.output)
    assert len(logs) == 2
Exemplo n.º 4
0
def test_contents_listing() -> None:
    """Test contents listing and filtering."""
    runner = CliRunner()
    branch = "contents_listing_dev"
    _run(runner, ["branch", branch])

    iceberg_table = IcebergTable(id="uuid", metadata_location="/a/b/c")
    delta_lake_table = DeltaLakeTable(id="uuid2",
                                      metadata_location_history=["asd"],
                                      checkpoint_location_history=["def"],
                                      last_checkpoint="x")
    refs = ReferenceSchema().loads(_run(
        runner, ["--json", "branch", "-l", branch]).output,
                                   many=True)
    _run(
        runner,
        [
            "contents", "--set", "this.is.iceberg.foo", "--ref", branch, "-m",
            "test_message1", "-c", refs[0].hash_
        ],
        input=ContentsSchema().dumps(iceberg_table),
    )

    refs = ReferenceSchema().loads(_run(
        runner, ["--json", "branch", "-l", branch]).output,
                                   many=True)
    _run(
        runner,
        [
            "contents", "--set", "this.is.delta.bar", "--ref", branch, "-m",
            "test_message2", "-c", refs[0].hash_
        ],
        input=ContentsSchema().dumps(delta_lake_table),
    )

    result = _run(
        runner, ["--json", "contents", "--ref", branch, "this.is.iceberg.foo"])
    tables = ContentsSchema().loads(result.output, many=True)
    assert_that(tables).is_length(1)
    assert_that(tables[0]).is_equal_to(iceberg_table)

    result = _run(runner,
                  ["--json", "contents", "--ref", branch, "this.is.delta.bar"])
    tables = ContentsSchema().loads(result.output, many=True)
    assert_that(tables).is_length(1)
    assert_that(tables[0]).is_equal_to(delta_lake_table)

    result = _run(runner, [
        "--json", "contents", "--ref", branch, "--list", "--type",
        "ICEBERG_TABLE"
    ])
    tables = EntrySchema().loads(result.output, many=True)
    assert_that(tables).is_length(1)
    assert_that(tables[0].kind).is_equal_to("ICEBERG_TABLE")

    result = _run(runner, [
        "--json", "contents", "--ref", branch, "--list", "--type",
        "DELTA_LAKE_TABLE"
    ])
    tables = EntrySchema().loads(result.output, many=True)
    assert_that(tables).is_length(1)
    assert_that(tables[0].kind).is_equal_to("DELTA_LAKE_TABLE")

    result = _run(runner, [
        "--json", "contents", "--ref", branch, "--list", "--query",
        "entry.contentType == 'ICEBERG_TABLE'"
    ])
    tables = EntrySchema().loads(result.output, many=True)
    assert_that(tables).is_length(1)
    assert_that(tables[0].kind).is_equal_to("ICEBERG_TABLE")

    result = _run(runner, [
        "--json", "contents", "--ref", branch, "--list", "--query",
        "entry.contentType in ['ICEBERG_TABLE', 'DELTA_LAKE_TABLE']"
    ])
    tables = EntrySchema().loads(result.output, many=True)
    assert_that(tables).is_length(2)
    assert_that(tables[0].kind).is_equal_to("ICEBERG_TABLE")
    assert_that(tables[1].kind).is_equal_to("DELTA_LAKE_TABLE")

    result = _run(runner, [
        "--json", "contents", "--ref", branch, "--list", "--query",
        "entry.namespace.startsWith('this.is.del')"
    ])
    tables = EntrySchema().loads(result.output, many=True)
    assert_that(tables).is_length(1)
    assert_that(tables[0].kind).is_equal_to("DELTA_LAKE_TABLE")

    result = _run(runner, [
        "--json", "contents", "--ref", branch, "--list", "--query",
        "entry.namespace.startsWith('this.is')"
    ])
    tables = EntrySchema().loads(result.output, many=True)
    assert_that(tables).is_length(2)
    assert_that(tables[0].kind).is_equal_to("ICEBERG_TABLE")
    assert_that(tables[1].kind).is_equal_to("DELTA_LAKE_TABLE")

    _run(runner, ["branch", branch, "--delete"])
Exemplo n.º 5
0
def test_transplant() -> None:
    """Test transplant operation."""
    runner = CliRunner()
    _run(runner, ["branch", "dev"])
    refs = ReferenceSchema().loads(_run(
        runner, ["--json", "branch", "-l", "dev"]).output,
                                   many=True)
    empty_hash = next(i.hash_ for i in refs if i.name == "dev")
    _run(
        runner,
        [
            "contents",
            "--set",
            "foo.bar",
            "--ref",
            "dev",
            "-m",
            "test_message",
            "-c",
            empty_hash,
        ],
        input=ContentsSchema().dumps(IcebergTable("uuid", "/a/b/c")),
    )
    _run(
        runner,
        [
            "contents",
            "--set",
            "bar.bar",
            "--ref",
            "dev",
            "-m",
            "test_message2",
            "-c",
            empty_hash,
        ],
        input=ContentsSchema().dumps(IcebergTable("uuid", "/a/b/c")),
    )
    _run(
        runner,
        [
            "contents",
            "--set",
            "foo.baz",
            "--ref",
            "main",
            "-m",
            "test_message3",
            "-c",
            empty_hash,
        ],
        input=ContentsSchema().dumps(IcebergTable("uuid", "/a/b/c")),
    )
    refs = ReferenceSchema().loads(_run(runner,
                                        ["--json", "branch", "-l"]).output,
                                   many=True)
    main_hash = next(i.hash_ for i in refs if i.name == "main")
    result = _run(runner, ["--json", "log", "dev"])
    logs = simplejson.loads(result.output)
    first_hash = [i["hash"] for i in logs]
    _run(runner,
         ["cherry-pick", "-c", main_hash, first_hash[1], first_hash[0]])

    result = _run(runner, ["--json", "log"])
    logs = simplejson.loads(result.output)
    assert len(logs) == 3
    _run(runner, [
        "--json", "contents", "--delete", "foo.bar", "--ref", "main", "-m",
        "delete_message", "-c", logs[0]["hash"]
    ])
    _run(runner, ["branch", "dev", "--delete"])
    _run(runner, ["branch", "main", "--delete"])
    _run(runner, ["branch", "main"])