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

perf: Only look up index of new key field once, not per row processed (MINOR) #3020

Merged
merged 1 commit into from
Jun 28, 2019
Merged
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 @@ -541,9 +541,12 @@ public SchemaKStream<?> selectKey(
);
}

final int keyIndexInValue = schema.valueFieldIndex(proposedKey.name())
.orElseThrow(IllegalStateException::new);

final KStream keyedKStream = kstream
.filter((key, value) -> value != null && extractColumn(proposedKey, value) != null)
.selectKey((key, value) -> extractColumn(proposedKey, value).toString())
.filter((key, value) -> value != null && extractColumn(keyIndexInValue, value) != null)
.selectKey((key, value) -> extractColumn(keyIndexInValue, value).toString())
.mapValues((key, row) -> {
if (updateRowKey) {
row.getColumns().set(SchemaUtil.ROWKEY_INDEX, key);
Expand Down Expand Up @@ -576,7 +579,7 @@ private static boolean isRowKey(final String fieldName) {
return SchemaUtil.isFieldName(fieldName, SchemaUtil.ROWKEY_NAME);
}

private Object extractColumn(final Field newKeyField, final GenericRow value) {
private Object extractColumn(final int keyIndexInValue, final GenericRow value) {
if (value.getColumns().size() != schema.valueFields().size()) {
throw new IllegalStateException("Field count mismatch. "
+ "Schema fields: " + schema
Expand All @@ -585,7 +588,7 @@ private Object extractColumn(final Field newKeyField, final GenericRow value) {

return value
.getColumns()
.get(schema.valueFieldIndex(newKeyField.name()).orElseThrow(IllegalStateException::new));
.get(keyIndexInValue);
}

private static String fieldNameFromExpression(final Expression expression) {
Expand Down