Jackie-Jiang commented on code in PR #13296: URL: https://github.com/apache/pinot/pull/13296#discussion_r1733654738
########## pinot-spi/src/test/java/org/apache/pinot/spi/data/SchemaInfoTest.java: ########## @@ -0,0 +1,91 @@ +/** + * 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. + */ +package org.apache.pinot.spi.data; + +import com.fasterxml.jackson.databind.JsonNode; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.apache.pinot.spi.utils.CommonConstants; +import org.apache.pinot.spi.utils.JsonUtils; +import org.testng.annotations.Test; + +import static org.apache.pinot.spi.data.FieldSpec.DataType.INT; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.testng.Assert.assertEquals; + + +public class SchemaInfoTest { + + @Test + public void testSchemaInfoSerDeserWithVirtualColumns() + throws IOException { + // Mock the Schema object + Schema schemaMock = mock(Schema.class); Review Comment: Let's make a real schema instead of mocking it. You may use `SchemaBuilder` to create it ########## pinot-spi/src/test/java/org/apache/pinot/spi/data/SchemaInfoTest.java: ########## @@ -0,0 +1,91 @@ +/** + * 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. + */ +package org.apache.pinot.spi.data; + +import com.fasterxml.jackson.databind.JsonNode; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import org.apache.pinot.spi.utils.CommonConstants; +import org.apache.pinot.spi.utils.JsonUtils; +import org.testng.annotations.Test; + +import static org.apache.pinot.spi.data.FieldSpec.DataType.INT; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.testng.Assert.assertEquals; + + +public class SchemaInfoTest { + + @Test + public void testSchemaInfoSerDeserWithVirtualColumns() + throws IOException { + // Mock the Schema object + Schema schemaMock = mock(Schema.class); + when(schemaMock.getSchemaName()).thenReturn("TestSchema"); + DimensionFieldSpec dimensionFieldSpec1 = new DimensionFieldSpec("dim1", FieldSpec.DataType.STRING, true); + DimensionFieldSpec dimensionFieldSpec2 = new DimensionFieldSpec("dim2", FieldSpec.DataType.INT, true); + DimensionFieldSpec dimensionFieldSpec3 = new DimensionFieldSpec("dim2", FieldSpec.DataType.INT, true); + DimensionFieldSpec dimensionFieldSpec4 = + new DimensionFieldSpec(CommonConstants.Segment.BuiltInVirtualColumn.DOCID, FieldSpec.DataType.INT, true); + DimensionFieldSpec dimensionFieldSpec5 = + new DimensionFieldSpec(CommonConstants.Segment.BuiltInVirtualColumn.HOSTNAME, FieldSpec.DataType.STRING, true); + DimensionFieldSpec dimensionFieldSpec6 = + new DimensionFieldSpec(CommonConstants.Segment.BuiltInVirtualColumn.SEGMENTNAME, FieldSpec.DataType.STRING, + true); + List<DimensionFieldSpec> dimensionFieldSpecs = new ArrayList<>(); + dimensionFieldSpecs.add(dimensionFieldSpec1); + dimensionFieldSpecs.add(dimensionFieldSpec2); + dimensionFieldSpecs.add(dimensionFieldSpec3); + dimensionFieldSpecs.add(dimensionFieldSpec4); + dimensionFieldSpecs.add(dimensionFieldSpec5); + dimensionFieldSpecs.add(dimensionFieldSpec6); + when(schemaMock.getDimensionFieldSpecs()).thenReturn(dimensionFieldSpecs); + DateTimeFieldSpec dateTimeFieldSpec1 = + new DateTimeFieldSpec("dt1", FieldSpec.DataType.LONG, "1:HOURS:EPOCH", "1:HOURS"); + DateTimeFieldSpec dateTimeFieldSpec2 = + new DateTimeFieldSpec("dt2", FieldSpec.DataType.LONG, "1:HOURS:EPOCH", "1:HOURS"); + List<DateTimeFieldSpec> dateTimeFieldSpecs = new ArrayList<>(); + dateTimeFieldSpecs.add(dateTimeFieldSpec1); + dateTimeFieldSpecs.add(dateTimeFieldSpec2); + when(schemaMock.getDateTimeFieldSpecs()).thenReturn(dateTimeFieldSpecs); + MetricFieldSpec metricFieldSpec1 = new MetricFieldSpec("metric", INT, -1); + List<MetricFieldSpec> metricFieldSpecs = new ArrayList<>(); + metricFieldSpecs.add(metricFieldSpec1); + when(schemaMock.getMetricFieldSpecs()).thenReturn(metricFieldSpecs); + SchemaInfo schemaInfo = new SchemaInfo(schemaMock); + List<SchemaInfo> schemaInfoList = new ArrayList<>(); + schemaInfoList.add(schemaInfo); + String response = JsonUtils.objectToPrettyString(schemaInfoList); + JsonNode jsonNodeResp = JsonUtils.stringToJsonNode(response); Review Comment: Let's try to serialize it back to `SchemaInfo` because client code might try to do that. I think it will throw exception because there is no constructor with `@JsonCreator` ########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSchemaRestletResource.java: ########## @@ -118,6 +121,26 @@ public List<String> listSchemaNames(@Context HttpHeaders headers) { return _pinotHelixResourceManager.getSchemaNames(headers.getHeaderString(DATABASE)); } + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/schemas/info") + @Authorize(targetType = TargetType.CLUSTER, action = Actions.Cluster.GET_SCHEMA_INFO) + @ApiOperation(value = "List all schemas info with count of field specs", notes = "Lists all schemas with field " + + "count details") + public String getSchemaInfo(@Context HttpHeaders headers) Review Comment: (minor) ```suggestion public String getSchemasInfo(@Context HttpHeaders headers) ``` ########## pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotSchemaRestletResource.java: ########## @@ -118,6 +121,26 @@ public List<String> listSchemaNames(@Context HttpHeaders headers) { return _pinotHelixResourceManager.getSchemaNames(headers.getHeaderString(DATABASE)); } + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("/schemas/info") + @Authorize(targetType = TargetType.CLUSTER, action = Actions.Cluster.GET_SCHEMA_INFO) + @ApiOperation(value = "List all schemas info with count of field specs", notes = "Lists all schemas with field " + + "count details") + public String getSchemaInfo(@Context HttpHeaders headers) + throws JsonProcessingException { + List<SchemaInfo> schemasInfo = new ArrayList<>(); + TableCache cache = _pinotHelixResourceManager.getTableCache(); + List<String> schemas = _pinotHelixResourceManager.getSchemaNames(headers.getHeaderString(DATABASE)); + for (String schemaName : schemas) { + Schema schema = cache.getSchema(schemaName); + if (schema != null) { + schemasInfo.add(new SchemaInfo(schema)); Review Comment: Consider adding an optional field `uncachedSchemas` for schemas not found in cache. We may show this info to the user in the UI. Something like: ``` { "schemasInfo": [ ... ], "uncachedSchemas": [ ... ] } ``` -- 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: commits-unsubscr...@pinot.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org