Skip to content

Commit ef873d9

Browse files
authored
Merge pull request #915 from Mats-SX/tighten-leaks
Tighten leaks of dependencies
2 parents 27f8bbb + 5a2fa75 commit ef873d9

File tree

11 files changed

+67
-51
lines changed

11 files changed

+67
-51
lines changed

graph-ddl/src/main/scala/org/opencypher/graphddl/GraphDdl.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import org.opencypher.okapi.api.graph.GraphName
3535
import org.opencypher.okapi.api.schema.PropertyKeys
3636
import org.opencypher.okapi.api.schema.PropertyKeys.PropertyKeys
3737
import org.opencypher.okapi.api.types.CypherType
38+
import org.opencypher.okapi.api.types.CypherTypeHelp.joinMonoid
3839

3940
import scala.language.higherKinds
4041

okapi-api/src/main/scala/org/opencypher/okapi/api/schema/LabelPropertyMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import cats.instances.all._
3030
import cats.syntax.semigroup._
3131
import org.opencypher.okapi.api.schema.PropertyKeys.PropertyKeys
3232
import org.opencypher.okapi.api.types.CypherType
33-
import org.opencypher.okapi.api.types.CypherType.joinMonoid
33+
import org.opencypher.okapi.api.types.CypherTypeHelp.joinMonoid
3434

