Skip to content

HIVE-28667: Error initializing field trimmer instance when starting HS2 #5879

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zabetak
Copy link
Member

@zabetak zabetak commented Jun 17, 2025

What changes were proposed in this pull request?

  1. Change trimFields(JdbcRel) to trimFields(JdbcSort) to break the ambiguity and avoid the error.
  2. Make CalcitePlanner#HIVE_REL_NODE_CLASSES public mainly to facilitate testing. In fact, it makes sense to expose this information somewhere so why not in CalcitePlanner.

Why are the changes needed?

Avoid the ambiguity exception during HS2 startup. For more details see commit message or HIVE-28667.

Does this PR introduce any user-facing change?

No. There is no change in behavior since anyways the trimmer cannot be called with a JdbcSort operator.

How was this patch tested?

mvn test -Dtest=TestHiveRelFieldTrimmer -pl ql
mvn test -Dtest=TestMiniLlapLocalCliDriver -Dqfile_regex=".*jdbc.*" -pl itests/qtest -Pitests

RelFieldTrimmer class is a reflection based visitor that tries to find the appropriate method based on the type (Class) of the argument. The errors occurs while trying to register a method dispatcher for `JdbcSort.class` since there are multiple candidate methods that qualify:
* trimFields(JdbcRel rel, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields)
* trimFields(Sort sort, ImmutableBitSet fieldsUsed, Set<RelDataTypeField> extraFields)
Given that there is no inheritance relationship between `Sort` and `JdbcRel` it is unclear which method should be used to handle JdbcSort leading to an exception that informs the user/dev about the ambiguous semantics.

It seems that the intention of adding trimFields(JdbcRel...) method was to have a fallback for Jdbc operators that are not handled explicitly by the trimmer but this can never work and creates ambiguity as explained above.
The reason that we get this error only during startup of HS2 and not during compilation is because in the current code it is impossible to call the RelFieldTrimmer code with Jdbc operators other than HiveJdbcConverter and JdbcHiveTableScan.

1. Change trimFields(JdbcRel) to trimFields(JdbcSort) to break the ambiguity and avoid the error. There is no change in behavior since anyways the trimmer cannot be called with a JdbcSort operator.
2. Make CalcitePlanner#HIVE_REL_NODE_CLASSES public mainly to facilitate testing. In fact, it makes sense to expose this information somewhere so why not in CalcitePlanner.
Copy link

@@ -587,6 +576,13 @@ public TrimResult trimFields(
return result(relBuilder.build(), inputMapping);
}

public TrimResult trimFields(
JdbcSort rel,
Copy link
Contributor

@ngsg ngsg Jun 26, 2025

Choose a reason for hiding this comment

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

If I understand correctly, trimFields for JdbcSort is now hiding trimFields for Sort. Then do we need trimFields for JdbcUnion to hide the one for SetOp as well?

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.

3 participants