Skip to content

Commit

Permalink
[BugFix][Spark] Fix the comparison behavior of Property/PropertyGroup…
Browse files Browse the repository at this point in the history
…/AdjList (#306)
  • Loading branch information
acezen authored Dec 28, 2023
1 parent 96b8e3b commit 9a7e042
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
32 changes: 32 additions & 0 deletions spark/src/main/scala/com/alibaba/graphar/GraphInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ class Property() {
GarType.StringToGarType(data_type)
}

override def equals(that: Any): Boolean = {
that match {
case other: Property =>
this.name == other.name &&
this.data_type == other.data_type &&
this.is_primary == other.is_primary
case _ => false
}
}

def toMap(): java.util.HashMap[String, Object] = {
val data = new java.util.HashMap[String, Object]()
data.put("name", name)
Expand All @@ -194,6 +204,16 @@ class PropertyGroup() {
@BeanProperty var file_type: String = ""
@BeanProperty var properties = new java.util.ArrayList[Property]()

override def equals(that: Any): Boolean = {
that match {
case other: PropertyGroup =>
this.prefix == other.prefix &&
this.file_type == other.file_type &&
this.properties == other.properties
case _ => false
}
}

/** Get file type in gar of property group */
def getFile_type_in_gar: FileType.Value = {
FileType.StringToFileType(file_type)
Expand Down Expand Up @@ -223,6 +243,18 @@ class AdjList() {
@BeanProperty var file_type: String = ""
@BeanProperty var property_groups = new java.util.ArrayList[PropertyGroup]()

override def equals(that: Any): Boolean = {
that match {
case other: AdjList =>
this.ordered == other.ordered &&
this.aligned_by == other.aligned_by &&
this.prefix == other.prefix &&
this.file_type == other.file_type &&
this.property_groups == other.property_groups
case _ => false
}
}

/** Get file type in gar of adj list */
def getFile_type_in_gar: FileType.Value = {
FileType.StringToFileType(file_type)
Expand Down
39 changes: 39 additions & 0 deletions spark/src/test/scala/com/alibaba/graphar/TestGraphInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,43 @@ class GraphInfoSuite extends AnyFunSuite {
assertThrows[IllegalArgumentException](edge_info.isPrimaryKey("not_exist"))
}

test("== of Property/PropertyGroup/AdjList") {
val p1 = new Property()
val p2 = new Property()
assert(p1 == p2)
p1.setName("name")
assert(p1 != p2)
p2.setName("name")
assert(p1 == p2)
p1.setData_type("INT64")
assert(p1 != p2)
p2.setData_type("INT64")
assert(p1 == p2)
val pg1 = new PropertyGroup()
val pg2 = new PropertyGroup()
assert(pg1 == pg2)
pg1.setPrefix("/tmp")
assert(pg1 != pg2)
pg2.setPrefix("/tmp")
assert(pg1 == pg2)
pg1.setProperties(
new java.util.ArrayList[Property](java.util.Arrays.asList(p1))
)
assert(pg1 != pg2)
pg2.setProperties(
new java.util.ArrayList[Property](java.util.Arrays.asList(p2))
)
assert(pg1 == pg2)
val al1 = new AdjList()
val al2 = new AdjList()
assert(al1 == al2)
al1.setProperty_groups(
new java.util.ArrayList[PropertyGroup](java.util.Arrays.asList(pg1))
)
assert(al1 != al2)
al2.setProperty_groups(
new java.util.ArrayList[PropertyGroup](java.util.Arrays.asList(pg2))
)
assert(al1 == al2)
}
}

0 comments on commit 9a7e042

Please sign in to comment.