Skip to content

handle catalog and namespace properly in Iceberg REST api - #324

Merged
alexreid-db merged 7 commits into
unitycatalog:mainfrom
alexreid-db:handle-catalog-properly-iceberg-rest
Nov 12, 2024
Merged

alexreid-db merged 7 commits into
unitycatalog:mainfrom
alexreid-db:handle-catalog-properly-iceberg-rest

Conversation

@alexreid-db

@alexreid-db alexreid-db commented Aug 5, 2024 •

Copy link
Copy Markdown
Collaborator

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 docs is updated

Description of changes

Prior to this PR, users were required to lookup namespace and tables by supplying the uc catalog name in the namespace identifier which isn't proper and lead to problems. This PR implements the REST client flow of configuring calls to the API with a defined prefix containing the catalog name. The catalog name is now part of the API paths and broken apart from the namespace.

Client (passes warehouse parameter) -> Server Config Endpoint (response has override for URL prefix) -> Client
Subsequent calls to the API now has url prefixed with /catalogs/{warehouse/catalog-name}

This PR "binds" the spark catalog to a UC catalog using the client config endpoint. Users must now add to their catalog configurations something like (example in spark):

"spark.sql.catalog.<spark-catalog-name>.warehouse": "<catalog-name>" and now address tables like <spark-catalog-name>.<namespace-name>.<table-name>

This should address #182 and parts of #3.

@alexreid-db
alexreid-db requested a review from MrPowers as a code owner August 5, 2024 17:57
@alexreid-db
alexreid-db requested review from creechy, haogang and tdas August 5, 2024 18:08
@alexreid-db
alexreid-db force-pushed the handle-catalog-properly-iceberg-rest branch from 6d31dbc to 7fa4aca Compare August 8, 2024 22:51
@alexreid-db

Copy link
Copy Markdown
Collaborator Author

