Skip to content

Commit

Permalink
Mysql source: mark unknown column exception as config error (#20289)
Browse files Browse the repository at this point in the history
* Source mysql: mark unknown column exception as config error

* Source mysql: format code

* Source mysql: bump version

* Source mysql: bump version

* Source mysql: bump spec and definition version

* Source mysql: bump spec and definition version

* Source mysql: revert spec and definition version with unfamiliar changes

* Source mysql: bump spec and definition version

* Source mysql: revert manually bumped spec and definition version

* auto-bump connector version

Co-authored-by: Octavia Squidington III <octavia-squidington-iii@users.noreply.github.com>
  • Loading branch information
sashaNeshcheret and octavia-squidington-iii authored Dec 14, 2022
1 parent cdb26cd commit 9366b12
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@
- name: MySQL
sourceDefinitionId: 435bb9a5-7887-4809-aa58-28c27df0d7ad
dockerRepository: airbyte/source-mysql
dockerImageTag: 1.0.16
dockerImageTag: 1.0.17
documentationUrl: https://docs.airbyte.com/integrations/sources/mysql
icon: mysql.svg
sourceType: database
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8733,7 +8733,7 @@
supportsNormalization: false
supportsDBT: false
supported_destination_sync_modes: []
- dockerImage: "airbyte/source-mysql:1.0.16"
- dockerImage: "airbyte/source-mysql:1.0.17"
spec:
documentationUrl: "https://docs.airbyte.com/integrations/sources/mysql"
connectionSpecification:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import io.airbyte.commons.exceptions.ConnectionErrorException;
import io.airbyte.integrations.base.errors.messages.ErrorMessage;
import java.sql.SQLException;
import java.sql.SQLSyntaxErrorException;
import java.util.List;
import java.util.Locale;
import java.util.function.Predicate;
Expand All @@ -22,7 +23,8 @@ public class ConnectorExceptionUtil {
"We're having issues syncing from a Postgres replica that is configured as a hot standby server. " +
"Please see https://docs.airbyte.com/integrations/sources/postgres/#sync-data-from-postgres-hot-standby-server for options and workarounds";
private static final List<Predicate<Throwable>> configErrorPredicates =
List.of(getConfigErrorPredicate(), getConnectionErrorPredicate(), isRecoveryConnectionExceptionPredicate());
List.of(getConfigErrorPredicate(), getConnectionErrorPredicate(),
isRecoveryConnectionExceptionPredicate(), isUnknownColumnInFieldListException());

public static boolean isConfigError(final Throwable e) {
return configErrorPredicates.stream().anyMatch(predicate -> predicate.test(e));
Expand All @@ -36,6 +38,8 @@ public static String getDisplayMessage(final Throwable e) {
return ErrorMessage.getErrorMessage(connEx.getStateCode(), connEx.getErrorCode(), connEx.getExceptionMessage(), connEx);
} else if (isRecoveryConnectionExceptionPredicate().test(e)) {
return RECOVERY_CONNECTION_ERROR_MESSAGE;
} else if (isUnknownColumnInFieldListException().test(e)) {
return e.getMessage();
} else {
return String.format(COMMON_EXCEPTION_MESSAGE_TEMPLATE, e.getMessage() != null ? e.getMessage() : "");
}
Expand Down Expand Up @@ -71,4 +75,14 @@ private static Predicate<Throwable> isRecoveryConnectionExceptionPredicate() {
.contains("due to conflict with recovery");
}

private static Predicate<Throwable> isUnknownColumnInFieldListException() {
return e -> e instanceof SQLSyntaxErrorException
&& e.getMessage()
.toLowerCase(Locale.ROOT)
.contains("unknown column")
&& e.getMessage()
.toLowerCase(Locale.ROOT)
.contains("in 'field list'");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.airbyte.commons.exceptions.ConfigErrorException;
import io.airbyte.commons.exceptions.ConnectionErrorException;
import java.sql.SQLException;
import java.sql.SQLSyntaxErrorException;
import org.junit.jupiter.api.Test;

class ConnectorExceptionUtilTest {
Expand All @@ -19,6 +20,7 @@ class ConnectorExceptionUtilTest {
public static final String RECOVERY_EXCEPTION_MESSAGE = "FATAL: terminating connection due to conflict with recovery";
public static final String COMMON_EXCEPTION_MESSAGE = "something happens with connection";
public static final String CONNECTION_ERROR_MESSAGE_TEMPLATE = "State code: %s; Error code: %s; Message: %s";
public static final String UNKNOWN_COLUMN_SQL_EXCEPTION_MESSAGE = "Unknown column 'table.column' in 'field list'";

@Test()
void isConfigErrorForConfigException() {
Expand All @@ -39,6 +41,12 @@ void isConfigErrorForRecoveryPSQLException() {
assertTrue(ConnectorExceptionUtil.isConfigError(recoveryPSQLException));
}

@Test
void isConfigErrorForUnknownColumnSQLSyntaxErrorException() {
SQLSyntaxErrorException unknownColumnSQLSyntaxErrorException = new SQLSyntaxErrorException(UNKNOWN_COLUMN_SQL_EXCEPTION_MESSAGE);
assertTrue(ConnectorExceptionUtil.isConfigError(unknownColumnSQLSyntaxErrorException));
}

@Test
void isConfigErrorForCommonSQLException() {
SQLException recoveryPSQLException = new SQLException(COMMON_EXCEPTION_MESSAGE);
Expand Down Expand Up @@ -73,6 +81,13 @@ void getDisplayMessageForRecoveryException() {
assertEquals(RECOVERY_CONNECTION_ERROR_MESSAGE, actualDisplayMessage);
}

@Test
void getDisplayMessageForUnknownSQLErrorException() {
SQLSyntaxErrorException unknownColumnSQLSyntaxErrorException = new SQLSyntaxErrorException(UNKNOWN_COLUMN_SQL_EXCEPTION_MESSAGE);
String actualDisplayMessage = ConnectorExceptionUtil.getDisplayMessage(unknownColumnSQLSyntaxErrorException);
assertEquals(UNKNOWN_COLUMN_SQL_EXCEPTION_MESSAGE, actualDisplayMessage);
}

@Test
void getDisplayMessageForCommonException() {
Exception exception = new SQLException(COMMON_EXCEPTION_MESSAGE);
Expand All @@ -99,6 +114,16 @@ void getRootConfigErrorFromRecoverySQLException() {
assertEquals(recoveryException, actualRootConfigError);
}

@Test
void getRootConfigErrorFromUnknownSQLErrorException() {
SQLException unknownSQLErrorException = new SQLSyntaxErrorException(UNKNOWN_COLUMN_SQL_EXCEPTION_MESSAGE);
RuntimeException runtimeException = new RuntimeException(COMMON_EXCEPTION_MESSAGE, unknownSQLErrorException);
Exception exception = new Exception(runtimeException);

Throwable actualRootConfigError = ConnectorExceptionUtil.getRootConfigError(exception);
assertEquals(unknownSQLErrorException, actualRootConfigError);
}

@Test
void getRootConfigErrorFromNonConfigException() {
SQLException configErrorException = new SQLException(CONFIG_EXCEPTION_MESSAGE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ ENV APPLICATION source-mysql-strict-encrypt

COPY --from=build /airbyte /airbyte

LABEL io.airbyte.version=1.0.16
LABEL io.airbyte.version=1.0.17

LABEL io.airbyte.name=airbyte/source-mysql-strict-encrypt
2 changes: 1 addition & 1 deletion airbyte-integrations/connectors/source-mysql/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ ENV APPLICATION source-mysql

COPY --from=build /airbyte /airbyte

LABEL io.airbyte.version=1.0.16
LABEL io.airbyte.version=1.0.17

LABEL io.airbyte.name=airbyte/source-mysql
1 change: 1 addition & 0 deletions docs/integrations/sources/mysql.md
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ WHERE actor_definition_id ='435bb9a5-7887-4809-aa58-28c27df0d7ad' AND (configura

| Version | Date | Pull Request | Subject |
|:--------|:-----------|:-----------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1.0.17 | 2022-12-13 | [20289](https://github.com/airbytehq/airbyte/pull/20289) | Mark unknown column exception as config error |
| 1.0.16 | 2022-12-12 | [18959](https://github.com/airbytehq/airbyte/pull/18959) | CDC : Don't timeout if snapshot is not complete. |
| 1.0.15 | 2022-12-06 | [20000](https://github.com/airbytehq/airbyte/pull/20000) | Add check and better messaging when user does not have permission to access binary log in CDC mode |
| 1.0.14 | 2022-11-22 | [19514](https://github.com/airbytehq/airbyte/pull/19514) | Adjust batch selection memory limits databases. |
Expand Down

0 comments on commit 9366b12

Please sign in to comment.