Skip to content

[BUG] buildColumnStmt() quotes SQL keyword DEFAULT values, causing DDL failure for CURRENT_TIMESTAMP #485

@cloneot

Description

@cloneot

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

  1. Create a PostgreSQL table with DEFAULT CURRENT_TIMESTAMP
  2. Set up a Flink CDC (>= 3.2.0) pipeline with StarRocks sink
  3. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions