Skip to content

Commit

Permalink
[#18] EdgeWriter refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
alberskib committed Aug 10, 2014
1 parent c7d7837 commit 48d2904
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
4 changes: 4 additions & 0 deletions src/main/scala/com/bio4j/dynamograph/AnyEdgeTypeWithId.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ trait AnyEdgeTypeWithId extends AnySealedEdgeType {
val idLookup: Lookup[record.Raw, relationId.Rep]
val sourceLookup: Lookup[record.Raw, SourceId#Rep]
val targetLookup: Lookup[record.Raw, TargetId#Rep]
type SourceType <: AnyVertexTypeWithId
type TargetType <: AnyVertexTypeWithId
}

abstract class EdgeTypeWithId[
Expand All @@ -40,4 +42,6 @@ abstract class EdgeTypeWithId[
val targetLookup: Lookup[R#Raw, targetId.Rep]
)extends AnyEdgeTypeWithId with From[S] with To[T] {
type Record = R
type SourceType = S
type TargetType = T
}
18 changes: 12 additions & 6 deletions src/main/scala/com/bio4j/dynamograph/model/edgeTables.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ trait AnyEdgeTables { edgeTables =>
}
val edgeType: EdgeType

type InVertexId = edgeTables.edgeType.targetType.Id
val inVertexId: InVertexId = edgeTables.edgeType.targetType.id
type OutVertexId = edgeTables.edgeType.sourceType.Id
val outVertexId: OutVertexId = edgeTables.edgeType.sourceType.id


type EdgeId = edgeType.Id
val edgeId: EdgeId = edgeType.id
type ContaintEdgeId = EdgeId EdgeRecord#Properties
Expand All @@ -43,12 +49,12 @@ trait AnyEdgeTables { edgeTables =>
val region: Region

type OutTable <: Singleton with AnyTable.inRegion[edgeTables.Region] with
AnyCompositeKeyTable.withHashKey[edgeTables.EdgeType#SourceType#Id] with
AnyCompositeKeyTable.withHashKey[OutVertexId] with
AnyCompositeKeyTable.withRangeKey[edgeTables.EdgeId]
val outTable: OutTable

type OutRecord = OutRecord.type; val outRecord = OutRecord
case object OutRecord extends Record(edgeType.sourceType.id :~: edgeId :~: )
case object OutRecord extends Record(outVertexId :~: edgeId :~: )
type OutItem <: Singleton with AnyItem with
AnyItem.ofTable[edgeTables.OutTable] with
AnyItem.withRecord[edgeTables.OutRecord]
Expand All @@ -66,12 +72,12 @@ trait AnyEdgeTables { edgeTables =>
val edgeItem : EdgeItem

type InTable <: Singleton with AnyTable.inRegion[edgeTables.Region] with
AnyCompositeKeyTable.withHashKey[edgeType.targetType.Id] with
AnyCompositeKeyTable.withHashKey[edgeTables.InVertexId] with
AnyCompositeKeyTable.withRangeKey[edgeTables.EdgeId]
val inTable: InTable

type InRecord = InRecord.type; val inRecord = InRecord
case object InRecord extends Record(edgeType.targetType.id :~: edgeId :~: )
case object InRecord extends Record(inVertexId :~: edgeId :~: )
type InItem <: Singleton with AnyItem with
AnyItem.ofTable[edgeTables.InTable] with
AnyItem.withRecord[edgeTables.InRecord]
Expand Down Expand Up @@ -111,7 +117,7 @@ extends AnyEdgeTables {
val targetIdLookup = edgeType.targetLookup

type OutTable = OutTable.type; val outTable = OutTable
case object OutTable extends CompositeKeyTable(s"${tableName}_OUT", edgeType.sourceType.id, edgeId, region)
case object OutTable extends CompositeKeyTable(s"${tableName}_OUT", outVertexId, edgeId, region)
type OutItem = OutItem.type; val outItem = OutItem
case object OutItem extends Item(outTable, outRecord)

Expand All @@ -123,7 +129,7 @@ extends AnyEdgeTables {
case object EdgeItem extends Item(edgeTable, edgeRecord)

type InTable = InTable.type; val inTable = InTable
case object InTable extends CompositeKeyTable(s"{tableName}_IN", edgeType.targetType.id, edgeId, region)
case object InTable extends CompositeKeyTable(s"{tableName}_IN", inVertexId, edgeId, region)
type InItem = InItem.type; val inItem = InItem
case object InItem extends Item(inTable, inRecord)

Expand Down
30 changes: 18 additions & 12 deletions src/main/scala/com/bio4j/dynamograph/writer/EdgeWriter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@ trait AnyEdgeWriter { edgeWriter =>

type EdgeTables <: Singleton with AnyEdgeTables
val edgeTables: EdgeTables


type EdgeType = edgeTables.EdgeType
val edgeType : EdgeType = edgeTables.edgeType
//
type InVertexId = edgeTables.InVertexId
val inVertexId: InVertexId = edgeTables.inVertexId
type OutVertexId = edgeTables.OutVertexId
val outVertexId: OutVertexId= edgeTables.outVertexId

type EdgeTable = edgeTables.EdgeTable
val edgeTable: EdgeTable = edgeTables.edgeTable
Expand All @@ -37,7 +44,7 @@ trait AnyEdgeWriter { edgeWriter =>
type InItem = edgeTables.InItem
val inItem: InItem = edgeTables.inItem
type InRecord = edgeTables.InRecord
val inRecord: InRecord = edgeTables.inRecord
val inRecord : InRecord= edgeTables.inRecord

type EdgeId = edgeTables.EdgeId
val edgeId : EdgeId = edgeTables.edgeId
Expand All @@ -46,9 +53,7 @@ trait AnyEdgeWriter { edgeWriter =>
type TargetId = edgeTables.TargetId
val tgtId : TargetId = edgeTables.tgtId

type InVertexId = edgeType.targetType.Id
val inVertexId : InVertexId = edgeType.targetType.id


implicit val containId : EdgeId EdgeRecord#Properties = edgeTables.containEdgeId
implicit val edgeIdLookup : Lookup[EdgeRecord#Raw, edgeId.Rep] = edgeTables.edgeIdLookup

Expand All @@ -61,31 +66,32 @@ trait AnyEdgeWriter { edgeWriter =>


def write(edgeItemValue: TaggedWith[EdgeRecord])(implicit transf: From.Item[EdgeItem, SDKRep]): List[AnyPutItemAction] = {
val inRep = inItem ->> (
inRecord ->> (
val inRep = edgeTables.inItem ->> (
inRecord ->> (
(inVertexId ->> edgeItemValue.get(srcId)) :~:

This comment has been minimized.

Copy link
@alberskib

alberskib Aug 10, 2014

Author Contributor

Hey @eparejatobes Could you take a look why there are problem with types? I try different ways but none of them works correctly. I will appreciate tip how to solve it. (I remove SourceVertexTable and TargetVertexTable as we no longer need this because of AnyVertexTypeWithId).

This comment has been minimized.

Copy link
@eparejatobes

eparejatobes Aug 10, 2014

Member

I was having lunch :) I took a look at it, and you have too many ids :) Things would be much simpler if you would just use the ids from the src/tgt vertex types, and type projections instead of x.y.z

This comment has been minimized.

Copy link
@alberskib

alberskib Aug 10, 2014

Author Contributor

I have next question - do we need to support extra attributes for edges: in other words not only attributes for conectivty with vertices but also attributes describing relation

This comment has been minimized.

Copy link
@eparejatobes

eparejatobes Aug 10, 2014

Member

yes, it is not needed for GO but it is certainly a need in the general case

This comment has been minimized.

Copy link
@eparejatobes

eparejatobes Aug 10, 2014

Member

Hey @alberskib I created a branch out of this with how I think you could do this, together with some short instructions spread across the code. see #49

This comment has been minimized.

Copy link
@alberskib

alberskib Aug 10, 2014

Author Contributor

Ok. Thanks

(edgeId ->> edgeItemValue.get(edgeId)) :~:
)
)

val outRep = outItem fields (
(outTable.hashKey is edgeItemValue.get(tgtId)) :~:
(outTable.rangeKey is edgeItemValue.get(edgeTables.edgeId)) :~:
val outRep = edgeTables.outItem fields (
edgeTables.outRecord ->> (
(outVertexId is edgeItemValue.get(tgtId)) :~:
(edgeId is edgeItemValue.get(edgeTables.edgeId)) :~:
)
)

val inTableRequest = InCompositeKeyTable(inTable, Active(inTable, ServiceProvider.service.account,
ThroughputStatus(1,1))) putItem inItem withValue inRep
val outTableRequest = InCompositeKeyTable(outTable, Active(outTable, ServiceProvider.service.account,
ThroughputStatus(1,1))) putItem outItem withValue outItem ->> outRep.fields
ThroughputStatus(1,1))) putItem outItem withValue outRep
val tableRequest = InHashKeyTable(edgeTable, Active(edgeTable, ServiceProvider.service.account,
ThroughputStatus(1,1))) putItem edgeItem withValue (edgeItem ->> edgeItemValue)

List(inTableRequest, outTableRequest, tableRequest)
}
}

class EdgeWriter[ET <: AnyEdgeTables](val edgeTables: ET) extends AnyEdgeWriter {
class EdgeWriter[ET <: Singleton with AnyEdgeTables](val edgeTables: ET) extends AnyEdgeWriter {

type EdgeTables = ET

Expand Down

0 comments on commit 48d2904

Please sign in to comment.