|
9 | 9 |
|
10 | 10 | use crate::input::proto::substrait; |
11 | 11 | use crate::output::diagnostic; |
12 | | -use crate::output::type_system::data; |
13 | 12 | use crate::parse::context; |
14 | | -use crate::parse::expressions; |
15 | 13 | use crate::util; |
16 | 14 |
|
17 | 15 | /// Parse fetch relation. |
18 | 16 | pub fn parse_fetch_rel( |
19 | 17 | x: &substrait::FetchRel, |
20 | 18 | y: &mut context::Context, |
21 | 19 | ) -> diagnostic::Result<()> { |
22 | | - use substrait::fetch_rel::CountMode; |
23 | | - use substrait::fetch_rel::OffsetMode; |
24 | | - |
25 | 20 | // Parse input. |
26 | 21 | let in_type = handle_rel_input!(x, y); |
27 | 22 |
|
28 | 23 | // Filters pass through their input schema unchanged. |
29 | 24 | y.set_schema(in_type); |
30 | 25 |
|
31 | | - // Parse offset and count. |
32 | | - // proto_primitive_field!(x, y, offset, |x, y| { |
33 | | - // if *x < 0 { |
34 | | - // diagnostic!(y, Error, IllegalValue, "offsets cannot be negative"); |
35 | | - // } |
36 | | - // Ok(()) |
37 | | - // }); |
38 | | - // proto_primitive_field!(x, y, count, |x, y| { |
39 | | - // if *x < 0 { |
40 | | - // diagnostic!(y, Error, IllegalValue, "count cannot be negative"); |
41 | | - // } |
42 | | - // Ok(()) |
43 | | - // }); |
44 | | - |
45 | | - proto_field!(x, y, offset_mode); // TODO add the check for negative values |
| 26 | + // Parse offset and count from the new oneof fields. |
| 27 | + // Extract offset value (default to 0 if not set) |
46 | 28 | let offset = match &x.offset_mode { |
47 | | - Some(OffsetMode::Offset(n)) => *n, |
48 | | - Some(OffsetMode::OffsetExpr(expr)) => { |
49 | | - let ex: expressions::Expression = expressions::parse_expression(expr, y)?; |
50 | | - match ex { |
51 | | - expressions::Expression::Literal(literal) => match literal.data_type().class() { |
52 | | - data::Class::Simple(data::class::Simple::I64) => todo!(), |
53 | | - _ => todo!(), |
54 | | - }, |
55 | | - _ => todo!(), |
| 29 | + Some(substrait::fetch_rel::OffsetMode::Offset(val)) => { |
| 30 | + if *val < 0 { |
| 31 | + diagnostic!(y, Error, IllegalValue, "offsets cannot be negative"); |
56 | 32 | } |
| 33 | + *val |
| 34 | + } |
| 35 | + Some(substrait::fetch_rel::OffsetMode::OffsetExpr(_)) => { |
| 36 | + // For now, we can't evaluate expressions, so we'll just note it |
| 37 | + diagnostic!( |
| 38 | + y, |
| 39 | + Warning, |
| 40 | + NotYetImplemented, |
| 41 | + "offset_expr evaluation not yet implemented" |
| 42 | + ); |
| 43 | + 0 |
57 | 44 | } |
58 | 45 | None => 0, |
59 | 46 | }; |
60 | 47 |
|
61 | | - proto_field!(x, y, count_mode); // TODO add the check for negative values |
| 48 | + // Extract count value (default to -1 for ALL if not set) |
62 | 49 | let count = match &x.count_mode { |
63 | | - Some(CountMode::Count(n)) => *n, |
64 | | - Some(CountMode::CountExpr(expr)) => { |
65 | | - let ex: expressions::Expression = expressions::parse_expression(expr, y)?; |
66 | | - match ex { |
67 | | - expressions::Expression::Literal(literal) => match literal.data_type().class() { |
68 | | - data::Class::Simple(data::class::Simple::I64) => todo!(), |
69 | | - _ => todo!(), |
70 | | - }, |
71 | | - _ => todo!(), |
| 50 | + Some(substrait::fetch_rel::CountMode::Count(val)) => { |
| 51 | + if *val < 0 { |
| 52 | + diagnostic!(y, Error, IllegalValue, "count cannot be negative"); |
72 | 53 | } |
| 54 | + *val |
73 | 55 | } |
74 | | - None => 0, |
| 56 | + Some(substrait::fetch_rel::CountMode::CountExpr(_)) => { |
| 57 | + // For now, we can't evaluate expressions, so we'll just note it |
| 58 | + diagnostic!( |
| 59 | + y, |
| 60 | + Warning, |
| 61 | + NotYetImplemented, |
| 62 | + "count_expr evaluation not yet implemented" |
| 63 | + ); |
| 64 | + -1 |
| 65 | + } |
| 66 | + None => -1, |
75 | 67 | }; |
76 | 68 |
|
77 | 69 | // Describe the relation. |
|
0 commit comments