HyukjinKwon commented on code in PR #53:
URL: https://github.com/apache/spark-connect-rust/pull/53#discussion_r3851620369


##########
docs/sql.md:
##########
@@ -0,0 +1,152 @@
+# SQL
+
+Execute SQL directly against DataFrames and data sources. Mix SQL queries with 
the DataFrame API for maximum flexibility.
+
+## Running SQL Queries
+
+Use `spark.sql()` to execute SQL and retrieve results as a DataFrame.
+
+```rust
+use spark_connect::SparkSession;
+
+let spark = SparkSession::builder()
+    .remote("sc://localhost:15002")
+    .get_or_create()?;
+
+// Simple query
+let df = spark.sql("SELECT 1 as id, 'hello' as msg")?;
+df.show(10)?;
+
+// Aggregate query
+let df = spark.sql(
+    r#"SELECT category, COUNT(*) as cnt, AVG(price) as avg_price
+       FROM products
+       GROUP BY category
+       ORDER BY cnt DESC"#
+)?;
+df.show(10)?;
+```
+
+## Registering Temporary Views
+
+Make DataFrames queryable via SQL by creating temporary views.
+
+```rust
+use spark_connect::SparkSession;
+
+let spark = SparkSession::builder()
+    .remote("sc://localhost:15002")
+    .get_or_create()?;
+
+// Create from range
+let df = spark.range(4)?;
+
+// Register as temp view
+df.create_or_replace_temp_view("users")?;
+
+// Query it
+let result = spark.sql("SELECT * FROM users WHERE id > 1")?;
+result.show(10)?;
+
+// Replace view
+let df_updated = spark.sql("SELECT id FROM users")?;
+df_updated.create_or_replace_temp_view("users")?;
+```
+
+!!! note
+    Temporary views are scoped to the session and are dropped when the session 
ends.
+
+## Parameterized SQL
+
+Pass dynamic values into SQL queries safely using parameter binding.
+
+```rust
+use spark_connect::SparkSession;
+

Review Comment:
   Fixed in 84c7599: retitled 'Dynamic values'; it now recommends the typed 
DataFrame API (.filter(f::col(..).gt(lit(..)))) as the injection-safe path, 
with format! interpolation demoted to a 'trusted input only, NOT 
injection-safe' warning. Noted that SparkSession::sql takes only a query string.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to