Submitting a Spark Job
Description
This section describes how to submit a Spark job using AI DataLake SDK.
Prerequisites
- The compute resources and endpoints in use are available.
- Permissions related to APIs and SQL jobs have been configured. For details, see Permissions and Supported Actions.
Functions
- SparkJarJob
# Synchronous submission function submit(); # Asynchronous submission function asyncSubmit();
- SparkSqlScriptingJob
# Synchronous submission function submit(); # Asynchronous submission function asyncSubmit();
- SparkPythonJob
# Synchronous submission function submit(); # Asynchronous submission function asyncSubmit();
Sample Code
- Synchronously submitting a SparkJar job
public static void submit(AIDataLakeSparkJobClient sparkJobClient) throws AIDataLakeException { String jobName = "JOB_NAME"; String endpointName = "ENDPOINT_NAME"; String catalogName = "CATALOG_NAME"; // set spark configs Map<String, String> config = new HashMap<>(); config.put("key", "value"); SparkJarJob sparkJob = sparkJobClient.newSparkJarJobBuilder(jobName, "com.example.Main", "obs://app.jar") .endpointName(endpointName) .jobAgency("agency") .catalogName(catalogName) .mainArgs(Arrays.asList("arg1")) .dependencyJars(Arrays.asList("obs://lib.jar")) .sparkConfig(config) .driverCpu(2000) .driverMemory(4096) .executorCpu(4000) .executorMemory(8192) .executorNumber(4) .build(); sparkJob.submit(); }Table 1 Parameter description Parameter
Mandatory (Yes/No)
Default Value
Description
catalogName
No
None
Default LakeFormation catalog name.
This parameter is optional if Spark.sql is executed within the job.
endpointName
Yes
None
SparkSQL endpoint name.
mainArgs
No
None
Arguments of the Main class.
dependencyJars
No
None
Dependent JAR files.
jobAgency
No
None
IAM agency for the job, which is used by users to access OBS or Lakeformation.
sparkConfig
No
None
Spark parameters.
driverCpu
No
None
Number of millicores of the Driver pod.
driverMemory
No
None
Memory size of the Driver pod, in MB.
executorCpu
No
None
Number of millicores of the Executor pod.
executorMemory
No
None
Memory size of the Executor pod, in MB.
executorNumber
No
None
Number of Executor instances.
- Asynchronously submitting a SparkSqlScript job
public static void submit(AIDataLakeSparkJobClient sparkJobClient) throws AIDataLakeException { String jobName = "JOB_NAME"; String endpointName = "ENDPOINT_NAME"; String catalogName = "CATALOG_NAME"; // set spark configs Map<String, String> config = new HashMap<>(); config.put("key", "value"); SparkSqlScriptingJob sparkScriptingJob = sparkJobClient.newSparkSqlScriptingJobBuilder(jobName) .endpointName(endpointName) .sqlScriptingFileUri("obs://xxx") .catalogName(catalogName) .jobAgency("agency") .sparkConfig(config) .driverCpu(2000) .driverMemory(4096) .executorCpu(4000) .executorMemory(8192) .executorNumber(4) .sqlScriptingResultToObs(true) .build(); sparkJob.asyncSubmit(); }Table 2 Parameter description Parameter
Mandatory (Yes/No)
Default Value
Description
catalogName
No
None
Default LakeFormation catalog name.
This parameter is optional if Spark.sql is executed within the job.
endpointName
Yes
None
SparkSQL endpoint name.
jobAgency
No
None
IAM agency for the job, which is used by users to access OBS or Lakeformation.
sqlScriptingFileUri
Yes
None
OBS path to the SQL scripting file.
sparkConfig
No
None
Spark parameters.
driverCpu
No
None
Number of millicores of the Driver pod.
driverMemory
No
None
Memory size of the Driver pod, in MB.
executorCpu
No
None
Number of millicores of the Executor pod.
executorMemory
No
None
Memory size of the Executor pod, in MB.
executorNumber
No
None
Number of Executor instances.
- Synchronously submitting a SparkPython job
public static void submit(AIDataLakeSparkJobClient sparkJobClient) throws AIDataLakeException { String jobName = "JOB_NAME"; String endpointName = "ENDPOINT_NAME"; String catalogName = "CATALOG_NAME"; return sparkJobClient.newSparkPythonJobBuilder(jobName, "obs://xxx/job.py") .endpointName(endpointName) .catalogName(catalogName) .jobAgency("agency") .sparkConfig(config) .driverCpu(1000) .driverMemory(1024) .driverDisk(20) .executorCpu(1000) .executorMemory(1024) .build(); sparkJob.submit(); }Table 3 Parameter description Parameter
Mandatory (Yes/No)
Default Value
Description
catalogName
No
None
Default LakeFormation catalog name.
This parameter is optional if Spark.sql is executed within the job.
endpointName
Yes
None
SparkSQL endpoint name.
jobAgency
No
None
IAM agency for the job, which is used by users to access OBS or LakeFormation.
sparkConfig
No
None
Spark parameters.
driverCpu
No
None
Number of millicores of the Driver pod.
driverMemory
No
None
Memory size of the Driver pod, in MB.
executorCpu
No
None
Number of millicores of the Executor pod.
executorMemory
No
None
Memory size of the Executor pod, in MB.
executorNumber
No
None
Number of Executor instances.
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot