Skip to content

Commit

Permalink
Add metadata to IcebergTable + IcebergView (#3947)
Browse files Browse the repository at this point in the history
This change only adds the fields to the model objects to include the Iceberg
metadata. No functionality added or changed.

The new field defaults to `null` and is not serialized if it is `null`.
  • Loading branch information
snazy authored Apr 14, 2022
1 parent 5db5419 commit a5ccf6a
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 6 deletions.
41 changes: 41 additions & 0 deletions model/src/main/java/org/projectnessie/model/GenericMetadata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2022 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.model;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
import org.eclipse.microprofile.openapi.annotations.media.Schema;
import org.immutables.value.Value;

@Value.Immutable
@JsonSerialize(as = ImmutableGenericMetadata.class)
@JsonDeserialize(as = ImmutableGenericMetadata.class)
public interface GenericMetadata {

@NotEmpty
String getVariant();

@Schema(type = SchemaType.OBJECT)
JsonNode getMetadata();

static GenericMetadata of(@NotNull String variant, @NotNull JsonNode metadata) {
return ImmutableGenericMetadata.builder().variant(variant).metadata(metadata).build();
}
}
19 changes: 17 additions & 2 deletions model/src/main/java/org/projectnessie/model/IcebergTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
*/
package org.projectnessie.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import javax.annotation.Nullable;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import org.eclipse.microprofile.openapi.annotations.enums.SchemaType;
Expand Down Expand Up @@ -60,22 +63,34 @@ public abstract class IcebergTable extends Content {
@NotBlank
public abstract String getMetadataLocation();

/** Corresponds to Iceberg's {@code currentSnapshotId}. */
public abstract long getSnapshotId();

/** Corresponds to Iceberg's {@code currentSchemaId}. */
public abstract int getSchemaId();

/** Corresponds to Iceberg's {@code defaultSpecId}. */
public abstract int getSpecId();

/** Corresponds to Iceberg's {@code defaultSortOrderId}. */
public abstract int getSortOrderId();

@Override
public Type getType() {
return Type.ICEBERG_TABLE;
}

@Nullable
@JsonInclude(Include.NON_NULL)
public abstract GenericMetadata getMetadata();

public static ImmutableIcebergTable.Builder builder() {
return ImmutableIcebergTable.builder();
}

public static IcebergTable of(
String metadataLocation, long snapshotId, int schemaId, int specId, int sortOrderId) {
return ImmutableIcebergTable.builder()
return builder()
.metadataLocation(metadataLocation)
.snapshotId(snapshotId)
.schemaId(schemaId)
Expand All @@ -91,7 +106,7 @@ public static IcebergTable of(
int specId,
int sortOrderId,
String contentId) {
return ImmutableIcebergTable.builder()
return builder()
.metadataLocation(metadataLocation)
.snapshotId(snapshotId)
.schemaId(schemaId)
Expand Down
19 changes: 15 additions & 4 deletions model/src/main/java/org/projectnessie/model/IcebergView.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@
*/
package org.projectnessie.model;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import javax.annotation.Nullable;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import org.immutables.value.Value;
Expand All @@ -36,6 +39,7 @@ public abstract class IcebergView extends Content {
@NotBlank
public abstract String getMetadataLocation();

/** Corresponds to Iceberg's {@code currentVersionId}. */
public abstract int getVersionId();

public abstract int getSchemaId();
Expand All @@ -44,18 +48,25 @@ public abstract class IcebergView extends Content {
@NotNull
public abstract String getSqlText();

@NotNull
@NotBlank
@Nullable // TODO this is currently undefined in Iceberg
public abstract String getDialect();

@Override
public Type getType() {
return Type.ICEBERG_VIEW;
}

@Nullable
@JsonInclude(Include.NON_NULL)
public abstract GenericMetadata getMetadata();

public static ImmutableIcebergView.Builder builder() {
return ImmutableIcebergView.builder();
}

public static IcebergView of(
String metadataLocation, int versionId, int schemaId, String dialect, String sqlText) {
return ImmutableIcebergView.builder()
return builder()
.metadataLocation(metadataLocation)
.versionId(versionId)
.schemaId(schemaId)
Expand All @@ -71,7 +82,7 @@ public static IcebergView of(
int schemaId,
String dialect,
String sqlText) {
return ImmutableIcebergView.builder()
return builder()
.id(id)
.metadataLocation(metadataLocation)
.versionId(versionId)
Expand Down

0 comments on commit a5ccf6a

Please sign in to comment.