Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(interactive): fix bugs when try to get labels or properties from an None entry #4341

Merged
merged 6 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,15 @@ public static QueryContext get_simple_match_query_17_test() {
List<String> expected = Arrays.asList("Record<{$f0: 851}>");
return new QueryContext(query, expected);
}

public static QueryContext get_simple_match_query_18_test() {
String query =
"MATCH (country:PLACE {name:"
+ " \"India\"})<-[:ISPARTOF]-(:PLACE)<-[:ISLOCATEDIN]-(zombie:PERSON)\n"
+ "OPTIONAL MATCH (zombie)<-[:HASCREATOR]-(message)\n"
+ "WHERE message.creationDate < 20100630000000000\n"
+ " Return count(country);";
List<String> expected = Arrays.asList("Record<{$f0: 25}>");
return new QueryContext(query, expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,13 @@ public void run_simple_match_17_test() {
Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString());
}

@Test
public void run_simple_match_18_test() {
QueryContext testQuery = SimpleMatchQueries.get_simple_match_query_18_test();
Result result = session.run(testQuery.getQuery());
Assert.assertEquals(testQuery.getExpectedResult().toString(), result.list().toString());
}

@AfterClass
public static void afterClass() {
if (session != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,40 +44,44 @@ impl PropKey {
let prop_obj = if let PropKey::Len = self {
element.len().into()
} else {
let graph_element = element
.as_graph_element()
.ok_or_else(|| ExprEvalError::UnexpectedDataType(self.into()))?;
match self {
PropKey::Id => graph_element.id().into(),
PropKey::Label => graph_element
.label()
.map(|label| label.into())
.unwrap_or(Object::None),
PropKey::Len => unreachable!(),
PropKey::All => graph_element
.get_all_properties()
.map(|obj| {
obj.into_iter()
.map(|(key, value)| {
let obj_key: Object = match key {
NameOrId::Str(str) => str.into(),
NameOrId::Id(id) => id.into(),
};
(obj_key, value)
})
.collect::<Vec<(Object, Object)>>()
.into()
})
.unwrap_or(Object::None),
PropKey::Key(key) => {
if let Some(prop_val) = graph_element.get_property(key) {
prop_val.try_to_owned().ok_or_else(|| {
ExprEvalError::OtherErr("cannot get `Object` from `BorrowObject`".to_string())
})?
} else {
Object::None
if let Some(graph_element) = element.as_graph_element() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the implementation such that calling as_graph_element() from an None object can return a special object that have implementation of getting None value from any properties?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Introduced a `NullGraphEntry' for a null graph element.

match self {
PropKey::Id => graph_element.id().into(),
PropKey::Label => graph_element
.label()
.map(|label| label.into())
.unwrap_or(Object::None),
PropKey::Len => unreachable!(),
PropKey::All => graph_element
.get_all_properties()
.map(|obj| {
obj.into_iter()
.map(|(key, value)| {
let obj_key: Object = match key {
NameOrId::Str(str) => str.into(),
NameOrId::Id(id) => id.into(),
};
(obj_key, value)
})
.collect::<Vec<(Object, Object)>>()
.into()
})
.unwrap_or(Object::None),
PropKey::Key(key) => {
if let Some(prop_val) = graph_element.get_property(key) {
prop_val.try_to_owned().ok_or_else(|| {
ExprEvalError::OtherErr(
"cannot get `Object` from `BorrowObject`".to_string(),
)
})?
} else {
Object::None
}
}
}
} else {
// if try to get property from non-graph-element, return None
Object::None
}
};
Ok(prop_obj)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ impl FilterMapFunction<Record, Record> for AuxiliaOperator {
// then we set tag=None and alias="a" in auxilia

// 1. If to filter by labels, and the entry itself carries label information already, directly eval it without query the store
if self.query_params.has_labels() && entry.label().is_some() {
if self.query_params.has_labels() && entry.as_graph_path().is_some() && entry.label().is_some()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix this if condition when verifying the special implementation for None object.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

{
if !self
.query_params
.labels
Expand Down
Loading