1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//! Provides support for building and executing parameterized SQL queries through [`SparkSession::query`].
//!
//! # Overview
//!
//! This module defines the internal [`SqlQueryBuilder`] type used by [`SparkSession::query`] to
//! support a fluent, type-safe API for parameterized SQL queries.
//!
//! Users are not expected to instantiate [`SqlQueryBuilder`] directly; instead, call
//! [`SparkSession::query`], and then chain `.bind()` calls to attach
//! parameters before executing the query.
//!
//! # Example
//!
//! ```
//! use spark_connect::SparkSessionBuilder;
//! use arrow::array::RecordBatch;
//!
//! # tokio_test::block_on(async {
//! let session = SparkSessionBuilder::new("sc://localhost:15002").build().await.unwrap();
//!
//! // Build and execute a parameterized query fluently
//! let results: Vec<RecordBatch> = session
//! .query("SELECT ? AS id, ? AS name")
//! .bind(42)
//! .bind("Alice")
//! .execute()
//! .await
//! .unwrap();
//!
//! assert!(!results.is_empty());
//! # });
//! ```
//!
//! # How it works
//!
//! - [`SparkSession::query`] creates an internal [`SqlQueryBuilder`] instance tied to the session
//! and initializes it with a SQL query string containing `?` placeholders.
//! - `.bind()` attaches parameter values, converting each Rust type into a Spark [`Literal`] via
//! the [`ToLiteral`] trait.
//! - `.execute()` runs the query asynchronously and collects the resulting Arrow
//! [`RecordBatch`]es into memory.
//!
//! # See also
//! - [`ToLiteral`] — converts native Rust types into Spark literals.
//! - [`SparkSession::sql`] — executes parameterized SQL queries directly.
//!
//! # Errors
//!
//! Returns a [`SparkError`] if query preparation or execution fails.
use crate::;
use crateLiteral;
use crateToLiteral;
use RecordBatch;