ReduceResolution reduces the histogram's spans, buckets into target schema. An error is returned in the following cases: - The target schema is not smaller than the current histogram's schema. - The histogram has custom buckets. - The target schema is a custom buckets schema. - Any spans have an inv
(targetSchema int32)
| 625 | // - Any spans have an invalid offset. |
| 626 | // - The spans are inconsistent with the number of buckets. |
| 627 | func (h *Histogram) ReduceResolution(targetSchema int32) error { |
| 628 | // Note that the follow three returns are not returning a |
| 629 | // histogram.Error because they are programming errors. |
| 630 | if h.UsesCustomBuckets() { |
| 631 | return errors.New("cannot reduce resolution when there are custom buckets") |
| 632 | } |
| 633 | if IsCustomBucketsSchema(targetSchema) { |
| 634 | return errors.New("cannot reduce resolution to custom buckets schema") |
| 635 | } |
| 636 | if targetSchema >= h.Schema { |
| 637 | return fmt.Errorf("cannot reduce resolution from schema %d to %d", h.Schema, targetSchema) |
| 638 | } |
| 639 | |
| 640 | var err error |
| 641 | |
| 642 | if h.PositiveSpans, h.PositiveBuckets, err = reduceResolution( |
| 643 | h.PositiveSpans, h.PositiveBuckets, h.Schema, targetSchema, true, true, |
| 644 | ); err != nil { |
| 645 | return err |
| 646 | } |
| 647 | if h.NegativeSpans, h.NegativeBuckets, err = reduceResolution( |
| 648 | h.NegativeSpans, h.NegativeBuckets, h.Schema, targetSchema, true, true, |
| 649 | ); err != nil { |
| 650 | return err |
| 651 | } |
| 652 | h.Schema = targetSchema |
| 653 | return nil |
| 654 | } |