Skip to content

Commit 6997dff

Browse files
authored
Merge pull request #255 from cipherstash/unmappable-statement-no-matches-for-identifier
test: additional "real-world" statement tests
2 parents dfd8752 + 859c206 commit 6997dff

File tree

1 file changed

+109
-0
lines changed

1 file changed

+109
-0
lines changed

packages/eql-mapper/src/lib.rs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,4 +1602,113 @@ mod test {
16021602
Err(err) => panic!("type check failed: {err}"),
16031603
}
16041604
}
1605+
1606+
#[test]
1607+
fn select_with_multiple_joins() {
1608+
// init_tracing();
1609+
let schema = resolver(schema! {
1610+
tables: {
1611+
workspace: {
1612+
id,
1613+
resource_id,
1614+
}
1615+
workspace_entity: {
1616+
id,
1617+
workspace_id,
1618+
entity_id,
1619+
}
1620+
entity: {
1621+
id,
1622+
resource_id,
1623+
deleted_at,
1624+
}
1625+
}
1626+
});
1627+
1628+
let statement = parse(
1629+
r#"
1630+
SELECT
1631+
ARRAY_REMOVE(
1632+
ARRAY_AGG(e.resource_id), NULL
1633+
)::text [] AS entity_resource_ids,
1634+
workspace.*
1635+
FROM workspace
1636+
LEFT JOIN workspace_entity AS we ON workspace.id = we.workspace_id
1637+
LEFT JOIN entity AS e ON we.entity_id = e.id
1638+
WHERE
1639+
workspace.resource_id = $1
1640+
AND e.deleted_at IS NULL
1641+
GROUP BY workspace.id;
1642+
"#,
1643+
);
1644+
1645+
match type_check(schema.clone(), &statement) {
1646+
Ok(typed) => {
1647+
assert_eq!(
1648+
typed.projection,
1649+
projection![
1650+
(NATIVE as entity_resource_ids),
1651+
(NATIVE(workspace.id) as id),
1652+
(NATIVE(workspace.resource_id) as resource_id)
1653+
]
1654+
)
1655+
}
1656+
Err(err) => panic!("type check failed: {err}"),
1657+
}
1658+
1659+
let statement = parse(
1660+
r#"
1661+
SELECT
1662+
ARRAY_REMOVE(
1663+
ARRAY_AGG(e.resource_id), NULL
1664+
)::text [] AS entity_resource_ids,
1665+
workspace.id,
1666+
workspace.resource_id
1667+
FROM workspace
1668+
LEFT JOIN workspace_entity AS we ON workspace.id = we.workspace_id
1669+
LEFT JOIN entity AS e ON we.entity_id = e.id
1670+
WHERE
1671+
workspace.id < $1
1672+
AND (
1673+
CARDINALITY($2::text []) = 0
1674+
OR e.resource_id = ANY($3::text [])
1675+
)
1676+
GROUP BY workspace.id
1677+
ORDER BY workspace.id DESC
1678+
LIMIT
1679+
$4
1680+
OFFSET $5;
1681+
"#,
1682+
);
1683+
1684+
match type_check(schema.clone(), &statement) {
1685+
Ok(typed) => {
1686+
assert_eq!(
1687+
typed.projection,
1688+
projection![
1689+
(NATIVE as entity_resource_ids),
1690+
(NATIVE(workspace.id) as id),
1691+
(NATIVE(workspace.resource_id) as resource_id)
1692+
]
1693+
)
1694+
}
1695+
Err(err) => panic!("type check failed: {err}"),
1696+
}
1697+
1698+
let statement = parse(
1699+
r#"
1700+
SELECT COUNT(*) FROM workspace
1701+
JOIN workspace_entity AS we ON workspace.id = we.workspace_id
1702+
JOIN entity AS e on e.id = we.entity_id
1703+
WHERE e.resource_id = ANY($1::varchar[]);
1704+
"#,
1705+
);
1706+
1707+
match type_check(schema.clone(), &statement) {
1708+
Ok(typed) => {
1709+
assert_eq!(typed.projection, projection![(NATIVE as COUNT)])
1710+
}
1711+
Err(err) => panic!("type check failed: {err}"),
1712+
}
1713+
}
16051714
}

0 commit comments

Comments
 (0)