File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
datafusion/core/src/execution/context Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -1236,6 +1236,37 @@ impl SessionContext {
12361236 Ok ( ( ) )
12371237 }
12381238
1239+ /// Parse memory limit from string to number of bytes
1240+ /// Supports formats like '1.5G', '100M', '512K'
1241+ ///
1242+ /// # Examples
1243+ /// ```
1244+ /// use datafusion::execution::context::SessionContext;
1245+ ///
1246+ /// assert_eq!(
1247+ /// SessionContext::parse_memory_limit("1M").unwrap(),
1248+ /// 1024 * 1024
1249+ /// );
1250+ /// assert_eq!(
1251+ /// SessionContext::parse_memory_limit("1.5G").unwrap(),
1252+ /// (1.5 * 1024.0 * 1024.0 * 1024.0) as usize
1253+ /// );
1254+ /// ```
1255+ #[ deprecated( since="53.0.0" , note="please use `parse_capacity_limit` function instead." ) ]
1256+ pub fn parse_memory_limit ( limit : & str ) -> Result < usize > {
1257+ let ( number, unit) = limit. split_at ( limit. len ( ) - 1 ) ;
1258+ let number: f64 = number. parse ( ) . map_err ( |_| {
1259+ plan_datafusion_err ! ( "Failed to parse number from memory limit '{limit}'" )
1260+ } ) ?;
1261+
1262+ match unit {
1263+ "K" => Ok ( ( number * 1024.0 ) as usize ) ,
1264+ "M" => Ok ( ( number * 1024.0 * 1024.0 ) as usize ) ,
1265+ "G" => Ok ( ( number * 1024.0 * 1024.0 * 1024.0 ) as usize ) ,
1266+ _ => plan_err ! ( "Unsupported unit '{unit}' in memory limit '{limit}'" ) ,
1267+ }
1268+ }
1269+
12391270 /// Parse capacity limit from string to number of bytes by allowing units: K, M and G.
12401271 /// Supports formats like '1.5G', '100M', '512K'
12411272 ///
You can’t perform that action at this time.
0 commit comments