Problem
StarRocksCatalog.buildColumnStmt() wraps all default values with double quotes unconditionally:
|
if (column.getDefaultValue().isPresent()) { |
|
builder.append(String.format(" DEFAULT \"%s\"", column.getDefaultValue().get())); |
|
} |
This generates invalid DDL for SQL keywords like CURRENT_TIMESTAMP:
-- Generated (incorrect):
`created_at` DATETIME NOT NULL DEFAULT "CURRENT_TIMESTAMP"
-- Expected:
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
StarRocks rejects this with:
Getting analyzing error. Detail message: Invalid default value for 'created_at': date literal [CURRENT_TIMESTAMP] is invalid.
How to reproduce
- Create a PostgreSQL table with DEFAULT CURRENT_TIMESTAMP
- Set up a Flink CDC (>= 3.2.0) pipeline with StarRocks sink
- Pipeline fails on StarRocksCatalog.createTable() with the error above
Suggested fix
Distinguish between literal values (need quotes) and SQL keywords/functions (must not be quoted):
if (column.getDefaultValue().isPresent()) {
String defaultValue = column.getDefaultValue().get();
if (isKeywordDefault(defaultValue)) {
builder.append(String.format(" DEFAULT %s", defaultValue));
} else {
builder.append(String.format(" DEFAULT \"%s\"", defaultValue));
}
}
Where isKeywordDefault() checks for known expressions such as CURRENT_TIMESTAMP.
Environment
- starrocks-connector-for-apache-flink: 1.2.10_flink-1.19
- Flink CDC: 3.5.0
- StarRocks: 4.0.6
- Source: PostgreSQL (DEFAULT CURRENT_TIMESTAMP)
References
- StarRocks CREATE TABLE docs — DEFAULT current_timestamp is supported (without quotes)
- FLINK-34638 — Flink CDC 3.2.0, default value propagation added
- FLINK-38248 — Flink CDC 3.5.0, 0000-00-00 00:00:00 default value fix (similar issue, different case)
Problem
StarRocksCatalog.buildColumnStmt()wraps all default values with double quotes unconditionally:starrocks-connector-for-apache-flink/src/main/java/com/starrocks/connector/flink/catalog/StarRocksCatalog.java
Lines 620 to 622 in 51394fd
This generates invalid DDL for SQL keywords like CURRENT_TIMESTAMP:
StarRocks rejects this with:
Getting analyzing error. Detail message: Invalid default value for 'created_at': date literal [CURRENT_TIMESTAMP] is invalid.
How to reproduce
Suggested fix
Distinguish between literal values (need quotes) and SQL keywords/functions (must not be quoted):
Where isKeywordDefault() checks for known expressions such as CURRENT_TIMESTAMP.
Environment
References