Skip to content
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

HIVE-20057: Fix Hive table conversion DESCRIBE table bug #388

Closed
wants to merge 4 commits into from

Conversation

animenon
Copy link

@animenon animenon commented Jul 2, 2018

Fix for #HIVE-20057

Issue: Table Type wrongly shown as MANAGED_TABLE after converting table from MANAGED to EXTERNAL using ALTER TABLE t SET TBLPROPERTIES ('EXTERNAL'='True')

(this is shown correctly only for 'EXTERNAL'='TRUE)

@rmsmani
Copy link
Contributor

rmsmani commented Feb 15, 2019

HI
Create the git diff file and apply in JIRA Ticket, so that the PRE-COMMITS testing will be done automatically.

@rmsmani
Copy link
Contributor

rmsmani commented Feb 15, 2019

Merge the source with your local branch and raise the pull request again, to resolve the conflicting issues.

@animenon
Copy link
Author

@rmsmani done.

@rmsmani
Copy link
Contributor

rmsmani commented Feb 18, 2019

+1

@rmsmani
Copy link
Contributor

rmsmani commented Feb 26, 2019

Hi @ashutosh-bapat, @sankarh
Can you merge the code

@@ -1802,12 +1802,12 @@ private MTable convertToMTable(Table tbl) throws InvalidObjectException,
// accordingly
String tableType = tbl.getTableType();
boolean isExternal = Boolean.parseBoolean(tbl.getParameters().get("EXTERNAL"));
if (TableType.MANAGED_TABLE.toString().equals(tableType)) {
if (TableType.MANAGED_TABLE.toString().equalsIgnoreCase(tableType)) {
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, this issue doesn't exist in master code.
We use Boolean.parseBoolean to read the "EXTERNAL" property which ignores case. Also, the fix in the patch is to use equalsIgnoreCase when compare the TableType and not "EXTERNAL" property which is irrelevant.
If I misunderstood your scenario, please let me know.
Also, it would be better to add a unit test to reproduce this bug in master code.

Copy link
Author

Choose a reason for hiding this comment

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

@sankarh The table type gets converted as expected but the describe formatted view shows it wrongly.
Example: I converted the below Managed table to External using .. SET TBLPROPERTIES ('EXTERNAL'='True')
image

If I do the same using .. SET TBLPROPERTIES ('EXTERNAL'='TRUE')
image

Let me know if you need further details.

Copy link
Contributor

@sankarh sankarh Mar 1, 2019

Choose a reason for hiding this comment

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

@animenon
I tested it myself and it worked fine for me. Probably, you are using different version of Hive or Java.
Take a look at this code (apache/master) which converts managed to external type.
https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java#L4092
It parses EXTERNAL property using Boolean.parseBoolean which ignores case and hence converts to EXTERNAL_TABLE type.

Copy link
Contributor

Choose a reason for hiding this comment

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

Even, if it behaves differently for different cases of EXTERNAL property, still I'm not sure how your fix would solve the issue as you are ignoring case of TableType but not EXTERNAL property. Pls explain.

Copy link
Author

Choose a reason for hiding this comment

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

IgnoreCase used here :
if (TableType.EXTERNAL_TABLE.toString().equalsIgnoreCase(tableType))
for EXTERNAL property and tableType equals check would check if equals ignoring the case of letters.

I agree the tableType ignoreCase here may not be required.

Copy link
Author

@animenon animenon Mar 10, 2019

Choose a reason for hiding this comment

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

Yes the Boolean.parseBoolean would ignore case and give correct isExternal value, but the thing is you wouldn't reach there..

TableType.EXTERNAL_TABLE equals tableType is checked before if (!isExternal) that would fail. ref

Like you pointed out rightly, isExternal ignores case but the flow wouldn't goto that condition because the condition before that fails.

Copy link
Contributor

@sankarh sankarh Mar 11, 2019

Choose a reason for hiding this comment

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

@animenon
Thanks for thr reply! But, I'm still confused.
As per your point, isExternal is proper (both "True" and "TRUE"). But, why would tableType have different case based on input for EXTERNAL property?
Below is the code that reads EXTERNAL property from ALTER TABLE command and sets correct tableType.
https://github.com/apache/hive/blob/master/ql/src/java/org/apache/hadoop/hive/ql/exec/DDLTask.java#L4092

String externalProp = alterTbl.getProps().get("EXTERNAL");
      if (externalProp != null) {
        if (Boolean.parseBoolean(externalProp) && tbl.getTableType() == TableType.MANAGED_TABLE) {
          tbl.setTableType(TableType.EXTERNAL_TABLE);
        } else if (!Boolean.parseBoolean(externalProp) && tbl.getTableType() == TableType.EXTERNAL_TABLE) {
          tbl.setTableType(TableType.MANAGED_TABLE);
        }
      }

If you notice, we use Boolean.parseBoolean(externalProp) here which ignores case.
I didn't get how two values of externalProp ("True" and "TRUE") influences the table type set via setTableType.
Pls point to what I'm missing here.

@rmsmani
Please check if I miss anything.

Copy link
Contributor

Choose a reason for hiding this comment

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

@sankarh
How about changing the condition to equals in the below lines (both if & else condition)
if (Boolean.parseBoolean(externalProp) && tbl.getTableType() == TableType.MANAGED_TABLE) {

Copy link
Contributor

@sankarh sankarh Mar 14, 2019

Choose a reason for hiding this comment

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

@rmsmani and @animenon
HIVE-16324 and HIVE-19753 have already fixed this bug in apache/master. So, this bug doesn't exist anymore.
Probably, you might see it in older Hive versions which doesn't include these patches.
So, please close this jira as invalid.
If you want to push this patch in different branch where the bug exists, then pls let me know.

Copy link
Author

Choose a reason for hiding this comment

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

@sankarh - For the newer version, HIVE-16324 seems to fix it, the version of hive I am using still has this issue, will check my hive version update in appropriate branch.
Thanks for checking on this.

@animenon
Copy link
Author

Handled in HIVE-16324 for Hive v3, will re-raise patch for appropriate version.
Thanks @rmsmani and @sankarh .

@animenon animenon closed this Mar 16, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants