2525import io .crate .analyze .OrderBy ;
2626import io .crate .analyze .WhereClause ;
2727import io .crate .breaker .RamAccountingContext ;
28- import io .crate .core .collections .Bucket ;
29- import io .crate .core .collections .Row ;
30- import io .crate .executor .transport .distributed .ResultProviderBase ;
3128import io .crate .integrationtests .SQLTransportIntegrationTest ;
3229import io .crate .metadata .ReferenceIdent ;
3330import io .crate .metadata .ReferenceInfo ;
3431import io .crate .metadata .TableIdent ;
3532import io .crate .operation .projectors .CollectingProjector ;
3633import io .crate .operation .projectors .ProjectionToProjectorVisitor ;
37- import io .crate .operation .projectors .Projector ;
3834import io .crate .planner .RowGranularity ;
3935import io .crate .planner .node .dql .CollectNode ;
4036import io .crate .planner .symbol .Reference ;
5753import java .io .IOException ;
5854import java .util .List ;
5955import java .util .UUID ;
60- import java .util .Vector ;
6156
6257import static org .hamcrest .Matchers .is ;
6358import static org .mockito .Matchers .any ;
@@ -127,11 +122,7 @@ public void generateData() throws Exception {
127122 refresh (client ());
128123 }
129124
130- private LuceneDocCollector createDocCollector (OrderBy orderBy , Integer limit , List <Symbol > toCollect ) throws Exception {
131- return createDocCollector (orderBy , limit , toCollect , collectingProjector );
132- }
133-
134- private LuceneDocCollector createDocCollector (OrderBy orderBy , Integer limit , List <Symbol > toCollect , Projector projector ) throws Exception {
125+ private LuceneDocCollector createDocCollector (OrderBy orderBy , Integer limit , List <Symbol > toCollect ) throws Exception {
135126 CollectNode node = new CollectNode ();
136127 node .whereClause (WhereClause .MATCH_ALL );
137128 node .orderBy (orderBy );
@@ -141,7 +132,7 @@ private LuceneDocCollector createDocCollector(OrderBy orderBy, Integer limit, Li
141132 node .maxRowGranularity (RowGranularity .DOC );
142133
143134 ShardProjectorChain projectorChain = mock (ShardProjectorChain .class );
144- when (projectorChain .newShardDownstreamProjector (any (ProjectionToProjectorVisitor .class ))).thenReturn (projector );
135+ when (projectorChain .newShardDownstreamProjector (any (ProjectionToProjectorVisitor .class ))).thenReturn (collectingProjector );
145136
146137 int jobSearchContextId = 0 ;
147138 JobCollectContext jobCollectContext = collectContextService .acquireContext (node .jobId ().get ());
@@ -195,8 +186,7 @@ public void testOrderedWithoutLimit() throws Exception {
195186
196187 @ Test
197188 public void testOrderForNonSelected () throws Exception {
198- // select "countryName" from countries order by population
199- TestCollectingProjector projector = new TestCollectingProjector ();
189+ collectingProjector .rows .clear ();
200190 ReferenceIdent countriesIdent = new ReferenceIdent (new TableIdent ("doc" , "countries" ), "countryName" );
201191 Reference countries = new Reference (new ReferenceInfo (countriesIdent , RowGranularity .DOC , DataTypes .STRING ));
202192
@@ -205,77 +195,12 @@ public void testOrderForNonSelected() throws Exception {
205195
206196 OrderBy orderBy = new OrderBy (ImmutableList .of ((Symbol )population ), new boolean []{true }, new Boolean []{true });
207197
208- LuceneDocCollector docCollector = createDocCollector (orderBy , null , ImmutableList .of ((Symbol )countries ), projector );
198+ LuceneDocCollector docCollector = createDocCollector (orderBy , null , ImmutableList .of ((Symbol )countries ));
209199 docCollector .doCollect (RAM_ACCOUNTING_CONTEXT );
210- assertThat (projector .rows .size (), is (NUMBER_OF_DOCS ));
211-
212- assertThat (projector .rows .get (0 ).size (), is (1 ));
213- assertThat (((BytesRef )projector .rows .get (NUMBER_OF_DOCS - 3 ).get (0 )).utf8ToString (), is ("USA" ) );
214- assertThat ((Integer )projector .rows .get (NUMBER_OF_DOCS - 3 ).get (1 ), is (2 ));
215- assertThat (((BytesRef )projector .rows .get (NUMBER_OF_DOCS - 2 ).get (0 )).utf8ToString (), is ("Austria" ) );
216- assertThat ((Integer )projector .rows .get (NUMBER_OF_DOCS - 2 ).get (1 ), is (1 ));
217- assertThat (((BytesRef )projector .rows .get (NUMBER_OF_DOCS - 1 ).get (0 )).utf8ToString (), is ("Germany" ) );
218- assertThat ((Integer )projector .rows .get (NUMBER_OF_DOCS - 1 ).get (1 ), is (0 ));
219-
220- }
221-
222- @ Test
223- public void testOrderForSelectedAndNonSelected () throws Exception {
224- // select "countryName", population from countries order by continent desc, population
225- TestCollectingProjector projector = new TestCollectingProjector ();
226- ReferenceIdent countriesIdent = new ReferenceIdent (new TableIdent ("doc" , "countries" ), "countryName" );
227- Reference countries = new Reference (new ReferenceInfo (countriesIdent , RowGranularity .DOC , DataTypes .STRING ));
228-
229- ReferenceIdent populationIdent = new ReferenceIdent (new TableIdent ("doc" , "countries" ), "population" );
230- Reference population = new Reference (new ReferenceInfo (populationIdent , RowGranularity .DOC , DataTypes .INTEGER ));
231-
232- ReferenceIdent continentIdent = new ReferenceIdent (new TableIdent ("doc" , "countries" ), "continent" );
233- Reference continent = new Reference (new ReferenceInfo (continentIdent , RowGranularity .DOC , DataTypes .STRING ));
234-
235- OrderBy orderBy = new OrderBy (ImmutableList .of ((Symbol ) continent , (Symbol )population ), new boolean []{true , false }, new Boolean []{false , false });
236-
237- LuceneDocCollector docCollector = createDocCollector (orderBy , null , ImmutableList .of ((Symbol )countries , population ), projector );
238- docCollector .doCollect (RAM_ACCOUNTING_CONTEXT );
239- assertThat (projector .rows .size (), is (NUMBER_OF_DOCS ));
240-
241- Row row1 = projector .rows .get (0 );
242- Row row2 = projector .rows .get (1 );
243- Row row3 = projector .rows .get (2 );
244-
245- assertThat (row1 .size (), is (2 ));
246- assertThat (((BytesRef )row1 .get (0 )).utf8ToString (), is ("Germany" ));
247- assertThat ((Integer )row1 .get (1 ), is (0 ));
248- assertThat (((BytesRef )row1 .get (2 )).utf8ToString (), is ("Europe" ));
249-
250- assertThat (row2 .size (), is (2 ));
251- assertThat (((BytesRef )row2 .get (0 )).utf8ToString (), is ("Austria" ));
252- assertThat ((Integer )row2 .get (1 ), is (1 ));
253- assertThat (((BytesRef )row2 .get (2 )).utf8ToString (), is ("Europe" ));
254-
255- assertThat (row3 .size (), is (2 ));
256- assertThat (((BytesRef )row3 .get (0 )).utf8ToString (), is ("USA" ));
257- assertThat ((Integer )row3 .get (1 ), is (2 ));
258- assertThat (((BytesRef )row3 .get (2 )).utf8ToString (), is ("America" ));
259- }
260-
261- public class TestCollectingProjector extends ResultProviderBase {
262-
263- public final Vector <Row > rows = new Vector <>();
264-
265- @ Override
266- public boolean setNextRow (Row row ) {
267- rows .add (row );
268- return true ;
269- }
270-
271- @ Override
272- public Bucket doFinish () {
273- return null ;
274- }
275-
276- @ Override
277- public Throwable doFail (Throwable t ) {
278- return t ;
279- }
200+ assertThat (collectingProjector .rows .size (), is (NUMBER_OF_DOCS ));
201+ assertThat (collectingProjector .rows .get (0 ).length , is (1 ));
202+ assertThat (((BytesRef )collectingProjector .rows .get (NUMBER_OF_DOCS - 3 )[0 ]).utf8ToString (), is ("USA" ) );
203+ assertThat (((BytesRef )collectingProjector .rows .get (NUMBER_OF_DOCS - 2 )[0 ]).utf8ToString (), is ("Austria" ) );
204+ assertThat (((BytesRef )collectingProjector .rows .get (NUMBER_OF_DOCS - 1 )[0 ]).utf8ToString (), is ("Germany" ) );
280205 }
281206}
0 commit comments