Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GROUP BY with renamed table #176

Merged
merged 1 commit into from
Jul 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ protected void applyGroupBy(final GraphTraversal<?, ?> graphTraversal, final Str
graphTraversal.group();
final List<GraphTraversal> byUnion = new ArrayList<>();
for (final GremlinSqlIdentifier gremlinSqlIdentifier : gremlinSqlIdentifiers) {
final String table = sqlMetadata.getRenamedTable(gremlinSqlIdentifier.getName(0));
final String renamedTable = gremlinSqlIdentifier.getName(0);
final String table = sqlMetadata.getRenamedTable(renamedTable);
final String column = sqlMetadata
.getActualColumnName(sqlMetadata.getGremlinTable(table), gremlinSqlIdentifier.getName(1));
if (column.replace(GremlinTableBase.ID, "").equalsIgnoreCase(edgeLabel)) {
Expand All @@ -258,10 +259,10 @@ protected void applyGroupBy(final GraphTraversal<?, ?> graphTraversal, final Str
// TODO: Grouping edges that are not the edge that the vertex are connected - needs to be implemented.
throw SqlGremlinError.create(SqlGremlinError.CANNOT_GROUP_EDGES);
} else {
if (inVRename.equals(table)) {
if (inVRename.equals(renamedTable)) {
byUnion.add(__.inV().hasLabel(table)
.values(sqlMetadata.getActualColumnName(sqlMetadata.getGremlinTable(table), column)));
} else if (outVRename.equals(table)) {
} else if (outVRename.equals(renamedTable)) {
byUnion.add(__.outV().hasLabel(table)
.values(sqlMetadata.getActualColumnName(sqlMetadata.getGremlinTable(table), column)));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ void testJoinSameVertex() throws SQLException {
"GROUP BY person1.name",
columns("name"),
rows(r("Patty"), r("Juanita"), r("Susan"), r("Pavel")));

runJoinQueryTestResults("SELECT p.name FROM gremlin.person p " +
"INNER JOIN gremlin.person p1 ON (p.friendsWith_OUT_ID = p1.friendsWith_IN_ID) " +
"GROUP BY p.name",
columns("name"),
rows(r("Tom"), r("Patty"), r("Phil"), r("Susan")));

runJoinQueryTestResults("SELECT p.name, COUNT(p1.name) FROM gremlin.person p " +
"INNER JOIN gremlin.person p1 ON (p.friendsWith_OUT_ID = p1.friendsWith_IN_ID) " +
"GROUP BY p.name",
columns("name", "COUNT(name)"),
rows(r("Tom", 1L), r("Patty", 1L), r("Phil", 1L), r("Susan", 1L)));
}

@Test
Expand Down