amogh-jahagirdar commented on code in PR #6598:
URL: https://github.com/apache/iceberg/pull/6598#discussion_r1084397362


##########
core/src/main/java/org/apache/iceberg/view/SQLViewRepresentationParser.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.view;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonNode;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
+import org.apache.iceberg.util.JsonUtil;
+
+class SQLViewRepresentationParser {
+  private static final String SQL = "sql";
+  private static final String DIALECT = "dialect";
+  private static final String SCHEMA_ID = "schema-id";
+  private static final String DEFAULT_CATALOG = "default-catalog";
+  private static final String DEFAULT_NAMESPACE = "default-namespace";
+  private static final String FIELD_ALIASES = "field-aliases";
+  private static final String FIELD_COMMENTS = "field-comments";
+
+  private SQLViewRepresentationParser() {}
+
+  static String toJson(SQLViewRepresentation sqlViewRepresentation) {
+    return JsonUtil.generate(gen -> toJson(sqlViewRepresentation, gen), false);
+  }
+
+  static void toJson(SQLViewRepresentation view, JsonGenerator generator) 
throws IOException {
+    Preconditions.checkArgument(view != null, "Invalid SQL view 
representation: null");
+    generator.writeStartObject();
+    generator.writeStringField(ViewRepresentationParser.TYPE, view.type());
+    generator.writeStringField(SQL, view.sql());
+    generator.writeStringField(DIALECT, view.dialect());
+
+    if (view.schemaId() != null) {
+      generator.writeNumberField(SCHEMA_ID, view.schemaId());
+    }
+
+    if (view.defaultCatalog() != null) {
+      generator.writeStringField(DEFAULT_CATALOG, view.defaultCatalog());
+    }
+
+    if (view.defaultNamespace() != null) {
+      JsonUtil.writeStringArray(
+          DEFAULT_NAMESPACE, Arrays.asList(view.defaultNamespace().levels()), 
generator);
+    }
+
+    if (view.fieldAliases() != null && !view.fieldAliases().isEmpty()) {

Review Comment:
   See https://github.com/apache/iceberg/pull/6598#discussion_r1070708186 , 
there's pro's and cons for either leaving it be null at the data model level or 
just in serialization. In the end we just opted for having an empty list at the 
data model layer (and a client doesn't have to do a null check). So here one 
possible cleanup is not do the null check anyways! 



##########
core/src/main/java/org/apache/iceberg/view/SQLViewRepresentationParser.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.view;
+
+import com.fasterxml.jackson.core.JsonGenerator;
+import com.fasterxml.jackson.databind.JsonNode;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.relocated.com.google.common.collect.Iterables;
+import org.apache.iceberg.util.JsonUtil;
+
+class SQLViewRepresentationParser {
+  private static final String SQL = "sql";
+  private static final String DIALECT = "dialect";
+  private static final String SCHEMA_ID = "schema-id";
+  private static final String DEFAULT_CATALOG = "default-catalog";
+  private static final String DEFAULT_NAMESPACE = "default-namespace";
+  private static final String FIELD_ALIASES = "field-aliases";
+  private static final String FIELD_COMMENTS = "field-comments";
+
+  private SQLViewRepresentationParser() {}
+
+  static String toJson(SQLViewRepresentation sqlViewRepresentation) {
+    return JsonUtil.generate(gen -> toJson(sqlViewRepresentation, gen), false);
+  }
+
+  static void toJson(SQLViewRepresentation view, JsonGenerator generator) 
throws IOException {
+    Preconditions.checkArgument(view != null, "Invalid SQL view 
representation: null");
+    generator.writeStartObject();
+    generator.writeStringField(ViewRepresentationParser.TYPE, view.type());
+    generator.writeStringField(SQL, view.sql());
+    generator.writeStringField(DIALECT, view.dialect());
+
+    if (view.schemaId() != null) {
+      generator.writeNumberField(SCHEMA_ID, view.schemaId());
+    }
+
+    if (view.defaultCatalog() != null) {
+      generator.writeStringField(DEFAULT_CATALOG, view.defaultCatalog());
+    }
+
+    if (view.defaultNamespace() != null) {
+      JsonUtil.writeStringArray(
+          DEFAULT_NAMESPACE, Arrays.asList(view.defaultNamespace().levels()), 
generator);
+    }
+
+    if (view.fieldAliases() != null && !view.fieldAliases().isEmpty()) {

Review Comment:
   See https://github.com/apache/iceberg/pull/6598#discussion_r1070708186 , 
there's pro's and cons for either leaving it be null at the data model level or 
just in serialization. In the end we just opted for having an empty list at the 
data model layer (and a client doesn't have to do a null check). So here one 
possible cleanup is not do the null check anyways since we have the guarantee 
at the API level! 



-- 
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-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to