jerryshao commented on code in PR #13571: URL: https://github.com/apache/gravitino/pull/13571#discussion_r4214411281
########## api/src/main/java/org/apache/gravitino/semantic/OssieDocument.java: ########## @@ -0,0 +1,95 @@ +/* + * 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.semantic; + +import com.google.common.base.Preconditions; +import java.util.Objects; +import org.apache.gravitino.annotation.Evolving; + +/** + * An immutable standalone Apache Ossie document containing serialized content and its format. + * + * <p>The content is the document text, not a file path or URL. Constructing this value does not + * parse or validate its content; validation takes place when the document is imported. + */ +@Evolving +public final class OssieDocument { + + private final String content; + private final OssieFormat format; + + private OssieDocument(String content, OssieFormat format) { + Preconditions.checkArgument(content != null, "content must not be null"); Review Comment: Can you use StringUtils.nonBlank instead? ########## api/src/main/java/org/apache/gravitino/semantic/SemanticModelCatalog.java: ########## @@ -85,6 +85,55 @@ SemanticModel createSemanticModel( throws NoSuchSchemaException, SemanticModelAlreadyExistsException, IllegalSemanticModelException; + /** + * Imports a standalone Apache Ossie document as a new Semantic Model in a schema. + * + * <p>The model name comes from the document. Import uses the same validation as {@link + * #createSemanticModel}; it does not replace an existing model. The document is parsed according + * to its declared format, without falling back to another format. + * + * <p>REST clients send {@link OssieDocument#content()} as the raw request body, without + * JSON-encoding the document string again. The {@code Content-Type} header selects the parser: + * {@code application/json} for JSON, or {@code application/yaml}, {@code application/x-yaml}, or + * {@code text/yaml} for YAML. If the header is absent, the REST endpoint defaults to YAML. + * + * <p>A root {@link CustomExtension#GRAVITINO_PROPERTIES_VENDOR} extension is consumed as model + * properties before creation. Its data must encode a JSON object with string values, and at most + * one such extension is allowed. Other custom extensions are preserved. + * + * @param namespace The destination schema namespace. + * @param document The standalone Ossie document and its serialization format. + * @return The created Semantic Model. + * @throws NoSuchSchemaException If the schema does not exist. + * @throws SemanticModelAlreadyExistsException If a model with the document's name already exists. + * @throws IllegalSemanticModelException If the document or Semantic Model definition is invalid. + * @throws UnsupportedOperationException If Ossie import is not supported. + */ + default SemanticModel importOssieSemanticModel(Namespace namespace, OssieDocument document) Review Comment: How about changing to `importOssieDocument` and `exportOssieDocument`? ########## core/src/main/java/org/apache/gravitino/semantic/OssieSemanticModelDocumentConverter.java: ########## @@ -0,0 +1,795 @@ +/* + * 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.semantic; + +import static org.apache.gravitino.semantic.CustomExtension.GRAVITINO_PROPERTIES_VENDOR; +import static org.apache.gravitino.semantic.SemanticModel.DEFAULT_OSSIE_VERSION; +import static org.apache.gravitino.semantic.SemanticModel.PROPERTY_OSSIE_VERSION; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.StreamReadFeature; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; +import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import javax.annotation.Nullable; +import org.apache.commons.lang3.StringUtils; +import org.apache.gravitino.dto.requests.SemanticModelCreateRequest; +import org.apache.gravitino.dto.semantic.SemanticModelDefinitionDTO; +import org.apache.gravitino.exceptions.IllegalSemanticModelException; + +/** Converts between standalone Apache Ossie documents and Gravitino Semantic Models. */ +public final class OssieSemanticModelDocumentConverter { Review Comment: How about `OssieDocumentConverter`? ########## api/src/main/java/org/apache/gravitino/semantic/SemanticModel.java: ########## @@ -32,6 +32,12 @@ @Evolving public interface SemanticModel extends Auditable { + /** The property key for the Apache Ossie document version. */ + String PROPERTY_OSSIE_VERSION = "ossie-version"; + + /** The default Apache Ossie document version. */ + String DEFAULT_OSSIE_VERSION = "0.2.0.dev0"; Review Comment: I would suggest moving this definition to the `OssieFormat`, or create a new class like `OssieVersion`. ########## core/src/main/java/org/apache/gravitino/catalog/SemanticModelDispatcher.java: ########## @@ -18,7 +18,42 @@ */ package org.apache.gravitino.catalog; +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.Namespace; +import org.apache.gravitino.dto.requests.SemanticModelCreateRequest; +import org.apache.gravitino.semantic.OssieDocument; +import org.apache.gravitino.semantic.OssieFormat; +import org.apache.gravitino.semantic.OssieSemanticModelDocumentConverter; +import org.apache.gravitino.semantic.SemanticModel; import org.apache.gravitino.semantic.SemanticModelCatalog; /** A dispatcher specialization for schema-scoped Semantic Model operations. */ -public interface SemanticModelDispatcher extends SemanticModelCatalog {} +public interface SemanticModelDispatcher extends SemanticModelCatalog { + + /** + * {@inheritDoc} + * + * <p>Delegates to this dispatcher's native create operation so that the document follows the same + * normalization and validation chain as a structured create request. + */ + @Override + default SemanticModel importOssieSemanticModel(Namespace namespace, OssieDocument document) { + SemanticModelCreateRequest request = Review Comment: I think we can do this import/export in the server level, not in the core level. This could clearly separate the core functionalities provided by Gravitino, WDYT? -- 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]
