@@ -24,12 +24,17 @@ use std::{
24
24
convert:: { TryFrom , TryInto } ,
25
25
} ;
26
26
27
+ use super :: super :: proto_error;
27
28
use crate :: datasource:: DfTableAdapter ;
28
29
use crate :: serde:: { protobuf, BallistaError } ;
29
30
use datafusion:: arrow:: datatypes:: { DataType , Field , IntervalUnit , Schema , TimeUnit } ;
30
31
use datafusion:: datasource:: CsvFile ;
31
32
use datafusion:: logical_plan:: { Expr , JoinType , LogicalPlan } ;
32
33
use datafusion:: physical_plan:: aggregates:: AggregateFunction ;
34
+ use datafusion:: physical_plan:: functions:: BuiltinScalarFunction ;
35
+ use datafusion:: physical_plan:: window_frames:: {
36
+ WindowFrame , WindowFrameBound , WindowFrameUnits ,
37
+ } ;
33
38
use datafusion:: physical_plan:: window_functions:: {
34
39
BuiltInWindowFunction , WindowFunction ,
35
40
} ;
@@ -38,10 +43,6 @@ use protobuf::{
38
43
arrow_type, logical_expr_node:: ExprType , scalar_type, DateUnit , PrimitiveScalarType ,
39
44
ScalarListValue , ScalarType ,
40
45
} ;
41
- use sqlparser:: ast:: { WindowFrame , WindowFrameBound , WindowFrameUnits } ;
42
-
43
- use super :: super :: proto_error;
44
- use datafusion:: physical_plan:: functions:: BuiltinScalarFunction ;
45
46
46
47
impl protobuf:: IntervalUnit {
47
48
pub fn from_arrow_interval_unit ( interval_unit : & IntervalUnit ) -> Self {
@@ -1007,6 +1008,7 @@ impl TryInto<protobuf::LogicalExprNode> for &Expr {
1007
1008
ref fun,
1008
1009
ref args,
1009
1010
ref order_by,
1011
+ ref window_frame,
1010
1012
..
1011
1013
} => {
1012
1014
let window_function = match fun {
@@ -1026,10 +1028,16 @@ impl TryInto<protobuf::LogicalExprNode> for &Expr {
1026
1028
. iter ( )
1027
1029
. map ( |e| e. try_into ( ) )
1028
1030
. collect :: < Result < Vec < _ > , _ > > ( ) ?;
1031
+ let window_frame = window_frame. map ( |window_frame| {
1032
+ protobuf:: window_expr_node:: WindowFrame :: Frame (
1033
+ window_frame. clone ( ) . into ( ) ,
1034
+ )
1035
+ } ) ;
1029
1036
let window_expr = Box :: new ( protobuf:: WindowExprNode {
1030
1037
expr : Some ( Box :: new ( arg. try_into ( ) ?) ) ,
1031
1038
window_function : Some ( window_function) ,
1032
1039
order_by,
1040
+ window_frame,
1033
1041
} ) ;
1034
1042
Ok ( protobuf:: LogicalExprNode {
1035
1043
expr_type : Some ( ExprType :: WindowExpr ( window_expr) ) ,
@@ -1256,23 +1264,35 @@ impl From<WindowFrameUnits> for protobuf::WindowFrameUnits {
1256
1264
}
1257
1265
}
1258
1266
1259
- impl TryFrom < WindowFrameBound > for protobuf:: WindowFrameBound {
1260
- type Error = BallistaError ;
1261
-
1262
- fn try_from ( _bound : WindowFrameBound ) -> Result < Self , Self :: Error > {
1263
- Err ( BallistaError :: NotImplemented (
1264
- "WindowFrameBound => protobuf::WindowFrameBound" . to_owned ( ) ,
1265
- ) )
1267
+ impl From < WindowFrameBound > for protobuf:: WindowFrameBound {
1268
+ fn from ( bound : WindowFrameBound ) -> Self {
1269
+ match bound {
1270
+ WindowFrameBound :: CurrentRow => protobuf:: WindowFrameBound {
1271
+ window_frame_bound_type : protobuf:: WindowFrameBoundType :: CurrentRow
1272
+ . into ( ) ,
1273
+ bound_value : None ,
1274
+ } ,
1275
+ WindowFrameBound :: Preceding ( v) => protobuf:: WindowFrameBound {
1276
+ window_frame_bound_type : protobuf:: WindowFrameBoundType :: Preceding . into ( ) ,
1277
+ bound_value : v. map ( protobuf:: window_frame_bound:: BoundValue :: Value ) ,
1278
+ } ,
1279
+ WindowFrameBound :: Following ( v) => protobuf:: WindowFrameBound {
1280
+ window_frame_bound_type : protobuf:: WindowFrameBoundType :: Following . into ( ) ,
1281
+ bound_value : v. map ( protobuf:: window_frame_bound:: BoundValue :: Value ) ,
1282
+ } ,
1283
+ }
1266
1284
}
1267
1285
}
1268
1286
1269
- impl TryFrom < WindowFrame > for protobuf:: WindowFrame {
1270
- type Error = BallistaError ;
1271
-
1272
- fn try_from ( _window : WindowFrame ) -> Result < Self , Self :: Error > {
1273
- Err ( BallistaError :: NotImplemented (
1274
- "WindowFrame => protobuf::WindowFrame" . to_owned ( ) ,
1275
- ) )
1287
+ impl From < WindowFrame > for protobuf:: WindowFrame {
1288
+ fn from ( window : WindowFrame ) -> Self {
1289
+ protobuf:: WindowFrame {
1290
+ window_frame_units : protobuf:: WindowFrameUnits :: from ( window. units ) . into ( ) ,
1291
+ start_bound : Some ( window. start_bound . into ( ) ) ,
1292
+ end_bound : Some ( protobuf:: window_frame:: EndBound :: Bound (
1293
+ window. end_bound . into ( ) ,
1294
+ ) ) ,
1295
+ }
1276
1296
}
1277
1297
}
1278
1298
0 commit comments