Repository navigation
Add CLI support for MANAGED tables with CLI tests - #1136
Conversation
39ee382 to
24f7d76
Compare
5f24c7b to
35d9bfe
Compare
1ab15fc to
de632df
Compare
| @@ -0,0 +1,13 @@ | |||
| package io.unitycatalog.cli.utils; | |||
There was a problem hiding this comment.
Do you think we need to abstract a common module, and put all the shared classes & utility there, then we don't need to copy everything from server to client. Also the unitycatalog-spark-connector can use the common module.
Please file a separate issue to consider this thing, thanks.
| * "ftp://example.com/file" -> Throws BaseException with message: "Unsupported URI scheme: ftp" | ||
| * </pre> | ||
| */ | ||
| public static String toStandardizedURIString(String inputPath) { |
There was a problem hiding this comment.
Is this the same as FileOperation from the server module ? I really don't want to copy everything that we need to use in client side from the server side..... which is not fixing the tech debt, instead it's producing more tech debt.
There was a problem hiding this comment.
For both FileOperation.java and Constants.java, @tdas mentioned that we want the CLI to be a separate implementation that is only depending on the api models. It's not part of the server so it shouldn't depend on the server.
@tdas thinks it's OK to copy some code here in order to keep the CLI a separate package.
I am not sure how much value it brings to introduce and maintain a common package of these two files.
There was a problem hiding this comment.
Yes. CLI is an model "UC + Delta connector" implementation. Others will look at this implementaiton and implement their own connector. We shouldnt be showing that they need to depend on server and use server's internal classes for this.
There was a problem hiding this comment.
My thought is: it's better for us to abstract a common module, which all the client, server and connector can reuse the same common module. the common module should meet the following requirements:
- Abstracted enough, if not applicable, then may better to keep in the individual module.
- Clean dependencies, no conflicts with other. Since all the
client,server,connectorwill depend on thiscommon, we don't expect thecommonwill mess the runtime dependencies.
The utilties that I can think that can be made to common are:
- The
ApiClientconstruction. I had a comment before: Add an access control test to verify that user can't claim staging table created by other users. #1138 (comment) - General cred props settings for all the 3 cloud vendor. I will assume that lots of places will use it. ---> for example if we want to support streaming write without catalog-based path, then we need to inject those cred props.
- Other utilies, such as env var parser, properties parsers, config keys parsers etc.
There was a problem hiding this comment.
I think that we can further discuss this but it shouldn't be a blocker for this PR?
There was a problem hiding this comment.
+1 on having a separate conversation and not blocking this PR. We should think about
- is it only for our code deduplication, or is it for other connector developers to use. depending on that we should release the common module... or not. various different solutions are possible.
- if we do release the common module, we need to think about API stability guarantees, whether we want to take that. Today we are providing API stability guarantees for the clients (java, python) and very loosely for the server (so that others can start the server in embedded in the jvm. do we want to expand that guarantee to this new module?
| // temporaryCredentials = | ||
| // temporaryCredentialsApi.generateTemporaryPathCredentials( | ||
| // new GenerateTemporaryPathCredential() | ||
| // .url(storageLocation) | ||
| // .operation(PathOperation.PATH_CREATE_TABLE)); |
There was a problem hiding this comment.
Why just remove this commented code ?
There was a problem hiding this comment.
This commented code here is to show the reader how it is supposed to work. Eventually it will be uncommented when it's actually working.
| .operation(TableOperation.READ_WRITE)); | ||
| } else { | ||
| return Paths.get(path); | ||
| throw new CliException("Unknown table type"); |
There was a problem hiding this comment.
nit: Could you please also add the tableType inside the error message ?
| AwsCredentials awsTempCredentials = temporaryCredentials.getAwsTempCredentials(); | ||
| if (awsTempCredentials == null) { | ||
| throw new IllegalArgumentException("AWS temporary credentials are missing"); | ||
| } | ||
| conf.set("fs.s3a.access.key", awsTempCredentials.getAccessKeyId()); | ||
| conf.set("fs.s3a.secret.key", awsTempCredentials.getSecretAccessKey()); | ||
| conf.set("fs.s3a.session.token", awsTempCredentials.getSessionToken()); | ||
| conf.set("fs.s3a.impl", "org.apache.hadoop.fs.s3a.S3AFileSystem"); | ||
| conf.set("fs.s3a.path.style.access", "true"); |
There was a problem hiding this comment.
Could you please also file a separate issue, so that we can reuse the credential properties setting with the
I think the credentials properties setting should be same.
There was a problem hiding this comment.
Not a blocking issue for this PR, but a nice to have issue.
There was a problem hiding this comment.
This is similar to #1136 (comment)
@tdas how do you think about this?
There was a problem hiding this comment.
Thanks for the links, added my comment there: #1136 (comment)
There was a problem hiding this comment.
Also one more general question is: Is it possible for us to provide an abstraction so that we don't need to use the if schema == s3 else if schema == gcp else everywhere, for supporting all the 3 cloud vendors. It make us some kind of hard to maintane and iterate new features.
There was a problem hiding this comment.
@openinx ideally yes. This also depend on the discussion of a common package to decide where it should live. For now I don't think it should block this PR though.
| .catalogName(createTableRequest.getCatalogName()) | ||
| .schemaName(createTableRequest.getSchemaName()) | ||
| .name(createTableRequest.getName()); | ||
| StagingTableInfo stagingTableInfo = tablesApi.createStagingTable(createStagingTableRequest); |
There was a problem hiding this comment.
So for every normal table creation process, it requires us to create the staging table firstly ? Could you please explain more about ? Or is there any reference that I can read ?
There was a problem hiding this comment.
For managed tables, yes. This has description of this process:
https://github.com/delta-io/delta/blob/master/protocol_rfcs/catalog-managed.md#creating-and-dropping-catalog-managed-tables
d6e2b13 to
12432ea
Compare
| FileOperations.toStandardizedURIString( | ||
| json.getString(CliParams.STORAGE_LOCATION.getServerParam())); | ||
| createTable.setStorageLocation(storageLocation); | ||
| // Currently generateTemporaryPathCredentials doesn't quite work yet. So this step has to |
There was a problem hiding this comment.
why does it not work. can you write down the reason?
| } catch (Exception e) { | ||
| if (e instanceof TableAlreadyExistsException | ||
| || e.getCause() instanceof TableAlreadyExistsException) { | ||
| // TODO confirm the schema of the existing table matches the schema of the new table |
There was a problem hiding this comment.
why do we need to do this? are we building create semantics or create or replace semantics?
There was a problem hiding this comment.
This behavior is unchanged by this PR.
A common pattern is that many tests would test the failure cases of table creation. But they often leave the delta table on disk after failing to register a table in UC. Then they retry the table creation on the same location. This would allow those tests to continue.
There was a problem hiding this comment.
got it. but that makes sense of external tables where it is valid to create an external table in the catalog by pointing it to an existing file system table. however, thats not the case of managed tables. for managed tables, every attempt to create a managed table will be in a new path provided by the catalog. so it should never happen that the
does that mean some logic here should change? i think we should allow this exception to be swallowed only when its an external table. if table-already-exists exception is ever hit for a managed table ... thats a cause for alarm.
|
|
||
| private void createTableAndAssertReadTableSucceeds(String tablePath, List<ColumnInfo> columns) | ||
| @Test | ||
| public void testCreateManagedTable() throws IOException, ApiException { |
There was a problem hiding this comment.
should you also test that for managed, non-delta format fails?
think about code coverage a bit
There was a problem hiding this comment.
Are there Server tests that verify non-delta format does not work?
There was a problem hiding this comment.
Added a test here.
Also added a server test case in SdkTableCRUDTest.java:
https://github.com/unitycatalog/unitycatalog/pull/1136/files#diff-9cd3f897dc685e26940078c433780dd3803392311d324afff99dcdd1441c81e3R150
12432ea to
bca129d
Compare
tdas
left a comment
There was a problem hiding this comment.
LGTM. just a few more comments.
Can you confirm that the cli actually manually works from the command line? like you can create managed table when server is started with experimental managed table enabled? test the behavior and the output of the CLI is as expected for the scenarios that you have unit tests for (valid and invalid cases) and see if the output is user friendly
@tdas And if I try to create PARQUET table: And if it's not enabled in server properties: |
7bca4ca to
07bfa32
Compare
- Enhance TableCli with MANAGED table creation - Update DeltaKernelUtils with staging table support and writer capabilities - Add comprehensive test coverage for managed and staging tables This commit completes the staging table feature by adding CLI support and comprehensive test coverage for both server and CLI components. Signed-off-by: Yi Li <[email protected]>
Signed-off-by: Yi Li <[email protected]>
07bfa32 to
e2c6f57
Compare
| URI tablePathUri = URI.create(tablePath); | ||
| Engine engine = getEngine(tablePathUri, awsTempCredentials); | ||
| Engine engine = getEngine(tablePathUri, temporaryCredentials); | ||
| Table table = Table.forPath(engine, substituteSchemeForS3(tablePath)); |
There was a problem hiding this comment.
So basically, this is creating a path-based delta table right ?
There was a problem hiding this comment.
Since we currenlty don't support the managed table creation.
There was a problem hiding this comment.
I don't know the managed vs path-based delta table in the Delta Kernel's context.
This code seems to do the work of constructing a Delta table.
There was a problem hiding this comment.
Yeah, we need to have updated Delta Kernel that can actually construct a Delta table where catalogManaged table feature is enabled.
| TransactionCommitResult commitResult = txn.commit(engine, CloseableIterable.emptyIterable()); | ||
| if (commitResult.getVersion() >= 0) { | ||
| System.out.println("Table created successfully at: " + tablePath); | ||
| LOGGER.info("Table created successfully at: {}", tablePathUri); |
There was a problem hiding this comment.
Thanks for the change, I think we need to disable the System.out.println(), and enforce it in the checkstyle.
| throw new IllegalArgumentException("Failed to create delta table", e); | ||
| String errorMsg = | ||
| String.format("Failed to create Delta table at '%s': %s", tablePath, e.getMessage()); | ||
| LOGGER.error(errorMsg, e); |
There was a problem hiding this comment.
As we will finally throw the exception as root cause to the upper layer, do we still need to log this redudant stacktrace via logger ? I will assume it's not neccessary.
| * "ftp://example.com/file" -> Throws BaseException with message: "Unsupported URI scheme: ftp" | ||
| * </pre> | ||
| */ | ||
| public static String toStandardizedURIString(String inputPath) { |
There was a problem hiding this comment.
My thought is: it's better for us to abstract a common module, which all the client, server and connector can reuse the same common module. the common module should meet the following requirements:
- Abstracted enough, if not applicable, then may better to keep in the individual module.
- Clean dependencies, no conflicts with other. Since all the
client,server,connectorwill depend on thiscommon, we don't expect thecommonwill mess the runtime dependencies.
The utilties that I can think that can be made to common are:
- The
ApiClientconstruction. I had a comment before: Add an access control test to verify that user can't claim staging table created by other users. #1138 (comment) - General cred props settings for all the 3 cloud vendor. I will assume that lots of places will use it. ---> for example if we want to support streaming write without catalog-based path, then we need to inject those cred props.
- Other utilies, such as env var parser, properties parsers, config keys parsers etc.
e2c6f57 to
e75b357
Compare
e75b357 to
04b52f1
Compare
| AwsCredentials awsTempCredentials = temporaryCredentials.getAwsTempCredentials(); | ||
| if (awsTempCredentials == null) { | ||
| throw new IllegalArgumentException("AWS temporary credentials are missing"); | ||
| } | ||
| conf.set("fs.s3a.access.key", awsTempCredentials.getAccessKeyId()); | ||
| conf.set("fs.s3a.secret.key", awsTempCredentials.getSecretAccessKey()); | ||
| conf.set("fs.s3a.session.token", awsTempCredentials.getSessionToken()); | ||
| conf.set("fs.s3a.impl", "org.apache.hadoop.fs.s3a.S3AFileSystem"); | ||
| conf.set("fs.s3a.path.style.access", "true"); |
There was a problem hiding this comment.
Thanks for the links, added my comment there: #1136 (comment)
| conf.set("fs.file.impl", "org.apache.hadoop.fs.LocalFileSystem"); | ||
| } else { | ||
| throw new IllegalArgumentException("Unsupported URI scheme: " + tablePathUri.getScheme()); | ||
| throw new IllegalArgumentException("Unsupported URI scheme: " + scheme); |
There was a problem hiding this comment.
Will we also need to consider the gcp and azure abfs ?
There was a problem hiding this comment.
If so please file separate task to address them, thanks.
| AwsCredentials awsTempCredentials = temporaryCredentials.getAwsTempCredentials(); | ||
| if (awsTempCredentials == null) { | ||
| throw new IllegalArgumentException("AWS temporary credentials are missing"); | ||
| } | ||
| conf.set("fs.s3a.access.key", awsTempCredentials.getAccessKeyId()); | ||
| conf.set("fs.s3a.secret.key", awsTempCredentials.getSecretAccessKey()); | ||
| conf.set("fs.s3a.session.token", awsTempCredentials.getSessionToken()); | ||
| conf.set("fs.s3a.impl", "org.apache.hadoop.fs.s3a.S3AFileSystem"); | ||
| conf.set("fs.s3a.path.style.access", "true"); |
There was a problem hiding this comment.
Also one more general question is: Is it possible for us to provide an abstraction so that we don't need to use the if schema == s3 else if schema == gcp else everywhere, for supporting all the 3 cloud vendors. It make us some kind of hard to maintane and iterate new features.
| new CliOptions( | ||
| List.of(CliParams.FULL_NAME, CliParams.COLUMNS), | ||
| List.of( | ||
| CliParams.FULL_NAME, CliParams.COLUMNS, CliParams.STORAGE_LOCATION), |
There was a problem hiding this comment.
Sounds good to me, thanks for the comment.
| @@ -0,0 +1,13 @@ | |||
| package io.unitycatalog.cli.utils; | |||
There was a problem hiding this comment.
There are actually more and more classes need to be abstracted in the common module. As I commented here: #1136 (comment)
| @@ -0,0 +1,13 @@ | |||
| package io.unitycatalog.cli.utils; | |||
There was a problem hiding this comment.
And think from another hand, if there are only very few API that we need to maintain in common module, then we should be very easy to support the compability. but if there are more and more common classes that we need to maintain in the common module, while we just copy them in every modules, it will be a tough path for us to maintain.
Aslo I think we can limit those common classes to be exposed to the outside.
Signed-off-by: Yi Li <[email protected]>
04b52f1 to
815a7ab
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 updatedAdd CLI support for MANAGED tables and comprehensive tests
Related issue is: #1143