songwdfu commented on code in PR #16277: URL: https://github.com/apache/pinot/pull/16277#discussion_r2185763096
########## pinot-core/src/test/java/org/apache/pinot/core/data/table/ConcurrentSortedIndexedTableTest.java: ########## @@ -0,0 +1,214 @@ +/** + * 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.data.table; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import org.apache.pinot.common.utils.DataSchema; +import org.apache.pinot.common.utils.DataSchema.ColumnDataType; +import org.apache.pinot.core.query.request.context.QueryContext; +import org.apache.pinot.core.query.request.context.utils.QueryContextConverterUtils; +import org.apache.pinot.core.query.utils.OrderByComparatorFactory; +import org.testng.Assert; +import org.testng.annotations.Test; + + +public class ConcurrentSortedIndexedTableTest { + + @Test + public void testSingleValueAsc() { + QueryContext queryContext = QueryContextConverterUtils.getQueryContext( + "SELECT COUNT(*) FROM testTable GROUP BY d1 ORDER BY d1 LIMIT 3"); + DataSchema dataSchema = new DataSchema(new String[]{"d1", "count(*)"}, new ColumnDataType[]{ + ColumnDataType.STRING, ColumnDataType.LONG + }); + + ExecutorService executor = Executors.newCachedThreadPool(); + Comparator<Key> comparator = OrderByComparatorFactory.getGroupKeyComparator(queryContext.getOrderByExpressions(), + queryContext.getGroupByExpressions(), queryContext.isNullHandlingEnabled()); + ConcurrentSortedIndexedTable table = + new ConcurrentSortedIndexedTable(dataSchema, false, queryContext, 10, executor, comparator); + + // Insert out-of-order keys + upsert(table, new Object[]{"zebra", 1L}); + upsert(table, new Object[]{"apple", 1L}); + upsert(table, new Object[]{"applee", 1L}); + upsert(table, new Object[]{"banana", 1L}); + upsert(table, new Object[]{"cherry", 1L}); + upsert(table, new Object[]{"yak", 1L}); + + table.finish(false); + + Iterator<Record> it = table.iterator(); + String[] expected = {"apple", "applee", "banana"}; + int i = 0; + while (it.hasNext()) { + Record r = it.next(); + Assert.assertEquals(r.getValues()[0], expected[i]); + i++; + } + Assert.assertEquals(i, 3); + } + + @Test + public void testMultiThreadedWritersTop5000Asc() + throws Exception { + for (int i = 0; i < 5; i++) { + testMultiThreadedWritersTop5000AscInternal(); + } + } + Review Comment: Yes, I also realized in the case we may just need to merge the segment results since they are sorted, will think of a way to reduce contention doing that. Will definitely perf later! -- 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]
