gortiz commented on code in PR #14690: URL: https://github.com/apache/pinot/pull/14690#discussion_r1894034960
########## pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/custom/TimestampIndexTest.java: ########## @@ -0,0 +1,183 @@ +/** + * 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.custom; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import org.apache.pinot.integration.tests.BaseClusterIntegrationTest; +import org.apache.pinot.integration.tests.ClusterIntegrationTestUtils; +import org.apache.pinot.integration.tests.ExplainIntegrationTestTrait; +import org.apache.pinot.spi.config.table.FieldConfig; +import org.apache.pinot.spi.config.table.TableConfig; +import org.apache.pinot.spi.config.table.TimestampConfig; +import org.apache.pinot.spi.config.table.TimestampIndexGranularity; +import org.apache.pinot.spi.data.Schema; +import org.apache.pinot.spi.env.PinotConfiguration; +import org.apache.pinot.spi.utils.CommonConstants; +import org.apache.pinot.util.TestUtils; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + + +public class TimestampIndexTest extends BaseClusterIntegrationTest implements ExplainIntegrationTestTrait { + @BeforeClass + public void setUp() + throws Exception { + TestUtils.ensureDirectoriesExistAndEmpty(_tempDir, _segmentDir, _tarDir); + + // Start the Pinot cluster + startZk(); + startController(); + startBroker(); + startServers(2); + + // Create and upload the schema and table config + Schema schema = createSchema(); + addSchema(schema); + TableConfig tableConfig = createOfflineTableConfig(); + addTableConfig(tableConfig); + + // Unpack the Avro files + List<File> avroFiles = unpackAvroData(_tempDir); + + // Create and upload segments + ClusterIntegrationTestUtils.buildSegmentsFromAvro(avroFiles, tableConfig, schema, 0, _segmentDir, _tarDir); + uploadSegments(getTableName(), _tarDir); + + // Wait for all documents loaded + waitForAllDocsLoaded(600_000L); + } + + protected void overrideBrokerConf(PinotConfiguration brokerConf) { + String property = CommonConstants.MultiStageQueryRunner.KEY_OF_MULTISTAGE_EXPLAIN_INCLUDE_SEGMENT_PLAN; + brokerConf.setProperty(property, "true"); + } + + @Test + public void timestampIndexSubstitutedInProjectionsMSE() { + setUseMultiStageQueryEngine(true); + explain("SELECT datetrunc('SECOND',ArrTime) FROM mytable", + "Execution Plan\n" + + "PinotLogicalExchange(distribution=[broadcast])\n" + + " LeafStageCombineOperator(table=[mytable])\n" + + " StreamingInstanceResponse\n" + + " StreamingCombineSelect\n" + + " SelectStreaming(table=[mytable], totalDocs=[115545])\n" + + " Project(columns=[[$ArrTime$SECOND]])\n" + + " DocIdSet(maxDocs=[120000])\n" + + " FilterMatchEntireSegment(numDocs=[115545])\n"); + } + + @Test + public void timestampIndexSubstitutedInFiltersMSE() { + setUseMultiStageQueryEngine(true); + explain("SELECT 1 FROM mytable where datetrunc('SECOND',ArrTime) > 1", + "Execution Plan\n" + + "PinotLogicalExchange(distribution=[broadcast])\n" + + " LeafStageCombineOperator(table=[mytable])\n" + + " StreamingInstanceResponse\n" + + " StreamingCombineSelect\n" + + " SelectStreaming(table=[mytable], totalDocs=[115545])\n" + + " Transform(expressions=[['1']])\n" + + " Project(columns=[[]])\n" + + " DocIdSet(maxDocs=[120000])\n" + + " FilterRangeIndex(predicate=[$ArrTime$SECOND > '1'], " + + "indexLookUp=[range_index], operator=[RANGE])\n"); + } + Review Comment: > WHERE EXISTS (select * from tab t2 where datetrunc('SECOND',ArrTime) > 1 ) > WHERE EXISTS (select * from tab t2 where t1.x = datetrunc('SECOND',t2.ArrTime) > 1 ) ) This is tricky. Would we want to test all possible SQL constructors? In theory... maybe... But I don't think it is worth it. We know we are applying the hint with a visitor that walks through the relational nodes. Therefore we know we will visit the sub-query filters. Which means that it is the same case as a select in the main query. Obviously that is a grey area. A future refactor may not use a visitor and therefore may end up not visiting the inner query. But I don't think it is worth to test so deep. Probably, as said before, a lower level test (ie a unit test on the visitor) should make it more explicit why that case isn't worth to be tested, but here I'm using an integration test to test the overrideHint logic, which isn't great but is easier than testing `ServerPlanRequestVisitor` -- 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]
