{"record":{"id":"220da93c31bdf6f7","repo":"risingwavelabs/risingwave","slug":"columns-mismatch-risingwave-schema-has-fields-220da9","errorCode":null,"errorMessage":"Columns mismatch. RisingWave schema has {} fields, LanceDB table has {} fields","messagePattern":"Columns mismatch\\. RisingWave schema has (.+?) fields, LanceDB table has (.+?) fields","errorType":"exception","errorClass":"SinkError::LanceDb","httpStatus":null,"severity":"error","filePath":"src/connector/src/sink/lancedb.rs","lineNumber":292,"sourceCode":"        LanceDbSink::new(config, param)\n    }\n}\n\n// ---------------------------------------------------------------------------\n// Writer\n// ---------------------------------------------------------------------------\n\n// Re-export arrow types from the LanceDb arrow module so they're used consistently.\nuse risingwave_common::array::arrow::{\n    arrow_array_lancedb as arrow_array, arrow_schema_lancedb as arrow_schema,\n};\n\nfn validate_ordered_schema(\n    rw_arrow_schema: &arrow_schema::Schema,\n    lance_schema: &arrow_schema::Schema,\n) -> Result<()> {\n    if rw_arrow_schema.fields().len() != lance_schema.fields().len() {\n        return Err(SinkError::LanceDb(anyhow!(\n            \"Columns mismatch. RisingWave schema has {} fields, LanceDB table has {} fields\",\n            rw_arrow_schema.fields().len(),\n            lance_schema.fields().len()\n        )));\n    }\n\n    for (idx, (rw_field, lance_field)) in rw_arrow_schema\n        .fields()\n        .iter()\n        .zip_eq_fast(lance_schema.fields().iter())\n        .enumerate()\n    {\n        if rw_field.name() != lance_field.name() {\n            return Err(SinkError::LanceDb(anyhow!(\n                \"column order mismatch at position {}: LanceDB column is '{}', RisingWave column is '{}'\",\n                idx,\n                lance_field.name(),\n                rw_field.name()","sourceCodeStart":274,"sourceCodeEnd":310,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/connector/src/sink/lancedb.rs#L274-L310","documentation":"validate_ordered_schema requires the existing LanceDB table's Arrow schema to have exactly the same number of columns as the RisingWave sink schema. When the counts differ, the sink cannot safely map values, so validation fails with the two field counts.","triggerScenarios":"CREATE SINK into an existing LanceDB table whose column count differs from the RW schema — e.g., the table was created earlier with extra columns, or RW added/dropped a column since the table was created.","commonSituations":"Schema evolution drift: someone ALTERed the MV/table on one side only; reusing an old LanceDB table for a new sink with a different projection.","solutions":["Align the sink query's SELECT list to match the existing table's columns exactly (or vice versa)","Drop and recreate the LanceDB table with the schema RisingWave expects","Create the sink against a fresh table name and let RW create the table","Compare `SELECT * FROM table LIMIT 0` schema with the RW sink schema and reconcile differences"],"exampleFix":"// before\nCREATE SINK s AS SELECT a, b FROM t WITH ('connector'='lancedb', 'lancedb.table'='t_old'); -- t_old has 3 cols\n// after\nCREATE SINK s AS SELECT a, b, c FROM t WITH ('connector'='lancedb', 'lancedb.table'='t_old');","handlingStrategy":"validation","validationCode":"async function checkColumnCount(tableName, expected) {\n  const t = await conn.openTable(tableName);\n  const schema = await t.schema();\n  if (schema.fields.length !== expected)\n    throw new Error(`table ${tableName} has ${schema.fields.length} cols, sink has ${expected}`);\n}","typeGuard":null,"tryCatchPattern":"catch (SinkError::LanceDb(e)) if e.includes(\"Columns mismatch\") { align the SELECT projection or recreate the table }","preventionTips":["Inspect the existing LanceDB table schema before writing the sink query","Never ALTER one side without the other","Use a fresh table name when the sink projection changes"],"tags":["rust","arrow","schema","lancedb"],"backgroundTag":"schema-validation-failed","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}