apache / pulsar

Apache Pulsar - distributed pub-sub messaging system
https://pulsar.apache.org/
Apache License 2.0
14.06k stars 3.56k forks source link

[Pulsar SQL] Some optimized points in PR 8422 #9224

Closed gaoran10 closed 1 year ago

gaoran10 commented 3 years ago

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())) {
                   ...
            }
        }
kaori-seasons commented 2 years ago

@codelipenghui I want to fix this issues.

codelipenghui commented 2 years ago

The issue had no activity for 30 days, mark with Stale label.

ziang123 commented 1 year ago

Kindly to ask if there is somebody working for this issue? lf not, I'm glad to undertake it

tisonkun commented 1 year ago

@ziang123 I think no one is working on this issue yet. Go ahead!

tisonkun commented 1 year ago

Closed by #19027.

tisonkun commented 1 year ago

@ziang123 Thanks for your contribution!