Skip to content

Commit

Permalink
remove NessieApiV1 support from spark extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
XN137 committed Sep 12, 2024
1 parent 1a6f146 commit 44ecb83
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
package org.apache.spark.sql.execution.datasources.v2;

import org.apache.spark.sql.connector.catalog.CatalogPlugin;
import org.projectnessie.client.api.NessieApiV1;
import org.projectnessie.client.api.NessieApiV2;
import org.projectnessie.error.NessieReferenceNotFoundException;
import org.projectnessie.model.Reference;

public interface CatalogBridge extends AutoCloseable {
CatalogPlugin currentCatalog();

NessieApiV1 api();
NessieApiV2 api();

void setCurrentRefForSpark(Reference ref, boolean configureRefAtHash);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.projectnessie.api.v2.params.ParsedReference;
import org.projectnessie.client.NessieClientBuilder;
import org.projectnessie.client.NessieConfigConstants;
import org.projectnessie.client.api.NessieApiV1;
import org.projectnessie.client.api.NessieApiV2;
import org.projectnessie.client.config.NessieClientConfigSource;

Expand Down Expand Up @@ -76,22 +75,20 @@ public static CatalogBridge buildBridge(CatalogPlugin currentCatalog, String cat
}
}

static NessieApiV1 buildApi(NessieClientConfigSource nessieClientConfigMapper) {
static NessieApiV2 buildApi(NessieClientConfigSource nessieClientConfigMapper) {
NessieClientBuilder nessieClientBuilder =
NessieClientBuilder.createClientBuilderFromSystemSettings(nessieClientConfigMapper);
String clientApiVer = nessieClientConfigMapper.getValue("nessie.client-api-version");
if (clientApiVer == null) {
clientApiVer = "1";
clientApiVer = "2";
}
switch (clientApiVer) {
case "1":
return nessieClientBuilder.build(NessieApiV1.class);
case "2":
return nessieClientBuilder.build(NessieApiV2.class);
default:
throw new IllegalArgumentException(
String.format(
"Unsupported client-api-version value: %s. Can only be 1 or 2", clientApiVer));
"Unsupported client-api-version value: %s. Can only be '2'", clientApiVer));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.spark.SparkContext;
import org.apache.spark.sql.connector.catalog.CatalogPlugin;
import org.apache.spark.sql.util.CaseInsensitiveStringMap;
import org.projectnessie.client.api.NessieApiV1;
import org.projectnessie.client.api.NessieApiV2;
import org.projectnessie.error.NessieNotFoundException;
import org.projectnessie.error.NessieReferenceNotFoundException;
import org.projectnessie.model.Branch;
Expand All @@ -33,7 +33,7 @@

final class NessieCatalogBridge implements CatalogBridge {
private final SparkContext sparkContext;
private final NessieApiV1 api;
private final NessieApiV2 api;
private final CatalogPlugin currentCatalog;
private final String catalogName;
private final String confPrefix;
Expand Down Expand Up @@ -106,7 +106,7 @@ public void setCurrentRefForSpark(Reference ref, boolean configureRefAtHash) {
}

@Override
public NessieApiV1 api() {
public NessieApiV2 api() {
return api;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.apache.spark.sql.util.CaseInsensitiveStringMap;
import org.projectnessie.api.v2.params.ParsedReference;
import org.projectnessie.client.NessieConfigConstants;
import org.projectnessie.client.api.NessieApiV1;
import org.projectnessie.client.api.NessieApiV2;
import org.projectnessie.client.config.NessieClientConfigSource;
import org.projectnessie.error.NessieNotFoundException;
import org.projectnessie.error.NessieReferenceNotFoundException;
Expand All @@ -41,7 +41,7 @@

final class RestCatalogBridge implements CatalogBridge {
private final SparkContext sparkContext;
private final NessieApiV1 api;
private final NessieApiV2 api;
private final CatalogPlugin currentCatalog;
private final String catalogName;
private final String confPrefix;
Expand Down Expand Up @@ -188,7 +188,7 @@ private static String encode(String s) {
}

@Override
public NessieApiV1 api() {
public NessieApiV2 api() {
return api;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package org.apache.spark.sql.execution.datasources.v2

import org.projectnessie.client.api.NessieApiV1
import org.projectnessie.client.api.NessieApiV2
import org.projectnessie.error.NessieReferenceNotFoundException
import org.projectnessie.model._

Expand All @@ -36,7 +36,7 @@ object NessieUtils {
def calculateRef(
branch: String,
tsOrHash: Option[String],
api: NessieApiV1
api: NessieApiV2
): Reference = {
val refName = unquoteRefName(branch)

Expand Down Expand Up @@ -76,7 +76,7 @@ object NessieUtils {
private def findReferenceFromHash(
branch: String,
requestedHash: String,
api: NessieApiV1
api: NessieApiV2
) = {
val commit = Option(
api.getCommitLog
Expand Down Expand Up @@ -105,7 +105,7 @@ object NessieUtils {

private def findReferenceFromTimestamp(
branch: String,
api: NessieApiV1,
api: NessieApiV2,
timestamp: Instant
) = {
val commit = Option(
Expand Down

0 comments on commit 44ecb83

Please sign in to comment.