danielcweeks commented on code in PR #6428: URL: https://github.com/apache/iceberg/pull/6428#discussion_r1056638166
########## snowflake/src/main/java/org/apache/iceberg/snowflake/SnowflakeCatalog.java: ########## @@ -0,0 +1,258 @@ +/* + * 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.snowflake; + +import java.io.Closeable; +import java.io.IOException; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; +import org.apache.iceberg.BaseMetastoreCatalog; +import org.apache.iceberg.CatalogProperties; +import org.apache.iceberg.CatalogUtil; +import org.apache.iceberg.TableOperations; +import org.apache.iceberg.catalog.Namespace; +import org.apache.iceberg.catalog.SupportsNamespaces; +import org.apache.iceberg.catalog.TableIdentifier; +import org.apache.iceberg.exceptions.NoSuchNamespaceException; +import org.apache.iceberg.hadoop.Configurable; +import org.apache.iceberg.io.CloseableGroup; +import org.apache.iceberg.io.FileIO; +import org.apache.iceberg.jdbc.JdbcClientPool; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SnowflakeCatalog extends BaseMetastoreCatalog + implements Closeable, SupportsNamespaces, Configurable<Object> { + public static final String DEFAULT_CATALOG_NAME = "snowflake_catalog"; + public static final String DEFAULT_FILE_IO_IMPL = "org.apache.iceberg.io.ResolvingFileIO"; + + static class FileIOFactory { + public FileIO newFileIO(String impl, Map<String, String> properties, Object hadoopConf) { + return CatalogUtil.loadFileIO(impl, properties, hadoopConf); + } + } + + private static final Logger LOG = LoggerFactory.getLogger(SnowflakeCatalog.class); + + private CloseableGroup closeableGroup; + private Object conf; + private String catalogName; + private Map<String, String> catalogProperties; + private FileIOFactory fileIOFactory; + private SnowflakeClient snowflakeClient; + + public SnowflakeCatalog() {} + + @Override + public List<TableIdentifier> listTables(Namespace namespace) { + SnowflakeIdentifier scope = NamespaceHelpers.toSnowflakeIdentifier(namespace); + Preconditions.checkArgument( + scope.type() == SnowflakeIdentifier.Type.SCHEMA, + "listTables must be at SCHEMA level; got %s from namespace %s", + scope, + namespace); + + List<SnowflakeIdentifier> sfTables = snowflakeClient.listIcebergTables(scope); + + return sfTables.stream() + .map(NamespaceHelpers::toIcebergTableIdentifier) + .collect(Collectors.toList()); + } + + @Override + public boolean dropTable(TableIdentifier identifier, boolean purge) { + throw new UnsupportedOperationException( + "SnowflakeCatalog does not currently support dropTable"); + } + + @Override + public void renameTable(TableIdentifier from, TableIdentifier to) { + throw new UnsupportedOperationException( + "SnowflakeCatalog does not currently support renameTable"); + } + + @Override + public void initialize(String name, Map<String, String> properties) { + String uri = properties.get(CatalogProperties.URI); + Preconditions.checkNotNull(uri, "JDBC connection URI is required"); + try { + // We'll ensure the expected JDBC driver implementation class is initialized through + // reflection regardless of which classloader ends up using this JdbcSnowflakeClient, but + // we'll only warn if the expected driver fails to load, since users may use repackaged or + // custom JDBC drivers for Snowflake communication. + Class.forName(JdbcSnowflakeClient.EXPECTED_JDBC_IMPL); + } catch (ClassNotFoundException cnfe) { Review Comment: I feel like we should just fail here if the JDBC driver isn't able to load. Why would we continue to initialize if you don't have the expected jdbc driver? Are there other known drivers that are compatible and would load? -- 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