gianm commented on code in PR #18342: URL: https://github.com/apache/druid/pull/18342#discussion_r2259573163
########## 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 Review Comment: `public class`? not sure it matters, just odd not to see the keyword. ########## 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: We're going to need easier, more concise ways to write tests for filter matching. As the filter matching gets more sophisticated, there will be a lot of variations to test to ensure everything is working properly. Maybe we can define a few "standard" datasources for the tests, each one with a base table and some projection(s). Then each test would just need to define a `CursorBuildSpec` and the expected `ProjectionMatch`. ########## 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( Review Comment: nit- moving `ProjectionMatch` out into its own class would help a little with making the test code more concise. -- 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]
