JackieTien97 commented on code in PR #18924: URL: https://github.com/apache/iotdb/pull/18924#discussion_r4321294282
########## iotdb-core/node-commons/src/test/java/org/apache/iotdb/commons/queryengine/plan/relational/function/tvf/PatternMatchTableFunctionTest.java: ########## @@ -0,0 +1,139 @@ +/* + * 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.iotdb.commons.queryengine.plan.relational.function.tvf; + +import org.apache.iotdb.udf.api.relational.access.Record; +import org.apache.iotdb.udf.api.relational.table.MapTableFunctionHandle; +import org.apache.iotdb.udf.api.relational.table.TableFunctionProcessorProvider; +import org.apache.iotdb.udf.api.relational.table.processor.TableFunctionDataProcessor; + +import org.apache.tsfile.block.column.Column; +import org.apache.tsfile.block.column.ColumnBuilder; +import org.apache.tsfile.read.common.block.column.DoubleColumnBuilder; +import org.apache.tsfile.read.common.block.column.IntColumnBuilder; +import org.apache.tsfile.read.common.block.column.LongColumnBuilder; +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class PatternMatchTableFunctionTest { + + @Test + public void testPartitionStateIsIsolated() { + assertPartitionStateIsIsolated("1,2,3,2,1"); + } + + @Test + public void testRegexPartitionStateIsIsolated() { + assertPartitionStateIsIsolated("1,{2,3,2}+,1"); + } + + private void assertPartitionStateIsIsolated(String pattern) { + TableFunctionProcessorProvider provider = createProvider(pattern); + double[][] partitions = {{1, 2, 3, 2, 1}, {10, 20, 30, 20, 10}, {2, 3, 2, 1}}; Review Comment: **Handle singleton partitions without throwing.** The partition fixtures here all contain at least four rows, so they miss a real boundary failure: `processPartition(createProvider(pattern).getDataProcessor(), new double[] {1})` throws a `NullPointerException` for both `"1,2,3,2,1"` and `"1,{2,3,2}+,1"`, using the parameters already configured by `createProvider()`. `addPoint()` creates `nowSection` only after the second point, but `finish()` unconditionally calls `closeNowDataSegment()` → `closeNowSection()`, which dereferences it at [QetchAlgorithm.java:469](https://github.com/apache/iotdb/blob/d1728308b781c817c2f0591e21e5d7591a5f9a5b/iotdb-core/node-commons/src/main/java/org/apache/iotdb/commons/queryengine/plan/relational/function/tvf/match/QetchAlgorithm.java#L469). A one-row partition should finish with no matches. Please handle this boundary and add separate ordinary/regex regression tests, including singleton partitions before or after a matching partition. I reproduced this with both the base implementation (`2abe6e925e`) and the PR implementation (`d1728308b7`); this is a pre-existing defect, not a regression introduced by this PR. -- 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]
