yuqi1129 commented on code in PR #9097:
URL: https://github.com/apache/gravitino/pull/9097#discussion_r2563755900
##########
lance/lance-rest-server/src/test/java/org/apache/gravitino/lance/integration/test/LanceRESTServiceIT.java:
##########
@@ -686,6 +715,239 @@ void testDeregisterNonExistingTable() {
Assertions.assertEquals(406, lanceNamespaceException.getCode());
}
+ @Test
+ void testCreateTableIndex() throws IOException {
+ catalog = createCatalog(CATALOG_NAME);
+ createSchema();
+ List<String> ids = List.of(CATALOG_NAME, SCHEMA_NAME,
"non_existing_table");
+
+ // We need to create a table first;
+ org.apache.arrow.vector.types.pojo.Schema schema =
+ new org.apache.arrow.vector.types.pojo.Schema(
+ Arrays.asList(
+ Field.nullable("id", new ArrowType.Int(32, true)),
+ Field.nullable("value", new ArrowType.Utf8()),
+ new Field(
+ "vector",
+ FieldType.nullable(new ArrowType.FixedSizeList(4)),
+ ImmutableList.of(
+ Field.nullable(
+ "fake", new
ArrowType.FloatingPoint(FloatingPointPrecision.SINGLE))))));
+ byte[] body = ArrowUtils.generateIpcStream(schema);
+
+ CreateTableRequest request = new CreateTableRequest();
+ request.setId(ids);
+ request.setLocation(tempDir + "/" + "table_for_index/");
+ request.setProperties(
+ ImmutableMap.of(
+ "key1", "v1",
+ "lance.storage.a", "value_a",
+ "lance.storage.c", "value_c"));
+
+ CreateTableResponse response = ns.createTable(request, body);
+ Assertions.assertEquals(request.getLocation(), response.getLocation());
+
+ writeDataToLance(request.getLocation());
+
+ // Now try to create Btree index on an existing table
+ CreateTableIndexRequest createTableIndexRequest = new
CreateTableIndexRequest();
+ createTableIndexRequest.setId(ids);
+ createTableIndexRequest.setIndexType(IndexTypeEnum.BTREE);
+ createTableIndexRequest.setColumn("id");
+ createTableIndexRequest.setMetricType(MetricTypeEnum.L2);
+ CreateTableIndexResponse createTableIndexResponse =
+ Assertions.assertDoesNotThrow(() ->
ns.createTableIndex(createTableIndexRequest));
+ Assertions.assertNotNull(createTableIndexResponse);
+
+ // Now try to create bitmap index on an existing table
+ createTableIndexRequest.setIndexType(IndexTypeEnum.BITMAP);
+ createTableIndexRequest.setColumn("value");
+ createTableIndexResponse =
+ Assertions.assertDoesNotThrow(() ->
ns.createTableIndex(createTableIndexRequest));
+ Assertions.assertNotNull(createTableIndexResponse);
+ List<String> indices = listIndices(request.getLocation());
+ Assertions.assertEquals(2, indices.size());
+ // Now try to create vector index on an existing table
+ createTableIndexRequest.setIndexType(IndexTypeEnum.IVF_FLAT);
+ createTableIndexRequest.setColumn("vector");
+ createTableIndexResponse =
+ Assertions.assertDoesNotThrow(() ->
ns.createTableIndex(createTableIndexRequest));
+ Assertions.assertNotNull(createTableIndexResponse);
+
+ ListTableIndicesRequest listTableIndicesRequest = new
ListTableIndicesRequest();
+ listTableIndicesRequest.setId(ids);
+ ListTableIndicesResponse listTableIndicesResponse =
+ ns.listTableIndices(listTableIndicesRequest);
+ Assertions.assertEquals(3, listTableIndicesResponse.getIndexes().size());
+ List<String> expectedIndexName = listIndices(request.getLocation());
+ for (IndexContent indexContent : listTableIndicesResponse.getIndexes()) {
+ Assertions.assertTrue(
+ expectedIndexName.contains(indexContent.getIndexName()),
+ "Index name should be in the expected index names.");
+ if (indexContent.getIndexName().equals("id_idx")) {
+ Assertions.assertEquals("id", indexContent.getColumns().get(0));
+ } else if (indexContent.getIndexName().equals("value_idx")) {
+ Assertions.assertEquals("value", indexContent.getColumns().get(0));
+ } else if (indexContent.getIndexName().equals("vector_idx")) {
+ Assertions.assertEquals("vector", indexContent.getColumns().get(0));
+ }
+ }
+
+ // create another table to test other index types
+ ids = List.of(CATALOG_NAME, SCHEMA_NAME, "table_for_other_indexes");
+ request.setId(ids);
+ request.setLocation(tempDir + "/" + "table_for_other_indexes/");
+ response = ns.createTable(request, body);
+ Assertions.assertEquals(request.getLocation(), response.getLocation());
+ writeDataToLance(request.getLocation());
+
+ // Now try to create FTS index on an existing table
+ createTableIndexRequest.setId(ids);
+ createTableIndexRequest.setIndexType(IndexTypeEnum.FTS);
+ createTableIndexRequest.setColumn("value");
+
+ LanceNamespaceException exception =
+ Assertions.assertThrows(
+ LanceNamespaceException.class, () ->
ns.createTableIndex(createTableIndexRequest));
+ // com.lancedb.lance.index.IndexType does not have FTS yet, so it should
throw exception
+ Assertions.assertTrue(
+ exception.getMessage().contains("No enum constant
com.lancedb.lance.index.IndexType.FTS"));
+ }
Review Comment:
This is thirty-party API and I can't remove 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]