Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import java.util.Arrays;
import java.util.function.Function;

import static org.apache.fluss.types.DataTypeChecks.getLength;

/**
* Collector for {@link LogRecordBatchStatistics} that accumulates statistics during record batch
* construction. Manages statistics data in memory arrays and supports schema-aware statistics
Expand Down Expand Up @@ -160,6 +162,11 @@ private void updateMinMax(int statsIndex, int schemaIndex, InternalRow row) {
double doubleValue = row.getDouble(schemaIndex);
updateMinMaxInternal(statsIndex, doubleValue, Double::compare);
break;
case CHAR:
BinaryString charValue = row.getChar(schemaIndex, getLength(fieldType));
updateMinMaxInternal(
statsIndex, charValue, BinaryString::compareTo, BinaryString::copy);
break;
case STRING:
BinaryString stringValue = row.getString(schemaIndex);
updateMinMaxInternal(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.IOException;

import static org.apache.fluss.record.LogRecordBatchFormat.STATISTICS_VERSION;
import static org.apache.fluss.types.DataTypeChecks.getLength;

/**
* A high-performance writer for LogRecordBatch statistics that efficiently serializes statistical
Expand Down Expand Up @@ -205,6 +206,10 @@ private AlignedRow convertToAlignedRow(InternalRow row) {
case DOUBLE:
reusableRowWriter.writeDouble(i, row.getDouble(i));
break;
case CHAR:
int charLength = getLength(fieldType);
reusableRowWriter.writeChar(i, row.getChar(i, charLength), charLength);
break;
case STRING:
reusableRowWriter.writeString(i, row.getString(i));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,34 @@ void testProcessNullValues() throws IOException {
assertThat(statistics.getMaxValues().getInt(0)).isEqualTo(3);
}

@Test
void testCharStatisticsSerializationRoundTrip() throws IOException {
RowType charRowType = DataTypes.ROW(new DataField("char_val", DataTypes.CHAR(3)));
LogRecordBatchStatisticsCollector charCollector =
new LogRecordBatchStatisticsCollector(charRowType, new int[] {0});

List<Object[]> charData =
Arrays.asList(
new Object[] {"cat"},
new Object[] {"a"},
new Object[] {null},
new Object[] {"dog"});
for (Object[] data : charData) {
charCollector.processRow(DataTestUtils.row(data));
}

MemorySegment segment = MemorySegment.allocateHeapMemory(1024);
charCollector.writeStatistics(new MemorySegmentOutputView(segment));

DefaultLogRecordBatchStatistics statistics =
LogRecordBatchStatisticsParser.parseStatistics(segment, 0, charRowType, 1);

assertThat(statistics.getMinValues().getChar(0, 3)).isEqualTo(BinaryString.fromString("a"));
assertThat(statistics.getMaxValues().getChar(0, 3))
.isEqualTo(BinaryString.fromString("dog"));
assertThat(statistics.getNullCounts()[0]).isEqualTo(1);
}

@Test
void testPartialStatsIndexMapping() throws IOException {
RowType fullRowType =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,27 @@ void testSchemaAwareStatisticsWithNullStats() {
assertThat(result).isTrue();
}

@Test
void testCharStatisticsCanPruneRecordBatch() throws IOException {
RowType rowType = RowType.of(DataTypes.CHAR(3));
LogRecordBatchStatisticsCollector collector =
new LogRecordBatchStatisticsCollector(rowType, new int[] {0});
collector.processRow(GenericRow.of(BinaryString.fromString("cat")));
collector.processRow(GenericRow.of(BinaryString.fromString("ant")));
collector.processRow(GenericRow.of(BinaryString.fromString("dog")));

MemorySegmentOutputView outputView = new MemorySegmentOutputView(1024);
collector.writeStatistics(outputView);
DefaultLogRecordBatchStatistics statistics =
LogRecordBatchStatisticsParser.parseStatistics(
outputView.getMemorySegment(), 0, rowType, TEST_SCHEMA_ID);

Predicate predicate =
new PredicateBuilder(rowType).greaterThan(0, BinaryString.fromString("zoo"));

assertThat(mayMatch(predicate, TEST_SCHEMA_ID, null, 3L, statistics)).isFalse();
}

// =====================================================
// Schema Evolution Tests
// =====================================================
Expand Down
Loading