|
175 | 175 | :venues (dissoc (venues-price-mbql-gtap-def) :query)}
|
176 | 176 | :attributes {"user" 5, "price" 1}}
|
177 | 177 | (testing "Should add a filter for attributes-only GTAP"
|
178 |
| - (is (= (mt/query checkins |
179 |
| - {:type :query |
180 |
| - :query {:source-query {:source-table $$checkins |
181 |
| - :fields [$id !default.$date $user_id $venue_id] |
182 |
| - :filter [:and |
183 |
| - [:>= !default.date [:absolute-datetime #t "2014-01-02T00:00Z[UTC]" :default]] |
184 |
| - [:= |
185 |
| - $user_id |
186 |
| - [:value 5 {:base_type :type/Integer |
187 |
| - :effective_type :type/Integer |
188 |
| - :coercion_strategy nil |
189 |
| - :semantic_type :type/FK |
190 |
| - :database_type "INTEGER" |
191 |
| - :name "USER_ID"}]]] |
192 |
| - ::row-level-restrictions/gtap? true} |
193 |
| - :joins [{:source-query |
194 |
| - {:source-table $$venues |
195 |
| - :fields [$venues.id $venues.name $venues.category_id |
196 |
| - $venues.latitude $venues.longitude $venues.price] |
197 |
| - :filter [:= |
198 |
| - $venues.price |
199 |
| - [:value 1 {:base_type :type/Integer |
| 178 | + (is (=? (mt/query checkins |
| 179 | + {:type :query |
| 180 | + :query {:source-query {:source-table $$checkins |
| 181 | + :fields [$id !default.$date $user_id $venue_id] |
| 182 | + :filter [:and |
| 183 | + [:>= !default.date [:absolute-datetime #t "2014-01-02T00:00Z[UTC]" :default]] |
| 184 | + [:= |
| 185 | + $user_id |
| 186 | + [:value 5 {:base_type :type/Integer |
200 | 187 | :effective_type :type/Integer
|
201 | 188 | :coercion_strategy nil
|
202 |
| - :semantic_type :type/Category |
| 189 | + :semantic_type :type/FK |
203 | 190 | :database_type "INTEGER"
|
204 |
| - :name "PRICE"}]] |
205 |
| - ::row-level-restrictions/gtap? true} |
206 |
| - :alias "v" |
207 |
| - :strategy :left-join |
208 |
| - :condition [:= $venue_id &v.venues.id]}] |
209 |
| - :aggregation [[:count]]} |
210 |
| - |
211 |
| - ::row-level-restrictions/original-metadata [{:base_type :type/Integer |
212 |
| - :semantic_type :type/Quantity |
213 |
| - :name "count" |
214 |
| - :display_name "Count" |
215 |
| - :source :aggregation |
216 |
| - :field_ref [:aggregation 0]}] |
217 |
| - ::qp.perms/perms {:gtaps #{(perms/table-query-path (mt/id :checkins)) |
218 |
| - (perms/table-query-path (mt/id :venues))}}}) |
219 |
| - (apply-row-level-permissions |
220 |
| - (mt/mbql-query checkins |
221 |
| - {:aggregation [[:count]] |
222 |
| - :joins [{:source-table $$venues |
223 |
| - :alias "v" |
224 |
| - :strategy :left-join |
225 |
| - :condition [:= $venue_id &v.venues.id]}]})))))))) |
226 |
| - |
227 |
| -(deftest middleware-native-quest-test |
| 191 | + :name "USER_ID"}]]] |
| 192 | + ::row-level-restrictions/gtap? true} |
| 193 | + :joins [{:source-query |
| 194 | + {:source-table $$venues |
| 195 | + :fields [$venues.id $venues.name $venues.category_id |
| 196 | + $venues.latitude $venues.longitude $venues.price] |
| 197 | + :filter [:= |
| 198 | + $venues.price |
| 199 | + [:value 1 {:base_type :type/Integer |
| 200 | + :effective_type :type/Integer |
| 201 | + :coercion_strategy nil |
| 202 | + :semantic_type :type/Category |
| 203 | + :database_type "INTEGER" |
| 204 | + :name "PRICE"}]] |
| 205 | + ::row-level-restrictions/gtap? true} |
| 206 | + :alias "v" |
| 207 | + :strategy :left-join |
| 208 | + :condition [:= $venue_id &v.venues.id]}] |
| 209 | + :aggregation [[:count]]} |
| 210 | + |
| 211 | + ::row-level-restrictions/original-metadata [{:base_type :type/Integer |
| 212 | + :semantic_type :type/Quantity |
| 213 | + :name "count" |
| 214 | + :display_name "Count" |
| 215 | + :source :aggregation |
| 216 | + :field_ref [:aggregation 0]}] |
| 217 | + ::qp.perms/perms {:gtaps #{(perms/table-query-path (mt/id :checkins)) |
| 218 | + (perms/table-query-path (mt/id :venues))}}}) |
| 219 | + (apply-row-level-permissions |
| 220 | + (mt/mbql-query checkins |
| 221 | + {:aggregation [[:count]] |
| 222 | + :joins [{:source-table $$venues |
| 223 | + :alias "v" |
| 224 | + :strategy :left-join |
| 225 | + :condition [:= $venue_id &v.venues.id]}]})))))))) |
| 226 | + |
| 227 | +(deftest middleware-native-query-test |
228 | 228 | (testing "Make sure the middleware does the correct transformation given the GTAPs we have"
|
229 | 229 | (testing "Should substitute appropriate value in native query"
|
230 | 230 | (met/with-gtaps {:gtaps {:venues (venues-category-native-gtap-def)}
|
231 | 231 | :attributes {"cat" 50}}
|
232 |
| - (is (= (mt/query nil |
233 |
| - {:database (mt/id) |
234 |
| - :type :query |
235 |
| - :query {:aggregation [[:count]] |
236 |
| - :source-query {:native (str "SELECT * FROM \"PUBLIC\".\"VENUES\" " |
237 |
| - "WHERE \"PUBLIC\".\"VENUES\".\"CATEGORY_ID\" = 50 " |
238 |
| - "ORDER BY \"PUBLIC\".\"VENUES\".\"ID\" ASC") |
239 |
| - :params []}} |
240 |
| - |
241 |
| - ::row-level-restrictions/original-metadata [{:base_type :type/Integer |
242 |
| - :semantic_type :type/Quantity |
243 |
| - :name "count" |
244 |
| - :display_name "Count" |
245 |
| - :source :aggregation |
246 |
| - :field_ref [:aggregation 0]}] |
247 |
| - ::qp.perms/perms {:gtaps #{(perms/adhoc-native-query-path (mt/id))}}}) |
248 |
| - (apply-row-level-permissions |
249 |
| - (mt/mbql-query venues |
250 |
| - {:aggregation [[:count]]})))))))) |
| 232 | + (is (=? (mt/query nil |
| 233 | + {:database (mt/id) |
| 234 | + :type :query |
| 235 | + :query {:aggregation [[:count]] |
| 236 | + :source-query {:native (str "SELECT * FROM \"PUBLIC\".\"VENUES\" " |
| 237 | + "WHERE \"PUBLIC\".\"VENUES\".\"CATEGORY_ID\" = 50 " |
| 238 | + "ORDER BY \"PUBLIC\".\"VENUES\".\"ID\" ASC") |
| 239 | + :params []}} |
| 240 | + |
| 241 | + ::row-level-restrictions/original-metadata [{:base_type :type/Integer |
| 242 | + :semantic_type :type/Quantity |
| 243 | + :name "count" |
| 244 | + :display_name "Count" |
| 245 | + :source :aggregation |
| 246 | + :field_ref [:aggregation 0]}] |
| 247 | + ::qp.perms/perms {:gtaps #{(perms/adhoc-native-query-path (mt/id))}}}) |
| 248 | + (apply-row-level-permissions |
| 249 | + (mt/mbql-query venues |
| 250 | + {:aggregation [[:count]]})))))))) |
251 | 251 |
|
252 | 252 |
|
253 | 253 | ;;; +----------------------------------------------------------------------------------------------------------------+
|
|
0 commit comments