Sometimes it’s handy to be able to test Apache Spark developments locally. This might include testing cloud storage such as WASB (Windows Azure Storage Blob).
These steps describe the process for testing WASB locally without the need for an Azure account. These steps make use of the Azurite Storage Emulator.
- Create a new directory and start the Azurite Storage Emulator Docker container – e.g.:
docker run -p 10000:10000 -p 10001:10001 -v /home/david/blob/:/data mcr.microsoft.com/azure-storage/azurite
NB – in the above example, data will be persisted to the local linux directory /home/david/blob.
- Upload files with Storage Explorer:
Connect Storage Explorer to the Local Storage emulator (keep defaults when adding the connection):
Upload a sample file – e.g. to the “data” container:
- Start Spark using the packages option to include libraries needed to access Blob storage. The Maven coordinates are shown here are for the latest hadoop-azure package:
./pyspark --packages org.apache.hadoop:hadoop-azure:3.3.1
The PySpark shell should start as per normal after downloading hadoop-azure and its dependencies.
The following stack trace indicates the hadoop-azure driver or dependencies were not loaded successfully:
... py4j.protocol.Py4JJavaError: An error occurred while calling o33.load. : java.lang.RuntimeException: java.lang.ClassNotFoundException: Class org.apache.hadoop.fs.azure.NativeAzureFileSystem not found at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:2595) at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:3269) ... Caused by: java.lang.ClassNotFoundException: Class org.apache.hadoop.fs.azure.NativeAzureFileSystem not found at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:2499) at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:2593) ... 25 more ...
Ensure the “packages” option is correctly set when invoking pyspark above.
- Query the data using the emulated Blob storage location from the PySpark shell:
data – container where the data was uploaded earlier
@storageemulator – this is a fixed string used to tell the WASB connector to point to the local emulator
Local storage emulation allows testing of wasb locations without the need to connect to a remote Azure subscription / storage account.