Skip to content

Commit

Permalink
fixup! fixup! fixup! ensure sorting on a dynamic column in a partitio…
Browse files Browse the repository at this point in the history
…ned table works in all cases
  • Loading branch information
msbt committed Mar 24, 2015
1 parent e5ba03c commit 51d997d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ public SortField visitFunction(final Function function, final SortSymbolContext
final Input functionInput = inputs.get(0);
@SuppressWarnings("unchecked")
final List<LuceneCollectorExpression> expressions = inputContext.docLevelExpressions();
final SortField.Type type = LUCENE_TYPE_MAP.get(function.valueType());
// our boolean functions return booleans, no BytesRefs, handle them differently
// this is a hack, but that is how it worked before, so who cares :)
final SortField.Type type = function.valueType().equals(DataTypes.BOOLEAN) ? null : LUCENE_TYPE_MAP.get(function.valueType());
final SortField.Type reducedType = MoreObjects.firstNonNull(type, SortField.Type.DOC);

return new SortField(function.toString(), new IndexFieldData.XFieldComparatorSource() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,8 @@ public void testGroupOnDynamicColumn() throws Exception {
execute("insert into event (day) values ('2015-01-03')");
execute("insert into event (day, sessionid) values ('2015-01-01', 'hello')");
execute("refresh table event");
waitNoPendingTasksOnAll();

execute("select sessionid from event group by sessionid order by sessionid");
assertThat(response.rows().length, Is.is(2));
assertThat((String)response.rows()[0][0], Is.is("hello"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ public class QueryThenFetchIntegrationTest extends SQLTransportIntegrationTest {

@Test
public void testCrateSearchServiceSupportsOrderByOnFunctionWithBooleanReturnType() throws Exception {
execute("create table t (name string) with (number_of_replicas = 0)");
execute("insert into t (name) values ('Marvin'), ('Trillian')");
execute("create table t (name string, b byte) with (number_of_replicas = 0)");
execute("insert into t (name, b) values ('Marvin', 0), ('Trillian', 1), ('Arthur', 2), ('Max', 3)");
execute("refresh table t");
ensureGreen();

execute("select * from t order by substr(name, 1, 1) = 'M'");
assertThat(((String) response.rows()[0][0]), is("Trillian"));
assertThat(((String) response.rows()[1][0]), is("Marvin"));
execute("select * from t order by substr(name, 1, 1) = 'M', b");
assertThat(TestingHelpers.printedTable(response.rows()), is(
"1| Trillian\n" +
"2| Arthur\n" +
"0| Marvin\n" +
"3| Max\n"));
}

@Test
Expand Down

0 comments on commit 51d997d

Please sign in to comment.