arunkumarucet commented on code in PR #16497: URL: https://github.com/apache/pinot/pull/16497#discussion_r2260287924
########## pinot-core/src/test/java/org/apache/pinot/core/query/aggregation/function/MaxStringAggregationFunctionTest.java: ########## @@ -0,0 +1,287 @@ +/** + * 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.core.query.aggregation.function; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import org.apache.pinot.common.request.context.ExpressionContext; +import org.apache.pinot.common.request.context.RequestContextUtils; +import org.apache.pinot.core.common.BlockValSet; +import org.apache.pinot.core.query.aggregation.AggregationResultHolder; +import org.apache.pinot.core.query.aggregation.groupby.GroupByResultHolder; +import org.apache.pinot.queries.FluentQueryTest; +import org.apache.pinot.segment.spi.AggregationFunctionType; +import org.apache.pinot.spi.data.FieldSpec; +import org.apache.pinot.spi.data.Schema; +import org.apache.pinot.spi.exception.BadQueryRequestException; +import org.testng.annotations.Test; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; + + +public class MaxStringAggregationFunctionTest extends AbstractAggregationFunctionTest { + + /** + * Helper method to create a FluentQueryTest builder for a table with a single String field. + * This is used to simulate the DataTypeScenario concept from numeric aggregation tests, + * but fixed for the STRING data type. + */ + protected FluentQueryTest.DeclaringTable getDeclaringTable(boolean enableColumnBasedNullHandling) { + return FluentQueryTest.withBaseDir(_baseDir) + .givenTable( + new Schema.SchemaBuilder() + .setSchemaName("testTable") + .setEnableColumnBasedNullHandling(enableColumnBasedNullHandling) + .addSingleValueDimension("myField", FieldSpec.DataType.STRING) + .build(), SINGLE_FIELD_TABLE_CONFIG); + } + + @Test + public void testNumericColumnException() { + ExpressionContext expression = RequestContextUtils.getExpression("column"); + MaxStringAggregationFunction function = new MaxStringAggregationFunction(Collections.singletonList(expression), + false); + + AggregationResultHolder resultHolder = function.createAggregationResultHolder(); + GroupByResultHolder groupByResultHolder = function.createGroupByResultHolder(10, 20); + + Map<ExpressionContext, BlockValSet> blockValSetMap = new HashMap<>(); + BlockValSet mockBlockValSet = mock(BlockValSet.class); + when(mockBlockValSet.getValueType()).thenReturn(FieldSpec.DataType.INT); + blockValSetMap.put(expression, mockBlockValSet); + + // Test exception in aggregate method + try { + function.aggregate(10, resultHolder, blockValSetMap); + fail("Should throw BadQueryRequestException"); + } catch (BadQueryRequestException e) { + assertTrue(e.getMessage().contains("Cannot compute MAXSTRING for numeric column")); + } + + // Test exception in aggregateGroupBySV method + try { + function.aggregateGroupBySV(10, new int[10], groupByResultHolder, blockValSetMap); + fail("Should throw BadQueryRequestException"); + } catch (BadQueryRequestException e) { + assertTrue(e.getMessage().contains("Cannot compute MAXSTRING for numeric column")); + } Review Comment: Sure, split into three methods. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
