Skip to content

feat: add sql_server sink connector - #102

Open
tanokl wants to merge 2 commits into
mainfrom
feat/sql_server-sink-20260611182837-ceac93
Open

tanokl wants to merge 2 commits into
mainfrom
feat/sql_server-sink-20260611182837-ceac93

Conversation

@tanokl

@tanokl tanokl commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

Connector sql_server sink generado por la factory EZ-CDC.

  • Branch: feat/sql_server-sink-20260611182837-ceac93
  • Verify: ver handoff
  • Imagen dbmazz: dbmazz-sqlserver:dev

PR automático (no mergear sin review).

@dariomazzitelli-sys dariomazzitelli-sys left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Hermes Agent — Code Review: PR #102 (SQL Server sink)

Build: ✅ 0 errores · Tests: ✅ 173 passed · 0 failed · 4 features builds sin regresiones

En general el SQL Server sink está MEJOR que el Oracle sink — usa el shared compute_schema_evolution_plan, maneja correctamente BEGIN/COMMIT/ROLLBACK, usa parámetros tipados para TDS, y tiene CHANGELOG actualizado.

Mejora global importante: el cambio en src/source/converter.rs (timestamp Value::String → Value::Timestamp(i64)) beneficia a TODOS los sinks.

Pero hay algunos issues. Detalles en los inline comments 👇

@@ -0,0 +1,90 @@
# SQL Server Sink Connector

@dariomazzitelli-sys dariomazzitelli-sys Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Duplicate README: sql_server/README.md is a copy of sqlserver/README.md. Module is sqlserver/. Remove the duplicate.

let sink = PostgresSink::new(config, mode)?;
Ok(Box::new(sink))
}
#[cfg(feature = "sink-sqlserver")]

@dariomazzitelli-sys dariomazzitelli-sys Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ No factory test: Unlike Oracle PR (#101) which had test_create_oracle_sink, this has no factory wiring test. Add one.

// ── WHEN MATCHED THEN UPDATE SET ──
// Exclude PK columns (they are in the ON clause) and unchanged columns
// (Value::Unchanged from PG TOAST — must not overwrite with NULL).
sql.push_str("WHEN MATCHED THEN\n");

@dariomazzitelli-sys dariomazzitelli-sys Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Empty UPDATE SET: If all non-PK cols are Unchanged, SQL has UPDATE SET with nothing after — invalid T-SQL. Oracle PR omits the entire WHEN MATCHED clause when empty.

},
Value::Bool(b) => ParamOwned::Bool(*b),
Value::Int64(i) => ParamOwned::I64(*i),
Value::UInt64(u) => ParamOwned::String(u.to_string()),

@dariomazzitelli-sys dariomazzitelli-sys Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ UInt64 as String: DDL says NUMERIC(20,0) but value sent as NVARCHAR. Risks precision loss for values > 2^53.

.naive_utc(),
)
}
Value::Decimal(d) => ParamOwned::String(d.clone()),

@dariomazzitelli-sys dariomazzitelli-sys Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Decimal as String: Sent as NVARCHAR via String(d.clone()). Implicit conversion works but has perf implications.

/// Dispatch primary on `DataType` (source-agnostic). SQL Server has no
/// equivalent of PG OID refinement, so this is a pure delegation to
/// `data_type_to_sqlserver`.
#[allow(dead_code)]

@dariomazzitelli-sys dariomazzitelli-sys Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Dead code: column_type() with #[allow(dead_code)] — never called. setup.rs uses data_type_to_sqlserver() directly.

/// The placeholder does not vary by Value variant — all values use the
/// same `@P` convention. The caller is responsible for numbering and
/// binding the actual value through tiberius.
#[allow(dead_code)]

@dariomazzitelli-sys dariomazzitelli-sys Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Dead code: value_to_param() with #[allow(dead_code)] — never called. Params built via value_to_param_owned().

/// Each null variant carries the correct TDS type so SQL Server doesn't
/// reject it with "Operand type clash" when the column expects e.g.
/// DATETIME2 (naively sending `Option<i32>` as int NULL).
#[allow(dead_code)]

