Repository navigation
Support managed table creation - #1135
Conversation
7c101bb to
8000700
Compare
8000700 to
3c41fd4
Compare
e706611 to
402466e
Compare
| | **data\_source\_format** | [**DataSourceFormat**](DataSourceFormat.md) | | [default to null] | | ||
| | **columns** | [**List**](ColumnInfo.md) | The array of __ColumnInfo__ definitions of the table's columns. | [default to null] | | ||
| | **storage\_location** | **String** | Storage root URL for external table | [default to null] | | ||
| | **storage\_location** | **String** | Storage root URL for external table | [optional] [default to null] | |
There was a problem hiding this comment.
Why make this explicitly to be optional ? maybe, one dumb question, for managed table, do people have the access to specify the storage_location as they required, since it's a managed table, then people should not be able to perceive the storage_location.
There was a problem hiding this comment.
It's optional once it's removed from the requried section in all.yaml.
The reason is explained here: #1135 (comment)
| - table_type | ||
| - data_source_format | ||
| - columns | ||
| - storage_location |
There was a problem hiding this comment.
Is this auto-generated, or changed by manual ? seems like it's easily to be broken, I mean forgot to change this, and leave an inconsistent api definition.
There was a problem hiding this comment.
This is intentional.
Previously creating an EXTERNAL always required a storage_location.
With MANAGED tables there are two new ways:
- Create a staging table, then specify TableType=MANAGED and storage_location="staging_table_url" here to create a table
- Skip the staging table part, just create table with TableType=MANAGED and storage_location=null.
Both ways would end up with a managed table with valid managed URL.
There was a problem hiding this comment.
This file is manually changed.
There was a problem hiding this comment.
@tdas decided that we don't want to support the 2nd code path. So I am reverting this line.
| try { | ||
| TableInfo table = | ||
| isTableName | ||
| ? tableRepository.getTable(fullName) | ||
| : tableRepository.getTableById(fullName); | ||
| catalogName = table.getCatalogName(); | ||
| schemaName = table.getSchemaName(); | ||
| tableId = table.getTableId(); | ||
| } catch (BaseException e) { | ||
| if (!isTableName && e.getErrorCode() == ErrorCode.NOT_FOUND) { | ||
| // Check if this is actually a request for staging table. Staging tables are only | ||
| // addressed via their IDs. | ||
| StagingTableInfo stagingTable = stagingTableRepository.getStagingTableById(fullName); | ||
| catalogName = stagingTable.getCatalogName(); | ||
| schemaName = stagingTable.getSchemaName(); | ||
| tableId = stagingTable.getId(); | ||
| } else { | ||
| throw e; | ||
| } | ||
| } |
There was a problem hiding this comment.
Will it be more clear if we just seperate the id-based selection and name-based selection here ?
if (isTableName) {
TableInfo table = tableRepository.getTable(fullName);
catalogName = table.getCatalogName();
schemaName = table.getSchemaName();
tableId = table.getTableId();
} else {
try {
TableInfo table = tableRepository.getTableById(fullName);
catalogName = table.getCatalogName();
schemaName = table.getSchemaName();
tableId = table.getTableId();
} catch (BaseException e) {
if (e.getErrorCode() == ErrorCode.NOT_FOUND) {
StagingTableInfo stagingTable = stagingTableRepository.getStagingTableById(fullName);
catalogName = stagingTable.getCatalogName();
schemaName = stagingTable.getSchemaName();
tableId = stagingTable.getId();
} else {
throw e;
}
}
}| } | ||
|
|
||
| public static Pair<String, String> getCatalogAndSchemaNames(Session session, UUID schemaId) { | ||
| SchemaInfoDAO schemaInfoDAO = |
There was a problem hiding this comment.
nit: could you plesae help to make it to be a full line ?
SchemaInfoDAO schemaInfoDAO = session.get(SchemaInfoDAO.class, schemaId);
| this.catalogRepository = new CatalogRepository(this, sessionFactory); | ||
| this.schemaRepository = new SchemaRepository(this, sessionFactory); | ||
| this.tableRepository = new TableRepository(this, sessionFactory); | ||
| this.tableRepository = new TableRepository(this, sessionFactory, serverProperties); |
There was a problem hiding this comment.
Passing the whole serverProperties to the TableRepository seems strange to me, because the database layer should not be aware of the whole server-side properties. A better option is: use passing the managedTableEnabled boolean switch to the database layer.
There was a problem hiding this comment.
It wants to call a function checkManagedTableEnabled() from serverProperties.
If a boolean from serverProperties is passed into TableRepository, tableRepository and stagingTableRepository will have to check the boolean by themselves.
There was a problem hiding this comment.
i am okay with the server properties being passed as a whole. today there is one property that affects the behavior. tomorrow there may be many more properties. we dont want to keep changing the constructor signature every time. So better in the long run to send the whole serverproperties in the repo
think of it like hadoopConf. hadoopConf passed round everywhere for exactly this reason.
| stagingTableDAO.setStageCommitted(true); | ||
| stagingTableDAO.setStageCommittedAt(now); | ||
| stagingTableDAO.setAccessedAt(now); | ||
| session.merge(stagingTableDAO); |
There was a problem hiding this comment.
What will happen if two contention competitors are committing the same stagingTable at the same time ?
There was a problem hiding this comment.
The session is provided by TransactionManager.executeWithTransaction(... session -> {...})
So it's protected by a DB transaction. This is the same mechanism used for all DB operations in this repo.
| return TransactionManager.executeWithTransaction( | ||
| sessionFactory, | ||
| session -> { | ||
| LOGGER.debug("Getting storage location of table by id: {}", tableId); |
There was a problem hiding this comment.
nit: Please left a blank line to separate the different code blocks, which make it will be more easier to read.
There was a problem hiding this comment.
Do you mean before this line? Or before line 53 the next LOGGER.debug?
There was a problem hiding this comment.
Yea, I think the intention blank line separate the code block, which makes easily to read.
| this.serverProperties = serverProperties; | ||
| } | ||
|
|
||
| public String getStorageLocationForTableOrStagingTable(String tableId) { |
There was a problem hiding this comment.
Why do we need to mix both the normal table access and staging table access in the same method ? because the table id can always belongs to either specified normal table or staging table ?
( this make the code some kind of complicated --- since someone may forget to access the staging table, it's possible to use some abstraction to avoid other forgetting access the staging table ? )
There was a problem hiding this comment.
Do you meaning integrating the staging table access into getTableById to make it impossible to miss staging table?
The problem is that staging table and table are very different. Staging table is very incomplete that it lacks many essential metadata. In most code paths they should not care about staging table. There are only a limited number of scenarios that should access staging tables:
- creating a MANAGED table
- vending a table credential when it's still a staging table
- auth of vending a table credential when it's still a staging table
The other code paths of normal table operations should skip staging tables even if the ID/name matches
Mixing up tables and staging tables will be more error prone.
There was a problem hiding this comment.
Thanks for the context, I understand the staging table is a temporary status which is different from the normal table. Then the question is: how can we clearly org the code or comment , so that the following authors can easily got the points and context from your side, and finally they won't mistake when should we access the staging table and when should not. I think that's the key point.
There was a problem hiding this comment.
Added method doc to clarify the use cases of staging table.
| Pair<String, String> catalogAndSchemaNames = | ||
| RepositoryUtils.getCatalogAndSchemaNames(session, tableInfoDAO.getSchemaId()); | ||
| return tableInfoDAO.toTableInfo( | ||
| true, catalogAndSchemaNames.getLeft(), catalogAndSchemaNames.getRight()); |
There was a problem hiding this comment.
for the fetchColumns=true, is it lazily fetching or sync fetching ?
There was a problem hiding this comment.
It's lazily fetched. But this part is unchanged in this PR anyway. It's just a little code refactor to make it shorter and cleaner.
| if (createTable.getDataSourceFormat() != DataSourceFormat.DELTA) { | ||
| throw new BaseException( | ||
| ErrorCode.INVALID_ARGUMENT, | ||
| "MANAGED table creation is only supported for delta tables."); |
There was a problem hiding this comment.
Is this temporarly support delta only, or future we will support other table types ?
There was a problem hiding this comment.
I don't know about the future. But for now we just support delta tables.
There was a problem hiding this comment.
Okay, I just try to understand if we want to support further tables, then how could we do the changes to support it? Seems like currently we don't have the abstraction to support different types of managed table.....
There was a problem hiding this comment.
We can revise this when different types of managed table is to be supported.
| .accessKeyId(awsSessionCredentials.accessKeyId()) | ||
| .secretAccessKey(awsSessionCredentials.secretAccessKey()) | ||
| .sessionToken(awsSessionCredentials.sessionToken())); | ||
| if (storageScheme != null) { |
There was a problem hiding this comment.
When will the storageScheme to be nullable ?
There was a problem hiding this comment.
If it happens to be a local path like /tmp/something
4f9b239 to
6ad8a38
Compare
| return catalogInfoDAO; | ||
| } | ||
|
|
||
| public static Pair<String, String> getCatalogAndSchemaNames(Session session, UUID schemaId) { |
There was a problem hiding this comment.
this is doing two database query right?
it would be good add this to the methods docs.
e351cfd to
ec00da7
Compare
| UUID schemaId; | ||
| UUID tableId; | ||
| if (isTableName) { | ||
| TableInfo table = tableRepository.getTable(fullName); |
There was a problem hiding this comment.
Line 72-78 is basically doing the same thing as old code line 67,69-74.
| tableId = UUID.fromString(table.getTableId()); | ||
| } else { | ||
| // It may be the ID of either a table or staging table. | ||
| tableId = UUID.fromString(fullName); |
There was a problem hiding this comment.
This block goes to the new function to get catalog&schema ids if the fullName is considered a table ID.
| this.serverProperties = serverProperties; | ||
| } | ||
|
|
||
| public TableInfo getTableById(String tableId) { |
There was a problem hiding this comment.
getTableById is no longer needed.
It is replaced by getCatalogSchemaIdsByTableOrStagingTableId and getStorageLocationForTableOrStagingTable
ec00da7 to
d531938
Compare
| session -> { | ||
| UUID schemaId = getSchemaId(session, catalogName, schemaName); | ||
| UUID schemaId = | ||
| repositories.getSchemaRepository().getSchemaId(session, catalogName, schemaName); |
There was a problem hiding this comment.
super nit: not in this PR, but this seems like a repeated code pattern in many repos that can deduped by having an interface like SchemaUtils that every repo extends to get a simple function getSchemaId(...).
can you make this a issue and mark it as a starter task label so that others can pick it up?
- Update TableService for creation of managed tables - Update API for CreateTable to make storage_location optional for managed tables - Enhance TemporaryTableCredentialsService with staging table support - Update KeyMapper to also check staging tables - Update repository classes to use new helper methods Signed-off-by: Yi Li <[email protected]>
Signed-off-by: Yi Li <[email protected]>
Signed-off-by: Yi Li <[email protected]>
…hod docs to explain why staging table is required. Signed-off-by: Yi Li <[email protected]>
…itory.java Co-authored-by: Tathagata Das <[email protected]> Signed-off-by: Yi Li <[email protected]>
…itory.java Co-authored-by: Tathagata Das <[email protected]> Signed-off-by: Yi Li <[email protected]>
| * @return StagingTableInfo containing the staging table details | ||
| * @throws BaseException with ErrorCode.NOT_FOUND if the staging table does not exist | ||
| */ | ||
| public StagingTableInfo getStagingTableById(String stagingTableId) { |
There was a problem hiding this comment.
Seems like no usage in this PR ? Could we just remove it in this PR, and if it's required in the following PR, then I think it's better to have it in the next PR.
There was a problem hiding this comment.
Removed. I forgot this one when I introduced getCatalogSchemaIdsByTableOrStagingTableId
| * @throws BaseException with ErrorCode.NOT_FOUND if neither a table nor staging table is found | ||
| * with the given ID | ||
| */ | ||
| public String getStorageLocationForTableOrStagingTable(UUID tableId) { |
There was a problem hiding this comment.
Thank you so much for the javadoc, which makes more clear now.
0e8643d to
68f155c
Compare
Signed-off-by: Yi Li <[email protected]>
Signed-off-by: Yi Li <[email protected]>
beee7af to
90c0f2a
Compare
Use this [link](https://github.com/unitycatalog/unitycatalog/pull/1135/files) to review incremental changes. - [**staging_table_service**](unitycatalog#1135) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/1135/files)] - [refactor_base_table_crud_test](unitycatalog#1153) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/1153/files/90c0f2a454c595eeb19df146f38a74e404de61b9..9e82c72fb64a8f5b50a11e0558b01ebb86f906a5)] - [staging_table_cli_test](unitycatalog#1136) [[Files changed](https://github.com/unitycatalog/unitycatalog/pull/1136/files/9e82c72fb64a8f5b50a11e0558b01ebb86f906a5..b7cbb71bbf046d9926394052258e625b9921d303)] --------- **PR Checklist** - [x] A description of the changes is added to the description of this PR. - [x] If there is a related issue, make sure it is linked to this PR. - [ ] If you've fixed a bug or added code that should be tested, add tests! - [ ] If you've added or modified a feature, documentation in `docs` is updated Support managed table creation - Update TableService for creation of managed tables - Update API for CreateTable to make storage_location optional for managed tables - Enhance TemporaryTableCredentialsService with staging table support - Update KeyMapper to also check staging tables - Update repository classes to use new helper methods <!-- Please state what you've changed and how it might affect the users. --> Related issue is: unitycatalog#1143 --------- Signed-off-by: Yi Li <[email protected]> Co-authored-by: Tathagata Das <[email protected]>
🥞 Stacked PR
Use this link to review incremental changes.
PR Checklist
A description of the changes is added to the description of this PR.
If there is a related issue, make sure it is linked to this PR.
If you've fixed a bug or added code that should be tested, add tests!
If you've added or modified a feature, documentation in
docsis updatedSupport managed table creation
Related issue is: #1143