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

chore(core): allow to set MANY_TO_MANY relationship #827

Merged
merged 1 commit into from
Oct 16, 2024
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
16 changes: 6 additions & 10 deletions wren-base/src/main/java/io/wren/base/dto/JoinType.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import static io.wren.base.dto.JoinType.GenericJoinType.TO_MANY;
import static io.wren.base.dto.JoinType.GenericJoinType.TO_ONE;
import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

public enum JoinType
Expand All @@ -41,15 +40,12 @@ public enum GenericJoinType

public static JoinType reverse(JoinType joinType)
{
switch (joinType) {
case ONE_TO_ONE:
return ONE_TO_ONE;
case ONE_TO_MANY:
return MANY_TO_ONE;
case MANY_TO_ONE:
return ONE_TO_MANY;
}
throw new IllegalArgumentException(format("Invalid join type %s", joinType));
return switch (joinType) {
case ONE_TO_ONE -> ONE_TO_ONE;
case ONE_TO_MANY -> MANY_TO_ONE;
case MANY_TO_ONE -> ONE_TO_MANY;
case MANY_TO_MANY -> MANY_TO_MANY;
};
}

public GenericJoinType getType()
Expand Down
55 changes: 55 additions & 0 deletions wren-tests/src/test/java/io/wren/testing/TestMDLResourceV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,61 @@ LEFT JOIN (
""");
}

@Test
public void testSetManyToMany()
{
Manifest manifest = Manifest.builder()
.setCatalog("wrenai")
.setSchema("tpch")
.setModels(List.of(
model("Customer", "SELECT * FROM tpch.customer",
List.of(column("custkey", "integer", null, false, "c_custkey"),
column("name", "varchar", null, false, "c_name"))),
model("Orders", "SELECT * FROM tpch.orders",
List.of(column("orderkey", "integer", null, false, "o_orderkey"),
column("custkey", "integer", null, false, "o_custkey"),
column("customer", "Customer", "CustomerOrders", false),
caluclatedColumn("customer_name", "varchar", "customer.name")),
"orderkey")))
.setRelationships(List.of(relationship("CustomerOrders", List.of("Customer", "Orders"), JoinType.MANY_TO_MANY, "Customer.custkey = Orders.custkey")))
.build();

String manifestStr = base64Encode(toJson(manifest));
DryPlanDtoV2 dryPlanDto = new DryPlanDtoV2(manifestStr, "select orderkey from Orders limit 200");
String dryPlan = dryPlanV2(dryPlanDto);
assertThat(dryPlan).isEqualTo("""
WITH
"Orders" AS (
SELECT
"Orders"."orderkey" "orderkey"
, "Orders"."custkey" "custkey"
FROM
(
SELECT
"Orders"."orderkey" "orderkey"
, "Orders"."custkey" "custkey"
FROM
(
SELECT
o_orderkey "orderkey"
, o_custkey "custkey"
FROM
(
SELECT *
FROM
tpch.orders
) "Orders"
) "Orders"
) "Orders"
)\s
SELECT orderkey
FROM
Orders
LIMIT 200
""");

}

private String toJson(Manifest manifest)
{
return MANIFEST_JSON_CODEC.toJson(manifest);
Expand Down
Loading