MCPcopy Create free account
hub / github.com/ciphermodelabs/ciphercore / get_union_columns

Function get_union_columns

ciphercore-base/src/evaluators/join.rs:363–433  ·  view source on GitHub ↗

Computes the union join of given sets. These sets and necessary precomputations should be contained in the join input. In contrast to the SQL union, this operation does not require that input datasets have respective columns of the same type. This means that columns of both datasets are included and filled with zeros where no data can be retrieved. Namely, the rows of the second set in the union j

(join_input: &JoinInput)

Source from the content-addressed store, hash-verified

361// This means that columns of both datasets are included and filled with zeros where no data can be retrieved.
362// Namely, the rows of the second set in the union join will contain zeros in non-key columns of the first set and vice versa.
363fn get_union_columns(join_input: &JoinInput) -> Result<ColumnsMap> {
364 let mut result_columns = ColumnsMap::init_result_columns(join_input)?;
365
366 // Add all the rows of the first set that don't belong to the inner join
367 for row_ind0 in 0..join_input.set0.get_num_rows() {
368 // If the null bit is zero, just insert a zero row
369 if join_input.set0.null_column[row_ind0] == 0 {
370 result_columns.append_zero_row();
371 continue;
372 }
373
374 if join_input.row_has_empty_entries(row_ind0) {
375 // Extract the rows of the first set
376 for (header0, _) in join_input.headers_types0.iter() {
377 result_columns.copy_entry_from_column(header0, header0, &join_input.set0, row_ind0);
378 }
379 // Append the current row with zeros in the remaining unique columns of the second set
380 for h in &join_input.nonkey_headers1 {
381 if !join_input.same_headers.contains(h) {
382 result_columns.append_zero_entry(h);
383 }
384 }
385 continue;
386 }
387 // Merge the key columns of the first set
388 let row_key = join_input
389 .set0
390 .get_flattened_row(row_ind0, &join_input.key_headers0);
391 // Check that the row key of the first set is contained in the second set
392 if join_input.key_data_hashmap1.contains_key(&row_key) {
393 // Fill the current row with zeros
394 result_columns.append_zero_row();
395 } else {
396 // Extract the rows of the first set
397 for (header0, _) in join_input.headers_types0.iter() {
398 result_columns.copy_entry_from_column(header0, header0, &join_input.set0, row_ind0);
399 }
400 // Append the current row with zeros in the remaining unique columns of the second set
401 for h in &join_input.nonkey_headers1 {
402 if !join_input.same_headers.contains(h) {
403 result_columns.append_zero_entry(h);
404 }
405 }
406 }
407 }
408
409 // Add all the rows of the second set
410 for row_ind1 in 0..join_input.set1.get_num_rows() {
411 if join_input.set1.null_column[row_ind1] == 0 {
412 result_columns.append_zero_row();
413 continue;
414 }
415 for (h, _) in join_input.result_headers_types {
416 if h == NULL_HEADER {
417 // the null bit will be always 1 here
418 result_columns.null_column.push(1);
419 } else if join_input.key_headers0.contains(h) {
420 // extract the content of a key column of the second set

Callers 1

evaluate_joinFunction · 0.85

Calls 7

get_num_rowsMethod · 0.80
append_zero_rowMethod · 0.80
row_has_empty_entriesMethod · 0.80
append_zero_entryMethod · 0.80
get_flattened_rowMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected