-
Notifications
You must be signed in to change notification settings - Fork 3k
Add new SnowflakeCatalog implementation to enable directly using Snowflake-managed Iceberg tables #6428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
danielcweeks
merged 23 commits into
apache:master
from
Snowflake-Labs:snowflake-catalog-initial
Jan 14, 2023
Merged
Add new SnowflakeCatalog implementation to enable directly using Snowflake-managed Iceberg tables #6428
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
5ad32b0
Initial read-only Snowflake Catalog implementation by @sfc-gh-mparmar…
sfc-gh-dhuo 930a3f0
Add JdbcSnowflakeClientTest using mocks (#2)
dennishuo 86b3d11
Merge branch 'main' into snowflake-catalog-initial
dennishuo 076a14a
Add test { useJUnitPlatform() } tuple to iceberg-snowflake for
dennishuo a7b5aa7
Extract versions into versions.props per PR review
dennishuo dd5255c
Misc test-related refactors per review suggestions
dennishuo 500b36b
Fix unsupported behaviors of loadNamedpaceMetadata and defaultWarehou…
dennishuo ad2c55f
Move TableIdentifier checks out of newTableOps into the
dennishuo 7f13674
Refactor out any Namespace-related business logic from the lower
dennishuo 58d258e
Finish migrating JdbcSnowflakeClientTest off any usage of org.junit.A…
dennishuo 0183129
Style refactorings from review comments, expanded and moved InMemoryF…
dennishuo ca6deab
Fix behavior of getNamespaceMetadata to throw when the namespace doesn't
dennishuo b3a2842
Move private constructor to top, add assertion to test case.
dennishuo 676d024
Define minimal ResultSetParser/QueryHarness classes to fully replace
dennishuo cc493d0
Update snowflake/src/main/java/org/apache/iceberg/snowflake/Snowflake…
dennishuo ce7e28c
Refactor style suggestions; remove debug-level logging, arguments in …
dennishuo 2729e64
Fix precondition messages, remove getConf()
dennishuo 4c1e79f
Clean up varargs.
dennishuo bc0c6ee
Make data members final, include rawJsonVal in toString for debuggabi…
dennishuo 8240d9e
Merge branch 'main' into snowflake-catalog-initial
dennishuo ebe5dd6
Combine some small test cases into roundtrip test cases, misc cleanup
dennishuo 9e9b9e6
Add comment for why a factory class is exposed for testing purposes.
dennishuo e8fee31
Merge remote-tracking branch 'origin/main' into snowflake-catalog-ini…
dennishuo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,4 +81,6 @@ ALIYUN: | |
| GCP: | ||
| - gcp/**/* | ||
| DELL: | ||
| - dell/**/* | ||
| - dell/**/* | ||
| SNOWFLAKE: | ||
| - snowflake/**/* | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
core/src/test/java/org/apache/iceberg/io/InMemoryFileIO.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * 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.io; | ||
|
|
||
| import java.util.Map; | ||
| import org.apache.iceberg.exceptions.NotFoundException; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Maps; | ||
|
|
||
| public class InMemoryFileIO implements FileIO { | ||
|
|
||
| private Map<String, byte[]> inMemoryFiles = Maps.newHashMap(); | ||
| private boolean closed = false; | ||
|
|
||
| public void addFile(String path, byte[] contents) { | ||
| Preconditions.checkState(!closed, "Cannot call addFile after calling close()"); | ||
| inMemoryFiles.put(path, contents); | ||
| } | ||
|
|
||
| public boolean fileExists(String path) { | ||
| return inMemoryFiles.containsKey(path); | ||
| } | ||
|
|
||
| @Override | ||
| public InputFile newInputFile(String path) { | ||
| Preconditions.checkState(!closed, "Cannot call newInputFile after calling close()"); | ||
| if (!inMemoryFiles.containsKey(path)) { | ||
| throw new NotFoundException("No in-memory file found for path: %s", path); | ||
| } | ||
| return new InMemoryInputFile(path, inMemoryFiles.get(path)); | ||
| } | ||
|
|
||
| @Override | ||
| public OutputFile newOutputFile(String path) { | ||
| Preconditions.checkState(!closed, "Cannot call newOutputFile after calling close()"); | ||
| return new InMemoryOutputFile(path, this); | ||
| } | ||
|
|
||
| @Override | ||
| public void deleteFile(String path) { | ||
| Preconditions.checkState(!closed, "Cannot call deleteFile after calling close()"); | ||
| if (!inMemoryFiles.containsKey(path)) { | ||
| throw new NotFoundException("No in-memory file found for path: %s", path); | ||
| } | ||
| inMemoryFiles.remove(path); | ||
| } | ||
|
|
||
| public boolean isClosed() { | ||
| return closed; | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| closed = true; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
core/src/test/java/org/apache/iceberg/io/TestInMemoryFileIO.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| /* | ||
| * 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.io; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.io.OutputStream; | ||
| import org.apache.iceberg.exceptions.AlreadyExistsException; | ||
| import org.apache.iceberg.exceptions.NotFoundException; | ||
| import org.assertj.core.api.Assertions; | ||
| import org.junit.Test; | ||
|
|
||
| public class TestInMemoryFileIO { | ||
| String location = "s3://foo/bar.txt"; | ||
|
|
||
| @Test | ||
| public void testBasicEndToEnd() throws IOException { | ||
| InMemoryFileIO fileIO = new InMemoryFileIO(); | ||
| Assertions.assertThat(fileIO.fileExists(location)).isFalse(); | ||
|
|
||
| OutputStream outputStream = fileIO.newOutputFile(location).create(); | ||
| byte[] data = "hello world".getBytes(); | ||
| outputStream.write(data); | ||
| outputStream.close(); | ||
| Assertions.assertThat(fileIO.fileExists(location)).isTrue(); | ||
|
|
||
| InputStream inputStream = fileIO.newInputFile(location).newStream(); | ||
| byte[] buf = new byte[data.length]; | ||
| inputStream.read(buf); | ||
| inputStream.close(); | ||
| Assertions.assertThat(new String(buf)).isEqualTo("hello world"); | ||
|
|
||
| fileIO.deleteFile(location); | ||
| Assertions.assertThat(fileIO.fileExists(location)).isFalse(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNewInputFileNotFound() throws IOException { | ||
| InMemoryFileIO fileIO = new InMemoryFileIO(); | ||
| Assertions.assertThatExceptionOfType(NotFoundException.class) | ||
| .isThrownBy(() -> fileIO.newInputFile("s3://nonexistent/file")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testDeleteFileNotFound() throws IOException { | ||
| InMemoryFileIO fileIO = new InMemoryFileIO(); | ||
| Assertions.assertThatExceptionOfType(NotFoundException.class) | ||
| .isThrownBy(() -> fileIO.deleteFile("s3://nonexistent/file")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testCreateNoOverwrite() throws IOException { | ||
| InMemoryFileIO fileIO = new InMemoryFileIO(); | ||
| fileIO.addFile(location, "hello world".getBytes()); | ||
| Assertions.assertThatExceptionOfType(AlreadyExistsException.class) | ||
| .isThrownBy(() -> fileIO.newOutputFile(location).create()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testOverwriteBeforeAndAfterClose() throws IOException { | ||
| byte[] oldData = "old data".getBytes(); | ||
| byte[] newData = "new data".getBytes(); | ||
|
|
||
| InMemoryFileIO fileIO = new InMemoryFileIO(); | ||
| OutputStream outputStream = fileIO.newOutputFile(location).create(); | ||
| outputStream.write(oldData); | ||
|
|
||
| // Even though we've called create() and started writing data, this file won't yet exist | ||
| // in the parentFileIO before we've closed it. | ||
| Assertions.assertThat(fileIO.fileExists(location)).isFalse(); | ||
|
|
||
| // File appears after closing it. | ||
| outputStream.close(); | ||
| Assertions.assertThat(fileIO.fileExists(location)).isTrue(); | ||
|
|
||
| // Start a new OutputFile and write new data but don't close() it yet. | ||
| outputStream = fileIO.newOutputFile(location).createOrOverwrite(); | ||
| outputStream.write(newData); | ||
|
|
||
| // We'll still read old data. | ||
| InputStream inputStream = fileIO.newInputFile(location).newStream(); | ||
| byte[] buf = new byte[oldData.length]; | ||
| inputStream.read(buf); | ||
| inputStream.close(); | ||
| Assertions.assertThat(new String(buf)).isEqualTo("old data"); | ||
|
|
||
| // Finally, close the new output stream; data should be overwritten with new data now. | ||
| outputStream.close(); | ||
| inputStream = fileIO.newInputFile(location).newStream(); | ||
| buf = new byte[newData.length]; | ||
| inputStream.read(buf); | ||
| inputStream.close(); | ||
| Assertions.assertThat(new String(buf)).isEqualTo("new data"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.