Skip to content

Commit

Permalink
Merge pull request #81 from kazumatsudo/feature/divide_table_by_label
Browse files Browse the repository at this point in the history
divide table by label
  • Loading branch information
kazumatsudo committed Jan 18, 2024
2 parents d567894 + 2e877c0 commit 6d4c3f1
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 139 deletions.
2 changes: 0 additions & 2 deletions src/main/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,5 @@ column_name_edge_out_v_id="id_out_v"
column_name_edge_out_v_id=${?COLUMN_NAME_EDGE_OUT_V_ID}
column_name_vertex_id="id"
column_name_vertex_id=${?COLUMN_NAME_VERTEX_ID}
column_name_prefix_label="label_"
column_name_prefix_label=${?COLUMN_NAME_PREFIX_LABEL}
column_name_prefix_property="property_"
column_name_prefix_property=${?COLUMN_NAME_PREFIX_PROPERTY}
20 changes: 6 additions & 14 deletions src/main/scala/domain/graph/GraphEdge.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ case class GraphEdge(private val value: Edge) {

private val config = ConfigFactory.load()

// TODO: Set a more detailed table name
private val tableName = TableName(config.getString("table_name_edge"))
private val tableName = TableName(
s"${config.getString("table_name_edge")}_${value.label()}"
)
private val columnNamePrefixProperty =
config.getString("column_name_prefix_property")
private val columnNamePrefixLabel =
config.getString("column_name_prefix_label")

private val id = value.id()

Expand Down Expand Up @@ -54,15 +53,10 @@ case class GraphEdge(private val value: Edge) {
)
}
.toMap
val labelColumn = Map(
ColumnName(
s"$columnNamePrefixLabel${value.label()}"
) -> ColumnType.apply(true)
)

Map(
tableName -> ColumnList(
idColumn ++ inVColumn ++ outVColumn ++ propertyColumn ++ labelColumn
idColumn ++ inVColumn ++ outVColumn ++ propertyColumn
)
)
}
Expand All @@ -77,8 +71,6 @@ case class GraphEdge(private val value: Edge) {
}
.toMap

val labelColumn = s"$columnNamePrefixLabel${value.label()}"

val recordValue = Map(
(config.getString("column_name_edge_id"), value.id())
) ++ Map(
Expand All @@ -88,10 +80,10 @@ case class GraphEdge(private val value: Edge) {
config.getString("column_name_edge_out_v_id"),
value.outVertex().id()
)
) ++ propertyColumnList ++ Map((labelColumn, true))
) ++ propertyColumnList

RecordList(
Map((RecordKey(tableName, RecordId(id)), RecordValue(recordValue)))
Map(RecordKey(tableName, RecordId(id)) -> RecordValue(recordValue))
)
}
}
23 changes: 7 additions & 16 deletions src/main/scala/domain/graph/GraphVertex.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ case class GraphVertex(private val value: Vertex) {

private val config = ConfigFactory.load()

// TODO: Set a more detailed table name
private val tableName = TableName(config.getString("table_name_vertex"))
private val tableName = TableName(
s"${config.getString("table_name_vertex")}_${value.label()}"
)
private val columnNamePrefixProperty =
config.getString("column_name_prefix_property")
private val columnNamePrefixLabel =
config.getString("column_name_prefix_label")

val id: AnyRef = value.id()

Expand All @@ -35,27 +34,19 @@ case class GraphVertex(private val value: Vertex) {
value
)
}
val labelColumn = Map(
ColumnName(
s"$columnNamePrefixLabel${value.label()}"
) -> ColumnType.apply(true)
)

Map(tableName -> ColumnList(idColumn ++ propertyColumn ++ labelColumn))
Map(tableName -> ColumnList(idColumn ++ propertyColumn))
}

