MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / smoketest_decoder

Function smoketest_decoder

src/sql-server-util/src/desc.rs:1363–1442  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1361
1362 #[mz_ore::test]
1363 fn smoketest_decoder() {
1364 let sql_server_columns = [
1365 SqlServerColumnRaw::new("a", "varchar").max_length(16),
1366 SqlServerColumnRaw::new("b", "int").nullable(true),
1367 SqlServerColumnRaw::new("c", "bit"),
1368 ];
1369 let sql_server_desc = SqlServerTableRaw {
1370 schema_name: "my_schema".into(),
1371 name: "my_table".into(),
1372 capture_instance: Arc::new(SqlServerCaptureInstanceRaw {
1373 name: "my_table_CT".into(),
1374 create_date: NaiveDateTime::parse_from_str(
1375 "2024-01-01 00:00:00",
1376 "%Y-%m-%d %H:%M:%S",
1377 )
1378 .unwrap()
1379 .into(),
1380 }),
1381 columns: sql_server_columns.into(),
1382 };
1383 let sql_server_desc = SqlServerTableDesc::new(sql_server_desc, vec![]).unwrap();
1384
1385 let max_length = Some(VarCharMaxLength::try_from(16).unwrap());
1386 let relation_desc = RelationDesc::builder()
1387 .with_column("a", SqlScalarType::VarChar { max_length }.nullable(false))
1388 // Note: In the upstream table 'c' is ordered after 'b'.
1389 .with_column("c", SqlScalarType::Bool.nullable(false))
1390 .with_column("b", SqlScalarType::Int32.nullable(true))
1391 .finish();
1392
1393 // This decoder should shape the SQL Server Rows into Rows compatible with the RelationDesc.
1394 let decoder = sql_server_desc
1395 .decoder(&relation_desc)
1396 .expect("known valid");
1397
1398 let sql_server_columns = [
1399 tiberius::Column::new("a".to_string(), tiberius::ColumnType::BigVarChar),
1400 tiberius::Column::new("b".to_string(), tiberius::ColumnType::Int4),
1401 tiberius::Column::new("c".to_string(), tiberius::ColumnType::Bit),
1402 ];
1403
1404 let data_a = [
1405 tiberius::ColumnData::String(Some("hello world".into())),
1406 tiberius::ColumnData::I32(Some(42)),
1407 tiberius::ColumnData::Bit(Some(true)),
1408 ];
1409 let sql_server_row_a = tiberius::Row::build(
1410 sql_server_columns
1411 .iter()
1412 .cloned()
1413 .zip_eq(data_a.into_iter()),
1414 );
1415
1416 let data_b = [
1417 tiberius::ColumnData::String(Some("foo bar".into())),
1418 tiberius::ColumnData::I32(None),
1419 tiberius::ColumnData::Bit(Some(false)),
1420 ];

Callers

nothing calls this directly

Calls 13

StringClass · 0.85
max_lengthMethod · 0.80
unwrapMethod · 0.80
with_columnMethod · 0.80
expectMethod · 0.80
buildFunction · 0.50
nullableMethod · 0.45
finishMethod · 0.45
decoderMethod · 0.45
to_stringMethod · 0.45
iterMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected