@@ -101,13 +101,35 @@ public class CometFileKeyUnwrapper {
101101 // Cache the hadoopConf just to assert the assumption above.
102102 private Configuration conf = null ;
103103
104+ /**
105+ * Normalizes S3 URI schemes to a canonical form. S3 can be accessed via multiple schemes (s3://,
106+ * s3a://, s3n://) that refer to the same logical filesystem. This method ensures consistent cache
107+ * lookups regardless of which scheme is used.
108+ *
109+ * @param filePath The file path that may contain an S3 URI
110+ * @return The file path with normalized S3 scheme (s3a://)
111+ */
112+ private String normalizeS3Scheme (final String filePath ) {
113+ // Normalize s3:// and s3n:// to s3a:// for consistent cache lookups
114+ // This handles the case where ObjectStoreUrl uses s3:// but Spark uses s3a://
115+ String s3Prefix = "s3://" ;
116+ String s3nPrefix = "s3n://" ;
117+ if (filePath .startsWith (s3Prefix )) {
118+ return "s3a://" + filePath .substring (s3Prefix .length ());
119+ } else if (filePath .startsWith (s3nPrefix )) {
120+ return "s3a://" + filePath .substring (s3nPrefix .length ());
121+ }
122+ return filePath ;
123+ }
124+
104125 /**
105126 * Creates and stores a DecryptionKeyRetriever instance for the given file path.
106127 *
107128 * @param filePath The path to the Parquet file
108129 * @param hadoopConf The Hadoop Configuration to use for this file path
109130 */
110131 public void storeDecryptionKeyRetriever (final String filePath , final Configuration hadoopConf ) {
132+ final String normalizedPath = normalizeS3Scheme (filePath );
111133 // Use DecryptionPropertiesFactory.loadFactory to get the factory and then call
112134 // getFileDecryptionProperties
113135 if (factory == null ) {
@@ -122,7 +144,7 @@ public void storeDecryptionKeyRetriever(final String filePath, final Configurati
122144 factory .getFileDecryptionProperties (hadoopConf , path );
123145
124146 DecryptionKeyRetriever keyRetriever = decryptionProperties .getKeyRetriever ();
125- retrieverCache .put (filePath , keyRetriever );
147+ retrieverCache .put (normalizedPath , keyRetriever );
126148 }
127149
128150 /**
@@ -136,7 +158,8 @@ public void storeDecryptionKeyRetriever(final String filePath, final Configurati
136158 */
137159 public byte [] getKey (final String filePath , final byte [] keyMetadata )
138160 throws ParquetCryptoRuntimeException {
139- DecryptionKeyRetriever keyRetriever = retrieverCache .get (filePath );
161+ final String normalizedPath = normalizeS3Scheme (filePath );
162+ DecryptionKeyRetriever keyRetriever = retrieverCache .get (normalizedPath );
140163 if (keyRetriever == null ) {
141164 throw new ParquetCryptoRuntimeException (
142165 "Failed to find DecryptionKeyRetriever for path: " + filePath );
0 commit comments