Skip to content

Commit 8b8b823

Browse files
committed
refactoring
1 parent 31e95e6 commit 8b8b823

File tree

9 files changed

+190
-78
lines changed

9 files changed

+190
-78
lines changed

java/memory/src/main/java/io/netty/buffer/ArrowBuf.java

Lines changed: 42 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
*/
1818
package io.netty.buffer;
1919

20-
import io.netty.util.internal.PlatformDependent;
21-
2220
import java.io.IOException;
2321
import java.io.InputStream;
2422
import java.io.OutputStream;
@@ -30,16 +28,18 @@
3028
import java.util.concurrent.atomic.AtomicInteger;
3129
import java.util.concurrent.atomic.AtomicLong;
3230

31+
import org.apache.arrow.memory.AllocationManager.BufferLedger;
3332
import org.apache.arrow.memory.BaseAllocator;
33+
import org.apache.arrow.memory.BaseAllocator.Verbosity;
3434
import org.apache.arrow.memory.BoundsChecking;
3535
import org.apache.arrow.memory.BufferAllocator;
3636
import org.apache.arrow.memory.BufferManager;
37-
import org.apache.arrow.memory.AllocationManager.BufferLedger;
38-
import org.apache.arrow.memory.BaseAllocator.Verbosity;
3937
import org.apache.arrow.memory.util.HistoricalLog;
4038

4139
import com.google.common.base.Preconditions;
4240

41+
import io.netty.util.internal.PlatformDependent;
42+
4343
public final class ArrowBuf extends AbstractByteBuf implements AutoCloseable {
4444
private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ArrowBuf.class);
4545

@@ -307,7 +307,7 @@ public ByteOrder order() {
307307
}
308308

309309
@Override
310-
public ByteBuf order(ByteOrder endianness) {
310+
public ArrowBuf order(ByteOrder endianness) {
311311
return this;
312312
}
313313

@@ -344,7 +344,7 @@ public ByteBuf copy(int index, int length) {
344344
}
345345

346346
@Override
347-
public ByteBuf slice() {
347+
public ArrowBuf slice() {
348348
return slice(readerIndex(), readableBytes());
349349
}
350350

@@ -467,7 +467,7 @@ public boolean equals(Object obj) {
467467
}
468468

469469
@Override
470-
public ByteBuf retain(int increment) {
470+
public ArrowBuf retain(int increment) {
471471
Preconditions.checkArgument(increment > 0, "retain(%d) argument is not positive", increment);
472472

473473
if (isEmpty) {
@@ -484,7 +484,7 @@ public ByteBuf retain(int increment) {
484484
}
485485

486486
@Override
487-
public ByteBuf retain() {
487+
public ArrowBuf retain() {
488488
return retain(1);
489489
}
490490

@@ -535,109 +535,109 @@ public short getShort(int index) {
535535
}
536536

537537
@Override
538-
public ByteBuf setShort(int index, int value) {
538+
public ArrowBuf setShort(int index, int value) {
539539
chk(index, 2);
540540
PlatformDependent.putShort(addr(index), (short) value);
541541
return this;
542542
}
543543

544544
@Override
545-
public ByteBuf setInt(int index, int value) {
545+
public ArrowBuf setInt(int index, int value) {
546546
chk(index, 4);
547547
PlatformDependent.putInt(addr(index), value);
548548
return this;
549549
}
550550

551551
@Override
552-
public ByteBuf setLong(int index, long value) {
552+
public ArrowBuf setLong(int index, long value) {
553553
chk(index, 8);
554554
PlatformDependent.putLong(addr(index), value);
555555
return this;
556556
}
557557

558558
@Override
559-
public ByteBuf setChar(int index, int value) {
559+
public ArrowBuf setChar(int index, int value) {
560560
chk(index, 2);
561561
PlatformDependent.putShort(addr(index), (short) value);
562562
return this;
563563
}
564564

565565
@Override
566-
public ByteBuf setFloat(int index, float value) {
566+
public ArrowBuf setFloat(int index, float value) {
567567
chk(index, 4);
568568
PlatformDependent.putInt(addr(index), Float.floatToRawIntBits(value));
569569
return this;
570570
}
571571

572572
@Override
573-
public ByteBuf setDouble(int index, double value) {
573+
public ArrowBuf setDouble(int index, double value) {
574574
chk(index, 8);
575575
PlatformDependent.putLong(addr(index), Double.doubleToRawLongBits(value));
576576
return this;
577577
}
578578

579579
@Override
580-
public ByteBuf writeShort(int value) {
580+
public ArrowBuf writeShort(int value) {
581581
ensure(2);
582582
PlatformDependent.putShort(addr(writerIndex), (short) value);
583583
writerIndex += 2;
584584
return this;
585585
}
586586

587587
@Override
588-
public ByteBuf writeInt(int value) {
588+
public ArrowBuf writeInt(int value) {
589589
ensure(4);
590590
PlatformDependent.putInt(addr(writerIndex), value);
591591
writerIndex += 4;
592592
return this;
593593
}
594594

595595
@Override
596-
public ByteBuf writeLong(long value) {
596+
public ArrowBuf writeLong(long value) {
597597
ensure(8);
598598
PlatformDependent.putLong(addr(writerIndex), value);
599599
writerIndex += 8;
600600
return this;
601601
}
602602

603603
@Override
604-
public ByteBuf writeChar(int value) {
604+
public ArrowBuf writeChar(int value) {
605605
ensure(2);
606606
PlatformDependent.putShort(addr(writerIndex), (short) value);
607607
writerIndex += 2;
608608
return this;
609609
}
610610

611611
@Override
612-
public ByteBuf writeFloat(float value) {
612+
public ArrowBuf writeFloat(float value) {
613613
ensure(4);
614614
PlatformDependent.putInt(addr(writerIndex), Float.floatToRawIntBits(value));
615615
writerIndex += 4;
616616
return this;
617617
}
618618

619619
@Override
620-
public ByteBuf writeDouble(double value) {
620+
public ArrowBuf writeDouble(double value) {
621621
ensure(8);
622622
PlatformDependent.putLong(addr(writerIndex), Double.doubleToRawLongBits(value));
623623
writerIndex += 8;
624624
return this;
625625
}
626626

627627
@Override
628-
public ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) {
628+
public ArrowBuf getBytes(int index, byte[] dst, int dstIndex, int length) {
629629
udle.getBytes(index + offset, dst, dstIndex, length);
630630
return this;
631631
}
632632

633633
@Override
634-
public ByteBuf getBytes(int index, ByteBuffer dst) {
634+
public ArrowBuf getBytes(int index, ByteBuffer dst) {
635635
udle.getBytes(index + offset, dst);
636636
return this;
637637
}
638638

639639
@Override
640-
public ByteBuf setByte(int index, int value) {
640+
public ArrowBuf setByte(int index, int value) {
641641
chk(index, 1);
642642
PlatformDependent.putByte(addr(index), (byte) value);
643643
return this;
@@ -699,13 +699,13 @@ protected void _setLong(int index, long value) {
699699
}
700700

701701
@Override
702-
public ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
702+
public ArrowBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) {
703703
udle.getBytes(index + offset, dst, dstIndex, length);
704704
return this;
705705
}
706706

707707
@Override
708-
public ByteBuf getBytes(int index, OutputStream out, int length) throws IOException {
708+
public ArrowBuf getBytes(int index, OutputStream out, int length) throws IOException {
709709
udle.getBytes(index + offset, out, length);
710710
return this;
711711
}
@@ -724,12 +724,12 @@ public int getBytes(int index, GatheringByteChannel out, int length) throws IOEx
724724
}
725725

726726
@Override
727-
public ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) {
727+
public ArrowBuf setBytes(int index, ByteBuf src, int srcIndex, int length) {
728728
udle.setBytes(index + offset, src, srcIndex, length);
729729
return this;
730730
}
731731

732-
public ByteBuf setBytes(int index, ByteBuffer src, int srcIndex, int length) {
732+
public ArrowBuf setBytes(int index, ByteBuffer src, int srcIndex, int length) {
733733
if (src.isDirect()) {
734734
checkIndex(index, length);
735735
PlatformDependent.copyMemory(PlatformDependent.directBufferAddress(src) + srcIndex, this.memoryAddress() + index,
@@ -749,13 +749,13 @@ public ByteBuf setBytes(int index, ByteBuffer src, int srcIndex, int length) {
749749
}
750750

751751
@Override
752-
public ByteBuf setBytes(int index, byte[] src, int srcIndex, int length) {
752+
public ArrowBuf setBytes(int index, byte[] src, int srcIndex, int length) {
753753
udle.setBytes(index + offset, src, srcIndex, length);
754754
return this;
755755
}
756756

757757
@Override
758-
public ByteBuf setBytes(int index, ByteBuffer src) {
758+
public ArrowBuf setBytes(int index, ByteBuffer src) {
759759
udle.setBytes(index + offset, src);
760760
return this;
761761
}
@@ -860,4 +860,17 @@ public void print(StringBuilder sb, int indent, Verbosity verbosity) {
860860
}
861861
}
862862

863+
@Override
864+
public ArrowBuf readerIndex(int readerIndex) {
865+
super.readerIndex(readerIndex);
866+
return this;
867+
}
868+
869+
@Override
870+
public ArrowBuf writerIndex(int writerIndex) {
871+
super.writerIndex(writerIndex);
872+
return this;
873+
}
874+
875+
863876
}

java/vector/src/main/codegen/templates/NullableValueVectors.java

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public final class ${className} extends BaseDataValueVector implements <#if type
5757
private final Mutator mutator;
5858
private final Accessor accessor;
5959

60+
private final List<BufferBacked> innerVectors;
61+
6062
<#if minor.class == "Decimal">
6163
private final int precision;
6264
private final int scale;
@@ -69,6 +71,10 @@ public final class ${className} extends BaseDataValueVector implements <#if type
6971
mutator = new Mutator();
7072
accessor = new Accessor();
7173
field = new Field(name, true, new Decimal(precision, scale), null);
74+
innerVectors = Collections.unmodifiableList(Arrays.<BufferBacked>asList(
75+
bits,
76+
values
77+
));
7278
}
7379
<#else>
7480
public ${className}(String name, BufferAllocator allocator) {
@@ -107,51 +113,41 @@ public final class ${className} extends BaseDataValueVector implements <#if type
107113
<#elseif minor.class == "Bit">
108114
field = new Field(name, true, new Bool(), null);
109115
</#if>
116+
innerVectors = Collections.unmodifiableList(Arrays.<BufferBacked>asList(
117+
bits,
118+
<#if type.major = "VarLen">
119+
values.offsetVector,
120+
</#if>
121+
values
122+
));
110123
}
111124
</#if>
112125

113-
/**
114-
* Initializes the child vectors
115-
* to be later loaded with loadBuffers
116-
* @param children
117-
*/
126+
@Override
127+
public List<BufferBacked> getFieldInnerVectors() {
128+
return innerVectors;
129+
}
130+
131+
@Override
118132
public void initializeChildrenFromFields(List<Field> children) {
119133
if (!children.isEmpty()) {
120134
throw new IllegalArgumentException("primitive type vector ${className} can not have children: " + children);
121135
}
122136
}
123137

138+
@Override
124139
public List<FieldVector> getChildrenFromFields() {
125140
return Collections.emptyList();
126141
}
127142

143+
@Override
128144
public void loadFieldBuffers(ArrowFieldNode fieldNode, List<ArrowBuf> ownBuffers) {
129-
int expectedSize = <#if type.major = "VarLen">3<#else>2</#if>;
130-
if (ownBuffers.size() != expectedSize) {
131-
throw new IllegalArgumentException("Illegal buffer count, expected " + expectedSize + ", got: " + ownBuffers.size());
132-
}
133-
bits.load(ownBuffers.get(0));
134-
<#if type.major = "VarLen">
135-
values.offsetVector.load(ownBuffers.get(1));
136-
values.load(ownBuffers.get(2));
137-
<#else>
138-
values.load(ownBuffers.get(1));
139-
</#if>
145+
org.apache.arrow.vector.BaseDataValueVector.load(getFieldInnerVectors(), ownBuffers);
140146
// TODO: do something with the sizes in fieldNode?
141147
}
142148

143149
public List<ArrowBuf> getFieldBuffers() {
144-
bits.getBuffer().readerIndex(0);
145-
<#if type.major = "VarLen">
146-
values.offsetVector.getBuffer().readerIndex(0);
147-
</#if>
148-
values.getBuffer().readerIndex(0);
149-
return Arrays.asList(
150-
bits.getBuffer(),
151-
<#if type.major = "VarLen">
152-
values.offsetVector.getBuffer(),
153-
</#if>
154-
values.getBuffer());
150+
return org.apache.arrow.vector.BaseDataValueVector.unload(getFieldInnerVectors());
155151
}
156152

157153
@Override

java/vector/src/main/codegen/templates/UnionVector.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ public List<ArrowBuf> getFieldBuffers() {
121121
throw new UnsupportedOperationException();
122122
}
123123

124+
@Override
125+
public List<BufferBacked> getFieldInnerVectors() {
126+
// TODO
127+
throw new UnsupportedOperationException();
128+
}
129+
124130
public MapVector getMap() {
125131
if (mapVector == null) {
126132
int vectorCount = internalMap.size();

0 commit comments

Comments
 (0)