gortiz commented on code in PR #14690: URL: https://github.com/apache/pinot/pull/14690#discussion_r1894020253
########## 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: > GROUP BY datetrunc('SECOND',ArrTime) Added > HAVING datetrunc('SECOND',ArrTime) > 1 > HAVING sum(case when datetrunc('SECOND',ArrTime) > 1 then 2 else 0 end) > 1 In these cases the optimization is not supported in SSE and it isn't easy to support it. The main problem here is that `InstancePlanMakerImplV2.rewriteQueryContextWithHints` rewrites the query using a dirty trick: it modifies the lists returned by `queryContext.getSelectExpressions()`, `queryContext.getGroupByExpressions()`, etc. In the `queryContext.getAggregationFunctions()` case, it returns a list of `AggregationFunction` which have their own `AggregationFunction.getInputExpressions()`. But it is not guaranteed that modifying the list returned by that method actually modifies the `AggregationFunction`. In fact in cases most cases it doesn't. > UNION-ed second query ? Unions don't have expressions right? In case one of the unioned-queries have expressions, it should be treated by the other cases using recursion. This tests class is testing more than this feature. It is testing that the substitution is being done, which means that the overrideHint is added (what this PR changes) and that the override is actually applied (what is failing in some cases). We could create a test that just verifies that the overrideHint is added, but that may be a complex test to add, so I think the tests we have right now are good enough. -- 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]
