Skip to content

Commit e24a8e0

Browse files
committed
Speed up loading keyword fields with index sorts
1 parent 8639922 commit e24a8e0

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

server/src/main/java/org/elasticsearch/index/codec/tsdb/es819/ES819TSDBDocValuesProducer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
final class ES819TSDBDocValuesProducer extends DocValuesProducer {
5555
final IntObjectHashMap<NumericEntry> numerics;
5656
private int primarySortFieldNumber = -1;
57+
private boolean primarySortFieldReversed = false;
5758
final IntObjectHashMap<BinaryEntry> binaries;
5859
final IntObjectHashMap<SortedEntry> sorted;
5960
final IntObjectHashMap<SortedSetEntry> sortedSets;
@@ -93,9 +94,13 @@ final class ES819TSDBDocValuesProducer extends DocValuesProducer {
9394

9495
readFields(in, state.fieldInfos);
9596
final var indexSort = state.segmentInfo.getIndexSort();
96-
if (indexSort != null) {
97-
var primaryField = indexSort.getSort()[0];
98-
primarySortFieldNumber = state.fieldInfos.fieldInfo(primaryField.getField()).number;
97+
if (indexSort != null && indexSort.getSort().length > 0) {
98+
var primarySortField = indexSort.getSort()[0];
99+
var sortField = state.fieldInfos.fieldInfo(primarySortField.getField());
100+
if (sortField != null) {
101+
primarySortFieldNumber = sortField.number;
102+
primarySortFieldReversed = primarySortField.getReverse();
103+
}
99104
}
100105
} catch (Throwable exception) {
101106
priorE = exception;

server/src/test/java/org/elasticsearch/index/codec/tsdb/es819/ES819TSDBDocValuesFormatTests.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ public void testBulkLoading() throws Exception {
754754
{
755755
// bulk loading timestamp:
756756
var block = (TestBlock) timestampDV.tryRead(factory, docs, 0);
757-
assertNull(block);
757+
assertNotNull(block);
758758
assertEquals(size, block.size());
759759
for (int j = 0; j < block.size(); j++) {
760760
long actualTimestamp = (long) block.get(j);
@@ -766,7 +766,7 @@ public void testBulkLoading() throws Exception {
766766
{
767767
// bulk loading counter field:
768768
var block = (TestBlock) counterDV.tryRead(factory, docs, 0);
769-
assertNull(block);
769+
assertNotNull(block);
770770
assertEquals(size, block.size());
771771
for (int j = 0; j < block.size(); j++) {
772772
long actualCounter = (long) block.get(j);
@@ -778,7 +778,7 @@ public void testBulkLoading() throws Exception {
778778
{
779779
// bulk loading gauge field:
780780
var block = (TestBlock) gaugeDV.tryRead(factory, docs, 0);
781-
assertNull(block);
781+
assertNotNull(block);
782782
assertEquals(size, block.size());
783783
for (int j = 0; j < block.size(); j++) {
784784
long actualGauge = (long) block.get(j);
@@ -815,7 +815,7 @@ public void testBulkLoading() throws Exception {
815815
{
816816
// bulk loading timestamp:
817817
var block = (TestBlock) timestampDV.tryRead(blockFactory, docs, randomOffset);
818-
assertNull(block);
818+
assertNotNull(block);
819819
assertEquals(size, block.size());
820820
for (int j = 0; j < block.size(); j++) {
821821
long actualTimestamp = (long) block.get(j);
@@ -827,7 +827,7 @@ public void testBulkLoading() throws Exception {
827827
{
828828
// bulk loading counter field:
829829
var block = (TestBlock) counterDV.tryRead(factory, docs, randomOffset);
830-
assertNull(block);
830+
assertNotNull(block);
831831
assertEquals(size, block.size());
832832
for (int j = 0; j < block.size(); j++) {
833833
long actualCounter = (long) block.get(j);
@@ -839,7 +839,7 @@ public void testBulkLoading() throws Exception {
839839
{
840840
// bulk loading gauge field:
841841
var block = (TestBlock) gaugeDV.tryRead(factory, docs, randomOffset);
842-
assertNull(block);
842+
assertNotNull(block);
843843
assertEquals(size, block.size());
844844
for (int j = 0; j < block.size(); j++) {
845845
long actualGauge = (long) block.get(j);
@@ -863,7 +863,7 @@ public void testBulkLoading() throws Exception {
863863
{
864864
// bulk loading counter field:
865865
var block = (TestBlock) counterDV.tryRead(factory, docs, 0);
866-
assertNull(block);
866+
assertNotNull(block);
867867
assertEquals(size, block.size());
868868
for (int j = 0; j < block.size(); j++) {
869869
long actualCounter = (long) block.get(j);
@@ -947,7 +947,7 @@ public void testBulkLoadingWithSparseDocs() throws Exception {
947947
{
948948
timestampDV = getColumnAtTimeReader(leafReader, timestampField);
949949
var block = (TestBlock) timestampDV.tryRead(factory, docs, 0);
950-
assertNull(block);
950+
assertNotNull(block);
951951
assertEquals(numDocsPerQValue, block.size());
952952
for (int j = 0; j < block.size(); j++) {
953953
long actualTimestamp = (long) block.get(j);
@@ -958,7 +958,7 @@ public void testBulkLoadingWithSparseDocs() throws Exception {
958958
{
959959
counterDV = getColumnAtTimeReader(leafReader, counterField);
960960
var block = (TestBlock) counterDV.tryRead(factory, docs, 0);
961-
assertNull(block);
961+
assertNotNull(block);
962962
assertEquals(numDocsPerQValue, block.size());
963963
for (int j = 0; j < block.size(); j++) {
964964
long actualCounter = (long) block.get(j);

0 commit comments

Comments
 (0)