The following example demonstrates how to connect to an existing Spark Connect App and query its status information.
from emr_spark_connect import EMRSparkConnectSession, StaticCredentials app = ( EMRSparkConnectSession.builder .region("<region>") .credentials(StaticCredentials("<your-ak>", "<your-sk>")) .serverId("<connect-app-id>") .getOrCreateApp() ) print(app.getServerId()) print(app.getStatus()) print(app.getTrackingUrl())
The following example demonstrates how to connect to a specified Spark Connect App, create a SparkSession, and execute an SQL query.
from emr_spark_connect import EMRSparkConnectSession, StaticCredentials spark = ( EMRSparkConnectSession.builder .region("<region>") .credentials(StaticCredentials("<your-ak>", "<your-sk>")) .serverId("<connect-app-id>") .getOrCreate() ) spark.sql("select 'hello' as msg").show() spark.stop()
Parameter / Method | Required | Note |
|---|---|---|
| Yes | Specifies region information. |
| Yes | Specifies access credentials, including Access Key and Secret Key. |
| Required when connecting to an existing App | Specifies the unique identifier of the target Spark Connect App. Acquisition method:
|
| Yes | Create or get a Spark Connect App and return the App object. |
| Yes | Create a SparkSession and connect to the specified Spark Connect App. |
| No | Get Spark Connect App ID. |
| No | Get App status. |
| No | Get Tracking URL, typically used to navigate to the job/application details page or monitoring page. |
The following example demonstrates how to connect to an existing Spark Connect App and query its status information.
import com.volc.emr.spark.connect.EMRSparkConnectSession; import com.volc.emr.spark.connect.EMRSparkConnectProvider; import com.volc.emr.spark.connect.StaticCredentials; import com.volc.emr.spark.connect.SparkApp; import org.apache.spark.sql.SparkSession; public class SparkConnectJavaExample { public static void main(String[] args) { SparkApp app = EMRSparkConnectSession.builder() .region("<region>") .credentials(new StaticCredentials("<your-ak>", "<your-sk>")) .serverId("<connect-app-id>") .getOrCreateApp(); System.out.println(app.getConnectId()); System.out.println(app.getStatus()); System.out.println(app.getTrackingUrl()); } }
The following example demonstrates how to connect to a specified Spark Connect App, create a SparkSession, and execute an SQL query.
import com.volc.emr.spark.connect.EMRSparkConnectSession; import com.volc.emr.spark.connect.StaticCredentials; import org.apache.spark.sql.SparkSession; public class SparkConnectJavaExample { public static void main(String[] args) { SparkSession spark = EMRSparkConnectSession.builder() .region("<region>") .credentials(new StaticCredentials("<your-ak>", "<your-sk>")) .serverId("<connect-app-id>") .getOrCreate(); spark.sql("select 'hello' as msg").show(); spark.stop(); } }
Parameter / Method | Required | Note |
|---|---|---|
| Yes | Specifies region information. |
| Yes | Specifies access credentials, including Access Key and Secret Key. |
| Required when connecting to an existing App | Specifies the unique identifier of the target Spark Connect App. Acquisition method:
|
| Yes | Create or get a Spark Connect App and return the App object. |
| Yes | Create a SparkSession and connect to the specified Spark Connect App. |
| No | Get Spark Connect App ID. |
| No | Get App status. |
| No | Get Tracking URL, typically used to navigate to the job/application details page or monitoring page. |