Jackie-Jiang commented on code in PR #15844: URL: https://github.com/apache/pinot/pull/15844#discussion_r2101258157
########## pinot-core/src/main/java/org/apache/pinot/core/query/request/context/QueryContext.java: ########## @@ -275,6 +275,17 @@ public ExplainMode getExplain() { return _explain; } + /** + * Return true in-case deterministic result is expected + * @return + */ + public boolean isEnableDeterministicGroupTrim() { + return Boolean.parseBoolean(_queryOptions.getOrDefault("enableDeterministicGroupTrim", "false")); + } + + + Review Comment: (minor) Remove extra empty lines ########## pinot-core/src/main/java/org/apache/pinot/core/data/table/DeterministicConcurrentIndexedTable.java: ########## @@ -0,0 +1,81 @@ +/** + * 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.Comparator; +import java.util.concurrent.ConcurrentSkipListMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.apache.pinot.common.utils.DataSchema; +import org.apache.pinot.core.query.request.context.QueryContext; + + +public class DeterministicConcurrentIndexedTable extends IndexedTable { + private final AtomicBoolean _noMoreNewRecords = new AtomicBoolean(); + private final ReentrantReadWriteLock _readWriteLock = new ReentrantReadWriteLock(); + + public DeterministicConcurrentIndexedTable(DataSchema dataSchema, boolean hasFinalInput, + QueryContext queryContext, int resultSize, + int trimSize, int trimThreshold, int initialCapacity, ExecutorService executorService) { + super(dataSchema, hasFinalInput, queryContext, resultSize, trimSize, trimThreshold, + new ConcurrentSkipListMap<>(Comparator.comparing(Key::toString)), executorService); Review Comment: This compare is super expensive. We want to make `Key` comparable instead ########## pinot-core/src/main/java/org/apache/pinot/core/data/table/DeterministicConcurrentIndexedTable.java: ########## @@ -0,0 +1,81 @@ +/** + * 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.Comparator; +import java.util.concurrent.ConcurrentSkipListMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.apache.pinot.common.utils.DataSchema; +import org.apache.pinot.core.query.request.context.QueryContext; + + +public class DeterministicConcurrentIndexedTable extends IndexedTable { + private final AtomicBoolean _noMoreNewRecords = new AtomicBoolean(); + private final ReentrantReadWriteLock _readWriteLock = new ReentrantReadWriteLock(); + + public DeterministicConcurrentIndexedTable(DataSchema dataSchema, boolean hasFinalInput, + QueryContext queryContext, int resultSize, + int trimSize, int trimThreshold, int initialCapacity, ExecutorService executorService) { + super(dataSchema, hasFinalInput, queryContext, resultSize, trimSize, trimThreshold, + new ConcurrentSkipListMap<>(Comparator.comparing(Key::toString)), executorService); + } + + /** + * Thread safe implementation of upsert for inserting {@link Record} into {@link Table} + */ + @Override + public boolean upsert(Key key, Record record) { + if (_hasOrderBy) { + upsertWithOrderBy(key, record); + } else { + upsertWithoutOrderBy(key, record); + } + return true; + } + + protected void upsertWithOrderBy(Key key, Record record) { + _readWriteLock.readLock().lock(); + try { + addOrUpdateRecord(key, record); + } finally { + _readWriteLock.readLock().unlock(); + } + + if (_lookupMap.size() >= _trimThreshold) { + _readWriteLock.writeLock().lock(); + try { + if (_lookupMap.size() >= _trimThreshold) { + resize(); + } + } finally { + _readWriteLock.writeLock().unlock(); + } + } + } + + protected void upsertWithoutOrderBy(Key key, Record record) { + addOrUpdateRecord(key, record); Review Comment: Ideally we should only add the key only if it can make to the map ########## pinot-core/src/main/java/org/apache/pinot/core/query/request/context/QueryContext.java: ########## @@ -275,6 +275,17 @@ public ExplainMode getExplain() { return _explain; } + /** + * Return true in-case deterministic result is expected + * @return + */ + public boolean isEnableDeterministicGroupTrim() { + return Boolean.parseBoolean(_queryOptions.getOrDefault("enableDeterministicGroupTrim", "false")); + } + + + Review Comment: This is not the standard way of extracting query option flag. See `InstancePlanMakerImplV2.applyQueryOptions()` ########## pinot-core/src/main/java/org/apache/pinot/core/data/table/DeterministicConcurrentIndexedTable.java: ########## @@ -0,0 +1,81 @@ +/** + * 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.Comparator; +import java.util.concurrent.ConcurrentSkipListMap; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.apache.pinot.common.utils.DataSchema; +import org.apache.pinot.core.query.request.context.QueryContext; + + +public class DeterministicConcurrentIndexedTable extends IndexedTable { + private final AtomicBoolean _noMoreNewRecords = new AtomicBoolean(); + private final ReentrantReadWriteLock _readWriteLock = new ReentrantReadWriteLock(); + + public DeterministicConcurrentIndexedTable(DataSchema dataSchema, boolean hasFinalInput, + QueryContext queryContext, int resultSize, + int trimSize, int trimThreshold, int initialCapacity, ExecutorService executorService) { + super(dataSchema, hasFinalInput, queryContext, resultSize, trimSize, trimThreshold, + new ConcurrentSkipListMap<>(Comparator.comparing(Key::toString)), executorService); + } + + /** + * Thread safe implementation of upsert for inserting {@link Record} into {@link Table} + */ + @Override + public boolean upsert(Key key, Record record) { + if (_hasOrderBy) { Review Comment: Is this flag always false? -- 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