def toDml: RecordList = {
val propertyColumnList = value.valueMap.map { case (columnName, value) =>
(s"$columnNamePrefixProperty$columnName", value)
}
val labelColumn = s"$columnNamePrefixLabel${value.label()}"

val recordValue = Map(
(config.getString("column_name_vertex_id"), id)
) ++ propertyColumnList ++ Map((labelColumn, true))
val recordValue =
Map((config.getString("column_name_vertex_id"), id)) ++ propertyColumnList

RecordList(
Map((RecordKey(tableName, RecordId(id)), RecordValue(recordValue)))
Map(RecordKey(tableName, RecordId(id)) -> RecordValue(recordValue))
)
}
}
19 changes: 5 additions & 14 deletions src/test/scala/domain/graph/GraphEdgeSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@ class GraphEdgeSpec extends AnyFunSpec with Matchers {

edge.toDdl shouldBe TableList(
Map(
TableName("edge") -> ColumnList(
TableName("edge_knows") -> ColumnList(
Map(
ColumnName("id") -> ColumnTypeInt(ColumnLength(1)),
ColumnName("id_in_v") -> ColumnTypeInt(ColumnLength(1)),
ColumnName("id_out_v") -> ColumnTypeInt(ColumnLength(1)),
ColumnName("property_weight") -> ColumnTypeDouble(
ColumnLength(3)
),
ColumnName("label_knows") -> ColumnTypeBoolean
ColumnName("property_weight") -> ColumnTypeDouble(ColumnLength(3))
)
)
)
Expand All @@ -49,12 +46,11 @@ class GraphEdgeSpec extends AnyFunSpec with Matchers {

edge.toDml shouldBe RecordList(
Map(
RecordKey((TableName("edge"), RecordId(7))) -> RecordValue(
RecordKey((TableName("edge_knows"), RecordId(7))) -> RecordValue(
Map(
"id" -> 7,
"id_in_v" -> 2,
"id_out_v" -> 1,
"label_knows" -> true,
"property_weight" -> 0.5
)
)
Expand All @@ -71,13 +67,8 @@ class GraphEdgeSpec extends AnyFunSpec with Matchers {
val graphEdge = GraphEdge(edge)
graphEdge.toDml shouldBe RecordList(
Map(
RecordKey((TableName("edge"), RecordId(14))) -> RecordValue(
Map(
"id" -> 14,
"id_in_v" -> 13,
"id_out_v" -> 0,
"label_testEdge" -> true
)
RecordKey((TableName("edge_testEdge"), RecordId(14))) -> RecordValue(
Map("id" -> 14, "id_in_v" -> 13, "id_out_v" -> 0)
)
)
)
Expand Down
14 changes: 6 additions & 8 deletions src/test/scala/domain/graph/GraphVertexSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ class GraphVertexSpec extends AnyFunSpec with Matchers {

vertex.toDdl shouldBe TableList(
Map(
TableName("vertex") -> ColumnList(
TableName("vertex_person") -> ColumnList(
Map(
ColumnName("id") -> ColumnTypeInt(ColumnLength(1)),
ColumnName("property_name") -> ColumnTypeString(ColumnLength(5)),
ColumnName("property_age") -> ColumnTypeInt(ColumnLength(2)),
ColumnName("label_person") -> ColumnTypeBoolean
ColumnName("property_name") -> ColumnTypeString(ColumnLength(5))
)
)
)
Expand All @@ -45,12 +44,11 @@ class GraphVertexSpec extends AnyFunSpec with Matchers {

vertex.toDml shouldBe RecordList(
Map(
RecordKey((TableName("vertex"), RecordId(1))) -> RecordValue(
RecordKey((TableName("vertex_person"), RecordId(1))) -> RecordValue(
Map(
"id" -> 1,
"property_name" -> "marko",
"property_age" -> 29,
"label_person" -> true
"property_age" -> 29
)
)
)
Expand All @@ -65,9 +63,9 @@ class GraphVertexSpec extends AnyFunSpec with Matchers {
graphVertex.toDml shouldBe RecordList(
Map(
RecordKey(
(TableName("vertex"), RecordId(vertex1.id()))
(TableName("vertex_testVertex1"), RecordId(vertex1.id()))
) -> RecordValue(
Map(("id" -> 0), "label_testVertex1" -> true)
Map("id" -> 0)
)
)
)
Expand Down
16 changes: 11 additions & 5 deletions src/test/scala/domain/table/ddl/TableListSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ class TableListSpec extends AnyFunSpec with Matchers {

result shouldBe TableList(
Map(
TableName("vertex") -> ColumnList(
TableName("vertex_person") -> ColumnList(
Map(
ColumnName("id") -> ColumnTypeInt(ColumnLength(1)),
ColumnName("property_age") -> ColumnTypeInt(ColumnLength(2)),
ColumnName("property_name") -> ColumnTypeString(ColumnLength(5))
)
),
TableName("vertex_software") -> ColumnList(
Map(
ColumnName("id") -> ColumnTypeInt(ColumnLength(1)),
ColumnName("property_lang") -> ColumnTypeString(ColumnLength(4)),
ColumnName("property_name") -> ColumnTypeString(ColumnLength(6)),
ColumnName("label_person") -> ColumnTypeBoolean,
ColumnName("label_software") -> ColumnTypeBoolean
ColumnName("property_name") -> ColumnTypeString(ColumnLength(6))
)
)
)
Expand All @@ -50,7 +54,9 @@ class TableListSpec extends AnyFunSpec with Matchers {
accumulator.merge(currentValue)
}

vertexAnalyzedResult.toSqlSentence shouldBe "CREATE TABLE IF NOT EXISTS vertex (id INT(1), label_person BOOLEAN, label_software BOOLEAN, property_age INT(2), property_lang VARCHAR(4), property_name VARCHAR(6));"
vertexAnalyzedResult.toSqlSentence shouldBe
"""CREATE TABLE IF NOT EXISTS vertex_person (id INT(1), property_age INT(2), property_name VARCHAR(5));
|CREATE TABLE IF NOT EXISTS vertex_software (id INT(1), property_lang VARCHAR(4), property_name VARCHAR(6));""".stripMargin
}
}
}
12 changes: 6 additions & 6 deletions src/test/scala/domain/table/dml/RecordListSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ class RecordListSpec extends AnyFunSpec with Matchers {
}

vertexAnalyzedResult.toSqlSentence shouldBe
"""INSERT INTO vertex (id, label_software, property_lang, property_name) VALUES (5, true, "java", "ripple");
|INSERT INTO vertex (id, label_person, property_age, property_name) VALUES (6, true, 35, "peter");
|INSERT INTO vertex (id, label_person, property_age, property_name) VALUES (4, true, 32, "josh");
|INSERT INTO vertex (id, label_person, property_age, property_name) VALUES (2, true, 27, "vadas");
|INSERT INTO vertex (id, label_person, property_age, property_name) VALUES (1, true, 29, "marko");
|INSERT INTO vertex (id, label_software, property_lang, property_name) VALUES (3, true, "java", "lop");""".stripMargin
"""INSERT INTO vertex_software (id, property_lang, property_name) VALUES (5, "java", "ripple");
|INSERT INTO vertex_person (id, property_age, property_name) VALUES (1, 29, "marko");
|INSERT INTO vertex_software (id, property_lang, property_name) VALUES (3, "java", "lop");
|INSERT INTO vertex_person (id, property_age, property_name) VALUES (2, 27, "vadas");
|INSERT INTO vertex_person (id, property_age, property_name) VALUES (6, 35, "peter");
|INSERT INTO vertex_person (id, property_age, property_name) VALUES (4, 32, "josh");""".stripMargin

}
}
Expand Down

0 comments on commit 6d4c3f1

Please sign in to comment.