clintropolis commented on code in PR #18342: URL: https://github.com/apache/druid/pull/18342#discussion_r2259666290
########## processing/src/test/java/org/apache/druid/segment/projections/ProjectionsTest.java: ########## @@ -0,0 +1,297 @@ +/* + * 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.druid.segment.projections; + +import org.apache.druid.data.input.impl.AggregateProjectionSpec; +import org.apache.druid.data.input.impl.LongDimensionSchema; +import org.apache.druid.data.input.impl.StringDimensionSchema; +import org.apache.druid.query.aggregation.LongSumAggregatorFactory; +import org.apache.druid.query.filter.EqualityFilter; +import org.apache.druid.query.filter.Filter; +import org.apache.druid.query.filter.LikeDimFilter; +import org.apache.druid.segment.AggregateProjectionMetadata; +import org.apache.druid.segment.CursorBuildSpec; +import org.apache.druid.segment.column.ColumnType; +import org.apache.druid.segment.column.RowSignature; +import org.apache.druid.segment.filter.AndFilter; +import org.apache.druid.segment.filter.IsBooleanFilter; +import org.apache.druid.segment.filter.OrFilter; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.Map; +import java.util.Set; + +class ProjectionsTest +{ + @Test + void testSchemaMatchSimple() + { + RowSignature baseTable = RowSignature.builder() + .addTimeColumn() + .add("a", ColumnType.LONG) + .add("b", ColumnType.STRING) + .add("c", ColumnType.LONG) + .build(); + AggregateProjectionMetadata spec = new AggregateProjectionMetadata( + AggregateProjectionSpec.builder("some_projection") + .groupingColumns(new LongDimensionSchema("a"), new StringDimensionSchema("b")) + .aggregators(new LongSumAggregatorFactory("c_sum", "c")) + .build() + .toMetadataSchema(), + 12345 + ); + CursorBuildSpec cursorBuildSpec = CursorBuildSpec.builder() + .setPreferredOrdering(List.of()) + .setAggregators( + List.of( + new LongSumAggregatorFactory("c", "c") + ) + ) + .build(); + + Projections.ProjectionMatch projectionMatch = Projections.matchAggregateProjection( + spec.getSchema(), + cursorBuildSpec, + new RowSignatureChecker(baseTable) + ); + Projections.ProjectionMatch expected = new Projections.ProjectionMatch( + CursorBuildSpec.builder() + .setAggregators(List.of(new LongSumAggregatorFactory("c", "c"))) + .setPhysicalColumns(Set.of("c_sum")) + .setPreferredOrdering(List.of()) + .build(), + Map.of("c", "c_sum") + ); + Assertions.assertEquals(expected, projectionMatch); + } + + @Test + void testSchemaMatchFilter() Review Comment: ah yea, i was writing these tests as mainly synthetic to smoke test stuff as they are not backed by real data. I think for the bulk of tests I would agree we want something like what `CursorFactoryProjectionTest` is doing with a matrix of incremental and immutable segments but with a more cursor + filter focus and make it test that results are the same with and without the projection similar to what the native filter tests are doing -- 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]
