Skip to content

Commit 156754e

Browse files
committed
Refactor DateRange Block type (and element type) to LongRange
1 parent fea50ba commit 156754e

File tree

46 files changed

+160
-168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+160
-168
lines changed

server/src/main/java/org/elasticsearch/index/mapper/BlockLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ interface BlockFactory {
497497

498498
AggregateMetricDoubleBuilder aggregateMetricDoubleBuilder(int count);
499499

500-
DateRangeBuilder dateRangeBuilder(int count);
500+
LongRangeBuilder dateRangeBuilder(int count);
501501
}
502502

503503
/**
@@ -626,7 +626,7 @@ interface AggregateMetricDoubleBuilder extends Builder {
626626
IntBuilder count();
627627
}
628628

629-
interface DateRangeBuilder extends Builder {
629+
interface LongRangeBuilder extends Builder {
630630
LongBuilder from();
631631

632632
LongBuilder to();

server/src/main/java/org/elasticsearch/index/mapper/RangeFieldMapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public class RangeFieldMapper extends FieldMapper {
6464
public static final boolean DEFAULT_INCLUDE_UPPER = true;
6565
public static final boolean DEFAULT_INCLUDE_LOWER = true;
6666

67-
public static final TransportVersion ESQL_DATE_RANGE_CREATED_VERSION = TransportVersion.fromName("esql_date_range_created_version");
67+
public static final TransportVersion ESQL_LONG_RANGES = TransportVersion.fromName("esql_long_ranges");
6868

6969
public static class Defaults {
7070
public static final DateFormatter DATE_FORMATTER = DateFieldMapper.DEFAULT_DATE_TIME_FORMATTER;
@@ -398,7 +398,7 @@ public String toString() {
398398
@Override
399399
public BlockLoader.Block read(BlockLoader.BlockFactory factory, BlockLoader.Docs docs, int offset, boolean nullsFiltered)
400400
throws IOException {
401-
try (BlockLoader.DateRangeBuilder builder = factory.dateRangeBuilder(docs.count() - offset)) {
401+
try (BlockLoader.LongRangeBuilder builder = factory.dateRangeBuilder(docs.count() - offset)) {
402402
int lastDoc = -1;
403403
for (int i = offset; i < docs.count(); i++) {
404404
int doc = docs.get(i);
@@ -424,7 +424,7 @@ public BlockLoader.Block read(BlockLoader.BlockFactory factory, BlockLoader.Docs
424424

425425
@Override
426426
public void read(int doc, BlockLoader.StoredFields storedFields, BlockLoader.Builder builder) throws IOException {
427-
var blockBuilder = (BlockLoader.DateRangeBuilder) builder;
427+
var blockBuilder = (BlockLoader.LongRangeBuilder) builder;
428428
this.docId = doc;
429429
if (false == numericDocValues.advanceExact(doc)) {
430430
blockBuilder.appendNull();

server/src/main/resources/transport/definitions/referable/esql_date_range_created_version.csv

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
esql_date_range_created_version,9198000
1+
esql_long_ranges,9198000

test/framework/src/main/java/org/elasticsearch/index/mapper/TestBlock.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,8 +420,8 @@ public BlockLoader.AggregateMetricDoubleBuilder aggregateMetricDoubleBuilder(int
420420
}
421421

422422
@Override
423-
public BlockLoader.DateRangeBuilder dateRangeBuilder(int expectedSize) {
424-
return new DateRangeBuilder(expectedSize);
423+
public BlockLoader.LongRangeBuilder dateRangeBuilder(int expectedSize) {
424+
return new LongRangeBuilder(expectedSize);
425425
}
426426
};
427427
}
@@ -631,11 +631,11 @@ public void close() {
631631
}
632632
}
633633

634-
public static class DateRangeBuilder implements BlockLoader.DateRangeBuilder {
634+
public static class LongRangeBuilder implements BlockLoader.LongRangeBuilder {
635635
private final LongBuilder from;
636636
private final LongBuilder to;
637637

638-
DateRangeBuilder(int expectedSize) {
638+
LongRangeBuilder(int expectedSize) {
639639
from = new LongBuilder(expectedSize);
640640
to = new LongBuilder(expectedSize);
641641
}

x-pack/plugin/esql-core/src/main/java/org/elasticsearch/xpack/esql/core/type/DataType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import java.util.stream.Collectors;
3434

3535
import static java.util.stream.Collectors.toMap;
36-
import static org.elasticsearch.index.mapper.RangeFieldMapper.ESQL_DATE_RANGE_CREATED_VERSION;
36+
import static org.elasticsearch.index.mapper.RangeFieldMapper.ESQL_LONG_RANGES;
3737

3838
/**
3939
* This enum represents data types the ES|QL query processing layer is able to
@@ -274,7 +274,7 @@ public enum DataType implements Writeable {
274274
/**
275275
* Represents a half-inclusive range between two dates.
276276
*/
277-
DATE_RANGE(builder().esType("date_range").estimatedSize(2 * Long.BYTES).docValues().supportedOn(ESQL_DATE_RANGE_CREATED_VERSION)),
277+
DATE_RANGE(builder().esType("date_range").estimatedSize(2 * Long.BYTES).docValues().supportedOn(ESQL_LONG_RANGES)),
278278
/**
279279
* IP addresses. IPv4 address are always
280280
* <a href="https://datatracker.ietf.org/doc/html/rfc4291#section-2.5.5">embedded</a>

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/BlockFactory.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -481,12 +481,12 @@ public final AggregateMetricDoubleBlock newAggregateMetricDoubleBlock(
481481
return new AggregateMetricDoubleArrayBlock(min, max, sum, count);
482482
}
483483

484-
public DateRangeBlockBuilder newDateRangeBlockBuilder(int estimatedSize) {
485-
return new DateRangeBlockBuilder(estimatedSize, this);
484+
public LongRangeBlockBuilder newLongRangeBlockBuilder(int estimatedSize) {
485+
return new LongRangeBlockBuilder(estimatedSize, this);
486486
}
487487

488-
public DateRangeBlock newConstantDateRangeBlock(DateRangeBlockBuilder.DateRangeLiteral value, int positions) {
489-
try (var builder = newDateRangeBlockBuilder(positions)) {
488+
public LongRangeBlock newConstantLongRangeBlock(LongRangeBlockBuilder.LongRange value, int positions) {
489+
try (var builder = newLongRangeBlockBuilder(positions)) {
490490
for (int i = 0; i < positions; i++) {
491491
if (value.from() == null) {
492492
builder.from().appendNull();
@@ -503,10 +503,10 @@ public DateRangeBlock newConstantDateRangeBlock(DateRangeBlockBuilder.DateRangeL
503503
}
504504
}
505505

506-
public DateRangeBlock newDateRangeBlock(long[] fromValues, long[] toValues, int positions) {
506+
public LongRangeBlock newLongRangeBlock(long[] fromValues, long[] toValues, int positions) {
507507
var from = newLongArrayVector(fromValues, positions).asBlock();
508508
var to = newLongArrayVector(toValues, positions).asBlock();
509-
return new DateRangeArrayBlock(from, to);
509+
return new LongRangeArrayBlock(from, to);
510510
}
511511

512512
/**

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/BlockUtils.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public static void appendValue(Block.Builder builder, Object val, ElementType ty
224224
case DOUBLE -> ((DoubleBlock.Builder) builder).appendDouble((Double) val);
225225
case BOOLEAN -> ((BooleanBlock.Builder) builder).appendBoolean((Boolean) val);
226226
case AGGREGATE_METRIC_DOUBLE -> ((AggregateMetricDoubleBlockBuilder) builder).appendLiteral((AggregateMetricDoubleLiteral) val);
227-
case DATE_RANGE -> ((DateRangeBlockBuilder) builder).appendDateRange((DateRangeBlockBuilder.DateRangeLiteral) val);
227+
case LONG_RANGE -> ((LongRangeBlockBuilder) builder).appendDateRange((LongRangeBlockBuilder.LongRange) val);
228228
default -> throw new UnsupportedOperationException("unsupported element type [" + type + "]");
229229
}
230230
}
@@ -254,7 +254,7 @@ private static Block constantBlock(BlockFactory blockFactory, ElementType type,
254254
case BOOLEAN -> blockFactory.newConstantBooleanBlockWith((boolean) val, size);
255255
case AGGREGATE_METRIC_DOUBLE -> blockFactory.newConstantAggregateMetricDoubleBlock((AggregateMetricDoubleLiteral) val, size);
256256
case FLOAT -> blockFactory.newConstantFloatBlockWith((float) val, size);
257-
case DATE_RANGE -> blockFactory.newConstantDateRangeBlock((DateRangeBlockBuilder.DateRangeLiteral) val, size);
257+
case LONG_RANGE -> blockFactory.newConstantLongRangeBlock((LongRangeBlockBuilder.LongRange) val, size);
258258
default -> throw new UnsupportedOperationException("unsupported element type [" + type + "]");
259259
};
260260
}
@@ -308,11 +308,11 @@ yield new AggregateMetricDoubleLiteral(
308308
aggBlock.countBlock().getInt(offset)
309309
);
310310
}
311-
case DATE_RANGE -> {
312-
DateRangeBlock b = (DateRangeBlock) block;
311+
case LONG_RANGE -> {
312+
LongRangeBlock b = (LongRangeBlock) block;
313313
LongBlock fromBlock = b.getFromBlock();
314314
LongBlock toBlock = b.getToBlock();
315-
yield new DateRangeBlockBuilder.DateRangeLiteral(fromBlock.getLong(offset), toBlock.getLong(offset));
315+
yield new LongRangeBlockBuilder.LongRange(fromBlock.getLong(offset), toBlock.getLong(offset));
316316
}
317317
case UNKNOWN -> throw new IllegalArgumentException("can't read values from [" + block + "]");
318318
};

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/ConstantNullBlock.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public final class ConstantNullBlock extends AbstractNonThreadSafeRefCounted
2727
DoubleBlock,
2828
BytesRefBlock,
2929
AggregateMetricDoubleBlock,
30-
DateRangeBlock {
30+
LongRangeBlock {
3131

3232
private static final long BASE_RAM_BYTES_USED = RamUsageEstimator.shallowSizeOfInstance(ConstantNullBlock.class);
3333
private final int positionCount;

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/ElementType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public enum ElementType {
6666
AggregateMetricDoubleArrayBlock::readFrom
6767
),
6868

69-
DATE_RANGE(11, "DateRange", BlockFactory::newDateRangeBlockBuilder, DateRangeArrayBlock::readFrom);
69+
LONG_RANGE(11, "LongRange", BlockFactory::newLongRangeBlockBuilder, LongRangeArrayBlock::readFrom);
7070

7171
private static final TransportVersion ESQL_SERIALIZE_BLOCK_TYPE_CODE = TransportVersion.fromName("esql_serialize_block_type_code");
7272

@@ -115,8 +115,8 @@ public static ElementType fromJava(Class<?> type) {
115115
elementType = BOOLEAN;
116116
} else if (type == AggregateMetricDoubleBlockBuilder.AggregateMetricDoubleLiteral.class) {
117117
elementType = AGGREGATE_METRIC_DOUBLE;
118-
} else if (type == DateRangeBlockBuilder.DateRangeLiteral.class) {
119-
elementType = DATE_RANGE;
118+
} else if (type == LongRangeBlockBuilder.LongRange.class) {
119+
elementType = LONG_RANGE;
120120
} else if (type == null || type == Void.class) {
121121
elementType = NULL;
122122
} else {

0 commit comments

Comments
 (0)