Help Center/ AI DataLake/ SDK Reference/ Engine-specific SDKs/ Java SDKs/ Spark SDK (Java)/ Obtaining and Initializing the Spark SDK
Updated on 2026-11-06 GMT+08:00

Obtaining and Initializing the Spark SDK

The Spark SDK encapsulates the Spark APIs provided by the AI DataLake service to simplify development. You can directly call the API functions provided by the SDK to submit Spark SQL and Spark jobs. This section describes how to obtain and initialize the Spark SDK.

Prerequisites

You have completed the operations in Configuring the Java Environment.

Step 1: Obtaining the SDK

Download the SDK file. You are advised to download the .sha256 file as well, which can be used to verify the integrity of the SDK package. For details about the verification method, see Step 2: Verifying the Integrity of the SDK Package.

Step 2: Verifying the Integrity of the SDK Package

When downloading the SDK installation package, you also need to download the .sha256 file to verify the integrity of the SDK package. This section outlines the steps to use the .sha256 file for verifying the integrity of the SDK package.

  1. Querying the SHA-256 hash value of the SDK installation package
    • On Windows
      1. Search for cmd in the Start menu to open the command window.
      2. Run cd to go to the directory where the SDK installation package is saved.

        For example, if the SDK installation package is saved in the SDK folder on drive D, enter cd D:\SDK.

      3. Run the following command:
        certutil -hashfile <SDK installation package name> SHA-256

        Replace <SDK installation package name> with the actual SDK installation package name, for example, aidatalake-spark-sdk-1.0-261030.tar.gz.

      4. After the command is executed, the command prompt will display the SHA-256 hash value of the SDK installation package.
    • On Linux
      1. Run cd to go to the directory where the SDK installation package is saved.

        For example, if the SDK installation package is saved in the SDK folder in the home directory, enter cd ~/SDK.

      2. Enter the query command:
        sha256sum <SDK installation package name>

        Replace <SDK installation package name> with the actual SDK installation package name, for example, aidatalake-spark-sdk-1.0-261030.tar.gz.

      3. After the command is executed, the terminal will display the SHA-256 hash value of the SDK installation package.
  2. Comparing hash values
    1. Open the downloaded .sha256 file using the text editor.
    2. Find the SHA-256 hash value of the SDK installation package in the .sha256 file.

      It is typically a long string, for example, a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6xxxxxxxxxxxxxxxxxxxxxxxx.

    3. Compare the SHA-256 hash value in the SDK installation package obtained in Step 1 with the hash value in the .sha256 file.
      • If the two hash values are identical, the SDK installation package was not altered during the download process and the file is intact.
      • If the hash values are inconsistent, an error occurred during the download of the SDK installation package or that the file was maliciously modified.

        In this case, you are advised to download the SDK installation package and its corresponding .sha256 file again and then verify the package.

Step 3: Installing the SDK

  1. Click aidatalake-spark-sdk-x.x.x.jar to download the SDK package.
  2. Run the following command to install the JAR package to the local Maven repository:
    mvn install:install-file -Dfile=aidatalake-spark-sdk-x.x.x.jar -DgroupId=com.huawei.aidatalake -DartifactId=aidatalake-spark-sdk -Dversion=x.x.x -Dpackaging=jar
  3. Add the following dependencies to the pom.xml file:
    <dependency>
        <groupId>com.huawei.aidatalake</groupId>
        <artifactId>aidatalake-spark-sdk</artifactId>
        <version>x.x.x</version>
    </dependency>

Step 4: Initializing the Client

To use the AI DataLake SDK to access AI DataLake, you need to initialize the AI DataLake client. You can use the AK/SK authentication mode to initialize the client.

// Initialize the client context.
JobClientContext jobContext = new JobClientContext();
jobContext.setRegionName("cn-north-4");
jobContext.setProjectId("xxxx-xxxx");
jobContext.setWorkspaceId("xxx-xxxx");
jobContext.setLakeformationInstanceId("xxxx-xxxx");
jobContext.setEndpointName("xxxx");
// Use the STS token.
jobContext.setCredentialProvider(StaticCredentialProvider.create("{accesskey}", "{secretKey}", "{securityToken}", "{projectId}"));
jobClientContext.setAiDataLakeEndpoint("xxx.xxxx");
jobClientContext.setLakeformationInstanceId("xxx-xxxx");
jobClientContext.setObsEndpoint("xxx.xxxx");

// Initialize AIDataLakeSparkSqlClient (Spark SQL client).
AIDataLakeSparkSqlClient sparkSqlClient = new AIDataLakeSparkSqlClient(jobContext);

// Initialize AIDataLakeSparkJobClient (Spark Job client).
AIDataLakeSparkJobClient sparkJobClient = new AIDataLakeSparkJobClient(jobContext);

// Initialize AIDataLakeLakeFormationClient (Schema metadata query client).
AIDataLakeLakeFormationClient lakeformationClient = new AIDataLakeLakeFormationClient(jobContext);
Table 1 Parameter description

Parameter

Mandatory (Yes/No)

Default Value

Description

RegionName

Yes

None

Region name.

ProjectId

Yes

None

Project ID.

WorkspaceId

Yes

None

Workspace ID.

Lakeformation InstanceId

Yes

None

ID of the LakeFormation instance bound to the workspace.

AccessKey

Yes

None

Access key ID.

SecretKey

Yes

None

Secret key.

SecurityToken

No

None

Used when a temporary credential is used.

EndPointName

Yes

None

AI DataLake endpoint, for example, fabric.{regionName}.myhuaweicloud.com.

ObsEndpoint

No

None

OBS endpoint. If this parameter is not set, obs.{RegionName}.myhuaweicloud.com is used by default.