Jackie-Jiang commented on code in PR #15151: URL: https://github.com/apache/pinot/pull/15151#discussion_r1978243693
########## pinot-common/src/main/java/org/apache/pinot/common/utils/LogicalTableUtils.java: ########## @@ -0,0 +1,165 @@ +/** + * 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.common.utils; + +import com.google.common.base.Preconditions; +import java.io.IOException; +import java.net.URI; +import java.nio.charset.Charset; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import org.apache.commons.io.IOUtils; +import org.apache.hc.client5.http.classic.methods.HttpDelete; +import org.apache.hc.client5.http.classic.methods.HttpGet; +import org.apache.hc.client5.http.classic.methods.HttpPost; +import org.apache.hc.client5.http.impl.classic.CloseableHttpClient; +import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse; +import org.apache.hc.client5.http.impl.classic.HttpClients; +import org.apache.hc.core5.http.ContentType; +import org.apache.hc.core5.http.HttpEntity; +import org.apache.hc.core5.http.io.entity.EntityUtils; +import org.apache.hc.core5.http.io.entity.HttpEntities; +import org.apache.helix.zookeeper.datamodel.ZNRecord; +import org.apache.pinot.spi.data.LogicalTable; +import org.apache.pinot.spi.utils.CommonConstants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Utility class which contains {@link LogicalTable} related operations. + */ +public class LogicalTableUtils { + private static final Logger LOGGER = LoggerFactory.getLogger(LogicalTableUtils.class); + + private static final CloseableHttpClient HTTP_CLIENT = HttpClients.createDefault(); + + private LogicalTableUtils() { + } + + /** + * Fetch {@link LogicalTable} from a {@link ZNRecord}. + */ + public static LogicalTable fromZNRecord(@Nonnull ZNRecord record) Review Comment: (convention) Let's not use `@Nonnull` annotation. We assume allow parameters are non-null unless they are annotated with `@Nullable`. Same for other places ########## pinot-broker/src/main/java/org/apache/pinot/broker/requesthandler/BaseSingleStageBrokerRequestHandler.java: ########## @@ -730,144 +1044,147 @@ protected BrokerResponse doHandleRequest(long requestId, String query, SqlNodeAn _brokerMetrics.addMeteredTableValue(rawTableName, BrokerMeter.BROKER_RESPONSES_WITH_UNAVAILABLE_SEGMENTS, 1); } - if (offlineBrokerRequest == null && realtimeBrokerRequest == null) { - if (!exceptions.isEmpty()) { - ProcessingException firstException = exceptions.get(0); - String logTail = exceptions.size() > 1 ? (exceptions.size()) + " exceptions found. Logging only the first one" - : "1 exception found"; - LOGGER.info("No server found for request {}: {}. {}", requestId, query, logTail, firstException); - _brokerMetrics.addMeteredTableValue(rawTableName, BrokerMeter.NO_SERVER_FOUND_EXCEPTIONS, 1); - return new BrokerResponseNative(exceptions); - } else { - // When all segments have been pruned, we can just return an empty response. - return getEmptyBrokerOnlyResponse(pinotQuery, requestContext, tableName, requesterIdentity, schema, query, - database); + return new Requests(offlineRoutingTable, realtimeRoutingTable, offlineBrokerRequest, realtimeBrokerRequest, + numPrunedSegmentsTotal, exceptions); + } + + private BrokerResponse handleLogicalTableQuery(long requestId, String query, RequesterIdentity requesterIdentity, + RequestContext requestContext, HttpHeaders httpHeaders, AccessControl accessControl, PinotQuery pinotQuery, + PinotQuery serverPinotQuery, LogicalTable logicalTable, String database, BrokerRequest brokerRequest, + BrokerRequest serverBrokerRequest) + throws Exception { + long authStartTime = System.nanoTime(); + boolean ignoreCase = _tableCache.isIgnoreCase(); + Schema schema = _tableCache.getSchema(logicalTable.getPhysicalTableNames().get(0)); + + List<LogicalTableRequests> brokerRequests = new ArrayList<>(logicalTable.getPhysicalTableNames().size()); + long routingStartTimeNs = System.nanoTime(); + for (String tableName : logicalTable.getPhysicalTableNames()) { + try { + LogicalTableUtils.HybridTableName hybridTableName = + LogicalTableUtils.getHybridTableName(tableName, _routingManager); Review Comment: The `tableName` here should always be `tableNameWithType`, and we should not construct hybrid table from it. Say I have `t_OFFLINE` and `t_REALTIME`, and in my logical table I only want to query `t_OFFLINE`, the current logic will also query `t_REALTIME` which is wrong -- 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