Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
SessionContext in datafusion::execution::context - Rust
[go: Go Back, main page]

pub struct SessionContext {
    pub session_start_time: DateTime<Utc>,
    pub state: Arc<RwLock<SessionState>>,
    /* private fields */
}
Expand description

SessionContext is the main interface for executing queries with DataFusion. It stands for the connection between user and DataFusion/Ballista cluster. The context provides the following functionality

  • Create DataFrame from a CSV or Parquet data source.
  • Register a CSV or Parquet data source as a table that can be referenced from a SQL query.
  • Register a custom data source that can be referenced from a SQL query.
  • Execution a SQL query

The following example demonstrates how to use the context to execute a query against a CSV data source using the DataFrame API:

use datafusion::prelude::*;
let ctx = SessionContext::new();
let df = ctx.read_csv("tests/example.csv", CsvReadOptions::new()).await?;
let df = df.filter(col("a").lt_eq(col("b")))?
           .aggregate(vec![col("a")], vec![min(col("b"))])?
           .limit(0, Some(100))?;
let results = df.collect();

The following example demonstrates how to execute the same query using SQL:

use datafusion::prelude::*;

let mut ctx = SessionContext::new();
ctx.register_csv("example", "tests/example.csv", CsvReadOptions::new()).await?;
let results = ctx.sql("SELECT a, MIN(b) FROM example GROUP BY a LIMIT 100").await?;

Fields§

§session_start_time: DateTime<Utc>

Session start time

§state: Arc<RwLock<SessionState>>

Shared session state for the session

Implementations§

Creates a new execution context using a default session configuration.

Finds any ListSchemaProviders and instructs them to reload tables from “disk”

Creates a new session context using the provided session configuration.

Creates a new session context using the provided configuration and RuntimeEnv.

Creates a new session context using the provided session state.

Registers the [RecordBatch] as the specified table name

Return the RuntimeEnv used to run queries with this SessionContext

Return a handle to the shared configuration options

Return the session_id of this Session

Return a copied version of config for this Session

Creates a DataFrame that will execute a SQL query.

This method is async because queries of type CREATE EXTERNAL TABLE might require the schema to be inferred.

Creates a logical plan.

This function is intended for internal use and should not be called directly.

Registers a variable provider within this context.

Registers a scalar UDF within this context.

Note in SQL queries, function names are looked up using lowercase unless the query uses quotes. For example,

SELECT MY_FUNC(x)... will look for a function named "my_func" SELECT "my_FUNC"(x) will look for a function named "my_FUNC"

Registers an aggregate UDF within this context.

Note in SQL queries, aggregate names are looked up using lowercase unless the query uses quotes. For example,

SELECT MY_UDAF(x)... will look for an aggregate named "my_udaf" SELECT "my_UDAF"(x) will look for an aggregate named "my_UDAF"

Creates a DataFrame for reading an Avro data source.

Creates a DataFrame for reading an Json data source.

Creates an empty DataFrame.

Creates a DataFrame for reading a CSV data source.

Creates a DataFrame for reading a Parquet data source.

Creates a DataFrame for reading a custom TableProvider.

Creates a DataFrame for reading a [RecordBatch]

Registers a [ListingTable] that can assemble multiple files from locations in an ObjectStore instance into a single table.

This method is async because it might need to resolve the schema.

Registers a CSV file as a table which can referenced from SQL statements executed against this context.

Registers a Json file as a table that it can be referenced from SQL statements executed against this context.

Registers a Parquet file as a table that can be referenced from SQL statements executed against this context.

Registers an Avro file as a table that can be referenced from SQL statements executed against this context.

Registers a named catalog using a custom CatalogProvider so that it can be referenced from SQL statements executed against this context.

Returns the CatalogProvider previously registered for this name, if any

Retrieves the list of available catalog names.

Retrieves a CatalogProvider instance by name

Registers a TableProvider as a table that can be referenced from SQL statements executed against this context.

Returns the TableProvider previously registered for this reference, if any

Deregisters the given table.

Returns the registered provider, if any

Return true if the specified table exists in the schema provider.

Retrieves a DataFrame representing a table previously registered by calling the register_table function.

Returns an error if no table has been registered with the provided reference.

👎Deprecated: Please use the catalog provider interface (SessionContext::catalog) to examine available catalogs, schemas, and tables

Returns the set of available tables in the default catalog and schema.

Use table to get a specific table.

Optimizes the logical plan by applying optimizer rules.

Creates a physical plan from a logical plan.

Executes a query and writes the results to a partitioned CSV file.

Executes a query and writes the results to a partitioned JSON file.

Executes a query and writes the results to a partitioned Parquet file.

Get a new TaskContext to run in this session

Get a copy of the SessionState of this SessionContext

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Returns the “default value” for a type. Read more

Create a new task context instance from SessionContext

Converts to this type from the input type.
Set of all available udfs.
Returns a reference to the udf named name.
Returns a reference to the udaf named name.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.
Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more