Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flink](lookup) convert to Fluss GenericRow to avoid unnecessary deserialization #307

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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 @@ -89,12 +89,10 @@ public void open(FunctionContext context) {
LOG.info("start open ...");
connection = ConnectionFactory.createConnection(flussConfig);
table = connection.getTable(tablePath);
// TODO: convert to Fluss GenericRow to avoid unnecessary deserialization
int[] lookupKeyIndexes = lookupNormalizer.getLookupKeyIndexes();
flinkRowToFlussRowConverter =
FlinkRowToFlussRowConverter.create(
FlinkUtils.projectRowType(flinkRowType, lookupKeyIndexes),
table.getDescriptor().getKvFormat());
FlinkUtils.projectRowType(flinkRowType, lookupKeyIndexes));

final RowType outputRowType;
if (projection == null) {
Expand All @@ -116,7 +114,7 @@ public void open(FunctionContext context) {
public CompletableFuture<Collection<RowData>> asyncLookup(RowData keyRow) {
RowData normalizedKeyRow = lookupNormalizer.normalizeLookupKey(keyRow);
RemainingFilter remainingFilter = lookupNormalizer.createRemainingFilter(keyRow);
InternalRow flussKeyRow = flinkRowToFlussRowConverter.toInternalRow(normalizedKeyRow);
InternalRow flussKeyRow = flinkRowToFlussRowConverter.toGenericRow(normalizedKeyRow);
CompletableFuture<Collection<RowData>> future = new CompletableFuture<>();
// fetch result
fetchResult(future, 0, flussKeyRow, remainingFilter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,10 @@ public void open(FunctionContext context) {
LOG.info("start open ...");
connection = ConnectionFactory.createConnection(flussConfig);
table = connection.getTable(tablePath);
// TODO: convert to Fluss GenericRow to avoid unnecessary deserialization
int[] lookupKeyIndexes = lookupNormalizer.getLookupKeyIndexes();
flinkRowToFlussRowConverter =
FlinkRowToFlussRowConverter.create(
FlinkUtils.projectRowType(flinkRowType, lookupKeyIndexes),
table.getDescriptor().getKvFormat());
FlinkUtils.projectRowType(flinkRowType, lookupKeyIndexes));

final RowType outputRowType;
if (projection == null) {
Expand Down Expand Up @@ -121,7 +119,7 @@ public Collection<RowData> lookup(RowData keyRow) {
// first is converting from flink row to fluss row,
// second is extracting key from the fluss row when calling method table.get(flussKeyRow)
// todo: may be reduce to one data conversion when it's a bottle neck
InternalRow flussKeyRow = flinkRowToFlussRowConverter.toInternalRow(normalizedKeyRow);
InternalRow flussKeyRow = flinkRowToFlussRowConverter.toGenericRow(normalizedKeyRow);
for (int retry = 0; retry <= maxRetryTimes; retry++) {
try {
if (flussLookupType == LookupType.LOOKUP) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.alibaba.fluss.metadata.KvFormat;
import com.alibaba.fluss.row.BinaryString;
import com.alibaba.fluss.row.Decimal;
import com.alibaba.fluss.row.GenericRow;
import com.alibaba.fluss.row.InternalRow;
import com.alibaba.fluss.row.TimestampLtz;
import com.alibaba.fluss.row.TimestampNtz;
Expand Down Expand Up @@ -89,6 +90,16 @@ public InternalRow toInternalRow(RowData rowData) {
return rowEncoder.finishRow();
}

public InternalRow toGenericRow(RowData rowData) {
GenericRow genericRow = new GenericRow(fieldLength);
for (int i = 0; i < fieldLength; i++) {
genericRow.setField(
i,
toFlussFieldConverters[i].serialize(fieldGetters[i].getFieldOrNull(rowData)));
}
return genericRow;
}

private FlussSerializationConverter createNullableInternalConverter(LogicalType flinkField) {
return wrapIntoNullableInternalConverter(createInternalConverter(flinkField));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ void testConverter() throws Exception {
assertThat(internalRow.getFieldCount()).isEqualTo(19);
assertAllTypeEquals(internalRow);
}

// test GenericRow row converter
try (FlinkRowToFlussRowConverter converter =
FlinkRowToFlussRowConverter.create(toFlinkRowType(flussRowType))) {
InternalRow internalRow = converter.toGenericRow(genRowDataForAllType());
assertThat(internalRow.getFieldCount()).isEqualTo(19);
assertAllTypeEquals(internalRow);
}
}

private static RowData genRowDataForAllType() {
Expand Down
Loading