Skip to content

Conversation

@zhuwenzhuang
Copy link
Contributor

Use RelDataTypeDigest to reduce composite type's digest memory and digest relative operation's latency.
test case: HepPlannerTest.testLargeTypeDigest
This is the first part of latency/memory optimization of large plan.

@zhuwenzhuang zhuwenzhuang changed the title [CALCITE-6907] support RelDataTypeDigest [CALCITE-6907] Support RelDataTypeDigest Jan 22, 2026
@xiedeyantu
Copy link
Member

Thank you for your contribution! I have a few suggestions:
First, please ensure consistency between the Jira title, commit message, and PR title.
Second, please do not arbitrarily change or delete public/protected methods or variables in existing classes (they can be marked as deprecated).
Third, any errors in the CI need to be checked again.

/**
* Digest of a RelDataType.
*/
public interface RelDataTypeDigest {
Copy link
Contributor

Choose a reason for hiding this comment

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

This could be two interfaces, in case Digest is useful somewhere else.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed that the hashCode caching in RelDigest and RexCall already addresses some of the hashCode caching/comparison latency issues. Could you please clarify what you mean by “be two interfaces”?

Copy link
Contributor

Choose a reason for hiding this comment

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

interface HasDigestString {
   String getDigestString()
}

interface RelDataTypeDigest extends HasDigestString {
   RelDataType getType();
}

Other classes may implement HasDigestString.

}

@Override public boolean equals(@Nullable Object obj) {
@Override public boolean deepEquals(Object obj) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you'll need to leave the old implementations around too, they may break users who expect them to exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we allow user to implement equals/hashCode for nested type, cache for hashCode and pointer compare for deepEquals will not work for them.
This situation is similiar to https://issues.apache.org/jira/browse/CALCITE-3786


protected final @Nullable List<RelDataTypeField> fieldList;
protected @Nullable String digest;
protected RelDataTypeDigest digest;
Copy link
Contributor

Choose a reason for hiding this comment

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

Changing protected fields is a breaking change, which has to be reflected in the semantic versioning. This would require a 2.0 release.

Copy link
Contributor

Choose a reason for hiding this comment

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

On the other hand, I don't know what else you can do to make the digest lazy. Maybe other people can weigh on this dilemma. This is why you should probably file a JIRA issue just for this topic and discuss the design there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we can allow user to set String digest to define their own digest. otherwise, we use the RelDataTypeDigest

Copy link
Member

Choose a reason for hiding this comment

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

My suggestion is that some protected/public variables and methods must still be guaranteed to work properly. For example, this
"String digest" might eventually call
"toString" from
"RelDataTypeDigest" to get the value? Because these variables are exposed to users, and someone might currently be using them, we need to provide a compatibility fix. If you think reassigning the original variable would go against your design intention (e.g., it might increase memory usage instead of reducing it), then you need to declare that this is a breaking change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xiedeyantu Thanks, it should be a breaking change. I commented in the commit message.

@zhuwenzhuang zhuwenzhuang changed the title [CALCITE-6907] Support RelDataTypeDigest [CALCITE-7393] Support RelDataTypeDigest Jan 23, 2026
@zhuwenzhuang zhuwenzhuang force-pushed the CALCITE-6907 branch 4 times, most recently from 1f17a42 to 955f537 Compare January 26, 2026 01:49
@zhuwenzhuang zhuwenzhuang marked this pull request as draft January 26, 2026 01:55
@zhuwenzhuang zhuwenzhuang reopened this Jan 26, 2026
use RelDataTypeDigest to reduce composite type's digest
memory and digest relative operation's latency

This is a break change, computeDigest will not set the string
digest field, and innerDigest will be initialized by default.
We recommend users use innerDigest to replace legacy string digest
to archive better memory/latency for nested types.

For users rely on set String digest for UDT, we keep the old behavior
of hashCode/equals.
@sonarqubecloud
Copy link

@zhuwenzhuang zhuwenzhuang marked this pull request as ready for review January 26, 2026 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants