Repository navigation
Support managed table creation #1135
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
Changes from all commits
a63c9d5
fc419a3
f24eccb
8541f94
6ee6fda
68f155c
599e088
90c0f2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| import java.util.HashMap; | ||
| import java.util.Map; | ||
| import java.util.UUID; | ||
| import org.apache.commons.lang3.tuple.Pair; | ||
|
|
||
| public class KeyMapper { | ||
| private final CatalogRepository catalogRepository; | ||
|
|
@@ -63,22 +64,37 @@ public Map<SecurableType, Object> mapResourceKeys(Map<SecurableType, Object> res | |
| } | ||
|
|
||
| // If only TABLE is specified, assuming its value is a full table name (including catalog and | ||
| // schema) | ||
| // schema) or a table UUID. | ||
| if (!resourceKeys.containsKey(CATALOG) | ||
| && !resourceKeys.containsKey(SCHEMA) | ||
| && resourceKeys.containsKey(TABLE)) { | ||
| String fullName = (String) resourceKeys.get(TABLE); | ||
| // If the full name contains a dot, we assume it's a full name, otherwise we assume it's an id | ||
| TableInfo table = | ||
| fullName.contains(".") | ||
| ? tableRepository.getTable(fullName) | ||
| : tableRepository.getTableById(fullName); | ||
| String fullSchemaName = table.getCatalogName() + "." + table.getSchemaName(); | ||
| SchemaInfo schema = schemaRepository.getSchema(fullSchemaName); | ||
| CatalogInfo catalog = catalogRepository.getCatalog(table.getCatalogName()); | ||
| resourceIds.put(TABLE, UUID.fromString(table.getTableId())); | ||
| resourceIds.put(SCHEMA, UUID.fromString(schema.getSchemaId())); | ||
| resourceIds.put(CATALOG, UUID.fromString(catalog.getId())); | ||
| boolean isTableName = fullName.contains("."); | ||
|
|
||
| UUID catalogId; | ||
| UUID schemaId; | ||
| UUID tableId; | ||
| if (isTableName) { | ||
| TableInfo table = tableRepository.getTable(fullName); | ||
| String fullSchemaName = table.getCatalogName() + "." + table.getSchemaName(); | ||
| SchemaInfo schema = schemaRepository.getSchema(fullSchemaName); | ||
| CatalogInfo catalog = catalogRepository.getCatalog(table.getCatalogName()); | ||
| catalogId = UUID.fromString(catalog.getId()); | ||
| schemaId = UUID.fromString(schema.getSchemaId()); | ||
| tableId = UUID.fromString(table.getTableId()); | ||
| } else { | ||
| // It may be the ID of either a table or staging table. | ||
| tableId = UUID.fromString(fullName); | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This block goes to the new function to get catalog&schema ids if the fullName is considered a table ID. |
||
| Pair<UUID, UUID> catalogAndSchemaIds = | ||
| tableRepository.getCatalogSchemaIdsByTableOrStagingTableId(tableId); | ||
| catalogId = catalogAndSchemaIds.getLeft(); | ||
| schemaId = catalogAndSchemaIds.getRight(); | ||
| } | ||
|
|
||
| resourceIds.put(TABLE, tableId); | ||
| resourceIds.put(SCHEMA, schemaId); | ||
| resourceIds.put(CATALOG, catalogId); | ||
| } | ||
|
|
||
| if (resourceKeys.containsKey(CATALOG) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,15 +121,6 @@ private void addNamespaceData(FunctionInfo functionInfo, String catalogName, Str | |
| functionInfo.setFullName(catalogName + "." + schemaName + "." + functionInfo.getName()); | ||
| } | ||
|
|
||
| public UUID getSchemaId(Session session, String catalogName, String schemaName) { | ||
| SchemaInfoDAO schemaInfo = | ||
| repositories.getSchemaRepository().getSchemaDAO(session, catalogName, schemaName); | ||
| if (schemaInfo == null) { | ||
| throw new BaseException(ErrorCode.NOT_FOUND, "Schema not found: " + schemaName); | ||
| } | ||
| return schemaInfo.getId(); | ||
| } | ||
|
|
||
| /** | ||
| * Return the list of functions in ascending order of function name. | ||
| * | ||
|
|
@@ -147,7 +138,8 @@ public ListFunctionsResponse listFunctions( | |
| return TransactionManager.executeWithTransaction( | ||
| sessionFactory, | ||
| session -> { | ||
| UUID schemaId = getSchemaId(session, catalogName, schemaName); | ||
| UUID schemaId = | ||
| repositories.getSchemaRepository().getSchemaId(session, catalogName, schemaName); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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 can you make this a issue and mark it as a starter task label so that others can pick it up?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created #1165 |
||
| return listFunctions(session, schemaId, catalogName, schemaName, maxResults, pageToken); | ||
| }, | ||
| "Failed to list functions", | ||
|
|
@@ -205,7 +197,8 @@ public void addNamespaceInfo(FunctionInfo functionInfo, String catalogName, Stri | |
|
|
||
| public FunctionInfoDAO getFunctionDAO( | ||
| Session session, String catalogName, String schemaName, String functionName) { | ||
| UUID schemaId = getSchemaId(session, catalogName, schemaName); | ||
| UUID schemaId = | ||
| repositories.getSchemaRepository().getSchemaId(session, catalogName, schemaName); | ||
| return getFunctionDAO(session, schemaId, functionName); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line 72-78 is basically doing the same thing as old code line 67,69-74.