1515
1616import com .google .common .collect .ImmutableList ;
1717import io .airlift .slice .Slice ;
18- import io .trino .spi .Experimental ;
1918import io .trino .spi .Page ;
20- import io .trino .spi .block .ByteArrayBlock ;
21- import io .trino .spi .block .ValueBlock ;
19+ import io .trino .spi .block .Block ;
20+ import io .trino .spi .block .RunLengthEncodedBlock ;
2221import io .trino .spi .block .VariableWidthBlockBuilder ;
2322import io .trino .spi .type .Type ;
2423import io .trino .testing .MaterializedResult ;
2524import org .junit .jupiter .api .Test ;
2625
2726import java .util .List ;
28- import java .util .Optional ;
29- import java .util .function .ObjLongConsumer ;
3027
3128import static io .airlift .slice .Slices .wrappedBuffer ;
3229import static io .trino .SequencePageBuilder .createSequencePage ;
@@ -79,13 +76,13 @@ public void testSplitPageNonDecreasingPageSize()
7976 {
8077 int positionCount = 100 ;
8178 int maxPageSizeInBytes = 1 ;
79+ List <Type > types = ImmutableList .of (VARCHAR );
8280
8381 Slice expectedValue = wrappedBuffer ("test" .getBytes (UTF_8 ));
8482 VariableWidthBlockBuilder blockBuilder = VARCHAR .createBlockBuilder (null , 1 , expectedValue .length ());
85- for (int i = 0 ; i < positionCount ; i ++) {
86- blockBuilder .writeEntry (expectedValue );
87- }
88- Page initialPage = new Page (new FixedDataSizeBlock (expectedValue .length (), blockBuilder .buildValueBlock ()));
83+ blockBuilder .writeEntry (expectedValue );
84+ Block rleBlock = RunLengthEncodedBlock .create (blockBuilder .build (), positionCount );
85+ Page initialPage = new Page (rleBlock );
8986 List <Page > pages = splitPage (initialPage , maxPageSizeInBytes );
9087
9188 // the page should only be split in half as the recursion should terminate
@@ -98,89 +95,8 @@ public void testSplitPageNonDecreasingPageSize()
9895 assertThat ((int ) first .getSizeInBytes ()).isGreaterThan (maxPageSizeInBytes );
9996 assertThat ((int ) second .getSizeInBytes ()).isGreaterThan (maxPageSizeInBytes );
10097 assertPositionCount (pages , positionCount );
101- }
102-
103- // Fake block that has retains a fixed size when split
104- private record FixedDataSizeBlock (long fixedSize , ValueBlock delegate )
105- implements ValueBlock
106- {
107- @ Override
108- public ValueBlock copyPositions (int [] positions , int offset , int length )
109- {
110- return new FixedDataSizeBlock (fixedSize , delegate .copyPositions (positions , offset , length ));
111- }
112-
113- @ Override
114- public ValueBlock getRegion (int positionOffset , int length )
115- {
116- return new FixedDataSizeBlock (fixedSize , delegate .getRegion (positionOffset , length ));
117- }
118-
119- @ Override
120- public ValueBlock copyRegion (int position , int length )
121- {
122- return new FixedDataSizeBlock (fixedSize , delegate .copyRegion (position , length ));
123- }
124-
125- @ Override
126- public ValueBlock copyWithAppendedNull ()
127- {
128- return new FixedDataSizeBlock (fixedSize , delegate .copyWithAppendedNull ());
129- }
130-
131- @ Experimental (eta = "2025-01-01" )
132- @ Override
133- public Optional <ByteArrayBlock > getNulls ()
134- {
135- return delegate .getNulls ();
136- }
137-
138- @ Override
139- public ValueBlock getSingleValueBlock (int position )
140- {
141- return delegate .getSingleValueBlock (position );
142- }
143-
144- @ Override
145- public int getPositionCount ()
146- {
147- return delegate .getPositionCount ();
148- }
149-
150- @ Override
151- public long getSizeInBytes ()
152- {
153- return fixedSize ;
154- }
155-
156- @ Override
157- public long getRegionSizeInBytes (int position , int length )
158- {
159- return delegate .getRegionSizeInBytes (position , length );
160- }
161-
162- @ Override
163- public long getRetainedSizeInBytes ()
164- {
165- return delegate .getRetainedSizeInBytes ();
166- }
167-
168- @ Override
169- public long getEstimatedDataSizeForStats (int position )
170- {
171- return delegate .getEstimatedDataSizeForStats (position );
172- }
173-
174- @ Override
175- public void retainedBytesForEachPart (ObjLongConsumer <Object > consumer )
176- {
177- delegate .retainedBytesForEachPart (consumer );
178- }
179-
180- @ Override
181- public boolean isNull (int position )
182- {
183- return delegate .isNull (position );
184- }
98+ MaterializedResult actual = toMaterializedResult (TEST_SESSION , types , pages );
99+ MaterializedResult expected = toMaterializedResult (TEST_SESSION , types , ImmutableList .of (initialPage ));
100+ assertThat (actual ).containsExactlyElementsOf (expected );
185101 }
186102}
0 commit comments