Skip to content

Commit 05a5db9

Browse files
committed
[common] Improve the implementation of ARRAY type
1 parent 924f2df commit 05a5db9

File tree

108 files changed

+2225
-4097
lines changed

Some content is hidden

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

108 files changed

+2225
-4097
lines changed

fluss-client/pom.xml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,6 @@
113113
<include>*:*</include>
114114
</includes>
115115
</artifactSet>
116-
<filters>
117-
<filter>
118-
<artifact>*</artifact>
119-
<excludes>
120-
<exclude>LICENSE-EPL-1.0.txt</exclude>
121-
<exclude>LICENSE-EDL-1.0.txt</exclude>
122-
</excludes>
123-
</filter>
124-
</filters>
125116
</configuration>
126117
</execution>
127118
</executions>

fluss-client/src/main/resources/META-INF/NOTICE

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ This project bundles the following dependencies under the Apache Software Licens
1010
- com.ververica:frocksdbjni:6.20.3-ververica-2.0
1111
- org.apache.commons:commons-lang3:3.18.0
1212
- org.apache.commons:commons-math3:3.6.1
13-
- org.jetbrains:annotations:26.0.1
1413
- org.lz4:lz4-java:1.8.0
1514

1615
This project bundles the following dependencies under the MIT (https://opensource.org/licenses/MIT)
@@ -21,10 +20,4 @@ See bundled license files for details.
2120
This project bundles the following dependencies under BSD License (https://opensource.org/licenses/bsd-license.php).
2221
See bundled license files for details.
2322

24-
- com.github.luben:zstd-jni:1.5.7-1
25-
26-
This project bundles the following dependencies under the Eclipse Distribution License 1.0 (https://www.eclipse.org/org/documents/edl-v10.php) and Eclipse Public License 1.0 (https://www.eclipse.org/legal/epl-v10.html).
27-
See bundled license files for details.
28-
29-
- org.eclipse.collections:eclipse-collections-api:11.1.0
30-
- org.eclipse.collections:eclipse-collections:11.1.0
23+
- com.github.luben:zstd-jni:1.5.7-1

fluss-common/pom.xml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,7 @@
6262
<artifactId>fluss-shaded-arrow</artifactId>
6363
</dependency>
6464

65-
<!-- TODO: these three dependencies need to be shaded. -->
66-
<!-- Use the Arrow compatible version -->
67-
<dependency>
68-
<groupId>org.eclipse.collections</groupId>
69-
<artifactId>eclipse-collections</artifactId>
70-
<version>11.1.0</version>
71-
</dependency>
72-
65+
<!-- TODO: these two dependencies need to be shaded. -->
7366
<dependency>
7467
<groupId>org.lz4</groupId>
7568
<artifactId>lz4-java</artifactId>
@@ -116,12 +109,6 @@
116109
<version>${iceberg.version}</version>
117110
<scope>test</scope>
118111
</dependency>
119-
<dependency>
120-
<groupId>org.jetbrains</groupId>
121-
<artifactId>annotations</artifactId>
122-
<version>26.0.1</version>
123-
<scope>compile</scope>
124-
</dependency>
125112
</dependencies>
126113

127114
<build>

fluss-common/src/main/java/org/apache/fluss/memory/AbstractPagedOutputView.java

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,11 @@ public abstract class AbstractPagedOutputView implements OutputView, MemorySegme
4545
/** The list of memory segments that have been fully written and are immutable now. */
4646
private List<MemorySegmentBytesView> finishedPages;
4747

48-
/** the current memory segment to write to. */
49-
protected MemorySegment currentSegment;
48+
/** The current memory segment to write to. */
49+
private MemorySegment currentSegment;
5050

5151
/** the offset in the current segment. */
52-
protected int positionInSegment;
53-
54-
/** Flag indicating whether throw BufferExhaustedException or wait for available segment. */
55-
protected boolean waitingSegment;
56-
57-
/** the reusable array for UTF encodings. */
58-
protected byte[] utfBuffer;
52+
private int positionInSegment;
5953

6054
protected AbstractPagedOutputView(MemorySegment initialSegment, int pageSize) {
6155
if (initialSegment == null) {
@@ -307,62 +301,6 @@ public void writeDouble(double v) throws IOException {
307301
}
308302
}
309303

310-
@Override
311-
public void write(int b) throws IOException {
312-
writeByte(b);
313-
}
314-
315-
@Override
316-
public void writeChar(int v) throws IOException {
317-
if (positionInSegment < pageSize - 1) {
318-
currentSegment.putChar(positionInSegment, (char) v);
319-
positionInSegment += 2;
320-
} else if (positionInSegment == pageSize) {
321-
advance();
322-
writeChar(v);
323-
} else {
324-
writeByte(v);
325-
writeByte(v >> 8);
326-
}
327-
}
328-
329-
@Override
330-
public void writeBytes(String s) throws IOException {
331-
if (s == null) {
332-
throw new NullPointerException();
333-
}
334-
for (int i = 0; i < s.length(); i++) {
335-
writeByte(s.charAt(i));
336-
}
337-
}
338-
339-
@Override
340-
public void writeChars(String s) throws IOException {
341-
if (s == null) {
342-
throw new NullPointerException();
343-
}
344-
for (int i = 0; i < s.length(); i++) {
345-
writeChar(s.charAt(i));
346-
}
347-
}
348-
349-
@Override
350-
public void writeUTF(String str) throws IOException {
351-
if (str == null) {
352-
throw new NullPointerException();
353-
}
354-
355-
byte[] bytes = str.getBytes(java.nio.charset.StandardCharsets.UTF_8);
356-
int length = bytes.length;
357-
358-
if (length > 65535) {
359-
throw new IOException("String too long for UTF encoding: " + length);
360-
}
361-
362-
writeShort(length);
363-
write(bytes);
364-
}
365-
366304
@Override
367305
public void write(MemorySegment segment, int off, int len) throws IOException {
368306
int remaining = pageSize - positionInSegment;

fluss-common/src/main/java/org/apache/fluss/memory/InputView.java

Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* contributor license agreements. See the NOTICE file distributed with
44
* this work for additional information regarding copyright ownership.
55
* The ASF licenses this file to You under the Apache License, Version 2.0
6-
* (the "License"); you may not use this file except in compliance with the License.
7-
* You may obtain a copy of the License at
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
88
*
99
* http://www.apache.org/licenses/LICENSE-2.0
1010
*
@@ -23,13 +23,8 @@
2323
import java.io.IOException;
2424

2525
/**
26-
* A specialized interface for reading multi-byte primitive types in little endian byte order. This
27-
* interface is designed to be independent of Java's standard DataInput interface to avoid
28-
* endianness confusion and API semantic violations.
29-
*
30-
* <p>Note: This interface uses little endian byte order, which is different from Java's standard
31-
* DataInput interface that uses big endian. If you need big endian compatibility, use the {@link
32-
* #asDataInput()} method to get a DataInput wrapper.
26+
* A very similar interface to {@link java.io.DataInput} but reading multi-bytes primitive types in
27+
* little endian.
3328
*
3429
* @since 0.2
3530
*/
@@ -59,8 +54,8 @@ public interface InputView {
5954
byte readByte() throws IOException;
6055

6156
/**
62-
* Reads two input bytes and returns a {@code short} value in little endian byte order. This
63-
* method is suitable for reading the bytes written by the {@link OutputView#writeShort(int)}.
57+
* Reads two input bytes and returns a {@code short} value. This method is suitable for reading
58+
* the bytes written by the {@link OutputView#writeShort(int)}.
6459
*
6560
* @return the 16-bit value read.
6661
* @exception EOFException if this stream reaches the end before reading all the bytes.
@@ -69,8 +64,8 @@ public interface InputView {
6964
short readShort() throws IOException;
7065

7166
/**
72-
* Reads four input bytes and returns an {@code int} value in little endian byte order. This
73-
* method is suitable for reading bytes written by the {@link OutputView#writeInt(int)}.
67+
* Reads four input bytes and returns an {@code int} value. This method is suitable for reading
68+
* bytes written by the {@link OutputView#writeInt(int)}.
7469
*
7570
* @return the {@code int} value read.
7671
* @exception EOFException if this stream reaches the end before reading all the bytes.
@@ -79,28 +74,8 @@ public interface InputView {
7974
int readInt() throws IOException;
8075

8176
/**
82-
* Reads two input bytes and returns a {@code char} value in little endian byte order. This
83-
* method is suitable for reading bytes written by the {@link OutputView#writeChar(int)}.
84-
*
85-
* @return the {@code char} value read.
86-
* @exception EOFException if this stream reaches the end before reading all the bytes.
87-
* @exception IOException if an I/O error occurs.
88-
*/
89-
char readChar() throws IOException;
90-
91-
/**
92-
* Reads two input bytes and returns an unsigned 16-bit integer in little endian byte order.
93-
* This method is suitable for reading bytes written by the {@link OutputView#writeShort(int)}.
94-
*
95-
* @return the unsigned 16-bit value read.
96-
* @exception EOFException if this stream reaches the end before reading all the bytes.
97-
* @exception IOException if an I/O error occurs.
98-
*/
99-
int readUnsignedShort() throws IOException;
100-
101-
/**
102-
* Reads eight input bytes and returns a {@code long} value in little endian byte order. This
103-
* method is suitable for reading bytes written by the {@link OutputView#writeLong(long)}.
77+
* Reads eight input bytes and returns a {@code long} value. This method is suitable for reading
78+
* bytes written by the {@link OutputView#writeLong(long)}.
10479
*
10580
* @return the {@code long} value read.
10681
* @exception EOFException if this stream reaches the end before reading all the bytes.
@@ -186,28 +161,4 @@ public interface InputView {
186161
* @exception IOException if an I/O error occurs.
187162
*/
188163
void readFully(byte[] b, int offset, int len) throws IOException;
189-
190-
/**
191-
* Skips over and discards {@code n} bytes of data from the input stream. The skip method may,
192-
* for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. This
193-
* may result from any of a number of conditions; reaching end of file before {@code n} bytes
194-
* have been skipped is only one possibility. The actual number of bytes skipped is returned. If
195-
* {@code n} is negative, no bytes are skipped.
196-
*
197-
* @param n the number of bytes to be skipped.
198-
* @return the actual number of bytes skipped.
199-
* @exception IOException if an I/O error occurs.
200-
*/
201-
int skipBytes(int n) throws IOException;
202-
203-
/**
204-
* Reads a string that has been encoded using a modified UTF-8 format in little endian byte
205-
* order. This method is suitable for reading strings written by the {@link
206-
* OutputView#writeUTF(String)}.
207-
*
208-
* @return a Unicode string.
209-
* @exception EOFException if this stream reaches the end before reading all the bytes.
210-
* @exception IOException if an I/O error occurs.
211-
*/
212-
String readUTF() throws IOException;
213164
}

fluss-common/src/main/java/org/apache/fluss/memory/ManagedPagedOutputView.java

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.fluss.memory;
1919

2020
import java.io.IOException;
21-
import java.io.UTFDataFormatException;
2221
import java.util.ArrayList;
2322
import java.util.List;
2423

@@ -48,94 +47,4 @@ protected MemorySegment nextSegment() throws IOException {
4847
public List<MemorySegment> allocatedPooledSegments() {
4948
return pooledSegments;
5049
}
51-
52-
@Override
53-
public void write(int b) throws IOException {
54-
writeByte(b);
55-
}
56-
57-
@Override
58-
public void writeChar(int v) throws IOException {
59-
if (this.positionInSegment < this.pageSize - 1) {
60-
this.currentSegment.putCharBigEndian(this.positionInSegment, (char) v);
61-
this.positionInSegment += 2;
62-
} else if (this.positionInSegment == this.pageSize) {
63-
advance();
64-
writeChar(v);
65-
} else {
66-
writeByte(v >> 8);
67-
writeByte(v);
68-
}
69-
}
70-
71-
@Override
72-
public void writeBytes(String s) throws IOException {
73-
for (int i = 0; i < s.length(); i++) {
74-
writeByte(s.charAt(i));
75-
}
76-
}
77-
78-
@Override
79-
public void writeChars(String s) throws IOException {
80-
for (int i = 0; i < s.length(); i++) {
81-
writeChar(s.charAt(i));
82-
}
83-
}
84-
85-
@Override
86-
public void writeUTF(String str) throws IOException {
87-
int strlen = str.length();
88-
int utflen = 0;
89-
int c, count = 0;
90-
91-
/* use charAt instead of copying String to char array */
92-
for (int i = 0; i < strlen; i++) {
93-
c = str.charAt(i);
94-
if ((c >= 0x0001) && (c <= 0x007F)) {
95-
utflen++;
96-
} else if (c > 0x07FF) {
97-
utflen += 3;
98-
} else {
99-
utflen += 2;
100-
}
101-
}
102-
103-
if (utflen > 65535) {
104-
throw new UTFDataFormatException("encoded string too long: " + utflen + " memory");
105-
}
106-
107-
if (this.utfBuffer == null || this.utfBuffer.length < utflen + 2) {
108-
this.utfBuffer = new byte[utflen + 2];
109-
}
110-
final byte[] bytearr = this.utfBuffer;
111-
112-
bytearr[count++] = (byte) ((utflen >>> 8) & 0xFF);
113-
bytearr[count++] = (byte) (utflen & 0xFF);
114-
115-
int i;
116-
for (i = 0; i < strlen; i++) {
117-
c = str.charAt(i);
118-
if (!((c >= 0x0001) && (c <= 0x007F))) {
119-
break;
120-
}
121-
bytearr[count++] = (byte) c;
122-
}
123-
124-
for (; i < strlen; i++) {
125-
c = str.charAt(i);
126-
if ((c >= 0x0001) && (c <= 0x007F)) {
127-
bytearr[count++] = (byte) c;
128-
129-
} else if (c > 0x07FF) {
130-
bytearr[count++] = (byte) (0xE0 | ((c >> 12) & 0x0F));
131-
bytearr[count++] = (byte) (0x80 | ((c >> 6) & 0x3F));
132-
bytearr[count++] = (byte) (0x80 | (c & 0x3F));
133-
} else {
134-
bytearr[count++] = (byte) (0xC0 | ((c >> 6) & 0x1F));
135-
bytearr[count++] = (byte) (0x80 | (c & 0x3F));
136-
}
137-
}
138-
139-
write(bytearr, 0, utflen + 2);
140-
}
14150
}

fluss-common/src/main/java/org/apache/fluss/memory/MemorySegment.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import java.io.DataInput;
2525
import java.io.DataOutput;
2626
import java.io.IOException;
27-
import java.io.Serializable;
2827
import java.nio.BufferOverflowException;
2928
import java.nio.BufferUnderflowException;
3029
import java.nio.ByteBuffer;
@@ -66,7 +65,7 @@
6665
* implementations on invocations of abstract methods.
6766
*/
6867
@Internal
69-
public final class MemorySegment implements Serializable {
68+
public final class MemorySegment {
7069

7170
/** The unsafe handle for transparent memory copied (heap / off-heap). */
7271
private static final sun.misc.Unsafe UNSAFE = MemoryUtils.UNSAFE;

0 commit comments

Comments
 (0)