Skip to content

Commit 8c4473e

Browse files
authored
[query-engine] Refactor try_resolve_value_type calls in KQL parser to use new helper method (#1020)
nt
1 parent 8147563 commit 8c4473e

File tree

4 files changed

+15
-44
lines changed

4 files changed

+15
-44
lines changed

rust/experimental/query_engine/kql-parser/src/logical_expressions.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,7 @@ pub(crate) fn parse_logical_expression(
209209
if let ScalarExpression::Logical(l) = scalar {
210210
Ok(*l)
211211
} else {
212-
let value_type_result = scalar
213-
.try_resolve_value_type(&scope.get_pipeline().get_resolution_scope());
214-
if let Err(e) = value_type_result {
215-
return Err(ParserError::from(&e));
216-
}
217-
if let Some(t) = value_type_result.unwrap()
212+
if let Some(t) = scope.try_resolve_value_type(&mut scalar)?
218213
&& t != ValueType::Boolean
219214
{
220215
return Err(ParserError::QueryLanguageDiagnostic {

rust/experimental/query_engine/kql-parser/src/scalar_array_function_expressions.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ pub(crate) fn parse_array_concat_expression(
2020
for rule in array_concat_rules {
2121
let mut scalar = parse_scalar_expression(rule, scope)?;
2222

23-
if let Some(t) = scope.try_resolve_value_type(&mut scalar)? {
24-
if t != ValueType::Array {
25-
return Err(ParserError::QueryLanguageDiagnostic {
26-
location: scalar.get_query_location().clone(),
27-
diagnostic_id: "KS234",
28-
message: "The expression value must be a dynamic array".into(),
29-
});
30-
}
23+
if let Some(t) = scope.try_resolve_value_type(&mut scalar)?
24+
&& t != ValueType::Array
25+
{
26+
return Err(ParserError::QueryLanguageDiagnostic {
27+
location: scalar.get_query_location().clone(),
28+
diagnostic_id: "KS234",
29+
message: "The expression value must be a dynamic array".into(),
30+
});
3131
}
3232

3333
values.push(scalar);

rust/experimental/query_engine/kql-parser/src/scalar_primitive_expressions.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,13 +339,7 @@ pub(crate) fn parse_accessor_expression(
339339
Rule::scalar_expression => {
340340
let mut scalar = parse_scalar_expression(pair, scope)?;
341341

342-
let value_type_result =
343-
scalar.try_resolve_value_type(&scope.get_pipeline().get_resolution_scope());
344-
if let Err(e) = value_type_result {
345-
return Err(ParserError::from(&e));
346-
}
347-
348-
let value_type = value_type_result.unwrap();
342+
let value_type = scope.try_resolve_value_type(&mut scalar)?;
349343

350344
if negate_location.is_some() {
351345
if let Some(t) = value_type

rust/experimental/query_engine/kql-parser/src/scalar_string_function_expressions.rs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ pub(crate) fn parse_strlen_expression(
1919
let inner_expression_rule_location = to_query_location(&inner_expression_rule);
2020
let mut inner_expression = parse_scalar_expression(inner_expression_rule, scope)?;
2121

22-
let inner_expression_value_type_result = inner_expression
23-
.try_resolve_value_type(&scope.get_pipeline().get_resolution_scope())
24-
.map_err(|e| ParserError::from(&e))?;
25-
26-
if let Some(v) = inner_expression_value_type_result
22+
if let Some(v) = scope.try_resolve_value_type(&mut inner_expression)?
2723
&& v != ValueType::String
2824
{
2925
return Err(ParserError::QueryLanguageDiagnostic {
@@ -65,11 +61,7 @@ pub(crate) fn parse_replace_string_expression(
6561

6662
let mut scalar = parse_scalar_expression(rule, scope)?;
6763

68-
let scalar_value_type_result = scalar
69-
.try_resolve_value_type(&scope.get_pipeline().get_resolution_scope())
70-
.map_err(|e| ParserError::from(&e))?;
71-
72-
if let Some(v) = scalar_value_type_result
64+
if let Some(v) = scope.try_resolve_value_type(&mut scalar)?
7365
&& v != ValueType::String
7466
{
7567
return Err(ParserError::QueryLanguageDiagnostic {
@@ -96,11 +88,7 @@ pub(crate) fn parse_substring_expression(
9688
let starting_index_rule_location = to_query_location(&starting_index_rule);
9789
let mut starting_index_scalar = parse_scalar_expression(starting_index_rule, scope)?;
9890

99-
let starting_index_value_type_result = starting_index_scalar
100-
.try_resolve_value_type(&scope.get_pipeline().get_resolution_scope())
101-
.map_err(|e| ParserError::from(&e))?;
102-
103-
if let Some(v) = starting_index_value_type_result
91+
if let Some(v) = scope.try_resolve_value_type(&mut starting_index_scalar)?
10492
&& v != ValueType::Integer
10593
{
10694
return Err(ParserError::QueryLanguageDiagnostic {
@@ -114,11 +102,7 @@ pub(crate) fn parse_substring_expression(
114102
let length_scalar_rule_location = to_query_location(&length_rule);
115103
let mut length_scalar = parse_scalar_expression(length_rule, scope)?;
116104

117-
let length_scalar_value_type_result = length_scalar
118-
.try_resolve_value_type(&scope.get_pipeline().get_resolution_scope())
119-
.map_err(|e| ParserError::from(&e))?;
120-
121-
if let Some(v) = length_scalar_value_type_result
105+
if let Some(v) = scope.try_resolve_value_type(&mut length_scalar)?
122106
&& v != ValueType::Integer
123107
{
124108
return Err(ParserError::QueryLanguageDiagnostic {
@@ -153,9 +137,7 @@ pub(crate) fn parse_parse_json_expression(
153137
let inner_rule_location = to_query_location(&inner_rule);
154138
let mut inner_scalar = parse_scalar_expression(inner_rule, scope)?;
155139

156-
if let Some(v) = inner_scalar
157-
.try_resolve_value_type(&scope.get_pipeline().get_resolution_scope())
158-
.map_err(|e| ParserError::from(&e))?
140+
if let Some(v) = scope.try_resolve_value_type(&mut inner_scalar)?
159141
&& v != ValueType::String
160142
{
161143
return Err(ParserError::QueryLanguageDiagnostic {

0 commit comments

Comments
 (0)