Skip to content

Commit 74d0d49

Browse files
committed
[example] Add LogRecords example
1 parent bc49735 commit 74d0d49

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

fluss-common/src/test/java/com/alibaba/fluss/record/MemoryLogRecordsTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,20 @@
1717

1818
package com.alibaba.fluss.record;
1919

20+
import com.alibaba.fluss.row.InternalRow;
2021
import com.alibaba.fluss.testutils.DataTestUtils;
2122
import com.alibaba.fluss.testutils.LogRecordsAssert;
23+
import com.alibaba.fluss.utils.CloseableIterator;
2224

2325
import org.junit.jupiter.api.Test;
2426

2527
import java.nio.ByteBuffer;
28+
import java.util.Arrays;
2629
import java.util.function.Function;
2730

2831
import static com.alibaba.fluss.record.TestData.DATA1;
2932
import static com.alibaba.fluss.record.TestData.DATA1_ROW_TYPE;
33+
import static com.alibaba.fluss.record.TestData.DEFAULT_SCHEMA_ID;
3034

3135
/** Tests for {@link MemoryLogRecords}. */
3236
class MemoryLogRecordsTest {
@@ -81,4 +85,29 @@ void verifyPointToByteBuffer(Function<Integer, ByteBuffer> bufferSupplier) throw
8185
.withSchema(DATA1_ROW_TYPE)
8286
.isEqualTo(records);
8387
}
88+
89+
@Test
90+
void testReadMemoryLogRecords() throws Exception {
91+
MemoryLogRecords records =
92+
DataTestUtils.genMemoryLogRecordsByObject(
93+
Arrays.asList(
94+
new Object[] {1, "A"},
95+
new Object[] {2, "B"},
96+
new Object[] {3, "C"}));
97+
98+
Iterable<LogRecordBatch> batches = records.batches();
99+
for (LogRecordBatch batch : batches) {
100+
System.out.println(batch.getRecordCount());
101+
System.out.println(batch.lastLogOffset());
102+
CloseableIterator<LogRecord> it =
103+
batch.records(
104+
LogRecordReadContext.createArrowReadContext(
105+
DATA1_ROW_TYPE, DEFAULT_SCHEMA_ID));
106+
while (it.hasNext()) {
107+
LogRecord record = it.next();
108+
InternalRow row = record.getRow();
109+
System.out.printf("%d, %s\n", row.getInt(0), row.getString(1));
110+
}
111+
}
112+
}
84113
}

0 commit comments

Comments
 (0)