Skip to content

Commit 0d870bd

Browse files
authored
6339: error when attempting to use azure sql database within an elastic pool as source for cdc based replication (#13866)
* 6339: debug info * 6339: not using 'USE' on Azure SQL servers * 6339: cleanup * 6339: cleanup2 * 6339: cleanup3 * 6339: versions/changelogs updated * 6339: merge from master (consolidation issue) * 6339: dev connector version (for testing in airbyte cloud) * 6339: code review implementation * 6339: apply formatting
1 parent f69a78c commit 0d870bd

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

airbyte-integrations/connectors/source-mssql/Dockerfile

+1-1
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.3
19+
LABEL io.airbyte.version=0.4.4
2020
LABEL io.airbyte.name=airbyte/source-mssql

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
import java.io.File;
3838
import java.sql.JDBCType;
3939
import java.sql.PreparedStatement;
40+
import java.sql.ResultSet;
4041
import java.sql.SQLException;
42+
import java.sql.Statement;
4143
import java.time.Instant;
4244
import java.util.ArrayList;
4345
import java.util.List;
@@ -275,7 +277,17 @@ protected void assertCdcEnabledInDb(final JsonNode config, final JdbcDatabase da
275277
protected void assertCdcSchemaQueryable(final JsonNode config, final JdbcDatabase database)
276278
throws SQLException {
277279
final List<JsonNode> queryResponse = database.queryJsons(connection -> {
278-
final String sql = "USE " + config.get("database").asText() + "; SELECT * FROM cdc.change_tables";
280+
boolean isAzureSQL = false;
281+
282+
try (Statement stmt = connection.createStatement();
283+
ResultSet editionRS = stmt.executeQuery("SELECT ServerProperty('Edition')")) {
284+
isAzureSQL = editionRS.next() && "SQL Azure".equals(editionRS.getString(1));
285+
}
286+
287+
// Azure SQL does not support USE clause
288+
final String sql =
289+
isAzureSQL ? "SELECT * FROM cdc.change_tables" : "USE " + config.get("database").asText() + "; SELECT * FROM cdc.change_tables";
290+
279291
final PreparedStatement ps = connection.prepareStatement(sql);
280292
LOGGER.info(String.format(
281293
"Checking user '%s' can query the cdc schema and that we have at least 1 cdc enabled table using the query: '%s'",

docs/integrations/sources/mssql.md

+1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ If you do not see a type in this list, assume that it is coerced into a string.
302302

303303
| Version | Date | Pull Request | Subject |
304304
|:--------|:-----------| :----------------------------------------------------- |:-------------------------------------------------------------------------------------------------------|
305+
| 0.4.4 | 2022-07-20 | [13866](https://github.com/airbytehq/airbyte/pull/13866) | Omit using 'USE' keyword on Azure SQL with CDC |
305306
| 0.4.3 | 2022-07-17 | [13887](https://github.com/airbytehq/airbyte/pull/13887) | Increase version to include changes from [13854](https://github.com/airbytehq/airbyte/pull/13854) |
306307
| 0.4.2 | 2022-06-06 | [13435](https://github.com/airbytehq/airbyte/pull/13435) | Adjust JDBC fetch size based on max memory and max row size |
307308
| 0.4.1 | 2022-05-25 | [13419](https://github.com/airbytehq/airbyte/pull/13419) | Correct enum for Standard method. |

0 commit comments

Comments
 (0)