SparkSession
The entry point to programming Spark with the Dataset and DataFrame API. A SparkSession can be used to create DataFrames, register DataFrames as tables, execute SQL over tables, cache tables, and read parquet files.
Syntax
from pyspark.sql import SparkSession
spark = SparkSession.builder.getOrCreate()
Properties
Property | Description |
|---|---|
Interface for building the session configuration. | |
Interface through which the user may create, drop, alter or query underlying databases, tables, functions, etc. | |
Gives access to the Spark Connect client. Spark Connect only. | |
Runtime configuration interface for Spark. | |
Returns a DataSourceRegistration for data source registration. | |
Returns a Profile for performance/memory profiling. | |
Returns a DataFrameReader that can be used to read data as a DataFrame. | |
Returns a DataStreamReader that can be used to read data streams as a streaming DataFrame. | |
Returns the underlying SparkContext. Classic mode only. | |
Returns a StreamingQueryManager that allows managing all active streaming queries. | |
Returns a TableValuedFunction for calling table-valued functions (TVFs). | |
Returns a UDFRegistration for UDF registration. | |
Returns a UDTFRegistration for UDTF registration. | |
The version of Spark on which this application is running. |
Methods
Method | Description |
|---|---|
Creates a DataFrame from an RDD, a list, a pandas DataFrame, a numpy ndarray, or a pyarrow Table. | |
Returns a DataFrame representing the result of the given query. | |
Returns the specified table as a DataFrame. | |
Creates a DataFrame with a single LongType column named | |
Returns a new SparkSession with separate SQLConf, registered temporary views, and UDFs, but shared SparkContext and table cache. Classic mode only. | |
Returns the active SparkSession for the current thread. | |
Returns the active or default SparkSession for the current thread. | |
Stops the underlying SparkContext. | |
Adds artifact(s) to the client session. | |
Interrupts all operations of this session currently running on the server. | |
Interrupts all operations of this session with the given tag. | |
Interrupts an operation of this session with the given operationId. | |
Adds a tag to be assigned to all operations started by this thread in this session. | |
Removes a tag previously added for operations started by this thread. | |
Gets the tags currently set to be assigned to all operations started by this thread. | |
Clears the current thread's operation tags. |