From 7d518e8361ccadbe5a622d02631a6653c90602fc Mon Sep 17 00:00:00 2001 From: David Baker Effendi Date: Thu, 6 Jan 2022 17:46:38 +0200 Subject: [PATCH] Fixed bug in GremlinDriver::propertyFromNodes (#217) --- CHANGELOG.md | 7 +++++++ .../scala/com/github/plume/oss/drivers/GremlinDriver.scala | 6 +++--- .../github/plume/oss/testfixtures/PlumeDriverFixture.scala | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39c1867f..1051922f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.0.1] - 2022-01-04 + +### Fixed + +- `GremlinDriver` now handles nodes that do not include properties specified + under `GremlinDriver::propertyFromNodes` + ## [1.0.0] - 2022-01-04 ### Changed diff --git a/src/main/scala/com/github/plume/oss/drivers/GremlinDriver.scala b/src/main/scala/com/github/plume/oss/drivers/GremlinDriver.scala index 43ccdb54..c99d55e2 100644 --- a/src/main/scala/com/github/plume/oss/drivers/GremlinDriver.scala +++ b/src/main/scala/com/github/plume/oss/drivers/GremlinDriver.scala @@ -8,7 +8,7 @@ import io.shiftleft.proto.cpg.Cpg.DispatchTypes import org.apache.commons.configuration.BaseConfiguration import org.apache.tinkerpop.gremlin.process.traversal.P import org.apache.tinkerpop.gremlin.process.traversal.P.{neq, within} -import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.{coalesce, constant, has, values} import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.{ GraphTraversal, GraphTraversalSource, @@ -205,10 +205,10 @@ abstract class GremlinDriver(txMax: Int = 50) extends IDriver { .hasLabel(nodeType) .project[Any](T.id.toString, keys: _*) .by(T.id) - keys.foreach(k => ptr = ptr.by(k)) + keys.foreach(k => ptr = ptr.by(coalesce(values(k), constant("NULL")))) ptr.asScala .map(_.asScala.map { case (k, v) => - if (v == null) + if (v == "NULL") k -> IDriver.getPropertyDefault(k) else k -> v diff --git a/src/test/scala/com/github/plume/oss/testfixtures/PlumeDriverFixture.scala b/src/test/scala/com/github/plume/oss/testfixtures/PlumeDriverFixture.scala index 70b7addd..19f769dd 100644 --- a/src/test/scala/com/github/plume/oss/testfixtures/PlumeDriverFixture.scala +++ b/src/test/scala/com/github/plume/oss/testfixtures/PlumeDriverFixture.scala @@ -37,7 +37,7 @@ class PlumeDriverFixture(val driver: IDriver) val adg = DiffGraph.Applier.applyDiff(diffGraph.build(), cpg.graph, undoable = false, Option(keyPool)) driver.bulkTx(adg) - val List(m: Map[String, Any]) = driver.propertyFromNodes(METHOD, NAME, ORDER) + val List(m: Map[String, Any]) = driver.propertyFromNodes(METHOD, NAME, ORDER, DYNAMIC_TYPE_HINT_FULL_NAME) m.get(NAME) shouldBe Some("foo") m.get(ORDER) shouldBe Some(1) val List(b: Map[String, Any]) = driver.propertyFromNodes(BLOCK, ORDER)