Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST V2: Key ranges for entries + diff #6743

Merged
merged 3 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
* @since {@link NessieApiV1}
*/
public interface GetDiffBuilder
extends PagingBuilder<GetDiffBuilder, DiffResponse, DiffResponse.DiffEntry> {
extends PagingBuilder<GetDiffBuilder, DiffResponse, DiffResponse.DiffEntry>,
QueryBuilder<GetDiffBuilder>,
KeyRangeBuilder<GetDiffBuilder> {

GetDiffBuilder fromRefName(String fromRefName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
public interface GetEntriesBuilder
extends QueryBuilder<GetEntriesBuilder>,
KeyRangeBuilder<GetEntriesBuilder>,
PagingBuilder<GetEntriesBuilder, EntriesResponse, EntriesResponse.Entry>,
OnReferenceBuilder<GetEntriesBuilder> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2020 Dremio
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.projectnessie.client.api;

import java.util.Collection;
import org.projectnessie.model.ContentKey;

public interface KeyRangeBuilder<R extends KeyRangeBuilder<R>> {

R minKey(ContentKey key);

R maxKey(ContentKey key);

R prefixKey(ContentKey key);

R key(ContentKey key);

R keys(Collection<ContentKey> keys);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
*/
package org.projectnessie.client.builder;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.function.BiFunction;
import java.util.stream.Stream;
import org.projectnessie.client.StreamingUtil;
import org.projectnessie.client.api.GetDiffBuilder;
import org.projectnessie.error.NessieNotFoundException;
import org.projectnessie.model.ContentKey;
import org.projectnessie.model.DiffResponse;

public abstract class BaseGetDiffBuilder<PARAMS> implements GetDiffBuilder {
Expand All @@ -32,6 +36,11 @@ public abstract class BaseGetDiffBuilder<PARAMS> implements GetDiffBuilder {
protected String fromHashOnRef;
protected String toRefName;
protected String toHashOnRef;
protected final List<ContentKey> keys = new ArrayList<>();
protected ContentKey minKey;
protected ContentKey maxKey;
protected ContentKey prefixKey;
protected String filter;

protected BaseGetDiffBuilder(BiFunction<PARAMS, String, PARAMS> paramsForPage) {
this.paramsForPage = paramsForPage;
Expand Down Expand Up @@ -73,6 +82,42 @@ public GetDiffBuilder pageToken(String pageToken) {
return this;
}

@Override
public GetDiffBuilder key(ContentKey key) {
this.keys.add(key);
return this;
}

@Override
public GetDiffBuilder keys(Collection<ContentKey> keys) {
this.keys.addAll(keys);
return this;
}

@Override
public GetDiffBuilder minKey(ContentKey minKey) {
this.minKey = minKey;
return this;
}

@Override
public GetDiffBuilder maxKey(ContentKey maxKey) {
this.maxKey = maxKey;
return this;
}

@Override
public GetDiffBuilder prefixKey(ContentKey prefixKey) {
this.prefixKey = prefixKey;
return this;
}

@Override
public GetDiffBuilder filter(String filter) {
this.filter = filter;
return this;
}

@Override
public DiffResponse get() throws NessieNotFoundException {
return get(paramsForPage.apply(params(), pageToken));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
*/
package org.projectnessie.client.builder;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.function.BiFunction;
import java.util.stream.Stream;
import org.projectnessie.client.StreamingUtil;
import org.projectnessie.client.api.GetEntriesBuilder;
import org.projectnessie.error.NessieNotFoundException;
import org.projectnessie.model.ContentKey;
import org.projectnessie.model.EntriesResponse;
import org.projectnessie.model.EntriesResponse.Entry;

Expand All @@ -30,6 +34,10 @@ public abstract class BaseGetEntriesBuilder<PARAMS>
private String pageToken;

protected Integer maxRecords;
protected final List<ContentKey> keys = new ArrayList<>();
protected ContentKey minKey;
protected ContentKey maxKey;
protected ContentKey prefixKey;
protected String filter;
protected Integer namespaceDepth;
protected boolean withContent;
Expand All @@ -50,6 +58,36 @@ public GetEntriesBuilder pageToken(String pageToken) {
return this;
}

@Override
public GetEntriesBuilder key(ContentKey key) {
this.keys.add(key);
return this;
}

@Override
public GetEntriesBuilder keys(Collection<ContentKey> keys) {
this.keys.addAll(keys);
return this;
}

@Override
public GetEntriesBuilder minKey(ContentKey minKey) {
this.minKey = minKey;
return this;
}

@Override
public GetEntriesBuilder maxKey(ContentKey maxKey) {
this.maxKey = maxKey;
return this;
}

@Override
public GetEntriesBuilder prefixKey(ContentKey prefixKey) {
this.prefixKey = prefixKey;
return this;
}

@Override
public GetEntriesBuilder filter(String filter) {
this.filter = filter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*/
package org.projectnessie.client.http.v1api;

import java.util.Collection;
import org.projectnessie.api.v1.params.DiffParams;
import org.projectnessie.api.v1.params.DiffParamsBuilder;
import org.projectnessie.client.api.GetDiffBuilder;
import org.projectnessie.client.builder.BaseGetDiffBuilder;
import org.projectnessie.client.http.NessieApiClient;
import org.projectnessie.error.NessieNotFoundException;
import org.projectnessie.model.ContentKey;
import org.projectnessie.model.DiffResponse;

final class HttpGetDiff extends BaseGetDiffBuilder<DiffParams> {
Expand All @@ -46,6 +48,38 @@ public GetDiffBuilder maxRecords(int maxRecords) {
throw new UnsupportedOperationException(PAGINATION_ERROR_MESSAGE);
}

@Override
public GetDiffBuilder key(ContentKey key) {
throw new UnsupportedOperationException(
"Requesting individual keys is not supported in API v1.");
}

@Override
public GetDiffBuilder keys(Collection<ContentKey> keys) {
throw new UnsupportedOperationException(
"Requesting individual keys is not supported in API v1.");
}

@Override
public GetDiffBuilder minKey(ContentKey minKey) {
throw new UnsupportedOperationException("Requesting key ranges is not supported in API v1.");
}

@Override
public GetDiffBuilder maxKey(ContentKey maxKey) {
throw new UnsupportedOperationException("Requesting key ranges is not supported in API v1.");
}

@Override
public GetDiffBuilder prefixKey(ContentKey prefixKey) {
throw new UnsupportedOperationException("Requesting key prefix is not supported in API v1.");
}

@Override
public GetDiffBuilder filter(String filter) {
throw new UnsupportedOperationException("CEL key filter is not supported in API v1.");
}

@Override
protected DiffParams params() {
return DiffParams.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
*/
package org.projectnessie.client.http.v1api;

import java.util.Collection;
import org.projectnessie.api.v1.params.EntriesParams;
import org.projectnessie.client.api.GetEntriesBuilder;
import org.projectnessie.client.builder.BaseGetEntriesBuilder;
import org.projectnessie.client.http.NessieApiClient;
import org.projectnessie.error.NessieNotFoundException;
import org.projectnessie.model.ContentKey;
import org.projectnessie.model.EntriesResponse;

final class HttpGetEntries extends BaseGetEntriesBuilder<EntriesParams> {
Expand All @@ -40,6 +43,33 @@ protected EntriesParams params() {
.build();
}

@Override
public HttpGetEntries key(ContentKey key) {
throw new UnsupportedOperationException(
"Requesting individual keys is not supported in API v1.");
}

@Override
public HttpGetEntries keys(Collection<ContentKey> keys) {
throw new UnsupportedOperationException(
"Requesting individual keys is not supported in API v1.");
}

@Override
public HttpGetEntries minKey(ContentKey minKey) {
throw new UnsupportedOperationException("Requesting key ranges is not supported in API v1.");
}

@Override
public HttpGetEntries maxKey(ContentKey maxKey) {
throw new UnsupportedOperationException("Requesting key ranges is not supported in API v1.");
snazy marked this conversation as resolved.
Show resolved Hide resolved
}

@Override
public GetEntriesBuilder prefixKey(ContentKey prefixKey) {
throw new UnsupportedOperationException("Requesting key ranges is not supported in API v1.");
}

@Override
protected EntriesResponse get(EntriesParams p) throws NessieNotFoundException {
if (withContent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import org.projectnessie.api.v2.params.DiffParams;
import org.projectnessie.client.builder.BaseGetDiffBuilder;
import org.projectnessie.client.http.HttpClient;
import org.projectnessie.client.http.HttpRequest;
import org.projectnessie.error.NessieNotFoundException;
import org.projectnessie.model.ContentKey;
import org.projectnessie.model.DiffResponse;
import org.projectnessie.model.Reference;

Expand All @@ -36,20 +38,38 @@ protected DiffParams params() {
.fromRef(Reference.toPathString(fromRefName, fromHashOnRef))
.toRef(Reference.toPathString(toRefName, toHashOnRef))
.maxRecords(maxRecords)
.minKey(minKey)
.maxKey(maxKey)
.prefixKey(prefixKey)
.filter(filter)
.requestedKeys(keys)
.build();
}

@Override
public DiffResponse get(DiffParams params) throws NessieNotFoundException {
return client
.newRequest()
.path("trees/{from}/diff/{to}")
.resolveTemplate("from", params.getFromRef())
.resolveTemplate("to", params.getToRef())
.queryParam("max-records", params.maxRecords())
.queryParam("page-token", params.pageToken())
.unwrap(NessieNotFoundException.class)
.get()
.readEntity(DiffResponse.class);
HttpRequest req =
client
.newRequest()
.path("trees/{from}/diff/{to}")
.resolveTemplate("from", params.getFromRef())
.resolveTemplate("to", params.getToRef())
.queryParam("max-records", params.maxRecords())
.queryParam("page-token", params.pageToken())
.queryParam("filter", params.getFilter());
params.getRequestedKeys().forEach(k -> req.queryParam("key", k.toPathString()));
ContentKey k = params.minKey();
if (k != null) {
req.queryParam("min-key", k.toPathString());
dimas-b marked this conversation as resolved.
Show resolved Hide resolved
}
k = params.maxKey();
if (k != null) {
req.queryParam("max-key", k.toPathString());
}
k = params.prefixKey();
if (k != null) {
req.queryParam("prefix-key", k.toPathString());
}
return req.unwrap(NessieNotFoundException.class).get().readEntity(DiffResponse.class);
}
}