yuqi1129 commented on code in PR #9016:
URL: https://github.com/apache/gravitino/pull/9016#discussion_r2493604763
##########
lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/GravitinoLanceNamespaceWrapper.java:
##########
@@ -569,59 +581,65 @@ public CreateTableResponse createTable(
NameIdentifier.of(nsId.levelAtListPos(1), nsId.levelAtListPos(2));
Map<String, String> createTableProperties =
Maps.newHashMap(tableProperties);
- createTableProperties.put("location", tableLocation);
- createTableProperties.put("mode", mode);
- // TODO considering the mode (create, exist_ok, overwrite)
+ createTableProperties.put(LANCE_LOCATION, tableLocation);
+ // The format is defined in GenericLakehouseCatalog
+ createTableProperties.put("format", "lance");
- ModeEnum createMode = ModeEnum.fromValue(mode.toLowerCase());
- switch (createMode) {
- case EXIST_OK:
- if (catalog.asTableCatalog().tableExists(tableIdentifier)) {
- CreateTableResponse response = new CreateTableResponse();
- Table existingTable =
catalog.asTableCatalog().loadTable(tableIdentifier);
- response.setProperties(existingTable.properties());
- response.setLocation(existingTable.properties().get("location"));
- response.setVersion(0L);
- return response;
- }
- break;
- case CREATE:
- if (catalog.asTableCatalog().tableExists(tableIdentifier)) {
- throw LanceNamespaceException.conflict(
- "Table already exists: " + tableId,
- SchemaAlreadyExistsException.class.getSimpleName(),
- tableId,
- CommonUtil.formatCurrentStackTrace());
- }
- break;
- case OVERWRITE:
- if (catalog.asTableCatalog().tableExists(tableIdentifier)) {
- catalog.asTableCatalog().dropTable(tableIdentifier);
- }
- break;
- default:
- throw new IllegalArgumentException("Unknown mode: " + mode);
+ Table t;
+ try {
+ t =
+ catalog
+ .asTableCatalog()
+ .createTable(
+ tableIdentifier, columns.toArray(new Column[0]), null,
createTableProperties);
+ } catch (TableAlreadyExistsException exception) {
+ if (mode == CreateTableRequest.ModeEnum.CREATE) {
+ throw LanceNamespaceException.conflict(
+ "Table already exists: " + tableId,
+ TableAlreadyExistsException.class.getSimpleName(),
+ tableId,
+ CommonUtil.formatCurrentStackTrace());
+ } else if (mode == CreateTableRequest.ModeEnum.OVERWRITE) {
+ LOG.info("Overwriting existing table: {}", tableId);
+ catalog.asTableCatalog().purgeTable(tableIdentifier);
+
+ t =
+ catalog
+ .asTableCatalog()
+ .createTable(
+ tableIdentifier, columns.toArray(new Column[0]), null,
createTableProperties);
+ } else { // EXIST_OK
+ CreateTableResponse response = new CreateTableResponse();
+ Table existingTable =
catalog.asTableCatalog().loadTable(tableIdentifier);
+ response.setProperties(existingTable.properties());
+ response.setLocation(existingTable.properties().get(LANCE_LOCATION));
+ response.setVersion(null);
+ return response;
Review Comment:
Yeah, I miss it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]