Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 70e0add

Browse files
Philipp Bogensbergerseut
authored andcommitted
reverted adding OrderedRowDelegate
1 parent b84be21 commit 70e0add

5 files changed

Lines changed: 10 additions & 180 deletions

File tree

sql/src/main/java/io/crate/operation/collect/CollectInputSymbolVisitor.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ public static class Context<E> extends AbstractImplementationSymbolVisitor.Conte
5050

5151
protected ArrayList<E> docLevelExpressions = new ArrayList<>();
5252

53-
protected ArrayList<E> orderByOnlyExpressions = new ArrayList<>();
54-
5553
private @Nullable OrderBy orderBy = null;
5654

5755
public List<E> docLevelExpressions() {
@@ -65,15 +63,6 @@ public void orderBy(@Nullable OrderBy orderBy) {
6563
public @Nullable OrderBy orderBy() {
6664
return this.orderBy;
6765
}
68-
69-
public void addOrderByOnlyExpression(E expr) {
70-
orderByOnlyExpressions.add(expr);
71-
}
72-
73-
public ArrayList<E> orderByOnlyExpressions() {
74-
return orderByOnlyExpressions;
75-
}
76-
7766
}
7867

7968
public CollectInputSymbolVisitor(Functions functions, DocLevelReferenceResolver<E> referenceResolver) {
@@ -89,13 +78,6 @@ public Context process(CollectNode node) {
8978
for (Symbol symbol : node.toCollect()) {
9079
context.add(process(symbol, context));
9180
}
92-
if (node.orderBy() != null) {
93-
for (Symbol symbol : node.orderBy().orderBySymbols()) {
94-
if ( !node.toCollect().contains(symbol)) {
95-
context.addOrderByOnlyExpression(process(symbol, context));
96-
}
97-
}
98-
}
9981
}
10082
return context;
10183
}

sql/src/main/java/io/crate/operation/collect/LuceneDocCollector.java

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,14 @@
2121

2222
package io.crate.operation.collect;
2323

24-
import com.google.common.base.Function;
2524
import com.google.common.base.MoreObjects;
26-
import com.google.common.collect.Lists;
2725
import io.crate.action.sql.query.CrateSearchContext;
2826
import io.crate.action.sql.query.CrateSearchService;
2927
import io.crate.analyze.OrderBy;
3028
import io.crate.breaker.CrateCircuitBreakerService;
3129
import io.crate.breaker.RamAccountingContext;
32-
import io.crate.core.collections.Row;
3330
import io.crate.metadata.Functions;
3431
import io.crate.operation.*;
35-
import io.crate.operation.fetch.OrderedRowDelegate;
3632
import io.crate.operation.reference.doc.lucene.CollectorContext;
3733
import io.crate.operation.reference.doc.lucene.LuceneCollectorExpression;
3834
import io.crate.operation.reference.doc.lucene.LuceneDocLevelReferenceResolver;
@@ -97,7 +93,6 @@ public void required(boolean required) {
9793
private final int jobSearchContextId;
9894
private final boolean keepContextForFetcher;
9995
private final List<OrderByCollectorExpression> orderByCollectorExpressions = new ArrayList<>();
100-
private final List<OrderByCollectorExpression> orderByOnlyCollectorExpressions;
10196
private final Integer limit;
10297
private final OrderBy orderBy;
10398

@@ -110,7 +105,6 @@ public void required(boolean required) {
110105

111106
public LuceneDocCollector(List<Input<?>> inputs,
112107
List<LuceneCollectorExpression<?>> collectorExpressions,
113-
List<OrderByCollectorExpression> orderByOnlyCollectorExpressions,
114108
CollectNode collectNode,
115109
Functions functions,
116110
RowDownstream downStreamProjector,
@@ -123,7 +117,6 @@ public LuceneDocCollector(List<Input<?>> inputs,
123117
this.downstream = downStreamProjector.registerUpstream(this);
124118
this.inputRow = new InputRow(inputs);
125119
this.collectorExpressions = collectorExpressions;
126-
this.orderByOnlyCollectorExpressions = orderByOnlyCollectorExpressions;
127120
for (LuceneCollectorExpression expr : collectorExpressions) {
128121
if ( expr instanceof OrderByCollectorExpression) {
129122
orderByCollectorExpressions.add((OrderByCollectorExpression)expr);
@@ -168,21 +161,8 @@ public void collect(int doc) throws IOException {
168161
for (LuceneCollectorExpression e : collectorExpressions) {
169162
e.setNextDocId(doc);
170163
}
171-
Row output;
172-
if (orderByOnlyCollectorExpressions.size() > 0) {
173-
List<Object> orderByOnlyValues = new ArrayList<>(orderByCollectorExpressions.size());
174-
orderByOnlyValues.addAll(Lists.transform(orderByOnlyCollectorExpressions, new Function<OrderByCollectorExpression, Object>() {
175-
@Override
176-
public Object apply(OrderByCollectorExpression input) {
177-
return input.value();
178-
}
179-
}));
180-
output = new OrderedRowDelegate(inputRow, orderByOnlyValues);
181-
} else {
182-
output = inputRow;
183-
}
184164

185-
if (!downstream.setNextRow(output) || (limit != null && rowCount == limit)) {
165+
if (!downstream.setNextRow(inputRow) || (limit != null && rowCount == limit)) {
186166
// no more rows required, we can stop here
187167
throw new CollectionAbortedException();
188168
}

sql/src/main/java/io/crate/operation/collect/ShardCollectService.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ public LuceneDocCollector apply(Engine.Searcher engineSearcher) {
235235
return new LuceneDocCollector(
236236
docCtx.topLevelInputs(),
237237
docCtx.docLevelExpressions(),
238-
docCtx.orderByOnlyExpressions(),
239238
collectNode,
240239
functions,
241240
downstream,

sql/src/main/java/io/crate/operation/fetch/OrderedRowDelegate.java

Lines changed: 0 additions & 56 deletions
This file was deleted.

sql/src/test/java/io/crate/operation/collect/LuceneDocCollectorTest.java

Lines changed: 9 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,12 @@
2525
import io.crate.analyze.OrderBy;
2626
import io.crate.analyze.WhereClause;
2727
import 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;
3128
import io.crate.integrationtests.SQLTransportIntegrationTest;
3229
import io.crate.metadata.ReferenceIdent;
3330
import io.crate.metadata.ReferenceInfo;
3431
import io.crate.metadata.TableIdent;
3532
import io.crate.operation.projectors.CollectingProjector;
3633
import io.crate.operation.projectors.ProjectionToProjectorVisitor;
37-
import io.crate.operation.projectors.Projector;
3834
import io.crate.planner.RowGranularity;
3935
import io.crate.planner.node.dql.CollectNode;
4036
import io.crate.planner.symbol.Reference;
@@ -57,7 +53,6 @@
5753
import java.io.IOException;
5854
import java.util.List;
5955
import java.util.UUID;
60-
import java.util.Vector;
6156

6257
import static org.hamcrest.Matchers.is;
6358
import 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

Comments
 (0)