Skip to content

Commit

Permalink
ESQL: Move cast in Block reading
Browse files Browse the repository at this point in the history
This moves the cast required for reading `Block`s from the special
subclass a little earlier.
  • Loading branch information
nik9000 committed Oct 5, 2023
1 parent 9f72ce0 commit a67dc0a
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ default String getWriteableName() {
NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Block.class, "BooleanBlock", BooleanBlock::readFrom);

private static BooleanBlock readFrom(StreamInput in) throws IOException {
return readFrom((BlockStreamInput) in);
}

private static BooleanBlock readFrom(BlockStreamInput in) throws IOException {
final boolean isVector = in.readBoolean();
if (isVector) {
return BooleanVector.readFrom(((BlockStreamInput) in).blockFactory(), in).asBlock();
return BooleanVector.readFrom(in.blockFactory(), in).asBlock();
}
final int positions = in.readVInt();
try (BooleanBlock.Builder builder = ((BlockStreamInput) in).blockFactory().newBooleanBlockBuilder(positions)) {
try (BooleanBlock.Builder builder = in.blockFactory().newBooleanBlockBuilder(positions)) {
for (int i = 0; i < positions; i++) {
if (in.readBoolean()) {
builder.appendNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ default String getWriteableName() {
NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Block.class, "BytesRefBlock", BytesRefBlock::readFrom);

private static BytesRefBlock readFrom(StreamInput in) throws IOException {
return readFrom((BlockStreamInput) in);
}

private static BytesRefBlock readFrom(BlockStreamInput in) throws IOException {
final boolean isVector = in.readBoolean();
if (isVector) {
return BytesRefVector.readFrom(((BlockStreamInput) in).blockFactory(), in).asBlock();
return BytesRefVector.readFrom(in.blockFactory(), in).asBlock();
}
final int positions = in.readVInt();
try (BytesRefBlock.Builder builder = ((BlockStreamInput) in).blockFactory().newBytesRefBlockBuilder(positions)) {
try (BytesRefBlock.Builder builder = in.blockFactory().newBytesRefBlockBuilder(positions)) {
for (int i = 0; i < positions; i++) {
if (in.readBoolean()) {
builder.appendNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ default String getWriteableName() {
NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Block.class, "DoubleBlock", DoubleBlock::readFrom);

private static DoubleBlock readFrom(StreamInput in) throws IOException {
return readFrom((BlockStreamInput) in);
}

private static DoubleBlock readFrom(BlockStreamInput in) throws IOException {
final boolean isVector = in.readBoolean();
if (isVector) {
return DoubleVector.readFrom(((BlockStreamInput) in).blockFactory(), in).asBlock();
return DoubleVector.readFrom(in.blockFactory(), in).asBlock();
}
final int positions = in.readVInt();
try (DoubleBlock.Builder builder = ((BlockStreamInput) in).blockFactory().newDoubleBlockBuilder(positions)) {
try (DoubleBlock.Builder builder = in.blockFactory().newDoubleBlockBuilder(positions)) {
for (int i = 0; i < positions; i++) {
if (in.readBoolean()) {
builder.appendNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ default String getWriteableName() {
NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Block.class, "IntBlock", IntBlock::readFrom);

private static IntBlock readFrom(StreamInput in) throws IOException {
return readFrom((BlockStreamInput) in);
}

private static IntBlock readFrom(BlockStreamInput in) throws IOException {
final boolean isVector = in.readBoolean();
if (isVector) {
return IntVector.readFrom(((BlockStreamInput) in).blockFactory(), in).asBlock();
return IntVector.readFrom(in.blockFactory(), in).asBlock();
}
final int positions = in.readVInt();
try (IntBlock.Builder builder = ((BlockStreamInput) in).blockFactory().newIntBlockBuilder(positions)) {
try (IntBlock.Builder builder = in.blockFactory().newIntBlockBuilder(positions)) {
for (int i = 0; i < positions; i++) {
if (in.readBoolean()) {
builder.appendNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ default String getWriteableName() {
NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Block.class, "LongBlock", LongBlock::readFrom);

private static LongBlock readFrom(StreamInput in) throws IOException {
return readFrom((BlockStreamInput) in);
}

private static LongBlock readFrom(BlockStreamInput in) throws IOException {
final boolean isVector = in.readBoolean();
if (isVector) {
return LongVector.readFrom(((BlockStreamInput) in).blockFactory(), in).asBlock();
return LongVector.readFrom(in.blockFactory(), in).asBlock();
}
final int positions = in.readVInt();
try (LongBlock.Builder builder = ((BlockStreamInput) in).blockFactory().newLongBlockBuilder(positions)) {
try (LongBlock.Builder builder = in.blockFactory().newLongBlockBuilder(positions)) {
for (int i = 0; i < positions; i++) {
if (in.readBoolean()) {
builder.appendNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,16 @@ $endif$
NamedWriteableRegistry.Entry ENTRY = new NamedWriteableRegistry.Entry(Block.class, "$Type$Block", $Type$Block::readFrom);

private static $Type$Block readFrom(StreamInput in) throws IOException {
return readFrom((BlockStreamInput) in);
}

private static $Type$Block readFrom(BlockStreamInput in) throws IOException {
final boolean isVector = in.readBoolean();
if (isVector) {
return $Type$Vector.readFrom(((BlockStreamInput) in).blockFactory(), in).asBlock();
return $Type$Vector.readFrom(in.blockFactory(), in).asBlock();
}
final int positions = in.readVInt();
try ($Type$Block.Builder builder = ((BlockStreamInput) in).blockFactory().new$Type$BlockBuilder(positions)) {
try ($Type$Block.Builder builder = in.blockFactory().new$Type$BlockBuilder(positions)) {
for (int i = 0; i < positions; i++) {
if (in.readBoolean()) {
builder.appendNull();
Expand Down

0 comments on commit a67dc0a

Please sign in to comment.