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

[core] Shade roaringbitmap dependency into paimon-common #3100

Merged
merged 2 commits into from
Mar 27, 2024
Merged
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
11 changes: 11 additions & 0 deletions paimon-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ under the License.
<version>8.5.12</version>
</dependency>

<dependency>
<groupId>org.roaringbitmap</groupId>
<artifactId>RoaringBitmap</artifactId>
<version>1.0.5</version>
</dependency>

<!-- Test -->

<dependency>
Expand Down Expand Up @@ -266,6 +272,7 @@ under the License.
<include>org.antlr:antlr4-runtime</include>
<include>org.codehaus.janino:*</include>
<include>it.unimi.dsi:fastutil</include>
<include>org.roaringbitmap:RoaringBitmap</include>
</includes>
</artifactSet>
<filters>
Expand Down Expand Up @@ -301,6 +308,10 @@ under the License.
<pattern>io.airlift</pattern>
<shadedPattern>org.apache.paimon.shade.io.airlift</shadedPattern>
</relocation>
<relocation>
<pattern>org.roaringbitmap</pattern>
<shadedPattern>org.apache.paimon.shade.org.roaringbitmap</shadedPattern>
</relocation>
</relocations>
<minimizeJar>true</minimizeJar>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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.paimon.utils;

import org.roaringbitmap.RoaringBitmap;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

/** A compressed bitmap for 32-bit integer. */
public class RoaringBitmap32 {

public static final int MAX_VALUE = Integer.MAX_VALUE;

private final RoaringBitmap roaringBitmap;

public RoaringBitmap32() {
this.roaringBitmap = new RoaringBitmap();
}

public void add(int x) {
roaringBitmap.add(x);
}

public boolean checkedAdd(int x) {
return roaringBitmap.checkedAdd(x);
}

public boolean contains(int x) {
return roaringBitmap.contains(x);
}

public boolean isEmpty() {
return roaringBitmap.isEmpty();
}

public void serialize(DataOutput out) throws IOException {
roaringBitmap.runOptimize();
roaringBitmap.serialize(out);
}

public void deserialize(DataInput in) throws IOException {
roaringBitmap.deserialize(in);
}
}
3 changes: 3 additions & 0 deletions paimon-common/src/main/resources/META-INF/NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Copyright 2023-2024 The Apache Software Foundation
This product includes software developed at
The Apache Software Foundation (http://www.apache.org/).

This project bundles the following dependencies under the Apache Software License 2.0 (http://www.apache.org/licenses/LICENSE-2.0.txt)
- org.roaringbitmap:RoaringBitmap:1.0.5

This project bundles the following dependencies under the BSD 3-clause license.
You find them under licenses/LICENSE.antlr-runtime and licenses/LICENSE.janino.

Expand Down
7 changes: 0 additions & 7 deletions paimon-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ under the License.

<properties>
<frocksdbjni.version>6.20.3-ververica-2.0</frocksdbjni.version>
<RoaringBitmap.version>1.0.1</RoaringBitmap.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -64,12 +63,6 @@ under the License.
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.roaringbitmap</groupId>
<artifactId>RoaringBitmap</artifactId>
<version>${RoaringBitmap.version}</version>
</dependency>

<!-- test dependencies -->

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,28 @@

package org.apache.paimon.deletionvectors;

import org.roaringbitmap.RoaringBitmap;
import org.apache.paimon.utils.RoaringBitmap32;

import java.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataOutputStream;
import java.io.IOException;

/**
* A {@link DeletionVector} based on {@link RoaringBitmap}, it only supports files with row count
* not exceeding {@link Integer#MAX_VALUE}.
* A {@link DeletionVector} based on {@link RoaringBitmap32}, it only supports files with row count
* not exceeding {@link RoaringBitmap32#MAX_VALUE}.
*/
public class BitmapDeletionVector implements DeletionVector {

public static final int MAGIC_NUMBER = 1581511376;

private final RoaringBitmap roaringBitmap;
private final RoaringBitmap32 roaringBitmap;

BitmapDeletionVector() {
roaringBitmap = new RoaringBitmap();
roaringBitmap = new RoaringBitmap32();
}

private BitmapDeletionVector(RoaringBitmap roaringBitmap) {
private BitmapDeletionVector(RoaringBitmap32 roaringBitmap) {
this.roaringBitmap = roaringBitmap;
}

Expand Down Expand Up @@ -71,7 +71,6 @@ public byte[] serializeToBytes() {
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos)) {
dos.writeInt(MAGIC_NUMBER);
roaringBitmap.runOptimize();
roaringBitmap.serialize(dos);
return bos.toByteArray();
} catch (Exception e) {
Expand All @@ -80,13 +79,13 @@ public byte[] serializeToBytes() {
}

public static DeletionVector deserializeFromDataInput(DataInput bis) throws IOException {
RoaringBitmap roaringBitmap = new RoaringBitmap();
RoaringBitmap32 roaringBitmap = new RoaringBitmap32();
roaringBitmap.deserialize(bis);
return new BitmapDeletionVector(roaringBitmap);
}

private void checkPosition(long position) {
if (position > Integer.MAX_VALUE) {
if (position > RoaringBitmap32.MAX_VALUE) {
throw new IllegalArgumentException(
"The file has too many rows, RoaringBitmap32 only supports files with row count not exceeding 2147483647.");
}
Expand Down
Loading