Skip to content

Commit be36bb2

Browse files
Mssql source: add schemas for discovery during set up (#16002)
* Mssql source: add schemas during discovery * Source mssql: temp changes for testing ci * Source mssql: update expected version for strict encrypt version * Source mssql: update order in spec * Source mssql: added filter by requested schemas * Source mssql: bump versions * Source mssql: format * auto-bump connector version [ci skip] Co-authored-by: Octavia Squidington III <[email protected]>
1 parent bdfafe5 commit be36bb2

File tree

8 files changed

+85
-16
lines changed

8 files changed

+85
-16
lines changed

airbyte-config/init/src/main/resources/seed/source_definitions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@
599599
- name: Microsoft SQL Server (MSSQL)
600600
sourceDefinitionId: b5ea17b1-f170-46dc-bc31-cc744ca984c1
601601
dockerRepository: airbyte/source-mssql
602-
dockerImageTag: 0.4.18
602+
dockerImageTag: 0.4.19
603603
documentationUrl: https://docs.airbyte.io/integrations/sources/mssql
604604
icon: mssql.svg
605605
sourceType: database

airbyte-config/init/src/main/resources/seed/source_specs.yaml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5273,7 +5273,7 @@
52735273
supportsNormalization: false
52745274
supportsDBT: false
52755275
supported_destination_sync_modes: []
5276-
- dockerImage: "airbyte/source-mssql:0.4.18"
5276+
- dockerImage: "airbyte/source-mssql:0.4.19"
52775277
spec:
52785278
documentationUrl: "https://docs.airbyte.io/integrations/destinations/mssql"
52795279
connectionSpecification:
@@ -5307,30 +5307,41 @@
53075307
examples:
53085308
- "master"
53095309
order: 2
5310+
schemas:
5311+
title: "Schemas"
5312+
description: "The list of schemas to sync from. Defaults to user. Case sensitive."
5313+
type: "array"
5314+
items:
5315+
type: "string"
5316+
minItems: 0
5317+
uniqueItems: true
5318+
default:
5319+
- "dbo"
5320+
order: 3
53105321
username:
53115322
description: "The username which is used to access the database."
53125323
title: "Username"
53135324
type: "string"
5314-
order: 3
5325+
order: 4
53155326
password:
53165327
description: "The password associated with the username."
53175328
title: "Password"
53185329
type: "string"
53195330
airbyte_secret: true
5320-
order: 4
5331+
order: 5
53215332
jdbc_url_params:
53225333
title: "JDBC URL Params"
53235334
description: "Additional properties to pass to the JDBC URL string when\
53245335
\ connecting to the database formatted as 'key=value' pairs separated\
53255336
\ by the symbol '&'. (example: key1=value1&key2=value2&key3=value3)."
53265337
type: "string"
5327-
order: 5
5338+
order: 6
53285339
ssl_method:
53295340
title: "SSL Method"
53305341
type: "object"
53315342
description: "The encryption method which is used when communicating with\
53325343
\ the database."
5333-
order: 6
5344+
order: 7
53345345
oneOf:
53355346
- title: "Unencrypted"
53365347
description: "Data transfer will not be encrypted."

airbyte-integrations/connectors/source-mssql-strict-encrypt/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ ENV APPLICATION source-mssql-strict-encrypt
1616

1717
COPY --from=build /airbyte /airbyte
1818

19-
LABEL io.airbyte.version=0.4.18
19+
LABEL io.airbyte.version=0.4.19
2020
LABEL io.airbyte.name=airbyte/source-mssql-strict-encrypt

airbyte-integrations/connectors/source-mssql-strict-encrypt/src/test/resources/expected_spec.json

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,42 @@
2828
"examples": ["master"],
2929
"order": 2
3030
},
31+
"schemas": {
32+
"title": "Schemas",
33+
"description": "The list of schemas to sync from. Defaults to user. Case sensitive.",
34+
"type": "array",
35+
"items": {
36+
"type": "string"
37+
},
38+
"minItems": 0,
39+
"uniqueItems": true,
40+
"default": ["dbo"],
41+
"order": 3
42+
},
3143
"username": {
3244
"description": "The username which is used to access the database.",
3345
"title": "Username",
3446
"type": "string",
35-
"order": 3
47+
"order": 4
3648
},
3749
"password": {
3850
"description": "The password associated with the username.",
3951
"title": "Password",
4052
"type": "string",
4153
"airbyte_secret": true,
42-
"order": 4
54+
"order": 5
4355
},
4456
"jdbc_url_params": {
4557
"title": "JDBC URL Params",
4658
"description": "Additional properties to pass to the JDBC URL string when connecting to the database formatted as 'key=value' pairs separated by the symbol '&'. (example: key1=value1&key2=value2&key3=value3).",
4759
"type": "string",
48-
"order": 5
60+
"order": 6
4961
},
5062
"ssl_method": {
5163
"title": "SSL Method",
5264
"type": "object",
5365
"description": "The encryption method which is used when communicating with the database.",
54-
"order": 6,
66+
"order": 7,
5567
"oneOf": [
5668
{
5769
"title": "Encrypted (trust server certificate)",

airbyte-integrations/connectors/source-mssql/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ ENV APPLICATION source-mssql
1616

1717
COPY --from=build /airbyte /airbyte
1818

19-
LABEL io.airbyte.version=0.4.18
19+
LABEL io.airbyte.version=0.4.19
2020
LABEL io.airbyte.name=airbyte/source-mssql

airbyte-integrations/connectors/source-mssql/src/main/java/io/airbyte/integrations/source/mssql/MssqlSource.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class MssqlSource extends AbstractJdbcSource<JDBCType> implements Source
6363
public static final String CDC_LSN = "_ab_cdc_lsn";
6464
private static final String HIERARCHYID = "hierarchyid";
6565
private static final int INTERMEDIATE_STATE_EMISSION_FREQUENCY = 10_000;
66+
private List<String> schemas;
6667

6768
public static Source sshWrappedSource() {
6869
return new SshWrappedSource(new MssqlSource(), JdbcUtils.HOST_LIST_KEY, JdbcUtils.PORT_LIST_KEY);
@@ -184,6 +185,13 @@ public JsonNode toDatabaseConfig(final JsonNode mssqlConfig) {
184185
mssqlConfig.get(JdbcUtils.PORT_KEY).asText(),
185186
mssqlConfig.get(JdbcUtils.DATABASE_KEY).asText()));
186187

188+
if (mssqlConfig.has("schemas") && mssqlConfig.get("schemas").isArray()) {
189+
schemas = new ArrayList<>();
190+
for (final JsonNode schema : mssqlConfig.get("schemas")) {
191+
schemas.add(schema.asText());
192+
}
193+
}
194+
187195
if (mssqlConfig.has("ssl_method")) {
188196
readSsl(mssqlConfig, additionalParameters);
189197
}
@@ -236,6 +244,31 @@ public AirbyteCatalog discover(final JsonNode config) throws Exception {
236244
return catalog;
237245
}
238246

247+
@Override
248+
public List<TableInfo<CommonField<JDBCType>>> discoverInternal(JdbcDatabase database) throws Exception {
249+
final List<TableInfo<CommonField<JDBCType>>> internals = super.discoverInternal(database);
250+
if (schemas != null && !schemas.isEmpty()) {
251+
// process explicitly filtered (from UI) schemas
252+
List<TableInfo<CommonField<JDBCType>>> resultInternals = internals
253+
.stream()
254+
.filter(this::isTableInRequestedSchema)
255+
.toList();
256+
for (TableInfo<CommonField<JDBCType>> info : resultInternals) {
257+
LOGGER.debug("Found table (schema: {}): {}", info.getNameSpace(), info.getName());
258+
}
259+
return resultInternals;
260+
} else {
261+
LOGGER.info("No schemas explicitly set on UI to process, so will process all of existing schemas in DB");
262+
return internals;
263+
}
264+
}
265+
266+
private boolean isTableInRequestedSchema(TableInfo<CommonField<JDBCType>> tableInfo) {
267+
return schemas
268+
.stream()
269+
.anyMatch(schema -> schema.equals(tableInfo.getNameSpace()));
270+
}
271+
239272
@Override
240273
public List<CheckedConsumer<JdbcDatabase, Exception>> getCheckOperations(final JsonNode config)
241274
throws Exception {

airbyte-integrations/connectors/source-mssql/src/main/resources/spec.json

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,42 @@
2828
"examples": ["master"],
2929
"order": 2
3030
},
31+
"schemas": {
32+
"title": "Schemas",
33+
"description": "The list of schemas to sync from. Defaults to user. Case sensitive.",
34+
"type": "array",
35+
"items": {
36+
"type": "string"
37+
},
38+
"minItems": 0,
39+
"uniqueItems": true,
40+
"default": ["dbo"],
41+
"order": 3
42+
},
3143
"username": {
3244
"description": "The username which is used to access the database.",
3345
"title": "Username",
3446
"type": "string",
35-
"order": 3
47+
"order": 4
3648
},
3749
"password": {
3850
"description": "The password associated with the username.",
3951
"title": "Password",
4052
"type": "string",
4153
"airbyte_secret": true,
42-
"order": 4
54+
"order": 5
4355
},
4456
"jdbc_url_params": {
4557
"title": "JDBC URL Params",
4658
"description": "Additional properties to pass to the JDBC URL string when connecting to the database formatted as 'key=value' pairs separated by the symbol '&'. (example: key1=value1&key2=value2&key3=value3).",
4759
"type": "string",
48-
"order": 5
60+
"order": 6
4961
},
5062
"ssl_method": {
5163
"title": "SSL Method",
5264
"type": "object",
5365
"description": "The encryption method which is used when communicating with the database.",
54-
"order": 6,
66+
"order": 7,
5567
"oneOf": [
5668
{
5769
"title": "Unencrypted",

docs/integrations/sources/mssql.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ If you do not see a type in this list, assume that it is coerced into a string.
306306

307307
| Version | Date | Pull Request | Subject |
308308
|:--------|:-----------| :----------------------------------------------------- |:-------------------------------------------------------------------------------------------------------|
309+
| 0.4.19 | 2022-09-05 | [16002](https://github.com/airbytehq/airbyte/pull/16002) | Added ability to specify schemas for discovery during setting connector up |
309310
| 0.4.18 | 2022-09-03 | [14910](https://github.com/airbytehq/airbyte/pull/14910) | Standardize spec for CDC replication. Replace the `replication_method` enum with a config object with a `method` enum field. |
310311
| 0.4.17 | 2022-09-01 | [16261](https://github.com/airbytehq/airbyte/pull/16261) | Emit state messages more frequently |
311312
| 0.4.16 | 2022-08-18 | [14356](https://github.com/airbytehq/airbyte/pull/14356) | DB Sources: only show a table can sync incrementally if at least one column can be used as a cursor field |

0 commit comments

Comments
 (0)