gaoran10 opened a new issue #9224:
URL: https://github.com/apache/pulsar/issues/9224
# Motivation
The #8422 made a refactor for the Pulsar SQL, it's a major change. There are
some points that could be considered to optimize.
## 1. PulsarRowDecoderFactory
The various decoder factories could be initialized at the Pulsar SQL
beginning, one time is enough and they could be reused.
Refer to the method `private PulsarRowDecoderFactory
createDecoderFactory(SchemaInfo schemaInfo)` of the class
`PulsarDispatchingRowDecoderFactory`.
## 2. PulsarRowDecoderFactory
It seems that the multi-version schema decoder cache could be added and the
decoders could be reused.
Refer to the method `PulsarRowDecoder createRowDecoder(TopicName topicName,
SchemaInfo schemaInfo,
Set<DecoderColumnHandle> columns)` in
class `PulsarRowDecoderFactory`.
```
// PulsarRecordCursor.java
PulsarRowDecoder keyDecoder = decoderFactory.createRowDecoder(topicName,
schemaInfo,
columnHandles.stream()
.filter(col -> !col.isInternal())
.filter(col ->
PulsarColumnHandle.HandleKeyValueType.KEY
.equals(col.getHandleKeyValueType()))
.collect(toImmutableSet()));
```
## 3. Internal Column decode optimize
The `switch-case` is more efficient than `if-else` and the
PulsarInternalColumn could be changed to an enum.
```
// PulsarRecordCursor.java
for (DecoderColumnHandle columnHandle : columnHandles) {
if (columnHandle.isInternal()) {
if
(PulsarInternalColumn.PARTITION.getName().equals(columnHandle.getName())) {
currentRowValuesMap.put(columnHandle,
longValueProvider(this.partition));
} else if
(PulsarInternalColumn.EVENT_TIME.getName().equals(columnHandle.getName())) {
...
}
}
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]