polyzos commented on code in PR #11248: URL: https://github.com/apache/gravitino/pull/11248#discussion_r3316730678
########## catalogs/catalog-fluss/src/main/java/org/apache/gravitino/catalog/fluss/FlussSchema.java: ########## @@ -0,0 +1,96 @@ +/* + * 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.gravitino.catalog.fluss; + +import static org.apache.gravitino.StringIdentifier.DUMMY_ID; +import static org.apache.gravitino.StringIdentifier.newPropertiesWithId; + +import java.util.Map; +import lombok.ToString; +import org.apache.fluss.metadata.DatabaseDescriptor; +import org.apache.fluss.metadata.DatabaseInfo; +import org.apache.gravitino.Schema; +import org.apache.gravitino.connector.BaseSchema; + +/** Represents an Apache Fluss Database as a Gravitino {@link Schema}. */ +@ToString +public class FlussSchema extends BaseSchema { + + private FlussSchema() {} + + /** + * Creates a builder for {@link FlussSchema}. + * + * @return the schema builder + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Converts Gravitino schema metadata to a Fluss database descriptor. + * + * @param comment the schema comment + * @param properties the schema properties + * @return the converted Fluss database descriptor + */ + public static DatabaseDescriptor toDatabaseDescriptor( Review Comment: Keep the Gravitino `ID_KEY` in Fluss custom properties so it round-trips on load. Tables use the Fluss-assigned numeric table ID instead; schemas have no such ID. ``` DatabaseDescriptor.Builder builder = DatabaseDescriptor.builder() .customProperties(properties == null ? Map.of() : properties); ``` ########## catalogs/catalog-fluss/src/main/java/org/apache/gravitino/catalog/fluss/FlussSchema.java: ########## @@ -0,0 +1,96 @@ +/* + * 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.gravitino.catalog.fluss; + +import static org.apache.gravitino.StringIdentifier.DUMMY_ID; +import static org.apache.gravitino.StringIdentifier.newPropertiesWithId; + +import java.util.Map; +import lombok.ToString; +import org.apache.fluss.metadata.DatabaseDescriptor; +import org.apache.fluss.metadata.DatabaseInfo; +import org.apache.gravitino.Schema; +import org.apache.gravitino.connector.BaseSchema; + +/** Represents an Apache Fluss Database as a Gravitino {@link Schema}. */ +@ToString +public class FlussSchema extends BaseSchema { + + private FlussSchema() {} + + /** + * Creates a builder for {@link FlussSchema}. + * + * @return the schema builder + */ + public static Builder builder() { + return new Builder(); + } + + /** + * Converts Gravitino schema metadata to a Fluss database descriptor. + * + * @param comment the schema comment + * @param properties the schema properties + * @return the converted Fluss database descriptor + */ + public static DatabaseDescriptor toDatabaseDescriptor( + String comment, Map<String, String> properties) { + DatabaseDescriptor.Builder builder = + DatabaseDescriptor.builder() + .customProperties(FlussMetadataUtils.removeInternalProperties(properties)); + if (comment != null) { + builder.comment(comment); + } + return builder.build(); + } + + /** + * Converts a Fluss database info object to a Gravitino schema. + * + * @param databaseInfo the Fluss database info + * @return the converted Gravitino schema + */ + public static FlussSchema fromDatabaseInfo(DatabaseInfo databaseInfo) { + DatabaseDescriptor descriptor = databaseInfo.getDatabaseDescriptor(); + return FlussSchema.builder() + .withName(databaseInfo.getDatabaseName()) + .withComment(descriptor.getComment().orElse(null)) + .withProperties(newPropertiesWithId(DUMMY_ID, descriptor.getCustomProperties())) Review Comment: read ID_KEY to build a real StringIdentifier ``` .withProperties(descriptor.getCustomProperties()) ``` ########## catalogs/catalog-fluss/src/main/java/org/apache/gravitino/catalog/fluss/FlussCatalogOperations.java: ########## @@ -0,0 +1,644 @@ +/* + * 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.gravitino.catalog.fluss; + +import static org.apache.gravitino.StringIdentifier.ID_KEY; +import static org.apache.gravitino.connector.BaseCatalog.CATALOG_BYPASS_PREFIX; + +import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; +import java.io.IOException; +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.stream.Collectors; +import javax.annotation.Nullable; +import org.apache.fluss.client.Connection; +import org.apache.fluss.client.ConnectionFactory; +import org.apache.fluss.client.admin.Admin; +import org.apache.fluss.config.ConfigOptions; +import org.apache.fluss.config.Configuration; +import org.apache.fluss.metadata.AggFunction; +import org.apache.fluss.metadata.DatabaseDescriptor; +import org.apache.fluss.metadata.DatabaseInfo; +import org.apache.fluss.metadata.TableDescriptor; +import org.apache.fluss.metadata.TableInfo; +import org.apache.fluss.metadata.TablePath; +import org.apache.fluss.types.DataType; +import org.apache.gravitino.Catalog; +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.Namespace; +import org.apache.gravitino.Schema; +import org.apache.gravitino.SchemaChange; +import org.apache.gravitino.connector.CatalogInfo; +import org.apache.gravitino.connector.CatalogOperations; +import org.apache.gravitino.connector.HasPropertyMetadata; +import org.apache.gravitino.connector.SupportsSchemas; +import org.apache.gravitino.exceptions.ConnectionFailedException; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchColumnException; +import org.apache.gravitino.exceptions.NoSuchSchemaException; +import org.apache.gravitino.exceptions.NoSuchTableException; +import org.apache.gravitino.exceptions.NonEmptySchemaException; +import org.apache.gravitino.exceptions.SchemaAlreadyExistsException; +import org.apache.gravitino.exceptions.TableAlreadyExistsException; +import org.apache.gravitino.rel.Column; +import org.apache.gravitino.rel.Table; +import org.apache.gravitino.rel.TableCatalog; +import org.apache.gravitino.rel.TableChange; +import org.apache.gravitino.rel.expressions.distributions.Distribution; +import org.apache.gravitino.rel.expressions.sorts.SortOrder; +import org.apache.gravitino.rel.expressions.transforms.Transform; +import org.apache.gravitino.rel.indexes.Index; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Operations implementation for the Apache Fluss catalog connector. + * + * <p>Implements schema CRUD (via {@link SupportsSchemas}) and table CRUD (via {@link TableCatalog}) + * backed by the Apache Fluss Java client API. + */ +public class FlussCatalogOperations implements CatalogOperations, SupportsSchemas, TableCatalog { Review Comment: Should we also add a purgeTable implementation here? ``` @Override public boolean purgeTable(NameIdentifier ident) { return dropTable(ident); } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
