|
14 | 14 |
|
15 | 15 | package _go |
16 | 16 |
|
17 | | -import "testing" |
| 17 | +import ( |
| 18 | + "testing" |
| 19 | + |
| 20 | + "github.com/dolthub/go-mysql-server/sql" |
| 21 | +) |
18 | 22 |
|
19 | 23 | func TestIssues(t *testing.T) { |
20 | 24 | RunScripts(t, []ScriptTest{ |
@@ -51,5 +55,122 @@ func TestIssues(t *testing.T) { |
51 | 55 | }, |
52 | 56 | }, |
53 | 57 | }, |
| 58 | + { |
| 59 | + Name: "Issue #2030", |
| 60 | + SetUpScript: []string{ |
| 61 | + `CREATE TABLE sub_entities ( |
| 62 | + project_id VARCHAR(256) NOT NULL, |
| 63 | + entity_id VARCHAR(256) NOT NULL, |
| 64 | + id VARCHAR(256) NOT NULL, |
| 65 | + name VARCHAR(256) NOT NULL, |
| 66 | + PRIMARY KEY (project_id, entity_id, id) |
| 67 | +); |
| 68 | +`, |
| 69 | + ` |
| 70 | +CREATE TABLE entities ( |
| 71 | + project_id VARCHAR(256) NOT NULL, |
| 72 | + id VARCHAR(256) NOT NULL, |
| 73 | + name VARCHAR(256) NOT NULL, |
| 74 | + default_sub_entity_id VARCHAR(256), |
| 75 | + PRIMARY KEY (project_id, id) |
| 76 | +); |
| 77 | +`, |
| 78 | + ` |
| 79 | +CREATE TABLE conversations ( |
| 80 | + id VARCHAR(256) NOT NULL, |
| 81 | + tenant_id VARCHAR(256) NOT NULL, |
| 82 | + project_id VARCHAR(256) NOT NULL, |
| 83 | + active_sub_agent_id VARCHAR(256) NOT NULL, |
| 84 | + PRIMARY KEY (tenant_id, project_id, id) |
| 85 | +); |
| 86 | +`, |
| 87 | + `INSERT INTO sub_entities (project_id, entity_id, id, name) VALUES |
| 88 | + ('projectA', 'entityA', 'subA1', 'Sub-Entity A1'), |
| 89 | + ('projectA', 'entityB', 'subB1', 'Sub-Entity B1'); |
| 90 | +`, |
| 91 | + `INSERT INTO entities (project_id, id, name, default_sub_entity_id) VALUES |
| 92 | + ('projectA', 'entityA', 'Entity A', 'subA1'), |
| 93 | + ('projectA', 'entityB', 'Entity B', 'subB1'); |
| 94 | +`, |
| 95 | + `INSERT INTO conversations (tenant_id, project_id, id, active_sub_agent_id) VALUES |
| 96 | + ('tenant1', 'projectA', 'conv1', 'subA1'), |
| 97 | + ('tenant1', 'projectA', 'conv2', 'subB1'); |
| 98 | +`, |
| 99 | + }, |
| 100 | + Assertions: []ScriptTestAssertion{ |
| 101 | + { |
| 102 | + Query: `select |
| 103 | + "entities"."project_id", |
| 104 | + "entities"."id", |
| 105 | + "entities"."name", |
| 106 | + "entities"."default_sub_entity_id", |
| 107 | + "entities_defaultSubEntity"."data" as "defaultSubEntity" |
| 108 | +from "entities" "entities" |
| 109 | +left join lateral ( |
| 110 | + select json_build_array( |
| 111 | + "entities_defaultSubEntity"."project_id", |
| 112 | + "entities_defaultSubEntity"."entity_id", |
| 113 | + "entities_defaultSubEntity"."id", |
| 114 | + "entities_defaultSubEntity"."name" |
| 115 | + ) as "data" |
| 116 | + from ( |
| 117 | + select * from "sub_entities" "entities_defaultSubEntity" |
| 118 | + where "entities_defaultSubEntity"."id" = "entities"."default_sub_entity_id" |
| 119 | + limit $1 |
| 120 | + ) "entities_defaultSubEntity" |
| 121 | +) "entities_defaultSubEntity" on true |
| 122 | +where ("entities"."project_id" = $2 and "entities"."id" = $3) |
| 123 | +limit $4`, |
| 124 | + BindVars: []any{ |
| 125 | + int64(1), |
| 126 | + "projectA", |
| 127 | + "entityA", |
| 128 | + int64(1), |
| 129 | + }, |
| 130 | + Expected: []sql.Row{ |
| 131 | + { |
| 132 | + "projectA", |
| 133 | + "entityA", |
| 134 | + "Entity A", |
| 135 | + "subA1", |
| 136 | + `["projectA", "entityA", "subA1", "Sub-Entity A1"]`, |
| 137 | + }, |
| 138 | + }, |
| 139 | + }, |
| 140 | + { |
| 141 | + Query: `select |
| 142 | + "entities"."project_id", |
| 143 | + "entities"."id", |
| 144 | + "entities"."name", |
| 145 | + "entities"."default_sub_entity_id", |
| 146 | + "entities_defaultSubEntity"."data" as "defaultSubEntity" |
| 147 | +from "entities" "entities" |
| 148 | +left join lateral ( |
| 149 | + select json_build_array( |
| 150 | + "entities_defaultSubEntity"."project_id", |
| 151 | + "entities_defaultSubEntity"."entity_id", |
| 152 | + "entities_defaultSubEntity"."id", |
| 153 | + "entities_defaultSubEntity"."name" |
| 154 | + ) as "data" |
| 155 | + from ( |
| 156 | + select * from "sub_entities" "entities_defaultSubEntity" |
| 157 | + where "entities_defaultSubEntity"."id" = "entities"."default_sub_entity_id" |
| 158 | + limit 1 |
| 159 | + ) "entities_defaultSubEntity" |
| 160 | +) "entities_defaultSubEntity" on true |
| 161 | +where ("entities"."project_id" = 'projectA' and "entities"."id" = 'entityA') |
| 162 | +limit 1`, |
| 163 | + Expected: []sql.Row{ |
| 164 | + { |
| 165 | + "projectA", |
| 166 | + "entityA", |
| 167 | + "Entity A", |
| 168 | + "subA1", |
| 169 | + `["projectA", "entityA", "subA1", "Sub-Entity A1"]`, |
| 170 | + }, |
| 171 | + }, |
| 172 | + }, |
| 173 | + }, |
| 174 | + }, |
54 | 175 | }) |
55 | 176 | } |
0 commit comments