Skip to content

HIVE-27957: Better error message for STORED BY - #4954

Merged
deniskuzZ merged 4 commits into
apache:masterfrom
okumin:HIVE-27957-stored-by
Apr 10, 2024
Merged

HIVE-27957: Better error message for STORED BY#4954
deniskuzZ merged 4 commits into
apache:masterfrom
okumin:HIVE-27957-stored-by

Conversation

@okumin

@okumin okumin commented Dec 16, 2023

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

This PR would change an error message thrown when a user gives a wrong storage format in STORED BY.

Why are the changes needed?

The current messages are less informative. I got confused while I was testing Iceberg and non-Iceberg tables in turns.

0: jdbc:hive2://hive-hiveserver2:10000/defaul> CREATE TABLE test (a STRING) STORED BY ORC TBLPROPERTIES ("orc.compress"="ZSTD");
Error: Error while compiling statement: FAILED: SemanticException Cannot find class '' (state=42000,code=40000)
0: jdbc:hive2://hive-hiveserver2:10000/defaul> CREATE TABLE test (a STRING) STORED BY DEFAULT;
Error: Error while compiling statement: FAILED: NullPointerException null (state=42000,code=40000)

Does this PR introduce any user-facing change?

It changes only error messages.

Is the change a dependency upgrade?

No.

How was this patch tested?

I added test cases.

@okumin okumin changed the title [WIP] HIVE-27957: Better error message for STORED BY HIVE-27957: Better error message for STORED BY Dec 16, 2023
@okumin
okumin marked this pull request as ready for review December 16, 2023 11:49
Comment thread ql/src/java/org/apache/hadoop/hive/ql/parse/StorageFormat.java Outdated
Comment thread ql/src/test/results/clientnegative/create_table_stored_by_invalid3.q.out Outdated

@aturoczy aturoczy left a comment

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.

Minor change request

.map(Enum::toString)
.collect(Collectors.joining(", "));
throw new SemanticException(String.format(
"Unrecognized storage handler in STORED BY clause: %s. Supported types = %s or FQCN of a storage handler",

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.

I like this initiative because hive error message is too massy, and need a pilot certificate to understand it. So big plus for it!

On the other hand, I would recommend the following message like:
The storage handler specified in the STORED BY clause is not recognized: %s. Please use one of the supported types, which are %s, or provide the Fully Qualified Class Name (FQCN) of a valid storage handler.

Even thinking the second half of the sentence is too technical.

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 simply followed it as it sounds better. I will update more if anyone has a better idea
136035e

@aturoczy aturoczy left a comment

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.

+1

@akshat0395

Copy link
Copy Markdown
Contributor

Changes LGTM +1, Thanks

@aturoczy

aturoczy commented Jan 7, 2024

Copy link
Copy Markdown
Contributor

@deniskuzZ @ayushtkn @abstractdog Could you pls check this?


public enum StorageHandlerTypes {
DEFAULT(),
ICEBERG("\'org.apache.iceberg.mr.hive.HiveIcebergStorageHandler\'",

@abstractdog abstractdog Jan 8, 2024

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.

wow, what was this backslash used for and why?

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'm not sure about the original intention. IntelliJ asks me to remove the backslash and it seems to be safe to remove.

if (type.name().equalsIgnoreCase(node.getText())) {
inputFormat = type.inputFormat();
outputFormat = type.outputFormat();
assert type.className != null;

@abstractdog abstractdog Jan 8, 2024

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.

assert is not supposed for production AFAIK, please use explicit null checking here, e.g. Objects.requireNonNull

this assertion can be done before assigning inpoutFormat/outputFormat

className(), I guess you might want to use method / direct access consistently

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.

In my opinion, either is fine as this doesn't validate users' input but does assert invariant conditions of enum values for readability. I mean the current implementation doesn't care about the possibility where we add an enum value with null or a wrong class name. What do you think?
As for the direct access, I will fix that.

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.

the problem with assert is that it's not meant for production, it can be completely bypassed with JVM args

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.

Thanks. You mean we'd like this validation to be effective at runtime. I replaced the assertion, rebased it based on the latest master, and then confirmed tests succeeded.
df90d42

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

The SonarCloud Quality Gate passed, but some issues were introduced.

7 New issues
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Feel free to reach out on the dev@hive.apache.org list if the patch is in need of reviews.

@github-actions github-actions Bot added the stale label Mar 11, 2024
@deniskuzZ deniskuzZ removed the stale label Mar 13, 2024
@deniskuzZ

Copy link
Copy Markdown
Member

@abstractdog, could this be merged or some comments are still pending?

@abstractdog
abstractdog self-requested a review April 6, 2024 13:13
@abstractdog

Copy link
Copy Markdown
Contributor

@abstractdog, could this be merged or some comments are still pending?

there are minor comments unaddressed

@abstractdog

Copy link
Copy Markdown
Contributor

LGTM, pending tests

@sonarqubecloud

sonarqubecloud Bot commented Apr 7, 2024

Copy link
Copy Markdown

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@deniskuzZ
deniskuzZ merged commit cf0d4f1 into apache:master Apr 10, 2024
@okumin
okumin deleted the HIVE-27957-stored-by branch April 10, 2024 11:44
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.

6 participants