jbonofre commented on code in PR #9487:
URL: https://github.com/apache/iceberg/pull/9487#discussion_r1458451545


##########
core/src/main/java/org/apache/iceberg/jdbc/JdbcViewOperations.java:
##########
@@ -0,0 +1,190 @@
+/*
+ * 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.jdbc;
+
+import java.sql.SQLException;
+import java.sql.SQLIntegrityConstraintViolationException;
+import java.util.Map;
+import java.util.Objects;
+import org.apache.iceberg.catalog.Namespace;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.exceptions.AlreadyExistsException;
+import org.apache.iceberg.exceptions.CommitFailedException;
+import org.apache.iceberg.exceptions.NoSuchNamespaceException;
+import org.apache.iceberg.exceptions.NoSuchViewException;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.PropertyUtil;
+import org.apache.iceberg.view.BaseViewOperations;
+import org.apache.iceberg.view.ViewMetadata;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** JDBC implementation of Iceberg ViewOperations. */
+public class JdbcViewOperations extends BaseViewOperations {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(JdbcViewOperations.class);
+  private final String catalogName;
+  private final TableIdentifier viewIdentifier;
+  private final FileIO fileIO;
+  private final JdbcClientPool connections;
+  private final Map<String, String> catalogProperties;
+
+  protected JdbcViewOperations(
+      JdbcClientPool dbConnPool,
+      FileIO fileIO,
+      String catalogName,
+      TableIdentifier viewIdentifier,
+      Map<String, String> catalogProperties) {
+    this.catalogName = catalogName;
+    this.viewIdentifier = viewIdentifier;
+    this.fileIO = fileIO;
+    this.connections = dbConnPool;
+    this.catalogProperties = catalogProperties;
+  }
+
+  @Override
+  protected void doRefresh() {
+    Map<String, String> view;
+
+    try {
+      view = JdbcUtil.getView(connections, catalogName, viewIdentifier);
+    } catch (InterruptedException e) {
+      Thread.currentThread().interrupt();
+      throw new UncheckedInterruptedException(e, "Interrupted during refresh");
+    } catch (SQLException e) {
+      // SQL exception happened when getting view from catalog
+      throw new UncheckedSQLException(
+          e, "Failed to get view %s from catalog %s", viewIdentifier, 
catalogName);
+    }
+
+    if (view.isEmpty()) {
+      if (currentMetadataLocation() != null) {
+        throw new NoSuchViewException("View does not exist: %s", 
viewIdentifier);
+      } else {
+        this.disableRefresh();
+        return;
+      }
+    }
+
+    String newMetadataLocation = 
view.get(JdbcTableOperations.METADATA_LOCATION_PROP);
+    Preconditions.checkState(
+        newMetadataLocation != null, "Invalid view %s: metadata location is 
null", viewIdentifier);
+    refreshFromMetadataLocation(newMetadataLocation);
+  }
+
+  @Override
+  protected void doCommit(ViewMetadata base, ViewMetadata metadata) {
+    boolean newView = base == null;
+    String newMetadataLocation = writeNewMetadataIfRequired(metadata);
+    try {
+      Map<String, String> view = JdbcUtil.getView(connections, catalogName, 
viewIdentifier);
+
+      if (base != null) {
+        validateMetadataLocation(view, base);
+        String oldMetadataLocation = base.metadataFileLocation();
+        // Start atomic update
+        LOG.debug("Committing existing view: {}", viewName());
+        updateView(newMetadataLocation, oldMetadataLocation);
+      } else {
+        // view not exists create it
+        LOG.debug("Committing new view: {}", viewName());
+        createView(newMetadataLocation);
+      }
+

Review Comment:
   OK, at least checkstyle can do a warning/error. That would be helpful. I 
will check if we have checkstyle/code formatter for IntelliJ. 
   I will fix that. Thanks.



-- 
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