Skip to content

Commit be7a880

Browse files
amoghmargoorsopel39
authored andcommitted
Add Parquet decryption support for Hive tables
1 parent 465f48a commit be7a880

File tree

86 files changed

+5545
-146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+5545
-146
lines changed

Diff for: lib/trino-filesystem/pom.xml

+14
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,18 @@
188188
<scope>test</scope>
189189
</dependency>
190190
</dependencies>
191+
<build>
192+
<plugins>
193+
<plugin>
194+
<groupId>org.basepom.maven</groupId>
195+
<artifactId>duplicate-finder-maven-plugin</artifactId>
196+
<configuration>
197+
<ignoredResourcePatterns>
198+
<ignoredResourcePattern>about.html</ignoredResourcePattern>
199+
<ignoredResourcePattern>iceberg-build.properties</ignoredResourcePattern>
200+
</ignoredResourcePatterns>
201+
</configuration>
202+
</plugin>
203+
</plugins>
204+
</build>
191205
</project>

Diff for: lib/trino-orc/pom.xml

+10
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,16 @@
208208
</excludes>
209209
</configuration>
210210
</plugin>
211+
<plugin>
212+
<groupId>org.basepom.maven</groupId>
213+
<artifactId>duplicate-finder-maven-plugin</artifactId>
214+
<configuration>
215+
<ignoredResourcePatterns>
216+
<ignoredResourcePattern>about.html</ignoredResourcePattern>
217+
<ignoredResourcePattern>iceberg-build.properties</ignoredResourcePattern>
218+
</ignoredResourcePatterns>
219+
</configuration>
220+
</plugin>
211221
</plugins>
212222
</build>
213223
</project>

Diff for: lib/trino-parquet/pom.xml

+25-1
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,25 @@
1313
<description>Trino - Parquet file format support</description>
1414

1515
<dependencies>
16+
<dependency>
17+
<groupId>com.fasterxml.jackson.core</groupId>
18+
<artifactId>jackson-core</artifactId>
19+
<type>jar</type>
20+
<scope>compile</scope>
21+
</dependency>
22+
23+
<dependency>
24+
<groupId>com.fasterxml.jackson.core</groupId>
25+
<artifactId>jackson-databind</artifactId>
26+
<type>jar</type>
27+
<scope>compile</scope>
28+
</dependency>
29+
1630
<dependency>
1731
<groupId>com.google.errorprone</groupId>
1832
<artifactId>error_prone_annotations</artifactId>
1933
<optional>true</optional>
2034
</dependency>
21-
2235
<dependency>
2336
<groupId>com.google.guava</groupId>
2437
<artifactId>guava</artifactId>
@@ -29,6 +42,11 @@
2942
<artifactId>aircompressor-v3</artifactId>
3043
</dependency>
3144

45+
<dependency>
46+
<groupId>io.airlift</groupId>
47+
<artifactId>json</artifactId>
48+
</dependency>
49+
3250
<dependency>
3351
<groupId>io.airlift</groupId>
3452
<artifactId>log</artifactId>
@@ -95,6 +113,12 @@
95113
</exclusions>
96114
</dependency>
97115

116+
<dependency>
117+
<groupId>io.trino</groupId>
118+
<artifactId>trino-filesystem</artifactId>
119+
<scope>provided</scope>
120+
</dependency>
121+
98122
<dependency>
99123
<groupId>io.trino</groupId>
100124
<artifactId>trino-spi</artifactId>

