-
Notifications
You must be signed in to change notification settings - Fork 961
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
supported schemaEvolution when restarting the paimon cdc job
- Loading branch information
1 parent
06c0f4e
commit b7df66d
Showing
19 changed files
with
411 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
paimon-common/src/main/java/org/apache/paimon/compression/ZstdBlockCompressionFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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.compression; | ||
|
||
/** Implementation of {@link BlockCompressionFactory} for zstd codec. */ | ||
public class ZstdBlockCompressionFactory implements BlockCompressionFactory { | ||
|
||
@Override | ||
public BlockCompressor getCompressor() { | ||
return new ZstdBlockCompressor(); | ||
} | ||
|
||
@Override | ||
public BlockDecompressor getDecompressor() { | ||
return new ZstdBlockDecompressor(); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
paimon-common/src/main/java/org/apache/paimon/compression/ZstdBlockCompressor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* | ||
* 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.compression; | ||
|
||
import com.github.luben.zstd.RecyclingBufferPool; | ||
import com.github.luben.zstd.ZstdOutputStream; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
import static org.apache.paimon.compression.CompressorUtils.HEADER_LENGTH; | ||
|
||
/** A {@link BlockCompressor} for zstd. */ | ||
public class ZstdBlockCompressor implements BlockCompressor { | ||
|
||
private static final int MAX_BLOCK_SIZE = 128 * 1024; | ||
|
||
@Override | ||
public int getMaxCompressedSize(int srcSize) { | ||
return HEADER_LENGTH + zstdMaxCompressedLength(srcSize); | ||
} | ||
|
||
private int zstdMaxCompressedLength(int uncompressedSize) { | ||
// refer to io.airlift.compress.zstd.ZstdCompressor | ||
int result = uncompressedSize + (uncompressedSize >>> 8); | ||
if (uncompressedSize < MAX_BLOCK_SIZE) { | ||
result += (MAX_BLOCK_SIZE - uncompressedSize) >>> 11; | ||
} | ||
return result; | ||
} | ||
|
||
@Override | ||
public int compress(byte[] src, int srcOff, int srcLen, byte[] dst, int dstOff) | ||
throws BufferCompressionException { | ||
ByteArrayOutputStream stream = new ByteArrayOutputStream(dst, dstOff); | ||
try (ZstdOutputStream zstdStream = | ||
new ZstdOutputStream(stream, RecyclingBufferPool.INSTANCE, 1)) { | ||
zstdStream.setWorkers(0); | ||
zstdStream.write(src, srcOff, srcLen); | ||
} catch (IOException e) { | ||
throw new BufferCompressionException(e); | ||
} | ||
return stream.position() - dstOff; | ||
} | ||
|
||
private static class ByteArrayOutputStream extends OutputStream { | ||
|
||
private final byte[] buf; | ||
private int position; | ||
|
||
public ByteArrayOutputStream(byte[] buf, int position) { | ||
this.buf = buf; | ||
this.position = position; | ||
} | ||
|
||
@Override | ||
public void write(int b) { | ||
buf[position] = (byte) b; | ||
position += 1; | ||
} | ||
|
||
@Override | ||
public void write(byte[] b, int off, int len) throws IOException { | ||
if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) - b.length > 0)) { | ||
throw new IndexOutOfBoundsException(); | ||
} | ||
try { | ||
System.arraycopy(b, off, buf, position, len); | ||
} catch (IndexOutOfBoundsException e) { | ||
throw new IOException(e); | ||
} | ||
position += len; | ||
} | ||
|
||
int position() { | ||
return position; | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
paimon-common/src/main/java/org/apache/paimon/compression/ZstdBlockDecompressor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* 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.compression; | ||
|
||
import com.github.luben.zstd.RecyclingBufferPool; | ||
import com.github.luben.zstd.ZstdInputStream; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
|
||
/** A {@link BlockDecompressor} for zstd. */ | ||
public class ZstdBlockDecompressor implements BlockDecompressor { | ||
|
||
@Override | ||
public int decompress(byte[] src, int srcOff, int srcLen, byte[] dst, int dstOff) | ||
throws BufferDecompressionException { | ||
ByteArrayInputStream inputStream = new ByteArrayInputStream(src, srcOff, srcLen); | ||
try (ZstdInputStream decompressorStream = | ||
new ZstdInputStream(inputStream, RecyclingBufferPool.INSTANCE)) { | ||
int decompressedLen = 0; | ||
while (true) { | ||
int offset = dstOff + decompressedLen; | ||
int count = decompressorStream.read(dst, offset, dst.length - offset); | ||
if (count <= 0) { | ||
if (decompressorStream.available() != 0) { | ||
throw new BufferDecompressionException( | ||
"Dst is too small and the decompression was not completed."); | ||
} | ||
break; | ||
} | ||
decompressedLen += count; | ||
} | ||
return decompressedLen; | ||
} catch (IOException e) { | ||
throw new BufferDecompressionException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.