|
11 | 11 | import io.substrait.proto.Plan; |
12 | 12 | import io.substrait.proto.ReadRel; |
13 | 13 | import io.substrait.proto.Rel; |
| 14 | +import io.substrait.util.EmptyVisitationContext; |
14 | 15 | import org.junit.jupiter.api.Test; |
15 | 16 |
|
16 | 17 | class AggregateRelTest extends TestBase { |
@@ -90,6 +91,24 @@ void testDeprecatedGroupingExpressionConversion() { |
90 | 91 | Aggregate agg = (Aggregate) resultRel; |
91 | 92 | assertEquals(1, agg.getGroupings().size()); |
92 | 93 | assertEquals(2, agg.getGroupings().get(0).getExpressions().size()); |
| 94 | + |
| 95 | + Rel roundtripRel = relProtoConverter.visit(agg, EmptyVisitationContext.INSTANCE); |
| 96 | + assertTrue(roundtripRel.hasAggregate()); |
| 97 | + |
| 98 | + AggregateRel roundtripAggr = roundtripRel.getAggregate(); |
| 99 | + assertEquals(1, roundtripAggr.getGroupingsCount(), "grouping count should be 1"); |
| 100 | + assertEquals( |
| 101 | + 2, |
| 102 | + roundtripAggr.getGroupingExpressionsCount(), |
| 103 | + "grouping expressions count of aggregate should be 2"); |
| 104 | + assertEquals( |
| 105 | + 0, |
| 106 | + roundtripAggr.getGroupings(0).getGroupingExpressionsCount(), |
| 107 | + "grouping expressions count of grouping should be 0"); |
| 108 | + assertEquals( |
| 109 | + 2, |
| 110 | + roundtripAggr.getGroupings(0).getExpressionReferencesCount(), |
| 111 | + "expression reference count of grouping should be 2"); |
93 | 112 | } |
94 | 113 |
|
95 | 114 | @Test |
@@ -127,6 +146,24 @@ void testAggregateWithSingleGrouping() { |
127 | 146 | Aggregate agg = (Aggregate) resultRel; |
128 | 147 | assertEquals(1, agg.getGroupings().size()); |
129 | 148 | assertEquals(2, agg.getGroupings().get(0).getExpressions().size()); |
| 149 | + |
| 150 | + Rel roundtripRel = relProtoConverter.visit(agg, EmptyVisitationContext.INSTANCE); |
| 151 | + assertTrue(roundtripRel.hasAggregate()); |
| 152 | + |
| 153 | + AggregateRel roundtripAgg = roundtripRel.getAggregate(); |
| 154 | + assertEquals(1, roundtripAgg.getGroupingsCount(), "grouping count should be 1"); |
| 155 | + assertEquals( |
| 156 | + 2, |
| 157 | + roundtripAgg.getGroupingExpressionsCount(), |
| 158 | + "grouping expressions count of aggregate should be 2"); |
| 159 | + assertEquals( |
| 160 | + 0, |
| 161 | + roundtripAgg.getGroupings(0).getGroupingExpressionsCount(), |
| 162 | + "grouping expressions count of grouping should be 0"); |
| 163 | + assertEquals( |
| 164 | + 2, |
| 165 | + roundtripAgg.getGroupings(0).getExpressionReferencesCount(), |
| 166 | + "expression reference count of grouping should be 2"); |
130 | 167 | } |
131 | 168 |
|
132 | 169 | @Test |
@@ -169,5 +206,27 @@ void testAggregateWithMultipleGroupings() { |
169 | 206 | assertEquals(2, agg.getGroupings().size()); |
170 | 207 | assertEquals(2, agg.getGroupings().get(0).getExpressions().size()); |
171 | 208 | assertEquals(1, agg.getGroupings().get(1).getExpressions().size()); |
| 209 | + |
| 210 | + Rel roundtripRel = relProtoConverter.visit(agg, EmptyVisitationContext.INSTANCE); |
| 211 | + assertTrue(roundtripRel.hasAggregate()); |
| 212 | + |
| 213 | + AggregateRel roundtripAgg = roundtripRel.getAggregate(); |
| 214 | + assertEquals(2, roundtripAgg.getGroupingsCount(), "grouping count should be 2"); |
| 215 | + assertEquals( |
| 216 | + 2, |
| 217 | + roundtripAgg.getGroupingExpressionsCount(), |
| 218 | + "grouping expressions count of aggregate should be 2"); |
| 219 | + assertEquals( |
| 220 | + 0, |
| 221 | + roundtripAgg.getGroupings(0).getGroupingExpressionsCount(), |
| 222 | + "grouping expressions count of grouping should be 0"); |
| 223 | + assertEquals( |
| 224 | + 2, |
| 225 | + roundtripAgg.getGroupings(0).getExpressionReferencesCount(), |
| 226 | + "expression reference count of grouping should be 2"); |
| 227 | + assertEquals( |
| 228 | + 1, |
| 229 | + roundtripAgg.getGroupings(1).getExpressionReferencesCount(), |
| 230 | + "expression reference count of grouping should be 2"); |
172 | 231 | } |
173 | 232 | } |
0 commit comments