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
1 change: 1 addition & 0 deletions bom/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ dependencies {
api(project(":polaris-persistence-nosql-api"))
api(project(":polaris-persistence-nosql-impl"))
api(project(":polaris-persistence-nosql-benchmark"))
api(project(":polaris-persistence-nosql-metastore"))
api(project(":polaris-persistence-nosql-metastore-types"))
api(project(":polaris-persistence-nosql-correctness"))
api(project(":polaris-persistence-nosql-cdi-common"))
Expand Down
1 change: 1 addition & 0 deletions gradle/projects.main.properties
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ polaris-persistence-nosql-realms-store-nosql=persistence/nosql/realms/store-nosq
polaris-persistence-nosql-api=persistence/nosql/persistence/api
polaris-persistence-nosql-impl=persistence/nosql/persistence/impl
polaris-persistence-nosql-benchmark=persistence/nosql/persistence/benchmark
polaris-persistence-nosql-metastore=persistence/nosql/persistence/metastore
polaris-persistence-nosql-metastore-types=persistence/nosql/persistence/metastore-types
polaris-persistence-nosql-correctness=persistence/nosql/persistence/correctness
polaris-persistence-nosql-cdi-common=persistence/nosql/persistence/cdi/common
Expand Down
73 changes: 73 additions & 0 deletions persistence/nosql/persistence/metastore/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.
*/

plugins {
id("org.kordamp.gradle.jandex")
id("polaris-server")
}

description = "Polaris NoSQL persistence - bridge to meta-store"

dependencies {
implementation(project(":polaris-core"))

implementation(project(":polaris-persistence-nosql-api"))
implementation(project(":polaris-persistence-nosql-metastore-types"))
implementation(project(":polaris-persistence-nosql-authz-api"))
implementation(project(":polaris-persistence-nosql-authz-spi"))
implementation(project(":polaris-persistence-nosql-realms-api"))
implementation(project(":polaris-idgen-api"))
implementation(project(":polaris-api-catalog-service"))

implementation(platform(libs.iceberg.bom))
implementation("org.apache.iceberg:iceberg-api")
implementation("org.apache.iceberg:iceberg-core")

implementation(libs.guava)
implementation(libs.slf4j.api)

implementation(platform(libs.jackson.bom))
implementation("com.fasterxml.jackson.core:jackson-annotations")
implementation("com.fasterxml.jackson.core:jackson-core")
implementation("com.fasterxml.jackson.core:jackson-databind")

compileOnly(project(":polaris-immutables"))
annotationProcessor(project(":polaris-immutables", configuration = "processor"))

compileOnly(libs.jakarta.annotation.api)
compileOnly(libs.jakarta.validation.api)
compileOnly(libs.jakarta.inject.api)
compileOnly(libs.jakarta.enterprise.cdi.api)
compileOnly(libs.smallrye.common.annotation)

testImplementation(testFixtures(project(":polaris-core")))
testRuntimeOnly(project(":polaris-persistence-nosql-authz-impl"))
testRuntimeOnly(project(":polaris-persistence-nosql-authz-store-nosql"))
testRuntimeOnly(testFixtures(project(":polaris-persistence-nosql-cdi-weld")))
testImplementation(libs.weld.se.core)
testImplementation(libs.weld.junit5)
testRuntimeOnly(libs.smallrye.jandex)

testFixturesImplementation(project(":polaris-core"))
testFixturesImplementation(testFixtures(project(":polaris-core")))
testFixturesImplementation(libs.jakarta.annotation.api)
testFixturesImplementation(libs.jakarta.validation.api)
testFixturesImplementation(libs.jakarta.enterprise.cdi.api)
testCompileOnly(libs.smallrye.common.annotation)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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.apache.polaris.persistence.nosql.metastore;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;

import com.fasterxml.jackson.annotation.JsonValue;
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import java.util.ArrayList;
import java.util.List;
import org.apache.iceberg.catalog.Namespace;
import org.apache.iceberg.catalog.TableIdentifier;
import org.apache.polaris.core.storage.StorageLocation;
import org.apache.polaris.immutables.PolarisImmutable;
import org.apache.polaris.persistence.nosql.api.index.IndexKey;
import org.apache.polaris.service.types.PolicyIdentifier;
import org.immutables.value.Value;

@Value.Style(underrideToString = "asDotDelimitedString")
@PolarisImmutable
public interface ContentIdentifier {
@Value.Parameter
@JsonValue
List<String> elements();

static ContentIdentifier identifier(List<String> elements) {
return ImmutableContentIdentifier.of(elements);
}

static ContentIdentifier identifier(String[] namespace, String name) {
return ImmutableContentIdentifier.builder().addElements(namespace).addElements(name).build();
}

static ContentIdentifier identifier(String... elements) {
return ImmutableContentIdentifier.of(List.of(elements));
}

static ContentIdentifier identifierFor(PolicyIdentifier identifier) {
return identifier(identifier.getNamespace().levels(), identifier.getName());
}

static ContentIdentifier identifierFor(TableIdentifier identifier) {
return identifier(identifier.namespace().levels(), identifier.name());
}

static ContentIdentifier identifierFor(Namespace namespace) {
return identifier(namespace.levels());
}

/**
* Constructs a {@link ContentIdentifier} from a storage location without the scheme.
*
* <p>This is used for the locations index for location-overlap checks.
*
* <p>Valid inputs follow the values returned by {@link StorageLocation#withoutScheme()
* StorageLocation.of(previousBaseLocation).withoutScheme()}, which can, in case of "file"
* locations, contain system-specific file separators.
*/
static ContentIdentifier identifierFromLocationString(String locationString) {
Copy link
Contributor

Choose a reason for hiding this comment

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

All the other factory methods are mostly self-explanatory, but this one could use some javadocs explaining what locationString is, expected format, etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

yup, added

var builder = builder();
var len = locationString.length();
var off = -1;
for (var i = 0; i < len; i++) {
var c = locationString.charAt(i);
checkArgument(c >= ' ' && c != 127, "Control characters are forbidden in locations");
if (c == '/' || c == '\\') {
if (off != -1) {
builder.addElements(locationString.substring(off, i));
off = -1;
}
} else {
if (off == -1) {
off = i;
}
}
}
if (off != -1) {
builder.addElements(locationString.substring(off));
}
return builder.build();
}

default ContentIdentifier parent() {
var elems = elements();
checkState(!elems.isEmpty(), "Empty namespace has no parent");
return ImmutableContentIdentifier.of(elems.subList(0, elems.size() - 1));
}

default boolean isEmpty() {
return elements().isEmpty();
}

default int length() {
return elements().size();
}

default String leafName() {
var elems = elements();
return elems.isEmpty() ? "" : elems.getLast();
}

default ContentIdentifier childOf(String childName) {
var elems = elements();
var newElements = new ArrayList<String>(elems.size() + 1);
newElements.addAll(elems);
newElements.add(childName);
return ImmutableContentIdentifier.of(newElements);
}

default String asDotDelimitedString() {
return String.join(".", elements());
}

static ImmutableContentIdentifier.Builder builder() {
return ImmutableContentIdentifier.builder();
}

default IndexKey toIndexKey() {
return IndexKey.key(String.join("\u0000", elements()));
}

default boolean startsWith(ContentIdentifier other) {
var elems = elements();
var otherElems = other.elements();
var otherSize = otherElems.size();
if (otherSize > elems.size()) {
return false;
}
for (int i = 0; i < otherSize; i++) {
if (!elems.get(i).equals(otherElems.get(i))) {
return false;
}
}
return true;
}

@CanIgnoreReturnValue
static ImmutableContentIdentifier.Builder indexKeyToIdentifierBuilder(
IndexKey indexKey, ImmutableContentIdentifier.Builder builder) {
var str = indexKey.toString();
var l = str.length();
for (var i = 0; i < l; ) {
var iNull = str.indexOf(0, i);
if (iNull == -1) {
builder.addElements(str.substring(i));
return builder;
}
builder.addElements(str.substring(i, iNull));
i = iNull + 1;
}
return builder;
}

static ImmutableContentIdentifier.Builder indexKeyToIdentifierBuilder(IndexKey indexKey) {
return indexKeyToIdentifierBuilder(indexKey, ImmutableContentIdentifier.builder());
}

static ContentIdentifier indexKeyToIdentifier(IndexKey indexKey) {
return indexKeyToIdentifierBuilder(indexKey).build();
}
}
Loading