risingwavelabs/risingwave · error

unexpected default value type for integer

Error message

unexpected default value type for integer

What it means

derive_default_value converts a MySQL column's literal integer default into a RisingWave ScalarImpl based on the mapped RW data type. If the column's RW type is not Int32, Int64, or Varchar (e.g. the column was typed as timestamp/boolean/decimal while MySQL reported an integer default), the match falls through to bail!. This indicates a mismatch between the MySQL default value's inferred kind and the column's RW type.

Source

Thrown at src/connector/src/source/cdc/external/mysql.rs:234

                .iter()
                .map(|part| part.column.to_lowercase())
                .collect()
        })
        .filter(|names: &Vec<_>| !names.is_empty())
}

fn derive_default_value(default: ColumnDefault, data_type: &DataType) -> ConnectorResult<Datum> {
    let datum = match default {
        ColumnDefault::Null => None,
        ColumnDefault::Int(val) => match data_type {
            DataType::Int16 => Some(ScalarImpl::Int16(val as _)),
            DataType::Int32 => Some(ScalarImpl::Int32(val as _)),
            DataType::Int64 => Some(ScalarImpl::Int64(val)),
            DataType::Varchar => {
                // should be the Enum type which is mapped to Varchar
                Some(ScalarImpl::from(val.to_string()))
            }
            _ => bail!("unexpected default value type for integer"),
        },
        ColumnDefault::Real(val) => match data_type {
            DataType::Float32 => Some(ScalarImpl::Float32(F32::from(val as f32))),
            DataType::Float64 => Some(ScalarImpl::Float64(val.into())),
            DataType::Decimal => Some(ScalarImpl::Decimal(
                Decimal::try_from(val).context("failed to convert default value to decimal")?,
            )),
            _ => bail!("unexpected default value type for real"),
        },
        ColumnDefault::String(mut val) => {
            // mysql timestamp is mapped to timestamptz, we use UTC timezone to
            // interpret its value
            if data_type == &DataType::Timestamptz {
                val = timestamp_val_to_timestamptz(val.as_str())?;
            }
            Some(ScalarImpl::from_text(val.as_str(), data_type).map_err(|e| anyhow!(e)).context(
                "failed to parse mysql default value expression, only constant is supported",
            )?)

View on GitHub (pinned to 6469eb736d)

Solutions

  1. Check the column's MySQL type and its DEFAULT; make the default compatible (e.g. numeric default on a numeric column).
  2. Drop or ALTER the column default in MySQL to a supported constant.
  3. Upgrade/align the connector type-mapping code so integer defaults map to Int32/Int64/Varchar.

Example fix

// before (MySQL)
ALTER TABLE t ADD COLUMN flag BOOLEAN DEFAULT 1; -- integer default on mapped bool
// after
ALTER TABLE t MODIFY flag BOOLEAN DEFAULT TRUE;
Defensive patterns

Strategy: validation

Validate before calling

-- verify defaults match column types on MySQL
SELECT COLUMN_NAME, COLUMN_TYPE, COLUMN_DEFAULT FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA='mydb' AND TABLE_NAME='t'
  AND COLUMN_DEFAULT IS NOT NULL
  AND NOT (COLUMN_TYPE LIKE 'int%' OR COLUMN_TYPE LIKE 'bigint%' OR COLUMN_TYPE LIKE 'varchar%');

Type guard

function integerDefaultIsCompatible(mysqlColumnType, rwDataType) {
  return /^((tiny|small|medium|big)?int|varchar)/.test(mysqlColumnType) &&
    ["Int32","Int64","Varchar"].includes(rwDataType);
}

Try / catch

try { await createCdcTable('t'); } catch (e) { if (String(e).includes('unexpected default value type for integer')) { /* ALTER the MySQL column default, then retry */ } else throw e; }

Prevention

When it happens

Trigger: A MySQL column with an integer literal DEFAULT whose mapped RisingWave DataType is not one of Int32/Int64/Varchar — e.g. type mapping drift or a schema-change that re-typed the column.

Common situations: MySQL type mappings changed between versions (e.g. unsigned/serial remap) so an old default no longer matches; custom extensions treating an integer default on an unusual column type.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of risingwavelabs/risingwave@6469eb736d (2026-09-11). Data as JSON: /api/errors/c11d1039b359d46c. Report an issue: GitHub.