Skip to content

Commit

Permalink
fix(interactive): fix query cardinality of non-exist types or patterns (
Browse files Browse the repository at this point in the history
  • Loading branch information
BingqingLyu authored Aug 13, 2024
1 parent f4b3f87 commit 94c7964
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ public Double getCardinality(Pattern queryPattern) {
return this.patternCardinality.get(pattern);
}
}
return 0.0;
// if not exist, return 1.0
return 1.0;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

import org.jgrapht.Graph;
import org.jgrapht.graph.DirectedPseudograph;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.List;
Expand All @@ -30,6 +32,7 @@ public class GlogueSchema {
private Graph<Integer, EdgeTypeId> schemaGraph;
private HashMap<Integer, Double> vertexTypeCardinality;
private HashMap<EdgeTypeId, Double> edgeTypeCardinality;
private static Logger logger = LoggerFactory.getLogger(GlogueSchema.class);

public GlogueSchema(
GraphSchema graphSchema,
Expand Down Expand Up @@ -69,6 +72,7 @@ public GlogueSchema(GraphSchema graphSchema) {
edgeTypeCardinality.put(edgeType, 1.0);
}
}
logger.debug("GlogueSchema created with default cardinality 1.0: {}", this);
}

public GlogueSchema(GraphSchema graphSchema, GraphStatistics statistics) {
Expand Down Expand Up @@ -108,6 +112,7 @@ public GlogueSchema(GraphSchema graphSchema, GraphStatistics statistics) {
}
}
}
logger.debug("GlogueSchema created with statistics: {}", this);
}

public static GlogueSchema fromMeta(IrMetaStats irMeta) {
Expand Down Expand Up @@ -139,7 +144,9 @@ public List<EdgeTypeId> getEdgeTypes(Integer source, Integer target) {
public Double getVertexTypeCardinality(Integer vertexType) {
Double cardinality = this.vertexTypeCardinality.get(vertexType);
if (cardinality == null) {
return 0.0;
logger.debug(
"Vertex type {} not found in schema, assuming cardinality 1.0", vertexType);
return 1.0;
} else {
return cardinality;
}
Expand All @@ -148,7 +155,8 @@ public Double getVertexTypeCardinality(Integer vertexType) {
public Double getEdgeTypeCardinality(EdgeTypeId edgeType) {
Double cardinality = this.edgeTypeCardinality.get(edgeType);
if (cardinality == null) {
return 0.0;
logger.debug("Edge type {} not found in schema, assuming cardinality 1.0", edgeType);
return 1.0;
} else {
return cardinality;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ public void glogue_schema_test() {
// test get type cardinality
Assert.assertEquals(4.0, g.getVertexTypeCardinality(person), delta);
Assert.assertEquals(2.0, g.getVertexTypeCardinality(software), delta);
Assert.assertEquals(0.0, g.getVertexTypeCardinality(2), delta);
Assert.assertEquals(2.0, g.getEdgeTypeCardinality(knows), delta);
Assert.assertEquals(4.0, g.getEdgeTypeCardinality(creates), delta);
Assert.assertEquals(0.0, g.getEdgeTypeCardinality(new EdgeTypeId(0, 0, 2)), delta);

// when query a type that is not in the schema, return 1.0
Assert.assertEquals(1.0, g.getVertexTypeCardinality(2), delta);
Assert.assertEquals(1.0, g.getEdgeTypeCardinality(new EdgeTypeId(0, 0, 2)), delta);

// test get types
Assert.assertEquals(2, g.getAdjEdgeTypes(person).size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public void glogue_get_row_count_test() {
Assert.assertEquals(1.0d, count2, delta);

// pattern3: person2 <- person1 <- software (not exist)
// Note the non-exist pattern will return a cardinality of 1.0
Pattern pattern3 = new Pattern();
pattern3.addVertex(v0);
pattern3.addVertex(v1);
Expand All @@ -86,7 +87,7 @@ public void glogue_get_row_count_test() {
pattern3.reordering();

Double count3 = gl.getRowCount(pattern3);
Assert.assertEquals(0.0d, count3, delta);
Assert.assertEquals(1.0d, count3, delta);
}

@Test
Expand Down

0 comments on commit 94c7964

Please sign in to comment.