@@ -166,22 +166,23 @@ where
166166/// # #[tokio::main]
167167/// # async fn main() -> Result<()> {
168168/// let ctx = SessionContext::new();
169- /// let df = ctx.read_csv("tests/data/example.csv", CsvReadOptions::new()).await?;
170- /// let df = df.filter(col("a").lt_eq(col("b")))?
171- /// .aggregate(vec![col("a")], vec![min(col("b"))])?
172- /// .limit(0, Some(100))?;
173- /// let results = df
174- /// .collect()
175- /// .await?;
169+ /// let df = ctx
170+ /// .read_csv("tests/data/example.csv", CsvReadOptions::new())
171+ /// .await?;
172+ /// let df = df
173+ /// .filter(col("a").lt_eq(col("b")))?
174+ /// .aggregate(vec![col("a")], vec![min(col("b"))])?
175+ /// .limit(0, Some(100))?;
176+ /// let results = df.collect().await?;
176177/// assert_batches_eq!(
177- /// &[
178- /// "+---+----------------+",
179- /// "| a | min(?table?.b) |",
180- /// "+---+----------------+",
181- /// "| 1 | 2 |",
182- /// "+---+----------------+",
183- /// ],
184- /// &results
178+ /// &[
179+ /// "+---+----------------+",
180+ /// "| a | min(?table?.b) |",
181+ /// "+---+----------------+",
182+ /// "| 1 | 2 |",
183+ /// "+---+----------------+",
184+ /// ],
185+ /// &results
185186/// );
186187/// # Ok(())
187188/// # }
@@ -197,21 +198,22 @@ where
197198/// # #[tokio::main]
198199/// # async fn main() -> Result<()> {
199200/// let ctx = SessionContext::new();
200- /// ctx.register_csv("example", "tests/data/example.csv", CsvReadOptions::new()).await?;
201+ /// ctx.register_csv("example", "tests/data/example.csv", CsvReadOptions::new())
202+ /// .await?;
201203/// let results = ctx
202- /// .sql("SELECT a, min(b) FROM example GROUP BY a LIMIT 100")
203- /// .await?
204- /// .collect()
205- /// .await?;
204+ /// .sql("SELECT a, min(b) FROM example GROUP BY a LIMIT 100")
205+ /// .await?
206+ /// .collect()
207+ /// .await?;
206208/// assert_batches_eq!(
207- /// &[
208- /// "+---+----------------+",
209- /// "| a | min(example.b) |",
210- /// "+---+----------------+",
211- /// "| 1 | 2 |",
212- /// "+---+----------------+",
213- /// ],
214- /// &results
209+ /// &[
210+ /// "+---+----------------+",
211+ /// "| a | min(example.b) |",
212+ /// "+---+----------------+",
213+ /// "| 1 | 2 |",
214+ /// "+---+----------------+",
215+ /// ],
216+ /// &results
215217/// );
216218/// # Ok(())
217219/// # }
@@ -231,18 +233,18 @@ where
231233/// let config = SessionConfig::new().with_batch_size(4 * 1024);
232234///
233235/// // configure a memory limit of 1GB with 20% slop
234- /// let runtime_env = RuntimeEnvBuilder::new()
236+ /// let runtime_env = RuntimeEnvBuilder::new()
235237/// .with_memory_limit(1024 * 1024 * 1024, 0.80)
236238/// .build_arc()
237239/// .unwrap();
238240///
239241/// // Create a SessionState using the config and runtime_env
240242/// let state = SessionStateBuilder::new()
241- /// .with_config(config)
242- /// .with_runtime_env(runtime_env)
243- /// // include support for built in functions and configurations
244- /// .with_default_features()
245- /// .build();
243+ /// .with_config(config)
244+ /// .with_runtime_env(runtime_env)
245+ /// // include support for built in functions and configurations
246+ /// .with_default_features()
247+ /// .build();
246248///
247249/// // Create a SessionContext
248250/// let ctx = SessionContext::from(state);
@@ -428,16 +430,14 @@ impl SessionContext {
428430 /// # use datafusion::prelude::*;
429431 /// # use datafusion::execution::SessionStateBuilder;
430432 /// # use datafusion_optimizer::push_down_filter::PushDownFilter;
431- /// let my_rule = PushDownFilter{}; // pretend it is a new rule
432- /// // Create a new builder with a custom optimizer rule
433+ /// let my_rule = PushDownFilter {}; // pretend it is a new rule
434+ /// // Create a new builder with a custom optimizer rule
433435 /// let context: SessionContext = SessionStateBuilder::new()
434- /// .with_optimizer_rule(Arc::new(my_rule))
435- /// .build()
436- /// .into();
436+ /// .with_optimizer_rule(Arc::new(my_rule))
437+ /// .build()
438+ /// .into();
437439 /// // Enable local file access and convert context back to a builder
438- /// let builder = context
439- /// .enable_url_table()
440- /// .into_state_builder();
440+ /// let builder = context.enable_url_table().into_state_builder();
441441 /// ```
442442 pub fn into_state_builder ( self ) -> SessionStateBuilder {
443443 let SessionContext {
@@ -585,11 +585,10 @@ impl SessionContext {
585585 /// # #[tokio::main]
586586 /// # async fn main() -> Result<()> {
587587 /// let ctx = SessionContext::new();
588- /// ctx
589- /// .sql("CREATE TABLE foo (x INTEGER)")
590- /// .await?
591- /// .collect()
592- /// .await?;
588+ /// ctx.sql("CREATE TABLE foo (x INTEGER)")
589+ /// .await?
590+ /// .collect()
591+ /// .await?;
593592 /// assert!(ctx.table_exist("foo").unwrap());
594593 /// # Ok(())
595594 /// # }
@@ -614,14 +613,14 @@ impl SessionContext {
614613 /// # #[tokio::main]
615614 /// # async fn main() -> Result<()> {
616615 /// let ctx = SessionContext::new();
617- /// let options = SQLOptions::new()
618- /// .with_allow_ddl(false);
619- /// let err = ctx .sql_with_options("CREATE TABLE foo (x INTEGER)", options)
620- /// .await
621- /// .unwrap_err();
622- /// assert!(
623- /// err .to_string().starts_with("Error during planning: DDL not supported: CreateMemoryTable" )
624- /// );
616+ /// let options = SQLOptions::new().with_allow_ddl(false);
617+ /// let err = ctx
618+ /// .sql_with_options("CREATE TABLE foo (x INTEGER)", options)
619+ /// .await
620+ /// .unwrap_err();
621+ /// assert!(err
622+ /// .to_string()
623+ /// .starts_with("Error during planning: DDL not supported: CreateMemoryTable") );
625624 /// # Ok(())
626625 /// # }
627626 /// ```
@@ -653,8 +652,7 @@ impl SessionContext {
653652 /// // provide type information that `a` is an Int32
654653 /// let schema = Schema::new(vec![Field::new("a", DataType::Int32, true)]);
655654 /// let df_schema = DFSchema::try_from(schema).unwrap();
656- /// let expr = SessionContext::new()
657- /// .parse_sql_expr(sql, &df_schema)?;
655+ /// let expr = SessionContext::new().parse_sql_expr(sql, &df_schema)?;
658656 /// assert_eq!(expected, expr);
659657 /// # Ok(())
660658 /// # }
@@ -1143,8 +1141,14 @@ impl SessionContext {
11431141 /// ```
11441142 /// use datafusion::execution::context::SessionContext;
11451143 ///
1146- /// assert_eq!(SessionContext::parse_memory_limit("1M").unwrap(), 1024 * 1024);
1147- /// assert_eq!(SessionContext::parse_memory_limit("1.5G").unwrap(), (1.5 * 1024.0 * 1024.0 * 1024.0) as usize);
1144+ /// assert_eq!(
1145+ /// SessionContext::parse_memory_limit("1M").unwrap(),
1146+ /// 1024 * 1024
1147+ /// );
1148+ /// assert_eq!(
1149+ /// SessionContext::parse_memory_limit("1.5G").unwrap(),
1150+ /// (1.5 * 1024.0 * 1024.0 * 1024.0) as usize
1151+ /// );
11481152 /// ```
11491153 pub fn parse_memory_limit ( limit : & str ) -> Result < usize > {
11501154 let ( number, unit) = limit. split_at ( limit. len ( ) - 1 ) ;
0 commit comments