mchades commented on code in PR #9016:
URL: https://github.com/apache/gravitino/pull/9016#discussion_r2490405209


##########
lance/lance-rest-server/src/main/java/org/apache/gravitino/lance/service/rest/LanceTableOperations.java:
##########
@@ -97,13 +104,28 @@ public Response createTable(
       MultivaluedMap<String, String> headersMap = headers.getRequestHeaders();
       String tableLocation = headersMap.getFirst(LANCE_TABLE_LOCATION_HEADER);
       String tableProperties = 
headersMap.getFirst(LANCE_TABLE_PROPERTIES_PREFIX_HEADER);
+      CreateTableRequest.ModeEnum modeEnum = 
CreateTableRequest.ModeEnum.fromValue(mode);
 
       Map<String, String> props =
-          JsonUtil.mapper().readValue(tableProperties, new TypeReference<>() 
{});
+          StringUtils.isBlank(tableProperties)
+              ? ImmutableMap.of()
+              : JsonUtil.parse(
+                  tableProperties,
+                  jsonNode -> {
+                    Map<String, String> map = new HashMap<>();
+                    jsonNode
+                        .fields()
+                        .forEachRemaining(
+                            entry -> {
+                              map.put(entry.getKey(), 
entry.getValue().asText());
+                            });
+                    return map;

Review Comment:
   why not using `JsonUtil.mapper().readValue(tableProperties, new 
TypeReference<>() {})`



##########
lance/lance-rest-server/src/main/java/org/apache/gravitino/lance/service/rest/LanceTableOperations.java:
##########
@@ -116,24 +138,30 @@ public Response createTable(
   @ResponseMetered(name = "create-empty-table", absolute = true)
   public Response createEmptyTable(
       @PathParam("id") String tableId,
-      @QueryParam("mode") @DefaultValue("create") String mode, // create, 
exist_ok, overwrite
       @QueryParam("delimiter") @DefaultValue(NAMESPACE_DELIMITER_DEFAULT) 
String delimiter,
+      CreateEmptyTableRequest request,
       @Context HttpHeaders headers) {
     try {
-      // Extract table properties from header
-      MultivaluedMap<String, String> headersMap = headers.getRequestHeaders();
-      String tableLocation = headersMap.getFirst(LANCE_TABLE_LOCATION_HEADER);
-      String tableProperties = 
headersMap.getFirst(LANCE_TABLE_PROPERTIES_PREFIX_HEADER);
-
+      String tableLocation = request.getLocation();
       Map<String, String> props =
-          StringUtils.isBlank(tableProperties)
-              ? Map.of()
-              : JsonUtil.mapper().readValue(tableProperties, new 
TypeReference<>() {});
+          request.getProperties() == null
+              ? Maps.newHashMap()
+              : Maps.newHashMap(request.getProperties());
+      props.put("format", "lance");
       CreateTableResponse response =
           lanceNamespace
               .asTableOps()
-              .createTable(tableId, mode, delimiter, tableLocation, props, 
null);
-      return Response.ok(response).build();
+              .createTable(
+                  tableId,
+                  CreateTableRequest.ModeEnum.CREATE,
+                  delimiter,
+                  tableLocation,
+                  props,
+                  null);
+      CreateEmptyTableResponse responseObj = new CreateEmptyTableResponse();
+      responseObj.setProperties(response.getProperties());
+      responseObj.setLocation(response.getLocation());

Review Comment:
   you are missing `storage_options` for the `CreateEmptyTableResponse`



##########
lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/LanceTableOperations.java:
##########
@@ -18,26 +18,66 @@
  */
 package org.apache.gravitino.lance.common.ops;
 
+import com.lancedb.lance.namespace.model.CreateTableRequest;
 import com.lancedb.lance.namespace.model.CreateTableResponse;
 import com.lancedb.lance.namespace.model.DeregisterTableResponse;
 import com.lancedb.lance.namespace.model.DescribeTableResponse;
+import com.lancedb.lance.namespace.model.RegisterTableRequest;
 import com.lancedb.lance.namespace.model.RegisterTableResponse;
 import java.util.Map;
 
 public interface LanceTableOperations {
 
-  DescribeTableResponse describeTable(String tableId, String delimiter);
+  /**
+   * Describe the details of a table.
+   *
+   * @param tableId table ids are in the format of 
"namespace/delimiter/table_name"

Review Comment:
   The format should not include `/`



##########
lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/GravitinoLanceNamespaceWrapper.java:
##########
@@ -525,7 +522,8 @@ public ListTablesResponse listTables(
   }
 
   @Override
-  public DescribeTableResponse describeTable(String tableId, String delimiter) 
{
+  public DescribeTableResponse describeTable(String tableId, String delimiter, 
Long version) {
+    // TODO Currently we do not support versioned table description.

Review Comment:
   If so, I would suggest throwing an unsupported exception when the version is 
null.



##########
lance/lance-rest-server/src/main/java/org/apache/gravitino/lance/service/rest/LanceTableOperations.java:
##########
@@ -116,24 +138,30 @@ public Response createTable(
   @ResponseMetered(name = "create-empty-table", absolute = true)
   public Response createEmptyTable(
       @PathParam("id") String tableId,
-      @QueryParam("mode") @DefaultValue("create") String mode, // create, 
exist_ok, overwrite
       @QueryParam("delimiter") @DefaultValue(NAMESPACE_DELIMITER_DEFAULT) 
String delimiter,
+      CreateEmptyTableRequest request,
       @Context HttpHeaders headers) {
     try {
-      // Extract table properties from header
-      MultivaluedMap<String, String> headersMap = headers.getRequestHeaders();
-      String tableLocation = headersMap.getFirst(LANCE_TABLE_LOCATION_HEADER);
-      String tableProperties = 
headersMap.getFirst(LANCE_TABLE_PROPERTIES_PREFIX_HEADER);
-
+      String tableLocation = request.getLocation();
       Map<String, String> props =
-          StringUtils.isBlank(tableProperties)
-              ? Map.of()
-              : JsonUtil.mapper().readValue(tableProperties, new 
TypeReference<>() {});
+          request.getProperties() == null
+              ? Maps.newHashMap()
+              : Maps.newHashMap(request.getProperties());
+      props.put("format", "lance");

Review Comment:
   It's better to move this to `GravitinoLanceNamespaceWrapper` since it's a 
Gravitino-specific property.



##########
lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/GravitinoLanceNamespaceWrapper.java:
##########
@@ -673,7 +670,14 @@ public DeregisterTableResponse deregisterTable(String 
tableId, String delimiter)
     Table t = catalog.asTableCatalog().loadTable(tableIdentifier);
     Map<String, String> properties = t.properties();
     // TODO Support real deregister API.
-    catalog.asTableCatalog().purgeTable(tableIdentifier);
+    boolean result = catalog.asTableCatalog().purgeTable(tableIdentifier);

Review Comment:
   should not use `purgeTable` for `deregisterTable`



##########
lance/lance-common/src/test/java/org/apache/gravitino/lance/common/ops/gravitino/TestGravitinoLanceNamespaceWrapper.java:
##########
@@ -41,36 +35,9 @@ public void testParseArrowIpcStream() throws Exception {
             Arrays.asList(
                 Field.nullable("id", new ArrowType.Int(32, true)),
                 Field.nullable("value", new ArrowType.Utf8())));
-
-    GravitinoLanceNamespaceWrapper wrapper = new 
GravitinoLanceNamespaceWrapper();
-    byte[] ipcStream = generateIpcStream(schema);
-    Schema parsedSchema = wrapper.parseArrowIpcStream(ipcStream);
+    byte[] ipcStream = ArrowUtils.generateIpcStream(schema);
+    Schema parsedSchema = ArrowUtils.parseArrowIpcStream(ipcStream);

Review Comment:
   plz move this UT to `TestArrowUtils.java`



##########
lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/integration/test/LanceRESTServiceIT.java:
##########
@@ -24,38 +24,64 @@
 import com.lancedb.lance.namespace.LanceNamespace;
 import com.lancedb.lance.namespace.LanceNamespaceException;
 import com.lancedb.lance.namespace.LanceNamespaces;
+import com.lancedb.lance.namespace.client.apache.ApiException;
+import com.lancedb.lance.namespace.model.CreateEmptyTableRequest;
+import com.lancedb.lance.namespace.model.CreateEmptyTableResponse;
 import com.lancedb.lance.namespace.model.CreateNamespaceRequest;
 import com.lancedb.lance.namespace.model.CreateNamespaceResponse;
+import com.lancedb.lance.namespace.model.CreateTableRequest;
+import com.lancedb.lance.namespace.model.CreateTableResponse;
+import com.lancedb.lance.namespace.model.DeregisterTableRequest;
+import com.lancedb.lance.namespace.model.DeregisterTableResponse;
 import com.lancedb.lance.namespace.model.DescribeNamespaceRequest;
 import com.lancedb.lance.namespace.model.DescribeNamespaceResponse;
+import com.lancedb.lance.namespace.model.DescribeTableRequest;
+import com.lancedb.lance.namespace.model.DescribeTableResponse;
 import com.lancedb.lance.namespace.model.DropNamespaceRequest;
 import com.lancedb.lance.namespace.model.DropNamespaceResponse;
+import com.lancedb.lance.namespace.model.JsonArrowField;
 import com.lancedb.lance.namespace.model.ListNamespacesRequest;
 import com.lancedb.lance.namespace.model.ListNamespacesResponse;
+import com.lancedb.lance.namespace.model.ListTablesRequest;
 import com.lancedb.lance.namespace.model.NamespaceExistsRequest;
+import com.lancedb.lance.namespace.model.RegisterTableRequest;
+import com.lancedb.lance.namespace.model.RegisterTableRequest.ModeEnum;
+import com.lancedb.lance.namespace.model.RegisterTableResponse;
 import com.lancedb.lance.namespace.rest.RestNamespaceConfig;
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.Charset;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import org.apache.arrow.memory.BufferAllocator;
 import org.apache.arrow.memory.RootAllocator;
+import org.apache.arrow.vector.types.pojo.ArrowType;
+import org.apache.arrow.vector.types.pojo.Field;
 import org.apache.gravitino.Catalog;
 import org.apache.gravitino.NameIdentifier;
 import org.apache.gravitino.Schema;
 import org.apache.gravitino.client.GravitinoMetalake;
 import org.apache.gravitino.integration.test.util.BaseIT;
 import org.apache.gravitino.integration.test.util.GravitinoITUtils;
+import org.apache.gravitino.lance.common.utils.ArrowUtils;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.BeforeAll;
 import org.junit.jupiter.api.Test;
+import org.testcontainers.shaded.com.google.common.base.Joiner;
 
 public class LanceRESTServiceIT extends BaseIT {
+  public static final String CATALOG_NAME = 
GravitinoITUtils.genRandomName("lance_rest_catalog");
+  public static final String SCHEMA_NAME = 
GravitinoITUtils.genRandomName("lance_rest_schema");

Review Comment:
   It's better to use `private final`



##########
lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/integration/test/LanceRESTServiceIT.java:
##########
@@ -385,6 +626,13 @@ private Catalog createCatalog(String catalogName) {
         properties);
   }
 
+  protected void createSchema() {

Review Comment:
   private should be enough?



##########
lance/lance-rest-server/src/test/resources/log4j2.properties:
##########
@@ -0,0 +1,73 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+
+# Set to debug or trace if log4j initialization is failing
+status = info
+
+# Name of the configuration
+name = ConsoleLogConfig
+
+# Console appender configuration
+appender.console.type = Console
+appender.console.name = consoleLogger
+appender.console.layout.type = PatternLayout
+appender.console.layout.pattern = %d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L - 
%m%n
+
+# Log files location
+property.logPath = 
${sys:gravitino.log.path:-build/catalog-hive-integration-test.log}

Review Comment:
   wrong file name



##########
lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/GravitinoLanceNamespaceWrapper.java:
##########


Review Comment:
   wrong exception type



##########
lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/GravitinoLanceNamespaceWrapper.java:
##########
@@ -643,14 +639,16 @@ public RegisterTableResponse registerTable(
           CommonUtil.formatCurrentStackTrace());
     }
 
-    if (createMode == RegisterTableRequest.ModeEnum.OVERWRITE
+    if (mode == RegisterTableRequest.ModeEnum.OVERWRITE
         && catalog.asTableCatalog().tableExists(tableIdentifier)) {
       LOG.info("Overwriting existing table: {}", tableId);
-      catalog.asTableCatalog().dropTable(tableIdentifier);
+      catalog.asTableCatalog().purgeTable(tableIdentifier);

Review Comment:
   why using purgeTable?



##########
lance/lance-common/src/main/java/org/apache/gravitino/lance/common/ops/gravitino/GravitinoLanceNamespaceWrapper.java:
##########
@@ -570,11 +569,10 @@ public CreateTableResponse createTable(
 
     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("mode", mode.getValue());

Review Comment:
   why need to put the mode into the table properties?



##########
lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/integration/test/LanceRESTServiceIT.java:
##########
@@ -372,6 +398,221 @@ public void testNamespaceExists() {
     Assertions.assertEquals(404, exception.getCode());
   }
 
+  @Test
+  void testCreateEmptyTable() throws ApiException {
+    catalog = createCatalog(CATALOG_NAME);
+    createSchema();
+
+    CreateEmptyTableRequest request = new CreateEmptyTableRequest();
+    String location = tempDir + "/" + "empty_table/";
+    request.setLocation(location);
+    request.setProperties(ImmutableMap.of());
+    request.setId(List.of(CATALOG_NAME, SCHEMA_NAME, "empty_table"));
+
+    CreateEmptyTableResponse response = ns.createEmptyTable(request);
+    Assertions.assertNotNull(response);

Review Comment:
   you should also verify the response member



-- 
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]

Reply via email to