Skip to content

Commit

Permalink
PHOENIX-7482 Replace uses of org.iq80.snappy:snappy with org.xerial.s…
Browse files Browse the repository at this point in the history
…nappy:snappy-java
  • Loading branch information
apurtell committed Jan 13, 2025
1 parent 9af06d8 commit 858ea51
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 18 deletions.
4 changes: 2 additions & 2 deletions phoenix-core-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@
<artifactId>jsr305</artifactId>
</dependency>
<dependency>
<groupId>org.iq80.snappy</groupId>
<artifactId>snappy</artifactId>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
import org.apache.phoenix.schema.types.PDataType;
import org.apache.phoenix.schema.types.PVarbinary;
import org.xerial.snappy.Snappy;
import org.apache.phoenix.schema.SortOrder;
import org.apache.phoenix.schema.tuple.SingleKeyValueTuple;
import org.apache.phoenix.schema.tuple.Tuple;
import org.iq80.snappy.Snappy;

/**
* Client side Aggregator which will aggregate data and find distinct values with number of occurrences for each.
Expand Down Expand Up @@ -66,7 +66,7 @@ public void aggregate(Tuple tuple, ImmutableBytesWritable ptr) {
if (Bytes.equals(ptr.get(), ptr.getOffset(), 1, DistinctValueWithCountServerAggregator.COMPRESS_MARKER,
0, 1)) {
// This reads the uncompressed length from the front of the compressed input
int uncompressedLength = Snappy.getUncompressedLength(ptr.get(), ptr.getOffset() + 1);
int uncompressedLength = Snappy.uncompressedLength(ptr.get(), ptr.getOffset() + 1, ptr.getLength() - 1);
byte[] uncompressed = new byte[uncompressedLength];
// This will throw CorruptionException, a RuntimeException if the snappy data is invalid.
// We're making a RuntimeException out of a checked IOException below so assume it's ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.apache.phoenix.expression.aggregator;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
Expand All @@ -33,7 +34,7 @@
import org.apache.phoenix.schema.types.PVarbinary;
import org.apache.phoenix.util.ByteUtil;
import org.apache.phoenix.util.SizedUtil;
import org.iq80.snappy.Snappy;
import org.xerial.snappy.Snappy;

/**
* Server side Aggregator which will aggregate data and find distinct values with number of occurrences for each.
Expand Down Expand Up @@ -108,8 +109,12 @@ public boolean evaluate(Tuple tuple, ImmutableBytesWritable ptr) {
// The size for the map serialization is above the threshold. We will do the Snappy compression here.
byte[] compressed = new byte[COMPRESS_MARKER.length + Snappy.maxCompressedLength(buffer.length)];
System.arraycopy(COMPRESS_MARKER, 0, compressed, 0, COMPRESS_MARKER.length);
int compressedLen = Snappy.compress(buffer, 1, buffer.length - 1, compressed, COMPRESS_MARKER.length);
ptr.set(compressed, 0, compressedLen + 1);
try {
int compressedLen = Snappy.compress(buffer, 1, buffer.length - 1, compressed, COMPRESS_MARKER.length);
ptr.set(compressed, 0, compressedLen + 1);
} catch (IOException e) {
throw new RuntimeException(e);
}
return true;
}
ptr.set(buffer, 0, offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@
import org.apache.phoenix.util.ClientUtil;
import org.apache.phoenix.util.TrustedByteArrayOutputStream;
import org.apache.phoenix.util.TupleUtil;
import org.iq80.snappy.Snappy;

import org.xerial.snappy.Snappy;
import org.apache.phoenix.thirdparty.com.google.common.collect.Lists;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
import org.apache.phoenix.util.ResultUtil;
import org.apache.phoenix.util.SizedUtil;
import org.apache.phoenix.util.TupleUtil;
import org.iq80.snappy.CorruptionException;
import org.iq80.snappy.Snappy;
import org.xerial.snappy.Snappy;

public class HashCacheFactory implements ServerCacheFactory {

Expand All @@ -71,12 +70,11 @@ public void write(DataOutput output) throws IOException {
public Closeable newCache(ImmutableBytesWritable cachePtr, byte[] txState, MemoryChunk chunk, boolean useProtoForIndexMaintainer, int clientVersion) throws SQLException {
try {
// This reads the uncompressed length from the front of the compressed input
int uncompressedLen = Snappy.getUncompressedLength(cachePtr.get(), cachePtr.getOffset());
int uncompressedLen = Snappy.uncompressedLength(cachePtr.get(), cachePtr.getOffset(), cachePtr.getLength());
byte[] uncompressed = new byte[uncompressedLen];
Snappy.uncompress(cachePtr.get(), cachePtr.getOffset(), cachePtr.getLength(),
uncompressed, 0);
Snappy.uncompress(cachePtr.get(), cachePtr.getOffset(), cachePtr.getLength(), uncompressed, 0);
return new HashCacheImpl(uncompressed, chunk, clientVersion);
} catch (CorruptionException e) {
} catch (IOException e) {
throw ClientUtil.parseServerException(e);
}
}
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<sqlline.version>1.9.0</sqlline.version>
<jcip-annotations.version>1.0-1</jcip-annotations.version>
<jsr305.version>2.0.1</jsr305.version>
<snappy.version>0.5</snappy.version>
<snappy.version>1.1.10.5</snappy.version>
<commons-codec.version>1.16.0</commons-codec.version>
<htrace.version>3.1.0-incubating</htrace.version>
<jodatime.version>2.10.5</jodatime.version>
Expand Down Expand Up @@ -1644,8 +1644,8 @@
<version>${jsr305.version}</version>
</dependency>
<dependency>
<groupId>org.iq80.snappy</groupId>
<artifactId>snappy</artifactId>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
<version>${snappy.version}</version>
</dependency>
<dependency>
Expand Down

0 comments on commit 858ea51

Please sign in to comment.