Repository navigation
Add staging table creation support - #1134
Conversation
e46fdf0 to
cc968a8
Compare
| # If no root specified, defaults to file:///tmp | ||
| # Managed tables will be stored under this root in the path: {storageRoot}/tables/{tableId} | ||
|
|
||
| #storageRoot=s3://my-s3-bucket/tables |
There was a problem hiding this comment.
Thanks for adding this configuration, it's more clear. Seems like the table does not use the same style that the model already used, which introduce a naming inconsistent ?
There was a problem hiding this comment.
Renamed to storage-root.tables
| package io.unitycatalog.server.persist.dao; | ||
|
|
||
| import io.unitycatalog.server.model.StagingTableInfo; | ||
| import jakarta.persistence.*; |
There was a problem hiding this comment.
Maybe I need to enforce the checkstyle rules so that we won't introduce more * package here.
There was a problem hiding this comment.
Added it into this checkstyle improvement issue: #1142
| setCreatedAt(now); // Assuming current date for creation | ||
| setAccessedAt(now); // Assuming current date for last access | ||
| setStageCommitted(false); | ||
| setStageCommittedAt(null); |
There was a problem hiding this comment.
Seems like the stageCommitedAt is not nullable ? https://github.com/unitycatalog/unitycatalog/pull/1134/files#diff-aed7cf4e21b6a76835fc042779f60235d3e236398f146f9bcd112a348548c455R44
Is it able to set it to null here ?
There was a problem hiding this comment.
Oh, sorry. It's nullable.
| .schemaName(schemaName) | ||
| .tableType(TableType.valueOf(type)) | ||
| .dataSourceFormat(DataSourceFormat.valueOf(dataSourceFormat)) | ||
| .storageLocation(FileOperations.convertRelativePathToURI(url)) |
There was a problem hiding this comment.
What's the difference for this change ?
There was a problem hiding this comment.
It's about the same thing but with subtle differences:
- the new function checks that URL is from either local or a supported cloud.
- it avoids adding a trailing slash to local path
It's renamed because now it also cares about cloud urls.
There was a problem hiding this comment.
thank you for explaining. i had the same question
| * @throws BaseException with ErrorCode.NOT_FOUND if the specified catalog or schema does not | ||
| * exist | ||
| */ | ||
| public StagingTableInfo createStagingTable(CreateStagingTable createStagingTable) { |
There was a problem hiding this comment.
Seems no usage for this method, do we still need it ?
There was a problem hiding this comment.
The actual usage is in next PR. I have to split this to avoid a bigger than 500 lines PR.
There was a problem hiding this comment.
Got it, thanks for the explannation.
cc968a8 to
5019378
Compare
| #storage-root.tables=s3://my-s3-bucket/tables | ||
| #storage-root.tables=abfs://file_system@account_name.dfs.core.windows.net/tables | ||
| #storage-root.tables=gs://my-gc-bucket/tables | ||
| #storage-root.tables=file:///tmp |
There was a problem hiding this comment.
should we have a default local path defined like its for models? its will still be disabled by default
| } | ||
|
|
||
| private static URI adjustFileUri(URI fileUri) { | ||
| private static URI adjustLocalFileURI(URI fileUri) { |
There was a problem hiding this comment.
can add docs on what this method does? what kind of adjustment? maybe we can name it better?
i know this function was already there.. but lets togeter make an attempt to improve the code quality along the way. 🙏
| * ErrorCode.INVALID_ARGUMENT if it's disabled. | ||
| */ | ||
| public void checkManagedTableEnabled() { | ||
| String managedTableEnabled = getProperty("server.managed-table.enabled", "false"); |
There was a problem hiding this comment.
can defined a VARIABLE name for this string.
There was a problem hiding this comment.
and i a separate PR define constants variables for all the property strings
There was a problem hiding this comment.
Will do a follow up PR for this.
There was a problem hiding this comment.
A follow up PR https://github.com/unitycatalog/unitycatalog/pull/1144/commits (with this extra commit 1f84431 ) is sent
| "io.grpc" % "grpc-context" % "1.65.1", | ||
| "io.grpc" % "grpc-api" % "1.65.1", | ||
| "com.google.cloud" % "google-cloud-core" % "2.41.0", | ||
| "com.google.api" % "gax-grpc" % "2.48.0", |
There was a problem hiding this comment.
why are all these build changed needed??
There was a problem hiding this comment.
Removed. These are from the prototype. I guess they may be needed in order to enable the CLI tools to work with cloud files. But I am not sure as I haven't tested against cloud files.
c87c6a9 to
aebbe15
Compare
| Create a staging table | ||
|
|
||
| Creates a new staging table instance. Staging tables are used during managed table creation. Creating a managed table requires performing two actions – initializing the table data in cloud storage and creating the named table entry in the catalog – and these should appear as an atomic operation to other operations on catalog tables. A staging table is used to allocate storage for the managed table, and the catalog_name.schema_name.name parameters provided in this request are used to initialize any required storage properties and determine the storage URL that should be used for the data contained by this table. Temporary credentials can be obtained as though the staging table were a regular table to get access to the staging table’s storage. After the table’s data is initialized, the staging table is “promoted” to a managed table by creating a managed table with the same location as the staging table. This allows for the atomic creation of a managed table that already has full data written to its storage location. Note: the name provided must match the name used to initialize the staging table originally. WARNING: This API is experimental and will change in future versions. | ||
| Creates a new staging table instance. Staging tables are used during managed table creation. Creating a managed table requires performing two actions – initializing the table data in cloud storage and creating the named table entry in the catalog – and these should appear as an atomic operation to other operations on catalog tables. A staging table is used to allocate storage for the managed table, and the catalog_name.schema_name.name parameters provided in this request are used to initialize any required storage properties and determine the storage URL that should be used for the data contained by this table. Temporary credentials can be obtained as though the staging table were a regular table to get access to the staging table’s storage. After the table’s data is initialized, the staging table is “promoted” to a managed table by creating a managed table with the same location as the staging table. This allows for the atomic creation of a managed table that already has full data written to its storage location. Note: the name provided must match the name used to initialize the staging table originally. WARNING: This API is experimental and may change in future versions. |
There was a problem hiding this comment.
Nit: what's the change for this line ?
There was a problem hiding this comment.
That's the will->may change to address the comment on the last PR.
There was a problem hiding this comment.
thank you for addressing this.
| ## Experimental Feature Flags | ||
| # Enable MANAGED table (experimental feature) | ||
| # Default: false (disabled) | ||
| server.managed-table.enabled=false |
There was a problem hiding this comment.
if I remember correctly, for the catalog owned table seems like we are using the word catalog-owned for the table name. I'm not sure if we need to align with them ?
There was a problem hiding this comment.
catalogOwned means using UC as commit coordinator.
Here the managed table only means that the path is managed by UC.
There was a problem hiding this comment.
actually... slight nuance.
- from the delta protocol perspective catalogOwned means its own by some catalog... UC or otherwise.. and changes to the table needs to coordinated through the catalog, not by the usual filesystem atomic put if absent.
- UC Managed tables is going to be designed using "catalogOwned" delta tables.
There was a problem hiding this comment.
So here can I assume that this type of table, using UC assigned storage path and using catalog as commit coordinator, will be advertised as MANAGED table as its brand name?
If yes, this switch will be used for both code paths.
There was a problem hiding this comment.
Okay, then managed table is a user-facing product concept, while the catalogOwned seems like a technical concept, which specify who will coordinate the commit process.
Then here we defintely should use managed table.
There was a problem hiding this comment.
Absolutely right. "managed table" is user-facing UC-specific product concept, and catalogOwned is a internal implementation detail of how managed table implemented using delta's catalogOwned protocol. So for a UC server configuration, we should use "managed table"
| #storage-root.tables=s3://my-s3-bucket/tables | ||
| #storage-root.tables=abfs://file_system@account_name.dfs.core.windows.net/tables | ||
| #storage-root.tables=gs://my-gc-bucket/tables | ||
| storage-root.tables=file:///tmp/ucroot |
There was a problem hiding this comment.
the storage-root.tables seems imply that we can configure the multiple paths for different tables , do I understand correctly ?
There was a problem hiding this comment.
Or for the single uc server, we can only configure one path for the process ?
There was a problem hiding this comment.
storage-root.tables specify a storage root for all managed tables. Each table will be placed at {storage-root.tables}/tables/{tableId}
With this change only one storage root for all managed tables can be specified for a single UC server.
There was a problem hiding this comment.
Make sense, thanks for the explanation !
| package io.unitycatalog.server.persist.dao; | ||
|
|
||
| import io.unitycatalog.server.model.StagingTableInfo; | ||
| import jakarta.persistence.*; |
There was a problem hiding this comment.
Added it into this checkstyle improvement issue: #1142
| @Column(name = "schema_id") | ||
| private UUID schemaId; | ||
|
|
||
| @Column(name = "staging_location", length = 2048, nullable = false) |
There was a problem hiding this comment.
Does the spec explicitly state that the field is limited to 2048 bytes ?
There was a problem hiding this comment.
Just wanted to confirm that all the spec are matched.
There was a problem hiding this comment.
Where can I find the spec?
This limit was just copied from TableInfoDAO.url
There was a problem hiding this comment.
I also don't know, just want to cofirm. Maybe we can leave it here, and open a issue to review all of the field limitation for all API.
| } | ||
|
|
||
| public static Pair<String, String> getCatalogAndSchemaNames(Session session, UUID schemaId) { | ||
| SchemaInfoDAO schemaInfoDAO = |
There was a problem hiding this comment.
Nit: our checkstyle seems need to make a line as long as possible , so that it reach the 100 chars.
SchemaInfoDAO schemaInfoDAO = session.get(SchemaInfoDAO.class, schemaId);
if (schemaInfoDAO == null) {
throw new BaseException(
ErrorCode.NOT_FOUND, "Schema not found: " + schemaId);
}Let me consider how to enforce it.
| session.get(SchemaInfoDAO.class, schemaId); | ||
| if (schemaInfoDAO == null) { | ||
| throw new BaseException( | ||
| ErrorCode.NOT_FOUND, "Schema not found: " + schemaId); |
There was a problem hiding this comment.
Do we need to make it more clear ? the following schemaId is actually a schema id , not schema name or something.
There was a problem hiding this comment.
This function tries to find a schema (and its name) by id. At this stage if the schema itself is missing, only the id can be known.
There was a problem hiding this comment.
This error message isn't useful to end user. This internal error reflects an inconsistent state of the database, not user error, and is only useful for debugging.
| session.get(CatalogInfoDAO.class, schemaInfoDAO.getCatalogId()); | ||
| if (catalogInfoDAO == null) { | ||
| throw new BaseException( | ||
| ErrorCode.NOT_FOUND, "Catalog not found: " + schemaInfoDAO.getCatalogId()); |
| public UUID getCatalogId(Session session, String catalogName) { | ||
| CatalogInfoDAO catalogInfo = getCatalogDAO(session, catalogName); | ||
| if (catalogInfo == null) { | ||
| throw new BaseException(ErrorCode.NOT_FOUND, "Catalog not found: " + catalogName); |
There was a problem hiding this comment.
Here it's indeed a catalog name.
| * @throws BaseException with ErrorCode.NOT_FOUND if the specified catalog or schema does not | ||
| * exist | ||
| */ | ||
| public StagingTableInfo createStagingTable(CreateStagingTable createStagingTable) { |
There was a problem hiding this comment.
Got it, thanks for the explannation.
|
|
||
| // Netty dependencies | ||
| "io.netty" % "netty-all" % "4.1.111.Final", | ||
| "jakarta.annotation" % "jakarta.annotation-api" % "3.0.0" % Provided, |
There was a problem hiding this comment.
there is no test for the new functionality in this PR?
can you not test this until the changes in the 3rd PR?
how much extra LOC will be in this PR IF we merge the changes with tests in that PR into this PR?
There was a problem hiding this comment.
The majority changes of this PR is in StagingTableDAO.java and StagingTableRepository.java. They are essentially dead code until the next PR is in and until a test actually turns them on with server.managed-table.enabled=true.
In the code base there isn't usually a test for repository or dao under io/unitycatalog/server/persist. But instead the actual service handler will be tested via sdk or cli calling. In order to test these logics the next PR of adding service handler will be needed.
On the other hand I do see a small test FileOperationsTest.java from next PR that can be moved here if LOC of this PR isn't concern as it's already slightly above 500 lines. This small test targets FileOperations.toStandardizedURIString introduced here.
There was a problem hiding this comment.
- Add StagingTableDAO and StagingTableRepository for staging table persistence - Enhance FileOperations with URI conversion and validation utilities - Update TableRepository to support staging tables and refactor path handling - Add ServerProperties for managed table configuration - Update schema and catalog repositories with helper methods - Add Constants for URI scheme handling This commit provides the foundational infrastructure for staging table support without breaking existing functionality. Signed-off-by: Yi Li <[email protected]>
aebbe15 to
061eb3f
Compare
| ) ++ javacRelease17, | ||
| libraryDependencies ++= Seq( | ||
| "com.linecorp.armeria" % "armeria" % "1.28.4", | ||
| "org.apache.commons" % "commons-lang3" % "3.19.0", |
There was a problem hiding this comment.
This is not new usage. But existing test is failing on main branch. I had another PR fixing it and this comment describes the failure point.
If you prefer this can be fixed in that PR.
|
why are tests failing? |
The failed test integrations/langchain/tests/test_langchain_toolkit_oss.py::test_langgraph_agents is failing to configure credential on main branch. I have notified the ai maintainer. |
| #storage-root.tables=s3://my-s3-bucket/tables | ||
| #storage-root.tables=abfs://file_system@account_name.dfs.core.windows.net/tables | ||
| #storage-root.tables=gs://my-gc-bucket/tables | ||
| storage-root.tables=file:///tmp/ucroot |
There was a problem hiding this comment.
Make sense, thanks for the explanation !
| @Column(name = "schema_id") | ||
| private UUID schemaId; | ||
|
|
||
| @Column(name = "staging_location", length = 2048, nullable = false) |
There was a problem hiding this comment.
I also don't know, just want to cofirm. Maybe we can leave it here, and open a issue to review all of the field limitation for all API.
| private String stagingLocation; | ||
|
|
||
| @Column(name = "created_at", nullable = false) | ||
| private Date createdAt; |
There was a problem hiding this comment.
Got it, those are internal fields, which won't expose to user. Thanks for the explanation !
| } | ||
| } | ||
| } catch (URISyntaxException e) { | ||
| // Not a valid URI, treat it as a file path |
There was a problem hiding this comment.
In that case, will think it should be naturelly throw it out ? Seems like it's an invalid path string for this method to standarnize.
Also it's one kind of the exception that you mentioned, which may is possible to fallback to local file path. There are all kinds of exceptions that we may also don't know, we all fallback to local file path, which seems to be incorrect.
| * @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.
Could you please remove this in this PR, if we neither have any usage for it or test for it ? Because it seems unrelated to the changes.
If it's for the next PR, then it will be better to introduce in the next PR. since we can have test for that.
| stagingTableDAO.setSchemaId(schemaId); | ||
| stagingTableDAO.setName(createStagingTable.getName()); | ||
| stagingTableDAO.setStagingLocation(stagingLocation); | ||
| stagingTableDAO.setCreatedBy(callerId); |
There was a problem hiding this comment.
Do we also need to set other non-nullable fields also ? I'm not sure, just question.
There was a problem hiding this comment.
They are set in stagingTableDAO.setDefaultFields();
c3eed90 to
458b452
Compare
1. introduce the new changes of StagingTableService.java 2. remove the part that does staging table commit in TableRepository.java and StagingTableRepository.java 3. adding test in SdkTableCRUDTest.java Signed-off-by: Yi Li <[email protected]>
458b452 to
f803902
Compare
|
I have shuffled changes between this PR and next PRs. Now this PR contains the service RPC handler of staging table creation along with RPC test of staging table creation. Please take another look. |
| return catalogInfoDAO; | ||
| } | ||
|
|
||
| public static Pair<String, String> getCatalogAndSchemaNames(Session session, UUID schemaId) { |
There was a problem hiding this comment.
Nit: Seems this method is useless for this PR, then I think we can remove it in this PR.
|
|
||
| /** Test that staging table creation fails when the catalog doesn't exist. */ | ||
| @Test | ||
| public void testStagingTableCreationWithNonExistentCatalogShouldFail() throws Exception { |
There was a problem hiding this comment.
Nit: we can remove this throws Exception, since no exception will be thrown.
7a955b2 to
72dbbba
Compare
Signed-off-by: Yi Li <[email protected]>
72dbbba to
811ec6d
Compare
|
Seems unrelated failure tests. tests/test_langchain_toolkit_oss.py: 40 warnings
/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/pyspark/sql/pandas/utils.py:51: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
if LooseVersion(pandas.__version__) < LooseVersion(minimum_pandas_version):
tests/test_langchain_toolkit_oss.py: 40 warnings
/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/pyspark/sql/pandas/utils.py:85: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
if LooseVersion(pyarrow.__version__) < LooseVersion(minimum_pyarrow_version):
tests/test_langchain_toolkit_oss.py: 40 warnings
/opt/hostedtoolcache/Python/3.10.19/x64/lib/python3.10/site-packages/pyspark/sql/connect/utils.py:59: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
if LooseVersion(grpc.__version__) < LooseVersion(minimum_grpc_version):
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
=========================== short test summary info ============================
FAILED integrations/langchain/tests/test_langchain_toolkit_oss.py::test_langgraph_agents - ValueError: default auth: cannot configure default credentials, please check https://docs.databricks.com/en/dev-tools/auth.html#databricks-client-unified-authentication to configure credentials for your preferred authentication method.Let's try again. |
tdas
left a comment
There was a problem hiding this comment.
this is great. thank you for adding the missing functionality
**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
Add staging table creation support
- Add StagingTableDAO, StagingTableRepository and StagingTableService
for staging table creation
- Enhance FileOperations with URI conversion and validation utilities
- Add ServerProperties for managed table configuration
- Update schema and catalog repositories with helper methods
- Add Constants for URI scheme handling
Related issue is:
unitycatalog#1143
---------
Signed-off-by: Yi Li <[email protected]>
**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
Add staging table creation support
- Add StagingTableDAO, StagingTableRepository and StagingTableService
for staging table creation
- Enhance FileOperations with URI conversion and validation utilities
- Add ServerProperties for managed table configuration
- Update schema and catalog repositories with helper methods
- Add Constants for URI scheme handling
Related issue is:
unitycatalog#1143
---------
Signed-off-by: Yi Li <[email protected]>
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 staging table creation support
Related issue is: #1143