@creechy @tdas @ramesh-db It would be good to get this one in if anyone has cycles to give this a review.

}
// ListNamespaces from catalog
{
/*{

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

should we remove this?

@vikrantpuppala vikrantpuppala left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

minor comment but lgtm

When querying Iceberg REST Catalog for Unity Catalog, tables are identified using the following pattern `iceberg.<catalog-name>.<schema-name>.<table-name>` (e.g. `iceberg.unity.default.marksheet_uniform`).
When querying Iceberg REST Catalog for Unity Catalog, tables are identified using the following pattern `iceberg.<schema-name>.<table-name>` (e.g. `iceberg.default.marksheet_uniform`).

NOTE: If you want your Spark catalog name to be the same as your UC catalog name, replace `iceberg` in the above configurations with `<catalog-name>`, then tables are identified by the following pattern `<catalog-name>.<schema-name>.<table-name>` (e.g. `unity.default.marksheet_uniform`).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit / followup item: I think we might want to take a clarity pass on the docs here (I remember this being a little confusing back when I was starting w/ spark). Shouldn't block this PR though

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm confused about the difference between "Spark catalog name" and "UC catalog name". An Iceberg Catalog doesn't actually have a name that is part of the SQL identifier. Outside of the Iceberg Catalog, each engine will refer to the catalog using its own alias.

The fully qualified identifier to a table in the Iceberg Catalog is engine specific. So for engine A, the identifier to a particular table may look like:

CatalogForEngineA.namespace.table

And for engine B, the identifier may look like:

CatalogForEngineB.namespace.table

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Note that we would now be configuring a UC catalog per REST client through the warehouse config parameter.

In Spark for instance, you can set the Spark/Engine catalog name to whatever you want in the configuration. This is just saying if you want the Engine catalog name to match up to the UC catalog name you have set, then you would want to set the Engine catalog name to the UC catalog name.

Let's say I have a UC catalog named main and a schema named default that has tables in it named table1 and table2.

I could set a spark configuration to access this like:

"spark.sql.catalog.iceberg": "org.apache.iceberg.spark.SparkCatalog",
"spark.sql.catalog.iceberg.catalog-impl": "org.apache.iceberg.rest.RESTCatalog",
"spark.sql.catalog.iceberg.uri": "http://127.0.0.1:8080/api/2.1/unity-catalog/iceberg",
"spark.sql.catalog.iceberg.warehouse": "main"

I would then in spark-sql, list tables like so:

>show tables from iceberg.default;
table1
table2

If I wanted to make it so I could address the schemas/tables using the actual UC catalog name for the UC catalog I configured the Spark catalog for, then I would do:

"spark.sql.catalog.main": "org.apache.iceberg.spark.SparkCatalog",
"spark.sql.catalog.main.catalog-impl": "org.apache.iceberg.rest.RESTCatalog",
"spark.sql.catalog.main.uri": "http://127.0.0.1:8080/api/2.1/unity-catalog/iceberg",
"spark.sql.catalog.main.warehouse": "main"

>show tables from main.default;
table1
table2

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I see now. That makes sense. This diagram was helpful to understand the difference between the metastore vs catalog. https://docs.databricks.com/en/data-governance/unity-catalog/index.html#the-unity-catalog-object-model

Thanks for explaining!

}

@Get("/v1/namespaces/{namespace}/tables/{table}")
@Get("/v1/catalogs/{catalog}/namespaces/{namespace}/tables/{table}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What is the purpose of acatalog part here? The Iceberg specification doesn't have such concept, and this change would further deviate from the spec defined at https://github.com/apache/iceberg/blob/main/open-api/rest-catalog-open-api.yaml#L240-L254
Parent namespaces should be nested into a parent= GET parameter to conform the specification.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This does not deviate from the spec and is valid use of {prefix} as defined in the spec.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well isn't catalog part of the namespace here? If it is, the listNamespaces query should have a parent param, and listTables should use the %1F separator.

I don't think {prefix} was really meant to be used this way. Like what's the meaning of /v1/{prefix}/transactions/commit then (as seen here) if we give a catalog name there?

@alexreid-db alexreid-db Sep 19, 2024 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Well isn't catalog part of the namespace here

We are/would be saying that catalog is NOT considered part of the namespace.

I don't think {prefix} was really meant to be used this way.

Again, this is valid to the spec where an implementation performs operations within in the context of a catalog.

@szlta szlta Sep 19, 2024 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

catalog is NOT considered part of the namespace.

Then it makes sense of course.
But: catalog did use to be part of the namespace and on top of that, a client would be restricted to work with only one catalog from now on. That strikes me as a rather larger structural change compared to just a namespace separator fix, wouldn't you agree?

Also - how is this going to be backward compatible with older client versions? (Considering those that provided . as separator of course..)

Edit:
one more thing: I belive this also takes away the possibility for clients to discover what catalogs there are? Should we plan to substitute the lost functionality somehow?

@alexreid-db alexreid-db Sep 19, 2024 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

But: catalog did use to be part of the namespace and on top of that, a client would be restricted to work with only one catalog from now on. That strikes me as a rather larger structural change compared to just a namespace separator fix, wouldn't you agree?

Not if we felt the original implementation was incorrect. Other IRC implementations (Tabular, Polaris) utilize the prefix in this way and separate out a entity like catalog/warehouse and do not consider it to be part of the namespace so this is not a new/foreign concept.

I agree that using the . was not to spec for namespace separating, but since we consider the catalog to not be part of the namespace and UC OSS only has 1 level for namespace (Schema), we don't have to worry about a separator for now (and only if later it is decided UC wants to support nested schemas/namespaces).

Also - how is this going to be backward compatible with older client versions? (Considering those that provided . as separator of course..)

0.2 hasn't even been released yet, so not sure why anyone would expect it to be "stable" as far as things like this.
Also, per the spec, REST clients should be hitting the config endpoint first to get configurations.

one more thing: I belive this also takes away the possibility for clients to discover what catalogs there are? Should we plan to substitute the lost functionality somehow?

UC OSS has other endpoints for this that are not part of the IRC spec. (so this can be done through the cli, UI, etc.)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Okay, thanks for explaining @alexreid-db

@alexreid-db
alexreid-db force-pushed the handle-catalog-properly-iceberg-rest branch from 7fa4aca to e5f6536 Compare October 29, 2024 23:10
@alexreid-db
alexreid-db force-pushed the handle-catalog-properly-iceberg-rest branch from 84f3bd9 to 8a3012c Compare October 30, 2024 15:08
.isEqualTo(
"{\"defaults\":{},\"overrides\":{\"prefix\":\"catalogs/"
+ TestUtils.CATALOG_NAME
+ "\"}}");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can you add a test to ensure that non-warehouse fails?

.containsExactly(TableIdentifier.of(TestUtils.SCHEMA_NAME, TestUtils.TABLE_NAME));
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why remove these tests?

and can you also add tests that test failure of non-catalog-prefixed urls

@alexreid-db
alexreid-db force-pushed the handle-catalog-properly-iceberg-rest branch from 8a3012c to a9bd565 Compare November 12, 2024 00:28

@tdas tdas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thank you for this @alexreid-db this is great!

@tdas

tdas commented Nov 12, 2024

Copy link
Copy Markdown
Contributor

can you fix the DCO stuff? see the failing test.

@alexreid-db
alexreid-db force-pushed the handle-catalog-properly-iceberg-rest branch from d9ddde4 to 9ff7c35 Compare November 12, 2024 01:14
Signed-off-by: Alex Reid <[email protected]>
Signed-off-by: Alex Reid <[email protected]>
Signed-off-by: Alex Reid <[email protected]>
Signed-off-by: Alex Reid <[email protected]>
Signed-off-by: Alex Reid <[email protected]>
Signed-off-by: Alex Reid <[email protected]>
@alexreid-db
alexreid-db force-pushed the handle-catalog-properly-iceberg-rest branch from d4caf29 to ec78b1d Compare November 12, 2024 22:27
@alexreid-db
alexreid-db merged commit 3bf4a01 into unitycatalog:main Nov 12, 2024
creechy pushed a commit to creechy/unitycatalog that referenced this pull request Nov 15, 2024
…og#324)

**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.
- [x] If you've fixed a bug or added code that should be tested, add
tests!
- [x] If you've added or modified a feature, documentation in `docs` is
updated

**Description of changes**

Prior to this PR, users were required to lookup namespace and tables by
supplying the uc catalog name in the namespace identifier which isn't
proper and lead to problems. This PR implements the REST client flow of
configuring calls to the API with a defined prefix containing the
catalog name. The catalog name is now part of the API paths and broken
apart from the namespace.

Client (passes warehouse parameter) -> Server Config Endpoint (response
has override for URL prefix) -> Client
Subsequent calls to the API now has url prefixed with
`/catalogs/{warehouse/catalog-name}`

This PR "binds" the spark catalog to a UC catalog using the client
config endpoint. Users must now add to their catalog configurations
something like (example in spark):

`"spark.sql.catalog.<spark-catalog-name>.warehouse": "<catalog-name>"`
and now address tables like
`<spark-catalog-name>.<namespace-name>.<table-name>`

This should address
unitycatalog#182 and parts of
unitycatalog#3.

---------

Signed-off-by: Alex Reid <[email protected]>
Signed-off-by: Joseph Mocker <[email protected]>
alexreid-db pushed a commit to alexreid-db/unitycatalog that referenced this pull request Nov 19, 2024
…og#324)

**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.
- [x] If you've fixed a bug or added code that should be tested, add
tests!
- [x] If you've added or modified a feature, documentation in `docs` is
updated

**Description of changes**

Prior to this PR, users were required to lookup namespace and tables by
supplying the uc catalog name in the namespace identifier which isn't
proper and lead to problems. This PR implements the REST client flow of
configuring calls to the API with a defined prefix containing the
catalog name. The catalog name is now part of the API paths and broken
apart from the namespace.

Client (passes warehouse parameter) -> Server Config Endpoint (response
has override for URL prefix) -> Client
Subsequent calls to the API now has url prefixed with
`/catalogs/{warehouse/catalog-name}`

This PR "binds" the spark catalog to a UC catalog using the client
config endpoint. Users must now add to their catalog configurations
something like (example in spark):

`"spark.sql.catalog.<spark-catalog-name>.warehouse": "<catalog-name>"`
and now address tables like
`<spark-catalog-name>.<namespace-name>.<table-name>`

This should address
unitycatalog#182 and parts of
unitycatalog#3.

---------

Signed-off-by: Alex Reid <[email protected]>

(cherry picked from commit 3bf4a01)
tdas pushed a commit that referenced this pull request Nov 19, 2024
#742)

**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.
- [x] If you've fixed a bug or added code that should be tested, add
tests!
- [x] If you've added or modified a feature, documentation in `docs` is
updated

**Description of changes**

Prior to this PR, users were required to lookup namespace and tables by
supplying the uc catalog name in the namespace identifier which isn't
proper and lead to problems. This PR implements the REST client flow of
configuring calls to the API with a defined prefix containing the
catalog name. The catalog name is now part of the API paths and broken
apart from the namespace.

Client (passes warehouse parameter) -> Server Config Endpoint (response
has override for URL prefix) -> Client
Subsequent calls to the API now has url prefixed with
`/catalogs/{warehouse/catalog-name}`

This PR "binds" the spark catalog to a UC catalog using the client
config endpoint. Users must now add to their catalog configurations
something like (example in spark):

`"spark.sql.catalog.<spark-catalog-name>.warehouse": "<catalog-name>"`
and now address tables like
`<spark-catalog-name>.<namespace-name>.<table-name>`

This should address
#182 and parts of
#3.

---------

Signed-off-by: Alex Reid <[email protected]>

(cherry picked from commit 3bf4a01)

**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 `docs` is
updated

**Description of changes**

<!-- Please state what you've changed and how it might affect the users.
-->

---------

Signed-off-by: Alex Reid <[email protected]>
ebyhr added a commit to ebyhr/trino that referenced this pull request Nov 27, 2024
The property was added for supporting Unity catalog.
They changed the behavior to respect warehouse property in
unitycatalog/unitycatalog#324.
ebyhr added a commit to trinodb/trino that referenced this pull request Dec 3, 2024
The property was added for supporting Unity catalog.
They changed the behavior to respect warehouse property in
unitycatalog/unitycatalog#324.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants