wuchong commented on a change in pull request #10745:
[FLINK-15445][connectors/jdbc] JDBC Table Source didn't work for Type…
URL: https://github.com/apache/flink/pull/10745#discussion_r376203705
##########
File path:
flink-connectors/flink-jdbc/src/main/java/org/apache/flink/api/java/io/jdbc/dialect/JDBCDialects.java
##########
@@ -70,11 +105,33 @@ public String quoteIdentifier(String identifier) {
private static final long serialVersionUID = 1L;
+ private static final int MAX_MYSQL_TIMESTAMP_PRECISION = 6;
+
+ private static final int MIN_MYSQL_TIMESTAMP_PRECISION = 0;
+
@Override
public boolean canHandle(String url) {
return url.startsWith("jdbc:mysql:");
}
+ @Override
+ public void validate(TableSchema schema) {
+ for (int i = 0; i < schema.getFieldCount(); i++) {
+ DataType dt = schema.getFieldDataType(i).get();
+ String fieldName = schema.getFieldName(i).get();
+ if (TIMESTAMP_WITHOUT_TIME_ZONE ==
dt.getLogicalType().getTypeRoot()) {
+ int precision = ((TimestampType)
dt.getLogicalType()).getPrecision();
+ if (precision >
MAX_MYSQL_TIMESTAMP_PRECISION) {
+ throw new ValidationException(
+
String.format("The precision of %s is out of range [%d, %d].",
+
fieldName,
+
MIN_MYSQL_TIMESTAMP_PRECISION,
+
MAX_MYSQL_TIMESTAMP_PRECISION));
+ }
+ }
Review comment:
It seems that the validation logic is the same, maybe we can refactor it a
bit more to have a `AbstractJDBCDialect` which implements `JDBCDialect`.
```java
private abstract static class AbstractDialect implements JDBCDialect {
@Override
public void validate(TableSchema schema) throws
ValidationException {
// implement the common validation logic here
}
public abstract int maxDecimalPrecision();
public abstract int minDecimalPrecision();
public abstract int maxTimestampPrecision();
public abstract int minTimestampPrecision();
public abstract List<LogicalTypeRoot> unsupportedTypes();
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services