@dariomazzitelli-sys dariomazzitelli-sys Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Unnecessary #[allow(dead_code)]: All ParamOwned variants are constructed in value_to_param_owned(). Lint override not needed.


| Variable | Description | Default |
|----------|-------------|---------|
| `SINK_URL` | SQL Server hostname or IP | required |

@dariomazzitelli-sys dariomazzitelli-sys Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ README wrong: Shows SINK_URL but code uses SINK_HOST. Example config looks copied from another sink.

records_written, bytes_written
);

Ok(SinkResult {

@dariomazzitelli-sys dariomazzitelli-sys Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ No last_position in SinkResult: Verify pipeline handles checkpointing without position from sink.

@dariomazzitelli-sys dariomazzitelli-sys left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Hermes Agent — Code Review (English)

Build: ✅ 0 errors · Tests: ✅ 173/173 pass · Has CHANGELOG ✅

Better than the Oracle PR — uses shared compute_schema_evolution_plan, proper BEGIN/COMMIT/ROLLBACK, typed TDS parameters. However:

🔴 Out-of-scope change: src/source/converter.rs modifies timestamp handling (OIDs 1114, 1184 → Value::Timestamp(i64)) for ALL sinks, not just SQL Server. This should be a separate PR.

See inline comments for code-specific findings.

@@ -0,0 +1,90 @@
# SQL Server Sink Connector

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Duplicate README: This file at sql_server/README.md is an exact copy of sqlserver/README.md. The module lives at sqlserver/ (no underscore). Remove this duplicate.

// ── WHEN MATCHED THEN UPDATE SET ──
// Exclude PK columns (they are in the ON clause) and unchanged columns
// (Value::Unchanged from PG TOAST — must not overwrite with NULL).
sql.push_str("WHEN MATCHED THEN\n");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Empty UPDATE SET clause: If all non-PK columns are Value::Unchanged, set_parts is empty and SQL produces WHEN MATCHED THEN\n UPDATE SET\n WHEN NOT MATCHED... — invalid T-SQL. Oracle PR (#101) omits the entire UPDATE clause when there's nothing to update.

},
Value::Bool(b) => ParamOwned::Bool(*b),
Value::Int64(i) => ParamOwned::I64(*i),
Value::UInt64(u) => ParamOwned::String(u.to_string()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ UInt64 sent as String: Value::UInt64(u) => ParamOwned::String(u.to_string()). DDL creates NUMERIC(20, 0) but value is sent as NVARCHAR. Implicit conversion works but risks precision loss for values > 2^53.

.naive_utc(),
)
}
Value::Decimal(d) => ParamOwned::String(d.clone()),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Decimal sent as String: Value::Decimal(d) => ParamOwned::String(d.clone()). Tiberius has no native rust_decimal::Decimal type. Sent as NVARCHAR — implicit conversion works but has performance and precision implications.

DataType::UInt64 => "NUMERIC(20, 0)",
DataType::Float32 => "REAL",
DataType::Float64 => "FLOAT(53)",
DataType::Decimal {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Decimal ignores precision/scale: Always returns "NUMERIC(38, 0)" regardless of actual precision/scale. If source has DECIMAL(10, 2), target gets NUMERIC(38, 0) — truncating scale. Use DataType::Decimal { precision, scale } => format!("NUMERIC({}, {})", precision, scale).

/// The placeholder does not vary by Value variant — all values use the
/// same `@P` convention. The caller is responsible for numbering and
/// binding the actual value through tiberius.
#[allow(dead_code)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Dead code: value_to_param() with #[allow(dead_code)] — never called. Params built via value_to_param_owned() and build_params() in mod.rs.


| Variable | Description | Default |
|----------|-------------|---------|
| `SINK_URL` | SQL Server hostname or IP | required |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ README incorrect: Config table shows SINK_URL but config.rs uses SINK_HOST for SQL Server (not SINK_URL). The username/password/env vars in the example look like they were copied from another sink. Fix to reflect actual SQL Server configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants