Skip to content

Commit f6ddd72

Browse files
committed
fix empty result set issue
1 parent 12cbbb6 commit f6ddd72

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

rust/cubeorchestrator/src/query_message_parser.rs

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,38 +64,39 @@ impl QueryResult {
6464
.command_as_http_result_set()
6565
.ok_or(ParseError::EmptyResultSet)?;
6666

67-
let result_set_columns = result_set.columns().ok_or(ParseError::EmptyResultSet)?;
67+
if let Some(result_set_columns) = result_set.columns() {
68+
if result_set_columns.iter().any(|c| c.is_empty()) {
69+
return Err(ParseError::ColumnNameNotDefined);
70+
}
6871

69-
if result_set_columns.iter().any(|c| c.is_empty()) {
70-
return Err(ParseError::ColumnNameNotDefined);
71-
}
72-
73-
let (columns, columns_pos): (Vec<_>, HashMap<_, _>) = result_set_columns
74-
.iter()
75-
.enumerate()
76-
.map(|(index, column_name)| {
77-
(column_name.to_owned(), (column_name.to_owned(), index))
78-
})
79-
.unzip();
80-
81-
result.columns = columns;
82-
result.columns_pos = columns_pos;
83-
84-
let result_set_rows = result_set.rows().ok_or(ParseError::EmptyResultSet)?;
85-
result.rows = Vec::with_capacity(result_set_rows.len());
86-
87-
for row in result_set_rows.iter() {
88-
let values = row.values().ok_or(ParseError::NullRow)?;
89-
let row_obj: Vec<_> = values
72+
let (columns, columns_pos): (Vec<_>, HashMap<_, _>) = result_set_columns
9073
.iter()
91-
.map(|val| {
92-
DBResponseValue::Primitive(DBResponsePrimitive::String(
93-
val.string_value().unwrap_or("").to_owned(),
94-
))
74+
.enumerate()
75+
.map(|(index, column_name)| {
76+
(column_name.to_owned(), (column_name.to_owned(), index))
9577
})
96-
.collect();
78+
.unzip();
79+
80+
result.columns = columns;
81+
result.columns_pos = columns_pos;
82+
}
9783

98-
result.rows.push(row_obj);
84+
if let Some(result_set_rows) = result_set.rows() {
85+
result.rows = Vec::with_capacity(result_set_rows.len());
86+
87+
for row in result_set_rows.iter() {
88+
let values = row.values().ok_or(ParseError::NullRow)?;
89+
let row_obj: Vec<_> = values
90+
.iter()
91+
.map(|val| {
92+
DBResponseValue::Primitive(DBResponsePrimitive::String(
93+
val.string_value().unwrap_or("").to_owned(),
94+
))
95+
})
96+
.collect();
97+
98+
result.rows.push(row_obj);
99+
}
99100
}
100101

101102
Ok(result)
@@ -106,7 +107,11 @@ impl QueryResult {
106107

107108
pub fn from_js_raw_data(js_raw_data: JsRawData) -> Result<Self, ParseError> {
108109
if js_raw_data.is_empty() {
109-
return Err(ParseError::EmptyResultSet);
110+
return Ok(QueryResult {
111+
columns: vec![],
112+
rows: vec![],
113+
columns_pos: HashMap::new(),
114+
});
110115
}
111116

112117
let first_row = &js_raw_data[0];

0 commit comments

Comments
 (0)