-
Notifications
You must be signed in to change notification settings - Fork 97
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
SNOW-1658905 Integration tests setup for Iceberg #930
Merged
sfc-gh-wtrefon
merged 6 commits into
master
from
mbobowski-SNOW-1658905-table-validations
Sep 20, 2024
+184
−36
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2ccf52b
SNOW-1658905 Create snowflake.streaming.iceberg.enabled parameter
sfc-gh-mbobowski 270bdc9
PR fixes
sfc-gh-mbobowski c94f6c2
SNOW-1658905 Validate Iceberg table structure on startup
sfc-gh-mbobowski 7007096
SNOW-1658905 Missing ; and format
sfc-gh-mbobowski 76b7e8c
SNOW-1658905 Test improvements
sfc-gh-mbobowski 33e13ee
SNOW-1658905 Fix null pointer
sfc-gh-mbobowski 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 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
35 changes: 35 additions & 0 deletions
35
...ain/java/com/snowflake/kafka/connector/streaming/iceberg/IcebergTableSchemaValidator.java
This file contains 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,35 @@ | ||
package com.snowflake.kafka.connector.streaming.iceberg; | ||
|
||
import com.snowflake.kafka.connector.internal.SnowflakeConnectionService; | ||
|
||
/** Performs validations of Iceberg table schema on the connector startup. */ | ||
public class IcebergTableSchemaValidator { | ||
|
||
private final SnowflakeConnectionService snowflakeConnectionService; | ||
|
||
public IcebergTableSchemaValidator(SnowflakeConnectionService snowflakeConnectionService) { | ||
this.snowflakeConnectionService = snowflakeConnectionService; | ||
} | ||
|
||
/** | ||
* Ensure that table exists and record_metadata column is of type OBJECT(). | ||
* | ||
* <p>TODO SNOW-1658914 - write a test for table with record_metadata schema altered by the | ||
* connector | ||
*/ | ||
public void validateTable(String tableName, String role) { | ||
// TODO - plug into connector startup | ||
if (!snowflakeConnectionService.tableExist(tableName)) { | ||
// TODO - better errors | ||
throw new RuntimeException("TODO"); | ||
} | ||
|
||
// TODO - why is it so slow? | ||
if (!snowflakeConnectionService.hasSchemaEvolutionPermission(tableName, role)) { | ||
// TODO - better errors | ||
throw new RuntimeException("TODO"); | ||
} | ||
|
||
// TODO - call describe table and analyze record_metadata schema | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/test/java/com/snowflake/kafka/connector/internal/TestSnowflakeConnection.java
This file contains 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,23 @@ | ||
package com.snowflake.kafka.connector.internal; | ||
|
||
import static com.snowflake.kafka.connector.internal.TestUtils.getConfFromFileName; | ||
|
||
import com.snowflake.client.jdbc.SnowflakeDriver; | ||
import com.snowflake.kafka.connector.Utils; | ||
import java.sql.Connection; | ||
import java.util.Properties; | ||
|
||
/** Connection to test environment generated from a profile file stored locally. */ | ||
public class TestSnowflakeConnection { | ||
|
||
/** Given a profile file path name, generate a connection by constructing a snowflake driver. */ | ||
public static Connection getConnection() throws Exception { | ||
SnowflakeURL url = | ||
new SnowflakeURL(getConfFromFileName(TestUtils.PROFILE_PATH).get(Utils.SF_URL)); | ||
|
||
Properties properties = | ||
InternalUtils.createProperties(getConfFromFileName(TestUtils.PROFILE_PATH), url); | ||
|
||
return new SnowflakeDriver().connect(url.getJdbcUrl(), properties); | ||
} | ||
} |
This file contains 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
42 changes: 42 additions & 0 deletions
42
src/test/java/com/snowflake/kafka/connector/streaming/iceberg/BaseIcebergIT.java
This file contains 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,42 @@ | ||
package com.snowflake.kafka.connector.streaming.iceberg; | ||
|
||
import static com.snowflake.kafka.connector.internal.TestUtils.executeQueryWithParameter; | ||
|
||
import com.snowflake.kafka.connector.internal.SnowflakeConnectionService; | ||
import com.snowflake.kafka.connector.internal.TestUtils; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
|
||
public class BaseIcebergIT { | ||
|
||
protected static SnowflakeConnectionService conn; | ||
|
||
@BeforeAll | ||
public static void setup() { | ||
conn = TestUtils.getConnectionServiceForStreaming(); | ||
} | ||
|
||
@AfterAll | ||
public static void teardown() { | ||
conn.close(); | ||
} | ||
|
||
protected static void createIcebergTable(String tableName) throws Exception { | ||
String query = | ||
"create or replace iceberg table identifier(?) (record_metadata object())" | ||
+ "external_volume = 'test_exvol'" | ||
+ "catalog = 'SNOWFLAKE'" | ||
+ "base_location = 'it'"; | ||
executeQueryWithParameter(query, tableName); | ||
} | ||
|
||
protected static void dropIcebergTable(String tableName) { | ||
String query = "drop iceberg table if exists identifier(?)"; | ||
executeQueryWithParameter(query, tableName); | ||
} | ||
|
||
protected static void enableSchemaEvolution(String tableName) throws Exception { | ||
String query = "alter iceberg table identifier(?) set enable_schema_evolution = true"; | ||
executeQueryWithParameter(query, tableName); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
...t/java/com/snowflake/kafka/connector/streaming/iceberg/IcebergTableSchemaValidatorIT.java
This file contains 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,53 @@ | ||
package com.snowflake.kafka.connector.streaming.iceberg; | ||
|
||
import com.snowflake.kafka.connector.internal.TestUtils; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class IcebergTableSchemaValidatorIT extends BaseIcebergIT { | ||
|
||
private static final String TEST_ROLE = "testrole_kafka"; | ||
|
||
private static final IcebergTableSchemaValidator schemaValidator = | ||
new IcebergTableSchemaValidator(conn); | ||
|
||
private String tableName; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
tableName = TestUtils.randomTableName(); | ||
} | ||
|
||
@AfterEach | ||
public void tearDown() { | ||
dropIcebergTable(tableName); | ||
} | ||
|
||
@Test | ||
public void shouldValidateExpectedIcebergTableSchema() throws Exception { | ||
// given | ||
createIcebergTable(tableName); | ||
enableSchemaEvolution(tableName); | ||
|
||
// when, then | ||
schemaValidator.validateTable(tableName, TEST_ROLE); | ||
} | ||
|
||
@Test | ||
public void shouldThrowExceptionWhenTableDoesNotExist() { | ||
Assertions.assertThrows( | ||
RuntimeException.class, () -> schemaValidator.validateTable(tableName, TEST_ROLE)); | ||
} | ||
|
||
@Test | ||
public void shouldThrowExceptionWhenRecordMetadataDoesNotExist() { | ||
// TODO | ||
} | ||
|
||
@Test | ||
public void shouldThrowExceptionWhenRecordMetadataHasInvalidType() { | ||
// TODO | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually this was the only usage of the
conn
, so it was never initialized...