Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

Show all

Common Spark Commands

Updated on 2024-08-16 GMT+08:00

For details about how to use Spark commands, visit http://spark.apache.org/docs/latest/quick-start.html.

Common Commands

Methods of running shell commands:

  1. Go to the directory where the Spark client is installed.
  2. Run the following command to initialize environment variables:

    source /opt/client/bigdata_env

  3. If the Kerberos authentication is enabled for the current cluster, run the following command to authenticate the user. If the Kerberos authentication is disabled for the current cluster, skip this step. The current user is the development user added in Preparing a Spark Application Development User.

    kinit MRS cluster user

    Example:

    • If the development user is a machine-machine user, run kinit -kt user.keytab sparkuser.
    • If the development user is a human-machine user, run kinit sparkuser.

  4. Run the Spark shell command.

The common Spark commands are as follows:

  • spark-shell

    It provides a simple commissioning tool that supports Scala language.

    Run the spark-shell command on the shell console to enter the Scala interactive interface. Obtain data from HDFS, perform calculation by using the RDD, and output and print the result.

    Example: A line of code can be used to collect statistics on the frequency of all words in a file.

    scala> sc.textFile("hdfs://hacluster/tmp/wordcount_data.txt").flatMap(line=> line.split(" ")).map(w => (w,1)).reduceByKey(_+_).collect()

  • spark-submit

    This command is used to submit Spark applications to an MRS cluster for running and return the running result. The class, master, JAR file, and input parameters must be specified.

    Example: Run GroupByTest in the JAR file. There are four input parameters and the cluster running mode is the yarn-client mode.

    spark-submit --class org.apache.spark.examples.GroupByTest --master yarn --deploy-mode client ${SPARK_HOME}/examples/jars/spark-examples_2.11-2.3.2-mrs-2.0.jar 6 3000 3000 3

  • spark-sql

    Start a Spark application and execute Spark SQL. You can specify local(--master local) or cluster mode (--master yarn).

    Example of starting an instance:

    spark-sql --master yarn

    Example of SQL:

    • SELECT key FROM src GROUP BY key;
    • EXPLAIN EXTENDED SHOW TABLES;
  • spark-beeline

    Call Spark JDBCServer to execute Spark SQL to efficiently compute and analyze massive amounts of data. JDBCServer contains a long-term Spark task. All statements in the spark-beeline are submitted to the task for execution.

    Example of starting an instance:

    cd $SPARK_HOME/bin

    spark-beeline

    Example of SQL:

    1. CREATE TABLE info(id int, name string, company string);
    2. INSERT INTO TABLE info values(001,'jack','huawei');
    3. SELECT * FROM info;
  • beeline

    Call Spark JDBCServer to execute Spark SQL to efficiently compute and analyze massive amounts of data. JDBCServer contains a long-term Spark task. All statements in the beeline are submitted to the task for execution.

    For security clusters with Kerberos authentication enabled

    cd $SPARK_HOME/bin

    ./beeline -u 'jdbc:hive2://ha-cluster/default;user.principal=spark/hadoop.COM;saslQop=auth-conf;auth=KERBEROS;principal=spark/hadoop.COM;'

    NOTE:

    The spark/hadoop.COM character string is obtained from the principal character string displayed by running the klist -kt /opt/Bigdata/MRS_XXX/1_20_SparkResource/etc/spark.keytay command in the cluster. You can paste the character string to the beeline command.

    For normal clusters with Kerberos authentication disabled

    cd $SPARK_HOME/bin

    beeline

    Example of SQL:

    1. CREATE TABLE info(id int, name string, company string);
    2. INSERT INTO TABLE info values(001,'jack','huawei');
    3. SELECT * FROM info;

    You are advised to use spark-beeline because it is encapsulated based on beeline, which can be directly executed.

  • run-example

    This command is used to run or debug the built-in sample code in the Spark open source community.

    Example: Running SparkPi

    run-example --master yarn --deploy-mode client SparkPi 100

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback