You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/02/15 22:47:30 UTC
[GitHub] [iceberg] rdblue commented on a change in pull request #4037: [WIP] REST Catalog - Initial request / response objects and Jackson-based SerDe module for some components
rdblue commented on a change in pull request #4037:
URL: https://github.com/apache/iceberg/pull/4037#discussion_r807382003
##########
File path: core/src/main/java/org/apache/iceberg/catalog/TableIdentifierParser.java
##########
@@ -0,0 +1,98 @@
+/*
+ * 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.iceberg.catalog;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonNode;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.UncheckedIOException;
+import java.util.List;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.JsonUtil;
+
+/**
+ * Parses TableIdentifiers from a JSON representation, which is the JSON
+ * representation utilized in the REST catalog.
+ * <p>
+ * For TableIdentifier.of("dogs", "owners.and.handlers", "food"), we'd have
+ * the following JSON representation, where the dot character of an
+ * individual level is in the namespace is replaced by the null byte character.
+ * <pre>
+ * {
+ * "namespace": ["dogs", "owners.and.handlers"],
+ * "name": "food"
+ * }
+ * </pre>
+ */
+public class TableIdentifierParser {
+
+ private static final String NAMESPACE = "namespace";
+ private static final String NAME = "name";
+
+ private TableIdentifierParser() {
+ }
+
+ public static String toJson(TableIdentifier identifier) {
+ return toJson(identifier, false);
+ }
+
+ public static String toJson(TableIdentifier identifier, boolean pretty) {
+ try {
+ StringWriter writer = new StringWriter();
+ JsonGenerator generator = JsonUtil.factory().createGenerator(writer);
+ if (pretty) {
+ generator.useDefaultPrettyPrinter();
+ }
+ toJson(identifier, generator);
+ generator.flush();
+ return writer.toString();
+ } catch (IOException e) {
+ throw new UncheckedIOException(String.format("Failed to write json for: %s", identifier), e);
+ }
+ }
+
+ public static void toJson(TableIdentifier identifier, JsonGenerator generator) throws IOException {
Review comment:
I don't think this should be `public` because we don't want to leak Jackson in our API. Can it be private or package-private?
--
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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org