Skip to content

Compressed Big Decimal Cleanup and Extension - #13048

Merged
cheddar merged 1 commit into
apache:masterfrom
rash67:comp-big-decimal-work-1
Sep 14, 2022
Merged

cheddar merged 1 commit into
apache:masterfrom
rash67:comp-big-decimal-work-1

Conversation

@rash67

@rash67 rash67 commented Sep 7, 2022

Copy link
Copy Markdown
Contributor

This commit:

  1. remove unnecessary generic type from CompressedBigDecimal
  2. support Number input types
  3. support aggregator reading supported input types direclty (uningested data)
  4. fix scaling bug in buffer aggregator

This PR has:

  • [X ] been self-reviewed.
  • [ X] added documentation for new or modified features or behaviors.
  • [ X] added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • [ X] added or updated version, license, or notice information in licenses.yaml
  • [ X] added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • [ X] added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

if (selectedObject != null) {
if (selectedObject.getScale() != sum.getScale()) {
selectedObject = Utils.scaleUp(selectedObject);
selectedObject = Utils.scaleUp(selectedObject, sum.getScale());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason not to push the "scale up" part into the Utils.objToCompressedBigDecimal() call itself?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't think so. we should have this function throw an exception if the scales don't match. it doesn't even document that the scales must match. you have to follow into internalAdd and see that the scale isn't examined

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh and also Utils.objToCompressedBigDecimal() is called in the extractor which doesn't presently have the scale. unless ComplexMetricSerde can have a constructor with params?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and also^2, CBD.accumulate() already does this, but it seems to use Utils.accumulate() to avoid object creation...
(which interestingly makes the generified cbd.accumulate() method with various lambdas kind of pointless...it will be monomorphic in practice. I think the method it uses maybe is only used in tests(?)

basically CBD.accumulate() is only ever called on ArrayCompressedBigDecimal

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might be better to just have 2 impls of CompressedBigDecimal.accumulate() and have the buffer version use Utils.accumulate....

it would be easier to read code (though i'm a little scaled to change CompressedBigDecimal.internalAdd and break it....test coverage seems adequate

CompressedBigDecimal<?> addend = selector.getObject();
CompressedBigDecimal addend = Utils.objToCompressedBigDecimal(selector.getObject());
if (addend != null) {
Utils.accumulate(buf, position, size, scale, addend);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just double checking, this Utils.accumulate() will scale the scale right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i moved it there because

  1. we have access to scale to pass in
  2. accumulate will always be functionally correct

the only reason to move it elsewhere is if we somehow were going to use a CBD more than once in a new scale to avoid repeatedly changing the scale. that doesn't seem the case in druid

@rash67
rash67 force-pushed the comp-big-decimal-work-1 branch 3 times, most recently from c728946 to ad10f41 Compare September 12, 2022 22:35
1. remove unnecessary generic type from CompressedBigDecimal
2. support Number input types
3. support aggregator reading supported input types direclty (uningested
   data)
4. fix scaling bug in buffer aggregator
@rash67
rash67 force-pushed the comp-big-decimal-work-1 branch from ad10f41 to c312e72 Compare September 13, 2022 02:03
@cheddar
cheddar merged commit 54a2eb7 into apache:master Sep 14, 2022
@kfaraz kfaraz added this to the 25.0 milestone Nov 22, 2022
riovic918data pushed a commit to riovic918data/druid that referenced this pull request Jun 12, 2026
1. remove unnecessary generic type from CompressedBigDecimal
2. support Number input types
3. support aggregator reading supported input types directly (uningested
   data)
4. fix scaling bug in buffer aggregator
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants