MCPcopy Create free account
hub / github.com/apache/paimon-rust / create_index_mapping

Function create_index_mapping

crates/paimon/src/arrow/schema_evolution.rs:42–72  ·  view source on GitHub ↗

Create index mapping from table fields to underlying data fields using field IDs. For example, the table and data fields are as follows: - table fields: `1->c, 6->b, 3->a` - data fields: `1->a, 3->c` We get the index mapping `[0, -1, 1]`, where: - `0` is the index of table field `1->c` in data fields - `-1` means field `6->b` does not exist in data fields - `1` is the index of table field `3->a`

(
    table_fields: &[DataField],
    data_fields: &[DataField],
)

Source from the content-addressed store, hash-verified

40///
41/// Reference: [SchemaEvolutionUtil.createIndexMapping](https://github.com/apache/paimon/blob/release-1.3/paimon-core/src/main/java/org/apache/paimon/schema/SchemaEvolutionUtil.java)
42pub fn create_index_mapping(
43 table_fields: &[DataField],
44 data_fields: &[DataField],
45) -> Option<Vec<i32>> {
46 let mut field_id_to_index: HashMap<i32, i32> = HashMap::with_capacity(data_fields.len());
47 for (i, field) in data_fields.iter().enumerate() {
48 field_id_to_index.insert(field.id(), i as i32);
49 }
50
51 let mut index_mapping = Vec::with_capacity(table_fields.len());
52 for field in table_fields {
53 let data_index = field_id_to_index
54 .get(&field.id())
55 .copied()
56 .unwrap_or(NULL_FIELD_INDEX);
57 index_mapping.push(data_index);
58 }
59
60 // Check if mapping is identity (no evolution needed).
61 let is_identity = index_mapping.len() == data_fields.len()
62 && index_mapping
63 .iter()
64 .enumerate()
65 .all(|(i, &idx)| idx == i as i32);
66
67 if is_identity {
68 None
69 } else {
70 Some(index_mapping)
71 }
72}
73
74#[cfg(test)]
75mod tests {

Callers 3

build_field_mappingFunction · 0.85
resolve_stats_schemaFunction · 0.85

Calls 5

insertMethod · 0.80
lenMethod · 0.45
iterMethod · 0.45
idMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected