Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public boolean commit() {
public List<Table> getTables(String dbName, List<String> tableNames) {
List<RefKey> keys =
tableNames.stream()
.map(t -> new RefKey(defaultHash, ContentsKey.of(dbName, t)))
.map(t -> new RefKey(defaultName, ContentsKey.of(dbName, t)))
.collect(Collectors.toList());
try {
return store.getItemsForRef(keys).stream()
Expand Down Expand Up @@ -158,7 +158,7 @@ public void createDatabase(Database db) throws MetaException {

public void alterDatabase(Database db) throws MetaException {
try {
Optional<Item> oldDb = getItemForRef(defaultHash, db.getName());
Optional<Item> oldDb = getItemForRef(defaultName, db.getName());
setItem(
Item.wrap(db, oldDb.orElseThrow(() -> new MetaException("Db not found")).getId()),
db.getName());
Expand Down Expand Up @@ -228,7 +228,7 @@ public Optional<TableAndPartition> getTable(String dbName, String tableName)
throws NoSuchObjectException {

if (!tableName.contains("@")) {
return getItemForRef(defaultHash, dbName, tableName)
return getItemForRef(defaultName, dbName, tableName)
.map(i -> new TableAndPartition(i.getTable(), i.getPartitions(), i.getId()));
}

Expand All @@ -243,7 +243,7 @@ public Optional<TableAndPartition> getTable(String dbName, String tableName)

if (ref.equalsIgnoreCase(defaultName) || ref.equalsIgnoreCase(defaultHash)) {
// stay in transaction rather than possibly doing a newer read.
return getItemForRef(defaultHash, dbName, tableName)
return getItemForRef(defaultName, dbName, tableName)
.map(i -> new TableAndPartition(i.getTable(), i.getPartitions(), i.getId()));
}

Expand Down Expand Up @@ -308,7 +308,7 @@ public void removePartition(String dbName, String tableName, List<String> partit
}

Optional<Database> getDatabase(String database) throws NoSuchObjectException {
return getItemForRef(defaultHash, database).map(Item::getDatabase);
return getItemForRef(defaultName, database).map(Item::getDatabase);
}

private Optional<Item> getItemForRef(String ref, String... elements)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ public List<Reference> getReferences() {
}

public Stream<Entry> getEntriesForDefaultRef() throws NessieNotFoundException {
List<Entry> entries = tree.getEntries(reference.getHash(), null, null, null).getEntries();
List<Entry> entries = tree.getEntries(reference.getName(), null, null, null).getEntries();
Supplier<Stream<RefKey>> defaultRefKeys =
() -> cachedItems.keySet().stream().filter(k -> k.getRef().equals(reference.getHash()));
() -> cachedItems.keySet().stream().filter(k -> k.getRef().equals(reference.getName()));
Set<ContentsKey> toRemove =
defaultRefKeys.get().map(RefKey::getKey).collect(Collectors.toSet());
return Stream.concat(
Expand All @@ -137,7 +137,7 @@ public Stream<Entry> getEntriesForDefaultRef() throws NessieNotFoundException {

void setItem(ContentsKey key, Item item) {
checkWritable();
cachedItems.put(new RefKey(reference.getHash(), key), item);
cachedItems.put(new RefKey(reference.getName(), key), item);
operations.add(Operation.Put.of(key, item.toContents()));
}

Expand All @@ -159,7 +159,7 @@ void commit() throws NessieNotFoundException, NessieConflictException {

void deleteItem(ContentsKey key) {
checkWritable();
cachedItems.put(new RefKey(reference.getHash(), key), null);
cachedItems.put(new RefKey(reference.getName(), key), null);
operations.add(Operation.Delete.of(key));
}

Expand Down
7 changes: 5 additions & 2 deletions python/docs/log.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

Show commit log.

REVISION_RANGE optional branch, tag or hash to start viewing log from. If of
the form <hash>..<hash> only show log for given range
REVISION_RANGE optional hash to start viewing log from. If of the form
<hash>..<hash> only show log for given range on the particular ref that was
provided

PATHS optional list of paths. If given, only show commits which affected the
given paths

Options:
-r, --ref TEXT branch to list from. If not supplied the
default branch from config is used
-n, --number INTEGER number of log entries to return
--since, --after TEXT Only include commits newer than specific date
--until, --before TEXT Only include commits older than specific date
Expand Down
9 changes: 8 additions & 1 deletion python/pynessie/_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,20 @@ def show_log(
Note:
limiting by path is not yet supported.
"""
start = filtering_args.pop("start", None)
end = filtering_args.pop("end", None)
raw_log = nessie.get_log(start_ref=start_ref, **filtering_args)

def generator() -> Generator[CommitMeta, Any, None]:
# start returning data if we don't have a start point, otherwise
# only start returning data when the start point was found
start_yielding = start is None
for i in raw_log:
if start and i.hash_ == start:
start_yielding = True
if end and i.hash_ == end:
break
yield i
if start_yielding:
yield i

return generator()
22 changes: 13 additions & 9 deletions python/pynessie/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def set_head(ctx: ContextObject, head: str, delete: bool) -> None:


@cli.command("log")
@click.option("-r", "--ref", help="branch to list from. If not supplied the default branch from config is used")
@click.option("-n", "--number", help="number of log entries to return", type=int)
@click.option("--since", "--after", help="Only include commits newer than specific date")
@click.option("--until", "--before", help="Only include commits older than specific date")
Expand Down Expand Up @@ -221,6 +222,7 @@ def set_head(ctx: ContextObject, head: str, delete: bool) -> None:
@error_handler
def log( # noqa: C901
ctx: ContextObject,
ref: str,
number: int,
since: str,
until: str,
Expand All @@ -232,32 +234,34 @@ def log( # noqa: C901
) -> None:
"""Show commit log.

REVISION_RANGE optional branch, tag or hash to start viewing log from. If of the form <hash>..<hash> only show log
for given range
REVISION_RANGE optional hash to start viewing log from. If of the form <hash>..<hash> only show log
for given range on the particular ref that was provided

PATHS optional list of paths. If given, only show commits which affected the given paths
"""
if not revision_range:
start = ctx.nessie.get_default_branch()
end = None
else:
if not ref:
ref = ctx.nessie.get_default_branch()
start = None
end = None
if revision_range:
if ".." in revision_range:
start, end = revision_range.split("..")
else:
start = revision_range
end = None

filtering_args: Any = {}
if number:
filtering_args["max"] = str(number)
if start:
filtering_args["start"] = start
if end:
filtering_args["end"] = end

# TODO: we should eventually move "start..end" filtering to the server
expr = build_query_expression_for_commit_log_flags(query_expression, author, committer, since, until)
if expr:
filtering_args["query_expression"] = expr

log_result = show_log(nessie=ctx.nessie, start_ref=start, limits=paths, **filtering_args)
log_result = show_log(nessie=ctx.nessie, start_ref=ref, limits=paths, **filtering_args)
if ctx.json:
click.echo(CommitMetaSchema().dumps(log_result, many=True))
else:
Expand Down
Loading