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: Refactor HiveTableOperations with common code for View. #9011

Merged
merged 1 commit into from
Nov 24, 2023

Conversation

nk1506
Copy link
Contributor

@nk1506 nk1506 commented Nov 9, 2023

As part of issues #8698 , as discussed here , All the common piece between table and view has been moved from HiveTableOperations to a new helper class.

@github-actions github-actions bot added the hive label Nov 9, 2023
@nk1506 nk1506 force-pushed the hive_code_duplication branch 2 times, most recently from 28f8a54 to b26cc38 Compare November 9, 2023 05:46
@nk1506 nk1506 marked this pull request as ready for review November 9, 2023 07:06
@nk1506 nk1506 changed the title Refactor HiveTableOperations with common code for View. Hive: Refactor HiveTableOperations with common code for View. Nov 10, 2023
@nk1506 nk1506 force-pushed the hive_code_duplication branch from b26cc38 to a5d969d Compare November 13, 2023 18:37
@nk1506 nk1506 requested a review from pvary November 15, 2023 05:27

String table();

Map<String, String> hmsEnvContext(String metadataLocation);
Copy link
Contributor

Choose a reason for hiding this comment

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

How will this work for View-s?
Any thoughts here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In case of Table envContext is looking like here .
expectedMetadataLocation != null ? ImmutableMap.of( NO_LOCK_EXPECTED_KEY, METADATA_LOCATION_PROP, NO_LOCK_EXPECTED_VALUE, expectedMetadataLocation) : ImmutableMap.of()

In case of View it will look like
expectedMetadataLocation != null ? ImmutableMap.of( BaseMetastoreTableOperations.METADATA_LOCATION_PROP, expectedMetadataLocation) : ImmutableMap.of()

Copy link
Contributor

Choose a reason for hiding this comment

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

The goal of this setting is to send a map to Hive, that only execute the update, if the METADATA_LOCATION_PROP is still expectedMetadataLocation.

If for the views we still use the metadata location, then we probably want to use the same config here as for the tables.

@pvary
Copy link
Contributor

pvary commented Nov 16, 2023

I have one question left, which is somewhat related to the new usage of the HiveOperationsBase

@nk1506 nk1506 force-pushed the hive_code_duplication branch from a5d969d to 5a6c3ac Compare November 18, 2023 03:57
Comment on lines +199 to +200
newHmsTable(
metadata.property(HiveCatalog.HMS_TABLE_OWNER, HiveHadoopUtil.currentUser()));
Copy link
Contributor

@pvary pvary Nov 21, 2023

Choose a reason for hiding this comment

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

I am really sorry for missing this before.

Should we set this generally in the newHmsTable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it was fetching tableOwner from TableMetadata.

Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we have the same tableOwner for views as well?

Copy link
Contributor Author

@nk1506 nk1506 Nov 23, 2023

Choose a reason for hiding this comment

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

For views, I thought it's always going to be CurrentUser. But I think it makes sense to get the tableOwner from ViewMetadata as well if Present.
Still we will have to expect user information from Caller of newHmsTable , right?

Copy link
Contributor

Choose a reason for hiding this comment

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

You might be better positioned to suggest things from the View point of view 😄, but if it were only me, then I would have created the following method in HiveOperationsBase:

default Table newHmsTable(TableMetadata metadata) {
[..]
}

and kept the implementation the same (using the same metadata key to get the owner), like before:

    Preconditions.checkNotNull(metadata, "'metadata' parameter can't be null");
    final long currentTimeMillis = System.currentTimeMillis();

    Table newTable =
        new Table(
            tableName,
            database,
            metadata.property(HiveCatalog.HMS_TABLE_OWNER, HiveHadoopUtil.currentUser()),
            (int) currentTimeMillis / 1000,
            (int) currentTimeMillis / 1000,
            Integer.MAX_VALUE,
            null,
            Collections.emptyList(),
            Maps.newHashMap(),
            null,
            null,
            TableType.EXTERNAL_TABLE.toString());

    newTable
        .getParameters()
        .put("EXTERNAL", "TRUE"); // using the external table type also requires this
    return newTable;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TableMetadata and ViewMetadata both are unrelated. I am not able to find a better approach with newHmsTable(TableMetadata metadata) .
Please suggest.

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably it would be the best to have a common interface for the 2, but we should not hold back this part for it.

@pvary pvary merged commit c817c85 into apache:main Nov 24, 2023
@pvary
Copy link
Contributor

pvary commented Nov 24, 2023

Thanks for all the work and patience @nk1506 !

@nk1506
Copy link
Contributor Author

nk1506 commented Nov 24, 2023

Thanks @pvary for suggesting and reviewing this. I will start rebasing View PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants