Skip to content

Commit

Permalink
Update Azure SDK
Browse files Browse the repository at this point in the history
Azure SDK version 1.2.24 includes Azure Storage Blob 12.26, which
introduces a breaking change, where blob names used to create a new blob
client should not be URL-encoded anymore. Blob URLs in the storage don't
change, so after adjusting the API usage, data written by older Trino
versions should be readable by new Trino versions.
  • Loading branch information
nineinchnick authored and wendigo committed Jun 25, 2024
1 parent 68fb5c9 commit 88e4a5c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import java.util.OptionalLong;
import java.util.Set;

import static com.azure.storage.common.Utility.urlEncode;
import static com.azure.storage.common.implementation.Constants.HeaderConstants.ETAG_WILDCARD;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
Expand Down Expand Up @@ -178,8 +177,7 @@ private void deleteBlobDirectory(AzureLocation location)
BlobContainerClient blobContainerClient = createBlobContainerClient(location);
PagedIterable<BlobItem> blobItems = blobContainerClient.listBlobs(new ListBlobsOptions().setPrefix(location.directoryPath()), null);
for (BlobItem item : blobItems) {
String blobUrl = urlEncode(item.getName());
blobContainerClient.getBlobClient(blobUrl).deleteIfExists();
blobContainerClient.getBlobClient(item.getName()).deleteIfExists();
}
}

Expand Down Expand Up @@ -216,7 +214,7 @@ private void renameGen2File(AzureLocation source, AzureLocation target)
createDirectoryIfNotExists(fileSystemClient, target.location().parentDirectory().path());
dataLakeFileClient.renameWithResponse(
null,
urlEncode(target.path()),
target.path(),
null,
new DataLakeRequestConditions().setIfNoneMatch(ETAG_WILDCARD),
null,
Expand Down Expand Up @@ -353,7 +351,7 @@ public void renameDirectory(Location source, Location target)
if (!directoryClient.getProperties().isDirectory()) {
throw new IOException("Source is not a directory: " + source);
}
directoryClient.rename(null, urlEncode(targetLocation.path()));
directoryClient.rename(null, targetLocation.path());
}
catch (RuntimeException e) {
throw new IOException("Rename directory from %s to %s failed".formatted(source, target), e);
Expand Down Expand Up @@ -453,7 +451,7 @@ private boolean isHierarchicalNamespaceEnabled(AzureLocation location)

private BlobClient createBlobClient(AzureLocation location)
{
return createBlobContainerClient(location).getBlobClient(urlEncode(location.path()));
return createBlobContainerClient(location).getBlobClient(location.path());
}

private BlobContainerClient createBlobContainerClient(AzureLocation location)
Expand Down Expand Up @@ -488,16 +486,16 @@ private DataLakeFileSystemClient createFileSystemClient(AzureLocation location)

private static DataLakeDirectoryClient createDirectoryClient(DataLakeFileSystemClient fileSystemClient, String directoryName)
{
return fileSystemClient.getDirectoryClient(urlEncode(directoryName));
return fileSystemClient.getDirectoryClient(directoryName);
}

private static DataLakeFileClient createFileClient(DataLakeFileSystemClient fileSystemClient, String fileName)
{
return fileSystemClient.getFileClient(urlEncode(fileName));
return fileSystemClient.getFileClient(fileName);
}

private static DataLakeDirectoryClient createDirectoryIfNotExists(DataLakeFileSystemClient fileSystemClient, String name)
{
return fileSystemClient.createDirectoryIfNotExists(urlEncode(name));
return fileSystemClient.createDirectoryIfNotExists(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

import java.io.IOException;

import static com.azure.storage.common.Utility.urlEncode;
import static com.google.common.base.Preconditions.checkState;
import static java.util.Locale.ROOT;
import static java.util.Objects.requireNonNull;
Expand Down Expand Up @@ -158,7 +157,7 @@ private void cleanupFiles()
}
}
else {
blobContainerClient.listBlobs().forEach(item -> blobContainerClient.getBlobClient(urlEncode(item.getName())).deleteIfExists());
blobContainerClient.listBlobs().forEach(item -> blobContainerClient.getBlobClient(item.getName()).deleteIfExists());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ protected void registerTableFromResources(String table, String resourcePath, Que
.collect(toImmutableList());
for (ClassPath.ResourceInfo resourceInfo : resources) {
String fileName = resourceInfo.getResourceName()
.replaceFirst("^" + Pattern.quote(resourcePath), quoteReplacement(targetDirectory))
// Replace '%' (corresponding to '%' character url encoded) with '%25' in order
// to maintain also after URL decoding from the Azure client the original '%'
.replace("%", "%25");
.replaceFirst("^" + Pattern.quote(resourcePath), quoteReplacement(targetDirectory));
ByteSource byteSource = resourceInfo.asByteSource();
azureContainerClient.getBlobClient(fileName).upload(byteSource.openBufferedStream(), byteSource.size());
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-sdk-bom</artifactId>
<version>1.2.23</version>
<version>1.2.24</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down

0 comments on commit 88e4a5c

Please sign in to comment.