|
17 | 17 |
|
18 | 18 | //! Serde code to convert from protocol buffers to Rust data structures. |
19 | 19 |
|
| 20 | +use crate::error::BallistaError; |
| 21 | +use crate::serde::{proto_error, protobuf}; |
| 22 | +use crate::{convert_box_required, convert_required}; |
| 23 | +use sqlparser::ast::{WindowFrame, WindowFrameBound, WindowFrameUnits}; |
20 | 24 | use std::{ |
21 | 25 | convert::{From, TryInto}, |
22 | 26 | unimplemented, |
23 | 27 | }; |
24 | 28 |
|
25 | | -use crate::error::BallistaError; |
26 | | -use crate::serde::{proto_error, protobuf}; |
27 | | -use crate::{convert_box_required, convert_required}; |
28 | | - |
29 | 29 | use arrow::datatypes::{DataType, Field, Schema}; |
30 | 30 | use datafusion::logical_plan::{ |
31 | 31 | abs, acos, asin, atan, ceil, cos, exp, floor, ln, log10, log2, round, signum, sin, |
@@ -88,8 +88,10 @@ impl TryInto<LogicalPlan> for &protobuf::LogicalPlanNode { |
88 | 88 | .iter() |
89 | 89 | .map(|expr| expr.try_into()) |
90 | 90 | .collect::<Result<Vec<_>, _>>()?; |
| 91 | + // FIXME parse window frame |
| 92 | + let window_frame = None; |
91 | 93 | LogicalPlanBuilder::from(&input) |
92 | | - .window(partition_by_expr, order_by_expr)? |
| 94 | + .window(partition_by_expr, order_by_expr, window_frame)? |
93 | 95 | .build() |
94 | 96 | .map_err(|e| e.into()) |
95 | 97 | } |
@@ -1260,6 +1262,72 @@ fn parse_optional_expr( |
1260 | 1262 | } |
1261 | 1263 | } |
1262 | 1264 |
|
| 1265 | +impl From<protobuf::WindowFrameUnits> for WindowFrameUnits { |
| 1266 | + fn from(units: protobuf::WindowFrameUnits) -> Self { |
| 1267 | + match units { |
| 1268 | + protobuf::WindowFrameUnits::Rows => WindowFrameUnits::Rows, |
| 1269 | + protobuf::WindowFrameUnits::Range => WindowFrameUnits::Range, |
| 1270 | + protobuf::WindowFrameUnits::Groups => WindowFrameUnits::Groups, |
| 1271 | + } |
| 1272 | + } |
| 1273 | +} |
| 1274 | + |
| 1275 | +impl TryFrom<protobuf::WindowFrameBound> for WindowFrameBound { |
| 1276 | + type Error = BallistaError; |
| 1277 | + |
| 1278 | + fn try_from(bound: protobuf::WindowFrameBound) -> Result<Self, Self::Error> { |
| 1279 | + let bound_type = protobuf::WindowFrameBoundType::from_i32(bound.window_frame_bound_type).ok_or_else(|| { |
| 1280 | + proto_error(format!( |
| 1281 | + "Received a WindowFrameBound message with unknown WindowFrameBoundType {}", |
| 1282 | + bound.window_frame_bound_type |
| 1283 | + )) |
| 1284 | + })?.into(); |
| 1285 | + match bound_type { |
| 1286 | + protobuf::WindowFrameBoundType::CurrentRow => { |
| 1287 | + Ok(WindowFrameBound::CurrentRow) |
| 1288 | + } |
| 1289 | + protobuf::WindowFrameBoundType::Preceding => { |
| 1290 | + // FIXME implement bound value parsing |
| 1291 | + Ok(WindowFrameBound::Preceding(Some(1))) |
| 1292 | + } |
| 1293 | + protobuf::WindowFrameBoundType::Following => { |
| 1294 | + // FIXME implement bound value parsing |
| 1295 | + Ok(WindowFrameBound::Following(Some(1))) |
| 1296 | + } |
| 1297 | + } |
| 1298 | + } |
| 1299 | +} |
| 1300 | + |
| 1301 | +impl TryFrom<protobuf::WindowFrame> for WindowFrame { |
| 1302 | + type Error = BallistaError; |
| 1303 | + |
| 1304 | + fn try_from(window: protobuf::WindowFrame) -> Result<Self, Self::Error> { |
| 1305 | + let units = protobuf::WindowFrameUnits::from_i32(window.window_frame_units) |
| 1306 | + .ok_or_else(|| { |
| 1307 | + proto_error(format!( |
| 1308 | + "Received a WindowFrame message with unknown WindowFrameUnits {}", |
| 1309 | + window.window_frame_units |
| 1310 | + )) |
| 1311 | + })? |
| 1312 | + .into(); |
| 1313 | + let start_bound = window |
| 1314 | + .start_bound |
| 1315 | + .ok_or_else(|| { |
| 1316 | + proto_error( |
| 1317 | + "Received a WindowFrame message with no start_bound".to_owned(), |
| 1318 | + ) |
| 1319 | + })? |
| 1320 | + .try_into()?; |
| 1321 | + // FIXME parse end bound |
| 1322 | + let end_bound = None; |
| 1323 | + Ok(WindowFrame { |
| 1324 | + units, |
| 1325 | + start_bound, |
| 1326 | + end_bound, |
| 1327 | + }) |
| 1328 | + } |
| 1329 | +} |
| 1330 | + |
1263 | 1331 | impl From<protobuf::AggregateFunction> for AggregateFunction { |
1264 | 1332 | fn from(aggr_function: protobuf::AggregateFunction) -> Self { |
1265 | 1333 | match aggr_function { |
|
0 commit comments