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 @@ -33,24 +33,27 @@ public ClientContentsApi(HttpClient client) {
}

@Override
public Contents getContents(@NotNull ContentsKey key, String ref) throws NessieNotFoundException {
public Contents getContents(@NotNull ContentsKey key, String ref, String hashOnRef)
throws NessieNotFoundException {
return client
.newRequest()
.path("contents")
.path(key.toPathString())
.queryParam("ref", ref)
.queryParam("hashOnRef", hashOnRef)
.get()
.readEntity(Contents.class);
}

@Override
public MultiGetContentsResponse getMultipleContents(
@NotNull String ref, @NotNull MultiGetContentsRequest request)
@NotNull String ref, String hashOnRef, @NotNull MultiGetContentsRequest request)
throws NessieNotFoundException {
return client
.newRequest()
.path("contents")
.queryParam("ref", ref)
.queryParam("hashOnRef", hashOnRef)
.post(request)
.readEntity(MultiGetContentsResponse.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,15 @@ public Branch getDefaultBranch() {

@Override
public LogResponse getCommitLog(
String ref, Integer maxRecords, String pageToken, String queryExpression)
String ref, String hashOnRef, Integer maxRecords, String pageToken, String queryExpression)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess this should be startHash instead of hashOnRef. Since we're already changing this, can you add endHash as welll?:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather prefer to have this in a separate commit/PR since it's a slightly different feature

throws NessieNotFoundException {
HttpRequest builder =
client.newRequest().path("trees/tree/{ref}/log").resolveTemplate("ref", ref);
return builder
.queryParam("max", maxRecords != null ? maxRecords.toString() : null)
.queryParam("pageToken", pageToken)
.queryParam("query_expression", queryExpression)
.queryParam("hashOnRef", hashOnRef)
.get()
.readEntity(LogResponse.class);
}
Expand Down Expand Up @@ -159,14 +160,19 @@ public void mergeRefIntoBranch(

@Override
public EntriesResponse getEntries(
@NotNull String refName, Integer maxRecords, String pageToken, String queryExpression)
@NotNull String refName,
String hashOnRef,
Integer maxRecords,
String pageToken,
String queryExpression)
throws NessieNotFoundException {
HttpRequest builder =
client.newRequest().path("trees/tree/{ref}/entries").resolveTemplate("ref", refName);
return builder
.queryParam("max", maxRecords != null ? maxRecords.toString() : null)
.queryParam("pageToken", pageToken)
.queryParam("query_expression", queryExpression)
.queryParam("hashOnRef", hashOnRef)
.get()
.readEntity(EntriesResponse.class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,51 +34,57 @@ private StreamingUtil() {

/**
* Default implementation to return a stream of objects for a ref, functionally equivalent to
* calling {@link TreeApi#getEntries(String, Integer, String, String)} with manual paging.
* calling {@link TreeApi#getEntries(String, String, Integer, String, String)} with manual paging.
*
* <p>The {@link Stream} returned by {@code getEntriesStream(ref, OptionalInt.empty())}, if not
* limited, returns all commit-log entries.
*
* @param ref a named reference (branch or tag name) or a commit-hash
* @param ref a named reference (branch or tag name)
* @param hashOnRef the hash on the given ref
* @param pageSizeHint page-size hint for the backend
* @param queryExpression The query expression to filter by
* @return stream of {@link Entry} objects
*/
public static Stream<Entry> getEntriesStream(
@NotNull TreeApi treeApi,
@NotNull String ref,
String hashOnRef,
OptionalInt pageSizeHint,
String queryExpression)
throws NessieNotFoundException {
return new ResultStreamPaginator<>(
EntriesResponse::getEntries,
(ref1, pageSize, token) -> treeApi.getEntries(ref1, pageSize, token, queryExpression))
(ref1, pageSize, token) ->
treeApi.getEntries(ref1, hashOnRef, pageSize, token, queryExpression))
.generateStream(ref, pageSizeHint);
}

/**
* Default implementation to return a stream of commit-log entries, functionally equivalent to
* calling {@link TreeApi#getCommitLog(String, Integer, String, String)} with manual paging.
* calling {@link TreeApi#getCommitLog(String, String, Integer, String, String)} with manual
* paging.
*
* <p>The {@link Stream} returned by {@code getCommitLogStream(ref, OptionalInt.empty())}, if not
* limited, returns all commit-log entries.
*
* @param treeApi The {@link TreeApi} to use
* @param ref a named reference (branch or tag name) or a commit-hash
* @param ref a named reference (branch or tag name)
* @param hashOnRef the hash on the given ref
* @param pageSizeHint page-size hint for the backend
* @param queryExpression The query expression to filter by
* @return stream of {@link CommitMeta} objects
*/
public static Stream<CommitMeta> getCommitLogStream(
@NotNull TreeApi treeApi,
@NotNull String ref,
String hashOnRef,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(similar to above about startHash instead of hashOnRef + endHash)

OptionalInt pageSizeHint,
String queryExpression)
throws NessieNotFoundException {
return new ResultStreamPaginator<>(
LogResponse::getOperations,
(reference, pageSize, token) ->
treeApi.getCommitLog(reference, pageSize, token, queryExpression))
treeApi.getCommitLog(reference, hashOnRef, pageSize, token, queryExpression))
.generateStream(ref, pageSizeHint);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ class NessieLogStore(sparkConf: SparkConf, hadoopConf: Configuration)
}

private def getTable(path: Path, branch: String): Option[DeltaLakeTable] = {
Try(client.getContentsApi.getContents(pathToKey(path), branch))
Try(client.getContentsApi.getContents(pathToKey(path), branch, null))
.filter(x => x != null && x.isInstanceOf[DeltaLakeTable])
.map(_.asInstanceOf[DeltaLakeTable])
.toOption
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ void testCheckpoint() throws NessieNotFoundException {

String tableName = tempPath.getAbsolutePath() + "/_delta_log";
Contents contents =
client.getContentsApi().getContents(ContentsKey.of(tableName.split("/")), "main");
client.getContentsApi().getContents(ContentsKey.of(tableName.split("/")), "main", null);
Optional<DeltaLakeTable> table = contents.unwrap(DeltaLakeTable.class);
Assertions.assertTrue(table.isPresent());
Assertions.assertEquals(1, table.get().getCheckpointLocationHistory().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Optional<Item> getItemForRef(String ref, ContentsKey contentsKey) throws NoSuchO
}

try {
Item item = Item.fromContents(contents.getContents(contentsKey, ref));
Item item = Item.fromContents(contents.getContents(contentsKey, ref, null));
cachedItems.put(key, item);
return Optional.ofNullable(item);
} catch (NessieNotFoundException e) {
Expand Down Expand Up @@ -105,7 +105,9 @@ List<Optional<Item>> getItemsForRef(List<RefKey> refKeys) throws NessieNotFoundE
keysByRef.get(ref).stream().map(RefKey::getKey).collect(Collectors.toList());
MultiGetContentsResponse response =
contents.getMultipleContents(
ref, ImmutableMultiGetContentsRequest.builder().addAllRequestedKeys(keys).build());
ref,
null,
ImmutableMultiGetContentsRequest.builder().addAllRequestedKeys(keys).build());
response
.getContents()
.forEach(
Expand All @@ -123,7 +125,7 @@ public List<Reference> getReferences() {
}

public Stream<Entry> getEntriesForDefaultRef() throws NessieNotFoundException {
List<Entry> entries = tree.getEntries(reference.getName(), null, null, null).getEntries();
List<Entry> entries = tree.getEntries(reference.getName(), null, null, null, null).getEntries();
Supplier<Stream<RefKey>> defaultRefKeys =
() -> cachedItems.keySet().stream().filter(k -> k.getRef().equals(reference.getName()));
Set<ContentsKey> toRemove =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ public void crossNessieDelegateQuery() throws NessieNotFoundException {
assertEquals(4, results.size());

// make sure we created the database and single table object in the nessie db.
Contents db = client.getContentsApi().getContents(ContentsKey.of("mytestdb"), null);
Contents db = client.getContentsApi().getContents(ContentsKey.of("mytestdb"), null, null);
assertNotNull(db);
assertTrue(HiveDatabase.class.isAssignableFrom(db.getClass()));
Contents tbl = client.getContentsApi().getContents(ContentsKey.of("mytestdb", "nessie"), null);
Contents tbl =
client.getContentsApi().getContents(ContentsKey.of("mytestdb", "nessie"), null, null);
assertNotNull(tbl);
assertTrue(HiveTable.class.isAssignableFrom(tbl.getClass()));

// ensure only one table was created in Nessie.
assertEquals(2, client.getTreeApi().getEntries("main", null, null, null).getEntries().size());
assertEquals(
2, client.getTreeApi().getEntries("main", null, null, null, null).getEntries().size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ object NessieUtils {
.getCommitLogStream(
nessieClient.getTreeApi,
branch,
null,
OptionalInt.empty(),
String
.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ case class ShowLogExec(
val stream = StreamingUtil.getCommitLogStream(
nessieClient.getTreeApi,
refName,
null,
OptionalInt.empty(),
null
)
Expand Down
25 changes: 18 additions & 7 deletions model/src/main/java/org/projectnessie/api/ContentsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.projectnessie.api;

import javax.annotation.Nullable;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
Expand Down Expand Up @@ -69,14 +70,19 @@ Contents getContents(
examples = {@ExampleObject(ref = "ContentsKey")})
@PathParam("key")
ContentsKey key,
@Pattern(
regexp = Validation.REF_NAME_OR_HASH_REGEX,
message = Validation.REF_NAME_OR_HASH_MESSAGE)
@Pattern(regexp = Validation.REF_NAME_REGEX, message = Validation.REF_NAME_MESSAGE)
@Parameter(
description = "Reference to use. Defaults to default branch if not provided.",
examples = {@ExampleObject(ref = "ref")})
@QueryParam("ref")
String ref)
String ref,
@Nullable
@Pattern(regexp = Validation.HASH_REGEX, message = Validation.HASH_MESSAGE)
@Parameter(
description = "a particular hash on the given ref",
examples = {@ExampleObject(ref = "hash")})
@QueryParam("hashOnRef")
String hashOnRef)
throws NessieNotFoundException;

@POST
Expand All @@ -94,14 +100,19 @@ Contents getContents(
@APIResponse(responseCode = "404", description = "Provided ref doesn't exists")
})
MultiGetContentsResponse getMultipleContents(
@Pattern(
regexp = Validation.REF_NAME_OR_HASH_REGEX,
message = Validation.REF_NAME_OR_HASH_MESSAGE)
@Pattern(regexp = Validation.REF_NAME_REGEX, message = Validation.REF_NAME_MESSAGE)
@Parameter(
description = "Reference to use. Defaults to default branch if not provided.",
examples = {@ExampleObject(ref = "ref")})
@QueryParam("ref")
String ref,
@Nullable
@Pattern(regexp = Validation.HASH_REGEX, message = Validation.HASH_MESSAGE)
@Parameter(
description = "a particular hash on the given ref",
examples = {@ExampleObject(ref = "hash")})
@QueryParam("hashOnRef")
String hashOnRef,
@Valid @NotNull @RequestBody(description = "Keys to retrieve.")
MultiGetContentsRequest request)
throws NessieNotFoundException;
Expand Down
23 changes: 17 additions & 6 deletions model/src/main/java/org/projectnessie/api/TreeApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.projectnessie.api;

import java.util.List;
import javax.annotation.Nullable;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
Expand Down Expand Up @@ -203,14 +204,19 @@ Reference getReferenceByName(
})
public EntriesResponse getEntries(
@NotNull
@Pattern(
regexp = Validation.REF_NAME_OR_HASH_REGEX,
message = Validation.REF_NAME_OR_HASH_MESSAGE)
@Pattern(regexp = Validation.REF_NAME_REGEX, message = Validation.REF_NAME_MESSAGE)
@Parameter(
description = "name of ref to fetch from",
examples = {@ExampleObject(ref = "ref")})
@PathParam("ref")
String refName,
@Nullable
@Pattern(regexp = Validation.HASH_REGEX, message = Validation.HASH_MESSAGE)
@Parameter(
description = "a particular hash on the given ref",
examples = {@ExampleObject(ref = "hash")})
@QueryParam("hashOnRef")
String hashOnRef,
@Parameter(description = "maximum number of entries to return, just a hint for the server")
@QueryParam("max")
Integer maxRecords,
Expand Down Expand Up @@ -290,14 +296,19 @@ public EntriesResponse getEntries(
})
LogResponse getCommitLog(
@NotNull
@Pattern(
regexp = Validation.REF_NAME_OR_HASH_REGEX,
message = Validation.REF_NAME_OR_HASH_MESSAGE)
@Pattern(regexp = Validation.REF_NAME_REGEX, message = Validation.REF_NAME_MESSAGE)
@Parameter(
description = "ref to show log from",
examples = {@ExampleObject(ref = "ref")})
@PathParam("ref")
String ref,
@Nullable
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(similar to above about startHash instead of hashOnRef + endHash)

@Pattern(regexp = Validation.HASH_REGEX, message = Validation.HASH_MESSAGE)
@Parameter(
description = "a particular hash on the given ref",
examples = {@ExampleObject(ref = "hash")})
@QueryParam("hashOnRef")
String hashOnRef,
@Parameter(
description =
"maximum number of commit-log entries to return, just a hint for the server")
Expand Down
9 changes: 1 addition & 8 deletions python/pynessie/_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,13 @@ 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
if start_yielding:
yield i
yield i

return generator()
2 changes: 1 addition & 1 deletion python/pynessie/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def log( # noqa: C901
if number:
filtering_args["max"] = str(number)
if start:
filtering_args["start"] = start
filtering_args["hashOnRef"] = start
if end:
filtering_args["end"] = end
# TODO: we should eventually move "start..end" filtering to the server
Expand Down
Loading