Convert key columns to binary and merge them for each input database
(
context: Context,
column_types: ColumnTypesInfo,
key_headers: &[String],
is_private: bool,
)
| 405 | |
| 406 | // Convert key columns to binary and merge them for each input database |
| 407 | fn get_merging_graph( |
| 408 | context: Context, |
| 409 | column_types: ColumnTypesInfo, |
| 410 | key_headers: &[String], |
| 411 | is_private: bool, |
| 412 | ) -> Result<Graph> { |
| 413 | let mut headers_map = HashMap::new(); |
| 414 | for (h, t) in &column_types.headers_types { |
| 415 | headers_map.insert((*h).clone(), (*t).clone()); |
| 416 | } |
| 417 | |
| 418 | let merging_context = simple_context(|g| { |
| 419 | let data = g.input(column_types.get_plaintext_type())?; |
| 420 | |
| 421 | let num_entries = column_types.get_num_entries(); |
| 422 | |
| 423 | let mut bit_columns = vec![]; |
| 424 | for header in key_headers { |
| 425 | let t = headers_map.get(header).unwrap(); |
| 426 | |
| 427 | let mut column = data.named_tuple_get((*header).clone())?; |
| 428 | if t.has_mask() { |
| 429 | column = column.tuple_get(1)?; |
| 430 | } |
| 431 | let mut bit_column = if t.get_scalar_type() != BIT { |
| 432 | column.a2b()? |
| 433 | } else { |
| 434 | column |
| 435 | }; |
| 436 | // Flatten all the bits per entry |
| 437 | let flattened_shape = vec![num_entries, t.get_row_size_in_bits()]; |
| 438 | bit_column = bit_column.reshape(array_type(flattened_shape, BIT))?; |
| 439 | // Pull out bits to simplify merging of columns |
| 440 | bit_columns.push(bit_column); |
| 441 | } |
| 442 | // Merge key columns |
| 443 | let merged_columns = if bit_columns.len() > 1 { |
| 444 | g.concatenate(bit_columns, 1)? |
| 445 | } else { |
| 446 | bit_columns[0].clone() |
| 447 | }; |
| 448 | |
| 449 | Ok(merged_columns) |
| 450 | })?; |
| 451 | |
| 452 | convert_main_graph_to_mpc(merging_context, context, vec![is_private]) |
| 453 | } |
| 454 | |
| 455 | // Multiply the column by the mask/null column |
| 456 | // Assumes that column mask is binary and it has the same number of rows as the column |
no test coverage detected