This is an automated email from the ASF dual-hosted git repository. yuqi4733 pushed a commit to branch branch-lance-namepspace-dev in repository https://gitbox.apache.org/repos/asf/gravitino.git
commit 05c0cdac4ced6c28b0478bb9c59718b0f3091ce8 Merge: 25774a63d4 45c2dbcda7 Author: yuqi <[email protected]> AuthorDate: Thu Nov 13 09:37:09 2025 +0800 Merge branch 'branch-lance-namepspace-dev' of github.com:datastrato/graviton into branch-lance-namepspace-dev .../lance/service/rest/LanceTableOperations.java | 1 + .../lance/integration/test/LanceRESTServiceIT.java | 2 ++ .../service/rest/TestLanceTableOperations.java | 42 ++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --cc lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/integration/test/LanceRESTServiceIT.java index 0c7a04baf1,c7454442b6..75595161d9 --- a/lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/integration/test/LanceRESTServiceIT.java +++ b/lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/integration/test/LanceRESTServiceIT.java @@@ -617,6 -588,6 +617,8 @@@ public class LanceRESTServiceIT extend RegisterTableResponse response = ns.registerTable(registerTableRequest); Assertions.assertNotNull(response); ++ // Will not create the location on register ++ Assertions.assertFalse(new File(response.getLocation()).exists()); DescribeTableRequest describeTableRequest = new DescribeTableRequest(); describeTableRequest.setId(ids); diff --cc lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/service/rest/TestLanceTableOperations.java index 9187a7da93,0fc4df9cfd..c59159c0ea --- a/lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/service/rest/TestLanceTableOperations.java +++ b/lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/service/rest/TestLanceTableOperations.java @@@ -19,6 -19,9 +19,7 @@@ package org.apache.gravitino.lance.service.rest; import static org.mockito.ArgumentMatchers.any; + import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@@ -378,112 -665,4 +379,153 @@@ public class TestLanceTableOperations e Assertions.assertEquals("Runtime exception", errorResp.getError()); Assertions.assertEquals(RuntimeException.class.getSimpleName(), errorResp.getType()); } + + @Test + void testCreateTableIndex() { + String tableIds = "catalog.scheme.to_create_index_table"; + String delimiter = "."; + + // Test normal + CreateTableIndexRequest tableRequest = new CreateTableIndexRequest(); + + CreateTableIndexResponse response = new CreateTableIndexResponse(); + response.setProperties(ImmutableMap.of("key", "value")); + when(tableOps.createTableIndex(any(), any(), any())).thenReturn(response); + + Response resp = + target(String.format("/v1/table/%s/create_index", tableIds)) + .queryParam("delimiter", delimiter) + .request(MediaType.APPLICATION_JSON_TYPE) + .post(Entity.entity(tableRequest, MediaType.APPLICATION_JSON_TYPE)); + + Assertions.assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); + Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getMediaType()); + response = resp.readEntity(CreateTableIndexResponse.class); + Assertions.assertEquals(response.getProperties(), response.getProperties()); + + Mockito.reset(tableOps); + // Test illegal argument + when(tableOps.createTableIndex(any(), any(), any())) + .thenThrow(new IllegalArgumentException("Illegal argument")); + + resp = + target(String.format("/v1/table/%s/create_index", tableIds)) + .queryParam("delimiter", delimiter) + .request(MediaType.APPLICATION_JSON_TYPE) + .post(Entity.entity(tableRequest, MediaType.APPLICATION_JSON_TYPE)); + Assertions.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus()); + Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getMediaType()); + + // Test runtime exception + Mockito.reset(tableOps); + when(tableOps.createTableIndex(any(), any(), any())) + .thenThrow(new RuntimeException("Runtime exception")); + resp = + target(String.format("/v1/table/%s/create_index", tableIds)) + .queryParam("delimiter", delimiter) + .request(MediaType.APPLICATION_JSON_TYPE) + .post(Entity.entity(tableRequest, MediaType.APPLICATION_JSON_TYPE)); + + Assertions.assertEquals( + Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), resp.getStatus()); + Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getMediaType()); + ErrorResponse errorResp = resp.readEntity(ErrorResponse.class); + Assertions.assertEquals("Runtime exception", errorResp.getError()); + Assertions.assertEquals(RuntimeException.class.getSimpleName(), errorResp.getType()); + } + + @Test + void testListTableIndices() { + String tableIds = "catalog.scheme.to_list_index_table"; + String delimiter = "."; + + ListTableIndicesRequest tableRequest = new ListTableIndicesRequest(); + + ListTableIndicesResponse response = new ListTableIndicesResponse(); + IndexContent indexContent = new IndexContent(); + indexContent.setIndexName("test_index"); + indexContent.setColumns(List.of("col1")); + response.setIndexes(List.of(indexContent)); + when(tableOps.listTableIndices(any(), any(), any())).thenReturn(response); + + Response resp = + target(String.format("/v1/table/%s/index/list", tableIds)) + .queryParam("delimiter", delimiter) + .request(MediaType.APPLICATION_JSON_TYPE) + .post(Entity.entity(tableRequest, MediaType.APPLICATION_JSON_TYPE)); + + Assertions.assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); + Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getMediaType()); + ListTableIndicesResponse actualResponse = resp.readEntity(ListTableIndicesResponse.class); + Assertions.assertEquals(1, actualResponse.getIndexes().size()); + Assertions.assertEquals("test_index", actualResponse.getIndexes().get(0).getIndexName()); + Assertions.assertEquals(List.of("col1"), actualResponse.getIndexes().get(0).getColumns()); + + Mockito.reset(tableOps); + + // Test illegal argument + when(tableOps.listTableIndices(any(), any(), any())) + .thenThrow(new IllegalArgumentException("Illegal argument")); + resp = + target(String.format("/v1/table/%s/index/list", tableIds)) + .queryParam("delimiter", delimiter) + .request(MediaType.APPLICATION_JSON_TYPE) + .post(Entity.entity(tableRequest, MediaType.APPLICATION_JSON_TYPE)); + Assertions.assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus()); + Assertions.assertEquals(MediaType.APPLICATION_JSON_TYPE, resp.getMediaType()); + + // Test + Mockito.reset(tableOps); + when(tableOps.listTableIndices(any(), any(), any())) + .thenThrow( + LanceNamespaceException.notFound( + "Table not found", "NoSuchTableException", tableIds, "")); + resp = + target(String.format("/v1/table/%s/index/list", tableIds)) + .queryParam("delimiter", delimiter) + .request(MediaType.APPLICATION_JSON_TYPE) + .post(Entity.entity(tableRequest, MediaType.APPLICATION_JSON_TYPE)); + Assertions.assertEquals(Response.Status.NOT_FOUND.getStatusCode(), resp.getStatus()); + } ++ ++ @Test ++ void testRegisterTableSetsRegisterPropertyToTrue() { ++ String tableIds = "catalog.scheme.register_table_with_property"; ++ String delimiter = "."; ++ ++ // Reset mock to clear any previous test state ++ Mockito.reset(tableOps); ++ ++ // Test that the "register" property is set to "true" ++ RegisterTableResponse registerTableResponse = new RegisterTableResponse(); ++ registerTableResponse.setLocation("/path/to/registered_table"); ++ registerTableResponse.setProperties(ImmutableMap.of("key", "value", "register", "true")); ++ when(tableOps.registerTable(any(), any(), any(), any())).thenReturn(registerTableResponse); ++ ++ RegisterTableRequest tableRequest = new RegisterTableRequest(); ++ tableRequest.setLocation("/path/to/registered_table"); ++ tableRequest.setMode(RegisterTableRequest.ModeEnum.CREATE); ++ tableRequest.setProperties(ImmutableMap.of("custom-key", "custom-value")); ++ ++ Response resp = ++ target(String.format("/v1/table/%s/register", tableIds)) ++ .queryParam("delimiter", delimiter) ++ .request(MediaType.APPLICATION_JSON_TYPE) ++ .post(Entity.entity(tableRequest, MediaType.APPLICATION_JSON_TYPE)); ++ ++ Assertions.assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus()); ++ ++ // Verify that registerTable was called with properties containing "register": "true" ++ Mockito.verify(tableOps) ++ .registerTable( ++ eq(tableIds), ++ eq(RegisterTableRequest.ModeEnum.CREATE), ++ eq(delimiter), ++ Mockito.argThat( ++ props -> ++ props != null ++ && "true".equals(props.get("register")) ++ && "/path/to/registered_table".equals(props.get("location")) ++ && "custom-value".equals(props.get("custom-key")))); ++ } }
