MCPcopy
hub / github.com/uber/aresdb / getChangedBaseRow

Method getChangedBaseRow

memstore/backfill.go:599–630  ·  view source on GitHub ↗

getChangedBaseRow get changed row from base batch if there are any changes to sort columns or array columns. It will fetch the whole row in base batch and apply patch value to it. for array columns, only when array size change will trigger the base batch change, value change while size not change wi

(baseRecordID memCom.RecordID, changedPatchRow []*memCom.DataValue)

Source from the content-addressed store, hash-verified

597// for array columns, only when array size change will trigger the base batch change, value change while size not change will be covered in
598// the unsorted column change
599func (ctx *backfillContext) getChangedBaseRow(baseRecordID memCom.RecordID, changedPatchRow []*memCom.DataValue) []*memCom.DataValue {
600 var changedBaseRow []*memCom.DataValue
601 for columnID, patchValue := range changedPatchRow {
602 // loop through sorted columns and array columns
603 if patchValue != nil && (utils.IndexOfInt(ctx.sortColumns, columnID) >= 0 || ctx.new.Columns[columnID].IsList()) {
604 baseDataValue := ctx.new.Columns[columnID].GetDataValueByRow(int(baseRecordID.Index))
605 // there's change in sorted column or size change in array column
606 if (ctx.new.Columns[columnID].IsList() && memCom.ArrayLengthCompare(&baseDataValue, patchValue) != 0) ||
607 (!ctx.new.Columns[columnID].IsList() && baseDataValue.Compare(*patchValue) != 0) {
608 changedBaseRow = make([]*memCom.DataValue, len(ctx.new.Columns))
609 // Mark deletion for this row.
610 ctx.baseRowDeleted = append(ctx.baseRowDeleted, int(baseRecordID.Index))
611 // Copy the whole row in base batch to changed row and apply the change.
612 for newColumnID := 0; newColumnID < len(ctx.new.Columns); newColumnID++ {
613 if ctx.columnDeletions[newColumnID] {
614 continue
615 }
616 if changedPatchRow[newColumnID] != nil {
617 // column changed, get from patch
618 changedBaseRow[newColumnID] = changedPatchRow[newColumnID]
619 } else {
620 // column unchanged, get from base
621 existingValue := ctx.new.Columns[newColumnID].GetDataValueByRow(int(baseRecordID.Index))
622 changedBaseRow[newColumnID] = &existingValue
623 }
624 }
625 break
626 }
627 }
628 }
629 return changedBaseRow
630}
631
632// writePatchValueForUnsortColumn writes the patch value to forked columns if value changes.
633// this function return false if no column update happens

Callers 2

backfillMethod · 0.95
backfill_test.goFile · 0.80

Calls 4

IndexOfIntFunction · 0.92
CompareMethod · 0.80
IsListMethod · 0.65
GetDataValueByRowMethod · 0.65

Tested by

no test coverage detected