3535
object PropertyKeys {
3636
type PropertyKeys = Map[String, CypherType]

okapi-api/src/main/scala/org/opencypher/okapi/api/schema/RelTypePropertyMap.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import cats.instances.all._
3030
import cats.syntax.semigroup._
3131
import org.opencypher.okapi.api.schema.PropertyKeys.PropertyKeys
3232
import org.opencypher.okapi.api.types.CypherType
33-
import org.opencypher.okapi.api.types.CypherType.joinMonoid
33+
import org.opencypher.okapi.api.types.CypherTypeHelp.joinMonoid
3434

3535
object RelTypePropertyMap {
3636

okapi-api/src/main/scala/org/opencypher/okapi/api/types/CypherType.scala

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,8 @@
2626
*/
2727
package org.opencypher.okapi.api.types
2828

29-
import cats.Monoid
3029
import org.opencypher.okapi.api.graph.QualifiedGraphName
3130
import org.opencypher.okapi.impl.types.CypherTypeParser
32-
import upickle.default._
3331

3432
trait CypherType {
3533

@@ -174,14 +172,6 @@ object CypherType {
174172
*/
175173
def fromName(name: String): Option[CypherType] = CypherTypeParser.parseCypherType(name)
176174

177-
implicit val typeRw: ReadWriter[CypherType] = readwriter[String].bimap[CypherType](_.name, s => fromName(s).get)
178-
179-
implicit val joinMonoid: Monoid[CypherType] = new Monoid[CypherType] {
180-
override def empty: CypherType = CTVoid
181-
182-
override def combine(x: CypherType, y: CypherType): CypherType = x | y
183-
}
184-
185175
}
186176

187177
case object CTAnyMaterial extends CypherType {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.opencypher.okapi.api.types
2+
3+
import cats.Monoid
4+
import org.opencypher.okapi.api.types.CypherType.fromName
5+
import upickle.default.{readwriter, _}
6+
7+
object CypherTypeHelp {
8+
implicit val typeRw: ReadWriter[CypherType] = readwriter[String].bimap[CypherType](_.name, s => fromName(s).get)
9+
10+
implicit val joinMonoid: Monoid[CypherType] = new Monoid[CypherType] {
11+
override def empty: CypherType = CTVoid
12+
13+
override def combine(x: CypherType, y: CypherType): CypherType = x | y
14+
}
15+
}

okapi-api/src/main/scala/org/opencypher/okapi/api/util/ZeppelinSupport.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ package org.opencypher.okapi.api.util
2828

2929
import org.opencypher.okapi.api.graph.{CypherResult, PropertyGraph}
3030
import org.opencypher.okapi.api.table.CypherRecords
31-
import org.opencypher.okapi.api.value.CypherValue
31+
import org.opencypher.okapi.api.value.{CypherValue, CypherValueHelp}
3232
import org.opencypher.okapi.api.value.CypherValue.Element._
3333
import org.opencypher.okapi.api.value.CypherValue.Node._
3434
import org.opencypher.okapi.api.value.CypherValue.Relationship._
@@ -206,7 +206,7 @@ object ZeppelinSupport {
206206
* }}}
207207
*/
208208
def toZeppelinJson()(implicit formatValue: Any => String): Value = {
209-
val default = n.toJson
209+
val default = CypherValueHelp.toJson(n)
210210
Obj(
211211
idJsonKey -> default(idJsonKey),
212212
labelJsonKey -> Str(n.labels.headOption.getOrElse("")),
@@ -235,7 +235,7 @@ object ZeppelinSupport {
235235
* }}}
236236
*/
237237
def toZeppelinJson()(implicit formatValue: Any => String): Value = {
238-
val default = r.toJson
238+
val default = CypherValueHelp.toJson(r)
239239
Obj(
240240
idJsonKey -> default(idJsonKey),
241241
sourceJsonKey -> default(startIdJsonKey),

okapi-api/src/main/scala/org/opencypher/okapi/api/value/CypherValue.scala

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -234,38 +234,6 @@ object CypherValue {
234234
}
235235
}
236236

237-
def toJson()(implicit formatValue: Any => String): Value = {
238-
this match {
239-
case CypherNull => Null
240-
case CypherString(s) => Str(s)
241-
case CypherList(l) => l.map(_.toJson)
242-
case CypherMap(m) => m.mapValues(_.toJson).toSeq.sortBy(_._1)
243-
case Relationship(id, startId, endId, relType, properties) =>
244-
Obj(
245-
idJsonKey -> Str(formatValue(id)),
246-
typeJsonKey -> Str(relType),
247-
startIdJsonKey -> Str(formatValue(startId)),
248-
endIdJsonKey -> Str(formatValue(endId)),
249-
propertiesJsonKey -> properties.toJson
250-
)
251-
case Node(id, labels, properties) =>
252-
Obj(
253-
idJsonKey -> Str(formatValue(id)),
254-
labelsJsonKey -> labels.toSeq.sorted.map(Str),
255-
propertiesJsonKey -> properties.toJson
256-
)
257-
case CypherFloat(d) => Num(d)
258-
case CypherInteger(l) => Str(l.toString) // `Num` would lose precision
259-
case CypherBoolean(b) => Bool(b)
260-
case CypherBigDecimal(b) => Obj(
261-
"type" -> Str("BigDecimal"),
262-
"scale" -> Num(b.bigDecimal.scale()),
263-
"precision" -> Num(b.bigDecimal.precision())
264-
)
265-
case other => Str(formatValue(other.value))
266-
}
267-
}
268-
269237
private def escape(str: String): String = {
270238
str
271239
.replaceAllLiterally("""\""", """\\""")
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package org.opencypher.okapi.api.value
2+
3+
import org.opencypher.okapi.api.value.CypherValue.Element.{idJsonKey, propertiesJsonKey}
4+
import org.opencypher.okapi.api.value.CypherValue.Node.labelsJsonKey
5+
import org.opencypher.okapi.api.value.CypherValue.{CypherBigDecimal, CypherBoolean, CypherFloat, CypherInteger, CypherList, CypherMap, CypherNull, CypherString, CypherValue, Node, Relationship}
6+
import org.opencypher.okapi.api.value.CypherValue.Relationship.{endIdJsonKey, startIdJsonKey, typeJsonKey}
7+
import ujson.{Bool, Null, Num, Obj, Str, Value}
8+
9+
object CypherValueHelp {
10+
11+
def toJson(v: CypherValue)(implicit formatValue: Any => String): Value = {
12+
v match {
13+
case CypherNull => Null
14+
case CypherString(s) => Str(s)
15+
case CypherList(l) => l.map(toJson)
16+
case CypherMap(m) => m.mapValues(toJson).toSeq.sortBy(_._1)
17+
case Relationship(id, startId, endId, relType, properties) =>
18+
Obj(
19+
idJsonKey -> Str(formatValue(id)),
20+
typeJsonKey -> Str(relType),
21+
startIdJsonKey -> Str(formatValue(startId)),
22+
endIdJsonKey -> Str(formatValue(endId)),
23+
propertiesJsonKey -> toJson(properties)
24+
)
25+
case Node(id, labels, properties) =>
26+
Obj(
27+
idJsonKey -> Str(formatValue(id)),
28+
labelsJsonKey -> labels.toSeq.sorted.map(Str),
29+
propertiesJsonKey -> toJson(properties)
30+
)
31+
case CypherFloat(d) => Num(d)
32+
case CypherInteger(l) => Str(l.toString) // `Num` would lose precision
33+
case CypherBoolean(b) => Bool(b)
34+
case CypherBigDecimal(b) => Obj(
35+
"type" -> Str("BigDecimal"),
36+
"scale" -> Num(b.bigDecimal.scale()),
37+
"precision" -> Num(b.bigDecimal.precision())
38+
)
39+
case other => Str(formatValue(other.value))
40+
}
41+
}
42+
43+
}

okapi-api/src/main/scala/org/opencypher/okapi/impl/schema/PropertyGraphSchemaImpl.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import org.opencypher.okapi.api.schema.LabelPropertyMap._
3232
import org.opencypher.okapi.api.schema.PropertyKeys.PropertyKeys
3333
import org.opencypher.okapi.api.schema.RelTypePropertyMap._
3434
import org.opencypher.okapi.api.schema.{LabelPropertyMap, RelTypePropertyMap, _}
35-
import org.opencypher.okapi.api.types.CypherType.joinMonoid
35+
import org.opencypher.okapi.api.types.CypherTypeHelp._
3636
import org.opencypher.okapi.api.types.{CypherType, _}
3737
import org.opencypher.okapi.impl.exception.SchemaException
3838
import org.opencypher.okapi.impl.schema.PropertyGraphSchemaImpl._

okapi-api/src/test/scala/org/opencypher/okapi/api/schema/LabelPropertyMapTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import cats.instances.all._
3030
import cats.syntax.semigroup._
3131
import org.opencypher.okapi.ApiBaseTest
3232
import org.opencypher.okapi.api.schema.LabelPropertyMap._
33-
import org.opencypher.okapi.api.types.CypherType.joinMonoid
33+
import org.opencypher.okapi.api.types.CypherTypeHelp.joinMonoid
3434
import org.opencypher.okapi.api.types._
3535

3636
class LabelPropertyMapTest extends ApiBaseTest {

0 commit comments

Comments
 (0)