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

[Enhancement] fix compilable issue in UnmodifiableCollectionsSerializer #55016

Open
wants to merge 11 commits 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 @@ -20,6 +20,7 @@
import com.starrocks.connector.metadata.MetadataCollectJob;
import com.starrocks.connector.share.iceberg.CommonMetadataBean;
import com.starrocks.connector.share.iceberg.IcebergMetricsBean;
import com.starrocks.connector.share.iceberg.UnmodifiableCollectionsSerializer;
import com.starrocks.qe.ConnectContext;
import com.starrocks.qe.scheduler.Coordinator;
import com.starrocks.rpc.ConfigurableSerDesFactory;
Expand Down
6 changes: 6 additions & 0 deletions java-extensions/hadoop-ext/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
<version>${iceberg.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.esotericsoftware</groupId>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why you add dependency to here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes the CI failed

Copy link
Contributor Author

@zhaohehuhu zhaohehuhu Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnmodifiableCollectionsSerializer needs Kyro dependency.(line 16)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this module have any others dependency conflicts?

<artifactId>kryo-shaded</artifactId>
<version>4.0.2</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.starrocks.connector.share.iceberg;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
import com.esotericsoftware.kryo.io.Input;
import com.esotericsoftware.kryo.io.Output;
import java.io.Serializable;
import java.util.Map;

@SuppressWarnings("rawtypes")
public class JavaImmutableMapSerializer extends Serializer<Map<?, ?>> {

@Override
public void write(Kryo kryo, Output output, Map<?, ?> map) {
ImmSerMapEntry[] entries = map
.entrySet()
.stream()
.map(ImmSerMapEntry::new)
.toArray(ImmSerMapEntry[]::new);

kryo.writeObject(output, new ImmSerMap(entries));
}

@Override
public Map<?, ?> read(Kryo kryo, Input input, Class<Map<?, ?>> type) {
return Map.ofEntries(kryo.readObject(input, ImmSerMap.class).getEntries());
}


private static class ImmSerMap implements Serializable {

private final ImmSerMapEntry<?, ?>[] array;

private ImmSerMap(ImmSerMapEntry[] array) {
this.array = array;
}

private Map.Entry[] getEntries() {
return array;
}
}

private static class ImmSerMapEntry<K, V> implements Map.Entry<K, V>, Serializable {

private final Object[] entry;

private ImmSerMapEntry(Map.Entry<K, V> entry) {
this.entry = new Object[] { entry.getKey(), entry.getValue() };
}

@Override
public K getKey() {
return (K) entry[0];
}

@Override
public V getValue() {
return (V) entry[1];
}

@Override
public V setValue(V value) {
throw new UnsupportedOperationException();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.iceberg;
package com.starrocks.connector.share.iceberg;

import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.Serializer;
Expand Down
18 changes: 0 additions & 18 deletions java-extensions/iceberg-metadata-reader/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,6 @@
</exclusions>
</dependency>

<dependency>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo-shaded</artifactId>
<version>4.0.2</version>
</dependency>

<dependency>
<groupId>de.javakaffee</groupId>
<artifactId>kryo-serializers</artifactId>
<version>0.45</version>
<exclusions>
<exclusion>
<groupId>com.esotericsoftware</groupId>
<artifactId>kryo</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
import com.google.common.collect.ImmutableList;
import com.starrocks.connector.share.iceberg.CommonMetadataBean;
import com.starrocks.connector.share.iceberg.IcebergMetricsBean;
import com.starrocks.connector.share.iceberg.JavaImmutableMapSerializer;
import com.starrocks.connector.share.iceberg.UnmodifiableCollectionsSerializer;
import com.starrocks.jni.connector.ColumnValue;
import de.javakaffee.kryoserializers.UnmodifiableCollectionsSerializer;
import org.apache.iceberg.ContentFile;
import org.apache.iceberg.ManifestContent;
import org.apache.iceberg.ManifestFile;
Expand Down Expand Up @@ -165,6 +166,8 @@ private void initSerializer() {
this.kryo = new Kryo();
this.kryo.register(CommonMetadataBean.class);
this.kryo.register(IcebergMetricsBean.class);
this.kryo.register(Map.of().getClass(), new JavaImmutableMapSerializer());
this.kryo.register(Map.of(1, 1).getClass(), new JavaImmutableMapSerializer());
UnmodifiableCollectionsSerializer.registerSerializers(kryo);
this.stream = new ByteArrayOutputStream();
this.output = new Output(stream);
Expand Down
Loading