-
Notifications
You must be signed in to change notification settings - Fork 1
adding new property TableName in the ui and its functionality #5
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
base: develop
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,11 +71,13 @@ public class LoadActionConfig extends LoadUnloadConfig { | |
| @Nullable | ||
| private String pattern; | ||
|
|
||
| public LoadActionConfig(String accountName, String database, String schemaName, String username, String password, | ||
| public LoadActionConfig(String accountName, String database, String schemaName, String tableName, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tableName not required here as well |
||
| String username, String password, | ||
| @Nullable Boolean keyPairEnabled, @Nullable String path, @Nullable String passphrase, | ||
| @Nullable Boolean oauth2Enabled, @Nullable String clientId, @Nullable String clientSecret, | ||
| @Nullable String refreshToken, @Nullable String connectionArguments) { | ||
| super(accountName, database, schemaName, username, password, keyPairEnabled, path, passphrase, oauth2Enabled, | ||
| super(accountName, database, tableName, schemaName, username, password, keyPairEnabled, path, passphrase, | ||
| oauth2Enabled, | ||
| clientId, clientSecret, refreshToken, connectionArguments); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,6 +35,7 @@ public class BaseSnowflakeConfig extends PluginConfig { | |
| public static final String PROPERTY_ACCOUNT_NAME = "accountName"; | ||
| public static final String PROPERTY_DATABASE = "database"; | ||
| public static final String PROPERTY_SCHEMA_NAME = "schemaName"; | ||
| public static final String PROPERTY_TABLE_NAME = "TableName"; | ||
| public static final String PROPERTY_WAREHOUSE = "warehouse"; | ||
| public static final String PROPERTY_ROLE = "role"; | ||
| public static final String PROPERTY_USERNAME = "username"; | ||
|
|
@@ -63,6 +64,13 @@ public class BaseSnowflakeConfig extends PluginConfig { | |
| @Macro | ||
| private String schemaName; | ||
|
|
||
| @Name(PROPERTY_TABLE_NAME) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Table Name should be moved under Basic section using widgets.json |
||
| @Description("Name of the table to import data from. If specified, importQuery will be ignored.") | ||
| @Macro | ||
| @Nullable | ||
| private String tableName; | ||
|
|
||
|
|
||
| @Nullable | ||
| @Name(PROPERTY_WAREHOUSE) | ||
| @Description("Warehouse to connect to. If not specified default warehouse is used.") | ||
|
|
@@ -87,6 +95,7 @@ public class BaseSnowflakeConfig extends PluginConfig { | |
| @Nullable | ||
| private String password; | ||
|
|
||
|
|
||
| @Name(PROPERTY_KEY_PAIR_ENABLED) | ||
| @Description("If true, plugin will perform Key Pair authentication.") | ||
| @Nullable | ||
|
|
@@ -136,6 +145,7 @@ public class BaseSnowflakeConfig extends PluginConfig { | |
| public BaseSnowflakeConfig(String accountName, | ||
| String database, | ||
| String schemaName, | ||
| String tableName, | ||
| String username, | ||
| String password, | ||
| @Nullable Boolean keyPairEnabled, | ||
|
|
@@ -150,6 +160,7 @@ public BaseSnowflakeConfig(String accountName, | |
| this.database = database; | ||
| this.schemaName = schemaName; | ||
| this.username = username; | ||
| this.tableName = tableName; | ||
| this.password = password; | ||
| this.keyPairEnabled = keyPairEnabled; | ||
| this.privateKey = privateKey; | ||
|
|
@@ -161,6 +172,7 @@ public BaseSnowflakeConfig(String accountName, | |
| this.connectionArguments = connectionArguments; | ||
| } | ||
|
|
||
|
|
||
| public String getAccountName() { | ||
| return accountName; | ||
| } | ||
|
|
@@ -173,6 +185,11 @@ public String getSchemaName() { | |
| return schemaName; | ||
| } | ||
|
|
||
| @Nullable | ||
| public String getTableName() { | ||
| return tableName; | ||
| } | ||
|
|
||
| @Nullable | ||
| public String getWarehouse() { | ||
| return warehouse; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,8 +76,8 @@ public static Schema getSchema(SnowflakeSourceAccessor snowflakeAccessor, String | |
| if (!Strings.isNullOrEmpty(schema)) { | ||
| return getParsedSchema(schema); | ||
| } | ||
| return getSchema(snowflakeAccessor, snowflakeAccessor.getSchema(), tableName, importQuery); | ||
| } catch (SchemaParseException e) { | ||
| return getSchema(snowflakeAccessor, tableName, importQuery); | ||
| } catch (SchemaParseException | IllegalArgumentException e) { | ||
| collector.addFailure(String.format("Unable to retrieve output schema. Reason: '%s'", e.getMessage()), | ||
| null) | ||
| .withStacktrace(e.getStackTrace()) | ||
|
|
@@ -97,18 +97,17 @@ private static Schema getParsedSchema(String schema) { | |
| } | ||
| } | ||
|
|
||
| public static Schema getSchema(SnowflakeAccessor snowflakeAccessor, String schemaName, | ||
| public static Schema getSchema(SnowflakeAccessor snowflakeAccessor, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The getSchema method used within the SchemaHelper class only should be made private |
||
| String tableName, String importQuery) { | ||
| try { | ||
| List<SnowflakeFieldDescriptor> result; | ||
| // If tableName is provided, describe the table | ||
| if (!Strings.isNullOrEmpty(tableName)) { | ||
| result = snowflakeAccessor.describeTable(schemaName, tableName); | ||
| } else if (!Strings.isNullOrEmpty(importQuery)) { | ||
| result = snowflakeAccessor.describeQuery(importQuery); | ||
| result = snowflakeAccessor.describeTable(snowflakeAccessor.getSchema(), tableName); | ||
| } else { | ||
| return null; | ||
| result = snowflakeAccessor.describeQuery(importQuery); | ||
| } | ||
|
|
||
| List<Schema.Field> fields = result.stream() | ||
| .map(fieldDescriptor -> Schema.Field.of(fieldDescriptor.getName(), | ||
| getSchema(fieldDescriptor))) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,12 +58,12 @@ public class SnowflakeSinkConfig extends BaseSnowflakeConfig { | |
| private String copyOptions; | ||
|
|
||
| public SnowflakeSinkConfig(String referenceName, String accountName, String database, | ||
| String schemaName, String username, String password, | ||
| String schemaName, String tableName, String username, String password, | ||
| @Nullable Boolean keyPairEnabled, @Nullable String path, | ||
| @Nullable String passphrase, @Nullable Boolean oauth2Enabled, | ||
| @Nullable String clientId, @Nullable String clientSecret, | ||
| @Nullable String refreshToken, @Nullable String connectionArguments) { | ||
| super(accountName, database, schemaName, username, password, | ||
| super(accountName, database, schemaName, tableName, username, password, | ||
| keyPairEnabled, path, passphrase, oauth2Enabled, clientId, clientSecret, refreshToken, connectionArguments); | ||
| this.referenceName = referenceName; | ||
| } | ||
|
|
@@ -105,7 +105,7 @@ private void validateInputSchema(Schema schema, FailureCollector failureCollecto | |
|
|
||
| SnowflakeAccessor snowflakeAccessor = new SnowflakeAccessor(this); | ||
| // Schema expectedSchema = SchemaHelper.getSchema(snowflakeAccessor, String.format(GET_FIELDS_QUERY, tableName)); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove comments |
||
| Schema expectedSchema = SchemaHelper.getSchema(snowflakeAccessor, getSchemaName(), tableName, null); | ||
| Schema expectedSchema = SchemaHelper.getSchema(snowflakeAccessor, tableName, null); | ||
| try { | ||
| SchemaHelper.checkCompatibility(expectedSchema, schema); | ||
| } catch (IllegalArgumentException ex) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,12 +27,15 @@ | |
| import org.mockito.Mockito; | ||
|
|
||
| import java.io.IOException; | ||
| import java.sql.SQLException; | ||
| import java.sql.Types; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import static net.snowflake.client.loader.LoaderProperty.tableName; | ||
|
|
||
| /** | ||
| * Tests for {@link SchemaHelper} | ||
| */ | ||
|
|
@@ -50,11 +53,11 @@ public void testGetSchema() { | |
| ); | ||
|
|
||
| MockFailureCollector collector = new MockFailureCollector(MOCK_STAGE); | ||
| SnowflakeBatchSourceConfig mockConfig = Mockito.mock(SnowflakeBatchSourceConfig.class); | ||
| Mockito.when(mockConfig.canConnect()).thenReturn(false); | ||
| Mockito.when(mockConfig.getSchema()).thenReturn(expected.toString()); | ||
|
|
||
| Schema actual = SchemaHelper.getSchema(mockConfig, collector); | ||
| // SnowflakeBatchSourceConfig mockConfig = Mockito.mock(SnowflakeBatchSourceConfig.class); | ||
| // Mockito.when(mockConfig.canConnect()).thenReturn(false); | ||
| // Mockito.when(mockConfig.getSchema()).thenReturn(expected.toString()); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove comments |
||
| Schema actual = SchemaHelper.getSchema(null, expected.toString(), collector, null, | ||
| null); | ||
|
|
||
| Assert.assertTrue(collector.getValidationFailures().isEmpty()); | ||
| Assert.assertEquals(expected, actual); | ||
|
|
@@ -65,8 +68,8 @@ public void testGetSchemaInvalidJson() { | |
| MockFailureCollector collector = new MockFailureCollector(MOCK_STAGE); | ||
| SnowflakeBatchSourceConfig mockConfig = Mockito.mock(SnowflakeBatchSourceConfig.class); | ||
| Mockito.when(mockConfig.getSchema()).thenReturn("{}"); | ||
| // SchemaHelper.getSchema(null, "{}", collector, null); | ||
| SchemaHelper.getSchema(mockConfig, collector); | ||
| SchemaHelper.getSchema(null, "{}", collector, null, null); | ||
| // SchemaHelper.getSchema(mockConfig, collector); | ||
| ValidationAssertions.assertValidationFailed( | ||
| collector, Collections.singletonList(SnowflakeBatchSourceConfig.PROPERTY_SCHEMA)); | ||
| } | ||
|
|
@@ -81,15 +84,16 @@ public void testGetSchemaFromSnowflakeUnknownType() throws IOException { | |
| sample.add(new SnowflakeFieldDescriptor("field1", -1000, false)); | ||
|
|
||
| Mockito.when(snowflakeAccessor.describeQuery(importQuery)).thenReturn(sample); | ||
|
|
||
| SchemaHelper.getSchema(snowflakeAccessor, MOCK_SCHEMA, MOCK_TABLE, importQuery); | ||
| String tableName = "tableName"; | ||
| SchemaHelper.getSchema(snowflakeAccessor, null, collector, tableName, importQuery); | ||
| ValidationAssertions.assertValidationFailed( | ||
| collector, Collections.singletonList(SnowflakeBatchSourceConfig.PROPERTY_SCHEMA)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetSchemaFromSnowflake() throws IOException { | ||
| public void testGetSchemaFromSnowflake() throws IOException, SQLException { | ||
| String importQuery = "SELECT * FROM someTable"; | ||
| String tableName = "tableName"; | ||
| MockFailureCollector collector = new MockFailureCollector(MOCK_STAGE); | ||
| SnowflakeSourceAccessor snowflakeAccessor = Mockito.mock(SnowflakeSourceAccessor.class); | ||
|
|
||
|
|
@@ -148,12 +152,16 @@ public void testGetSchemaFromSnowflake() throws IOException { | |
| Schema.Field.of("field131", Schema.nullableOf(Schema.decimalOf(38))), | ||
| Schema.Field.of("field132", Schema.decimalOf(38)), | ||
| Schema.Field.of("field133", Schema.of(Schema.LogicalType.TIMESTAMP_MICROS)), | ||
| Schema.Field.of("field134", Schema.nullableOf(Schema.of(Schema.LogicalType.TIMESTAMP_MICROS))) | ||
| Schema.Field.of("field134", Schema.nullableOf(Schema.of(Schema.LogicalType.TIMESTAMP_MICROS))) | ||
|
|
||
| ); | ||
|
|
||
| Mockito.when(snowflakeAccessor.describeQuery(importQuery)).thenReturn(sample); | ||
| Mockito.when(snowflakeAccessor.describeTable(Mockito.any(), String.valueOf (Mockito.eq(tableName)))). | ||
| thenReturn(sample); | ||
|
|
||
|
|
||
| Schema actual = SchemaHelper.getSchema(snowflakeAccessor, MOCK_SCHEMA, MOCK_TABLE, importQuery); | ||
| Schema actual = SchemaHelper.getSchema(snowflakeAccessor, null, collector, tableName, importQuery); | ||
|
|
||
| Assert.assertTrue(collector.getValidationFailures().isEmpty()); | ||
| Assert.assertEquals(expected, actual); | ||
|
|
||
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.
tableName is not required here!