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

Method normalize

src/persist-client/src/fetch.rs:1406–1486  ·  view source on GitHub ↗

Returns the updates with all truncation / timestamp rewriting applied.

(&self, metrics: &ColumnarMetrics)

Source from the content-addressed store, hash-verified

1404
1405 /// Returns the updates with all truncation / timestamp rewriting applied.
1406 pub(crate) fn normalize(&self, metrics: &ColumnarMetrics) -> BlobTraceUpdates {
1407 let updates = self.part.updates.clone();
1408 if !self.needs_truncation && self.ts_rewrite.is_none() {
1409 return updates;
1410 }
1411
1412 let mut codec = updates
1413 .records()
1414 .map(|r| (r.keys().clone(), r.vals().clone()));
1415 let mut structured = updates.structured().cloned();
1416 let mut timestamps = updates.timestamps().clone();
1417 let mut diffs = updates.diffs().clone();
1418
1419 if let Some(rewrite) = self.ts_rewrite.as_ref() {
1420 timestamps = arrow::compute::unary(&timestamps, |i: i64| {
1421 let mut t = T::decode(i.to_le_bytes());
1422 t.advance_by(rewrite.borrow());
1423 i64::from_le_bytes(T::encode(&t))
1424 });
1425 }
1426
1427 let reallocated = if self.needs_truncation {
1428 let filter = BooleanArray::from_unary(&timestamps, |i| {
1429 let t = T::decode(i.to_le_bytes());
1430 let truncate_t = {
1431 !self.registered_desc.lower().less_equal(&t)
1432 || self.registered_desc.upper().less_equal(&t)
1433 };
1434 !truncate_t
1435 });
1436 if filter.false_count() == 0 {
1437 // If we're not filtering anything in practice, skip filtering and reallocating.
1438 false
1439 } else {
1440 let filter = FilterBuilder::new(&filter).optimize().build();
1441 let do_filter = |array: &dyn Array| filter.filter(array).expect("valid filter len");
1442 if let Some((keys, vals)) = codec {
1443 codec = Some((
1444 realloc_array(do_filter(&keys).as_binary(), metrics),
1445 realloc_array(do_filter(&vals).as_binary(), metrics),
1446 ));
1447 }
1448 if let Some(ext) = structured {
1449 structured = Some(ColumnarRecordsStructuredExt {
1450 key: realloc_any(do_filter(&*ext.key), metrics),
1451 val: realloc_any(do_filter(&*ext.val), metrics),
1452 });
1453 }
1454 timestamps = realloc_array(do_filter(&timestamps).as_primitive(), metrics);
1455 diffs = realloc_array(do_filter(&diffs).as_primitive(), metrics);
1456 true
1457 }
1458 } else {
1459 false
1460 };
1461
1462 if self.ts_rewrite.is_some() && !reallocated {
1463 timestamps = realloc_array(&timestamps, metrics);

Callers 4

newMethod · 0.45
from_encodedMethod · 0.45
fetch_batchFunction · 0.45
snapshotFunction · 0.45

Calls 15

realloc_arrayFunction · 0.85
realloc_anyFunction · 0.85
is_noneMethod · 0.80
valsMethod · 0.80
structuredMethod · 0.80
expectMethod · 0.80
is_someMethod · 0.80
inc_byMethod · 0.80
decodeFunction · 0.50
encodeFunction · 0.50
RowClass · 0.50
cloneMethod · 0.45

Tested by

no test coverage detected