abhishekbafna commented on code in PR #15634: URL: https://github.com/apache/pinot/pull/15634#discussion_r2081314313
########## pinot-query-planner/src/test/java/org/apache/pinot/query/routing/table/LogicalTableRouteProviderGetRouteTest.java: ########## @@ -0,0 +1,321 @@ +/** + * 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.query.routing.table; + +import com.google.common.collect.ImmutableList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import org.apache.pinot.core.transport.TableRouteInfo; +import org.apache.pinot.spi.data.LogicalTableConfig; +import org.apache.pinot.spi.data.PhysicalTableConfig; +import org.apache.pinot.spi.utils.builder.TableNameBuilder; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.when; +import static org.testng.Assert.*; Review Comment: Does pinot prefer * imports? ########## pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/logicaltable/BaseLogicalTableIntegrationTest.java: ########## @@ -0,0 +1,515 @@ +/** + * 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.integration.tests.logicaltable; + +import com.fasterxml.jackson.databind.JsonNode; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.apache.commons.io.FileUtils; +import org.apache.pinot.controller.helix.ControllerRequestClient; +import org.apache.pinot.controller.helix.ControllerTest; +import org.apache.pinot.integration.tests.BaseClusterIntegrationTestSet; +import org.apache.pinot.integration.tests.ClusterIntegrationTestUtils; +import org.apache.pinot.integration.tests.QueryGenerator; +import org.apache.pinot.spi.config.table.QueryConfig; +import org.apache.pinot.spi.config.table.TableConfig; +import org.apache.pinot.spi.config.table.TableType; +import org.apache.pinot.spi.data.LogicalTableConfig; +import org.apache.pinot.spi.data.PhysicalTableConfig; +import org.apache.pinot.spi.data.Schema; +import org.apache.pinot.spi.exception.QueryErrorCode; +import org.apache.pinot.spi.utils.builder.LogicalTableConfigBuilder; +import org.apache.pinot.spi.utils.builder.TableConfigBuilder; +import org.apache.pinot.spi.utils.builder.TableNameBuilder; +import org.apache.pinot.util.TestUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterSuite; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.expectThrows; + + +public abstract class BaseLogicalTableIntegrationTest extends BaseClusterIntegrationTestSet { + protected static final Logger LOGGER = LoggerFactory.getLogger(BaseLogicalTableIntegrationTest.class); + private static final String DEFAULT_TENANT = "DefaultTenant"; + private static final String DEFAULT_LOGICAL_TABLE_NAME = "mytable"; + protected static final String DEFAULT_TABLE_NAME = "physicalTable"; + private static final int NUM_OFFLINE_SEGMENTS = 12; + protected static BaseLogicalTableIntegrationTest _sharedClusterTestSuite = null; + + @BeforeSuite + public void setUpSuite() + throws Exception { + LOGGER.info("Setting up integration test suite"); + TestUtils.ensureDirectoriesExistAndEmpty(_tempDir, _segmentDir, _tarDir); + _sharedClusterTestSuite = this; + + // Start the Pinot cluster + startZk(); + LOGGER.info("Start Kafka in the integration test suite"); + startKafka(); + startController(); + startBroker(); + startServers(2); + LOGGER.info("Finished setting up integration test suite"); + } + + @AfterSuite + public void tearDownSuite() + throws Exception { + LOGGER.info("Tearing down integration test suite"); + // Stop Kafka + LOGGER.info("Stop Kafka in the integration test suite"); + stopKafka(); + // Shutdown the Pinot cluster + stopServer(); + stopBroker(); + stopController(); + stopZk(); + FileUtils.deleteDirectory(_tempDir); + LOGGER.info("Finished tearing down integration test suite"); + } + + @Override + protected String getTableName() { + return DEFAULT_TABLE_NAME; + } + + @BeforeClass + public void setUp() + throws Exception { + TestUtils.ensureDirectoriesExistAndEmpty(_tempDir, _segmentDir, _tarDir); + if (_sharedClusterTestSuite != this) { + _controllerRequestURLBuilder = _sharedClusterTestSuite._controllerRequestURLBuilder; + } + + List<File> avroFiles = getAllAvroFiles(); + int numSegmentsPerTable = NUM_OFFLINE_SEGMENTS / getOfflineTableNames().size(); + int index = 0; + for (String tableName : getOfflineTableNames()) { + File tarDir = new File(_tarDir, tableName); + + TestUtils.ensureDirectoriesExistAndEmpty(tarDir); + + // Create and upload the schema and table config + Schema schema = createSchema(getSchemaFileName()); + schema.setSchemaName(tableName); + addSchema(schema); + TableConfig offlineTableConfig = createOfflineTableConfig(tableName); + addTableConfig(offlineTableConfig); + + List<File> offlineAvroFiles = new ArrayList<>(numSegmentsPerTable); + for (int i = index; i < index + numSegmentsPerTable; i++) { + offlineAvroFiles.add(avroFiles.get(i)); + } + index += numSegmentsPerTable; + + // Create and upload segments + ClusterIntegrationTestUtils.buildSegmentsFromAvro(offlineAvroFiles, offlineTableConfig, schema, 0, _segmentDir, + tarDir); + uploadSegments(tableName, tarDir); + } + + createLogicalTable(); + + // Set up the H2 connection + setUpH2Connection(avroFiles); + + // Initialize the query generator + setUpQueryGenerator(avroFiles); + + // Wait for all documents loaded + waitForAllDocsLoaded(600_000L); + } + + @AfterClass + public void tearDown() + throws Exception { + // Try deleting the tables and check that they have no routing table + for (String tableName : getOfflineTableNames()) { + dropOfflineTable(tableName); + } Review Comment: Instead of these, we can call the `cleanup()` from the ControllerTest class. it should clean up all the logical tables, physical tables and schemas at once. ########## pinot-core/src/main/java/org/apache/pinot/core/transport/BaseTableRouteInfo.java: ########## @@ -0,0 +1,64 @@ +/** + * 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.transport; + +public abstract class BaseTableRouteInfo implements TableRouteInfo { + + @Override + public boolean isExists() { + return hasOffline() || hasRealtime(); + } + + @Override + public boolean isHybrid() { + return hasOffline() && hasRealtime(); + } + + @Override + public boolean isOffline() { + return hasOffline() && !hasRealtime(); + } + + @Override + public boolean isRealtime() { + return !hasOffline() && hasRealtime(); + } + + @Override + public boolean isRouteExists() { + if (isOffline()) { + return isOfflineRouteExists(); + } else if (isRealtime()) { + return isRealtimeRouteExists(); + } else { + return isOfflineRouteExists() || isRealtimeRouteExists(); Review Comment: Curious when is this true? Something that is neither offline not realtime but a route exists. ########## pinot-query-planner/src/test/java/org/apache/pinot/query/routing/table/BaseTableRouteTest.java: ########## @@ -263,4 +301,121 @@ public static Object[][] disabledTableProvider() { }; //@formatter:on } + + private static final String QUERY_FORMAT = "SELECT col1, col2 FROM %s LIMIT 10"; + + static class BrokerRequestPair { + public final BrokerRequest _offlineBrokerRequest; + public final BrokerRequest _realtimeBrokerRequest; + + public BrokerRequestPair(BrokerRequest offlineBrokerRequest, BrokerRequest realtimeBrokerRequest) { + _offlineBrokerRequest = offlineBrokerRequest; + _realtimeBrokerRequest = realtimeBrokerRequest; + } + } + + static BrokerRequestPair getBrokerRequestPair(String tableName, boolean hasOffline, boolean hasRealtime, + String offlineTableName, String realtimeTableName) { + String query = String.format(QUERY_FORMAT, tableName); + BrokerRequest brokerRequest = + CalciteSqlCompiler.convertToBrokerRequest(CalciteSqlParser.compileToPinotQuery(query)); + BrokerRequest offlineBrokerRequest = null; + BrokerRequest realtimeBrokerRequest = null; + + if (hasOffline) { + PinotQuery offlinePinotQuery = brokerRequest.getPinotQuery().deepCopy(); + offlinePinotQuery.getDataSource().setTableName(offlineTableName); + offlineBrokerRequest = CalciteSqlCompiler.convertToBrokerRequest(offlinePinotQuery); + } + + if (hasRealtime) { + PinotQuery realtimePinotQuery = brokerRequest.getPinotQuery().deepCopy(); + realtimePinotQuery.getDataSource().setTableName(realtimeTableName); + realtimeBrokerRequest = CalciteSqlCompiler.convertToBrokerRequest(realtimePinotQuery); + } + + return new BrokerRequestPair(offlineBrokerRequest, realtimeBrokerRequest); + } + + @DataProvider(name = "offlineTableAndRouteProvider") + public static Object[][] offlineTableAndRouteProvider() { + //@formatter:off + return new Object[][] { + {"b_OFFLINE", Map.of("Server_localhost_2", ImmutableSet.of("b2"))}, + {"c_OFFLINE", Map.of("Server_localhost_1", ImmutableSet.of("c1"), + "Server_localhost_2", ImmutableSet.of("c2", "c3"))}, + {"d_OFFLINE", Map.of("Server_localhost_1", ImmutableSet.of("d1"), + "Server_localhost_2", ImmutableSet.of("d3"))}, + {"e_OFFLINE", Map.of("Server_localhost_1", ImmutableSet.of("e1"), + "Server_localhost_2", ImmutableSet.of("e3"))}, + }; + //@formatter:on + } + + @DataProvider(name = "realtimeTableAndRouteProvider") + public static Object[][] realtimeTableAndRouteProvider() { + //@formatter:off + return new Object[][] { + {"a_REALTIME", Map.of("Server_localhost_1", ImmutableSet.of("a1", "a2"), + "Server_localhost_2", ImmutableSet.of("a3"))}, + {"b_REALTIME", Map.of("Server_localhost_1", ImmutableSet.of("b1"))}, + {"e_REALTIME", Map.of("Server_localhost_2", ImmutableSet.of("e2"))}, + }; + //@formatter:on + } + + @DataProvider(name = "hybridTableAndRouteProvider") + public static Object[][] hybridTableAndRouteProvider() { + //@formatter:off + return new Object[][] { + {"d", Map.of("Server_localhost_1", ImmutableSet.of("d1"), + "Server_localhost_2", ImmutableSet.of("d3")), null}, + {"e", Map.of("Server_localhost_1", ImmutableSet.of("e1"), + "Server_localhost_2", ImmutableSet.of("e3")), + Map.of("Server_localhost_2", ImmutableSet.of("e2"))}, + }; + //@formatter:on + } + + @DataProvider(name = "partiallyDisabledTableAndRouteProvider") + public static Object[][] partiallyDisabledTableAndRouteProvider() { + //@formatter:off + return new Object[][] { + {"hybrid_o_disabled", null, Map.of("Server_localhost_1", ImmutableSet.of("hor1"), + "Server_localhost_2", ImmutableSet.of("hor2"))}, + {"hybrid_r_disabled", Map.of("Server_localhost_1", ImmutableSet.of("hro1"), + "Server_localhost_2", ImmutableSet.of("hro2")), null}, + }; + //@formatter:on + } + + protected TableRouteInfo getLogicalTableRouteInfo(String tableName, String logicalTableName) { + LogicalTableConfig logicalTable = new LogicalTableConfig(); Review Comment: nit: Why not use `LogicalTableConfigBuilder` ########## pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/logicaltable/BaseLogicalTableIntegrationTest.java: ########## @@ -0,0 +1,350 @@ +/** + * 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.integration.tests.logicaltable; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import org.apache.commons.io.FileUtils; +import org.apache.pinot.controller.helix.ControllerRequestClient; +import org.apache.pinot.controller.helix.ControllerTest; +import org.apache.pinot.integration.tests.BaseClusterIntegrationTestSet; +import org.apache.pinot.integration.tests.ClusterIntegrationTestUtils; +import org.apache.pinot.integration.tests.QueryGenerator; +import org.apache.pinot.spi.config.table.TableConfig; +import org.apache.pinot.spi.config.table.TableType; +import org.apache.pinot.spi.data.LogicalTableConfig; +import org.apache.pinot.spi.data.Schema; +import org.apache.pinot.spi.utils.builder.TableConfigBuilder; +import org.apache.pinot.spi.utils.builder.TableNameBuilder; +import org.apache.pinot.util.TestUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.AfterSuite; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Test; + +import static org.testng.Assert.assertEquals; + + +public abstract class BaseLogicalTableIntegrationTest extends BaseClusterIntegrationTestSet { + protected static final Logger LOGGER = LoggerFactory.getLogger(BaseLogicalTableIntegrationTest.class); + private static final String DEFAULT_TENANT = "DefaultTenant"; + private static final String DEFAULT_LOGICAL_TABLE_NAME = "mytable"; + protected static final String DEFAULT_TABLE_NAME = "physicalTable"; + private static final int NUM_OFFLINE_SEGMENTS = 12; + protected static BaseLogicalTableIntegrationTest _sharedClusterTestSuite = null; + + @BeforeSuite + public void setUpSuite() + throws Exception { + LOGGER.info("Setting up integration test suite"); Review Comment: nit: "Setting up logical table integration test suite" -- 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