Diff for: lib/trino-parquet/src/main/java/io/trino/parquet/DataPage.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ public abstract sealed class DataPage
2121
{
2222
protected final int valueCount;
2323
private final OptionalLong firstRowIndex;
24+
private final int pageIndex;
2425

25-
public DataPage(int uncompressedSize, int valueCount, OptionalLong firstRowIndex)
26+
public DataPage(int uncompressedSize, int valueCount, OptionalLong firstRowIndex, int pageIndex)
2627
{
2728
super(uncompressedSize);
2829
this.valueCount = valueCount;
2930
this.firstRowIndex = firstRowIndex;
31+
this.pageIndex = pageIndex;
3032
}
3133

3234
/**
@@ -41,4 +43,9 @@ public int getValueCount()
4143
{
4244
return valueCount;
4345
}
46+
47+
public int getPageIndex()
48+
{
49+
return pageIndex;
50+
}
4451
}

Diff for: lib/trino-parquet/src/main/java/io/trino/parquet/DataPageV1.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,17 @@ public DataPageV1(
3535
OptionalLong firstRowIndex,
3636
ParquetEncoding repetitionLevelEncoding,
3737
ParquetEncoding definitionLevelEncoding,
38-
ParquetEncoding valuesEncoding)
38+
ParquetEncoding valuesEncoding,
39+
int pageIndex)
3940
{
40-
super(uncompressedSize, valueCount, firstRowIndex);
41+
super(uncompressedSize, valueCount, firstRowIndex, pageIndex);
4142
this.slice = requireNonNull(slice, "slice is null");
4243
this.repetitionLevelEncoding = repetitionLevelEncoding;
4344
this.definitionLevelEncoding = definitionLevelEncoding;
4445
this.valuesEncoding = valuesEncoding;
4546
}
4647

48+
@Override
4749
public Slice getSlice()
4850
{
4951
return slice;

Diff for: lib/trino-parquet/src/main/java/io/trino/parquet/DataPageV2.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ public DataPageV2(
4444
int uncompressedSize,
4545
OptionalLong firstRowIndex,
4646
Statistics<?> statistics,
47-
boolean isCompressed)
47+
boolean isCompressed,
48+
int pageIndex)
4849
{
49-
super(uncompressedSize, valueCount, firstRowIndex);
50+
super(uncompressedSize, valueCount, firstRowIndex, pageIndex);
5051
this.rowCount = rowCount;
5152
this.nullCount = nullCount;
5253
this.repetitionLevels = requireNonNull(repetitionLevels, "repetitionLevels slice is null");
@@ -82,6 +83,7 @@ public ParquetEncoding getDataEncoding()
8283
return dataEncoding;
8384
}
8485

86+
@Override
8587
public Slice getSlice()
8688
{
8789
return slice;

Diff for: lib/trino-parquet/src/main/java/io/trino/parquet/DictionaryPage.java

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public DictionaryPage(Slice slice, int uncompressedSize, int dictionarySize, Par
4343
encoding);
4444
}
4545

46+
@Override
4647
public Slice getSlice()
4748
{
4849
return slice;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package io.trino.parquet;
15+
16+
import io.airlift.log.Logger;
17+
import io.trino.filesystem.Location;
18+
import io.trino.filesystem.TrinoFileSystem;
19+
import io.trino.parquet.crypto.FileDecryptionProperties;
20+
import io.trino.parquet.crypto.InternalFileDecryptor;
21+
import io.trino.parquet.crypto.TrinoCryptoConfigurationUtil;
22+
import io.trino.parquet.crypto.TrinoDecryptionPropertiesFactory;
23+
24+
import java.lang.reflect.InvocationTargetException;
25+
import java.util.Optional;
26+
27+
public class EncryptionUtils
28+
{
29+
public static final Logger LOG = Logger.get(EncryptionUtils.class);
30+
31+
private EncryptionUtils() {}
32+
33+
public static Optional<InternalFileDecryptor> createDecryptor(ParquetReaderOptions parquetReaderOptions, Location filePath, TrinoFileSystem trinoFileSystem)
34+
{
35+
if (parquetReaderOptions == null || filePath == null || trinoFileSystem == null) {
36+
return Optional.empty();
37+
}
38+
39+
Optional<TrinoDecryptionPropertiesFactory> cryptoFactory = loadDecryptionPropertiesFactory(parquetReaderOptions);
40+
Optional<FileDecryptionProperties> fileDecryptionProperties = cryptoFactory.map(factory -> factory.getFileDecryptionProperties(parquetReaderOptions, filePath, trinoFileSystem));
41+
return fileDecryptionProperties.map(properties -> new InternalFileDecryptor(properties));
42+
}
43+
44+
private static Optional<TrinoDecryptionPropertiesFactory> loadDecryptionPropertiesFactory(ParquetReaderOptions trinoParquetCryptoConfig)
45+
{
46+
if (trinoParquetCryptoConfig.getCryptoFactoryClass() == null) {
47+
return Optional.empty();
48+
}
49+
final Class<?> foundClass = TrinoCryptoConfigurationUtil.getClassFromConfig(
50+
trinoParquetCryptoConfig.getCryptoFactoryClass(), TrinoDecryptionPropertiesFactory.class);
51+
52+
if (foundClass == null) {
53+
return Optional.empty();
54+
}
55+
56+
try {
57+
return Optional.ofNullable((TrinoDecryptionPropertiesFactory) foundClass.getConstructor().newInstance());
58+
}
59+
catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
60+
LOG.warn("could not instantiate decryptionPropertiesFactoryClass class: " + foundClass, e);
61+
return Optional.empty();
62+
}
63+
}
64+
}

Diff for: lib/trino-parquet/src/main/java/io/trino/parquet/Page.java

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
*/
1414
package io.trino.parquet;
1515

16+
import io.airlift.slice.Slice;
17+
1618
public abstract class Page
1719
{
1820
protected final int uncompressedSize;
@@ -26,4 +28,6 @@ public int getUncompressedSize()
2628
{
2729
return uncompressedSize;
2830
}
31+
32+
public abstract Slice getSlice();
2933
}

0 commit comments

Comments
 (0)