asereda-gs commented on a change in pull request #1097: [CALCITE-2902] Improve
performance of AbstractRelNode#computeDigest
URL: https://github.com/apache/calcite/pull/1097#discussion_r263902809
##########
File path: core/src/main/java/org/apache/calcite/rel/AbstractRelNode.java
##########
@@ -389,42 +384,68 @@ public RelOptTable getTable() {
* @return Digest
*/
protected String computeDigest() {
- StringWriter sw = new StringWriter();
- RelWriter pw =
- new RelWriterImpl(
- new PrintWriter(sw),
- SqlExplainLevel.DIGEST_ATTRIBUTES, false) {
- protected void explain_(
- RelNode rel, List<Pair<String, Object>> values) {
- pw.write(getRelTypeName());
-
- for (RelTrait trait : traitSet) {
- pw.write(".");
- pw.write(trait.toString());
- }
-
- pw.write("(");
- int j = 0;
- for (Pair<String, Object> value : values) {
- if (j++ > 0) {
- pw.write(",");
- }
- pw.write(value.left);
- pw.write("=");
- if (value.right instanceof RelNode) {
- RelNode input = (RelNode) value.right;
- pw.write(input.getRelTypeName());
- pw.write("#");
- pw.write(Integer.toString(input.getId()));
- } else {
- pw.write(String.valueOf(value.right));
- }
- }
- pw.write(")");
- }
- };
- explain(pw);
- return sw.toString();
+ RelDigestWriter rdw = new RelDigestWriter();
+ explain(rdw);
+ return rdw.digest;
+ }
+
+ /**
+ * A writer object used exclusively for computing the digest of a RelNode.
+ *
+ * <p>The writer is meant to be used only for computing a single digest and
then thrown away.
+ * After calling {@link #done(RelNode)} the writer should be used only to
obtain the computed
Review comment:
maybe add a flag `isDone` and throw `UnsupportedOperationException` when
digest is computed ?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services