|
2473 | 2473 | value op))))) |
2474 | 2474 |
|
2475 | 2475 | [["null?" column-name value]] |
2476 | | - (let [maybe-dotted-path (str/split column-name #"\.") |
2477 | | - cinfo (get-in query-rec [:projections (first maybe-dotted-path)])] |
2478 | | - |
| 2476 | + ;; For now, this assumes that foo[5] and match(...) are |
| 2477 | + ;; just custom fact names, and doesn't handle foo.5.bar as |
| 2478 | + ;; a foo array access, to maintain backward compatibility, |
| 2479 | + ;; i.e. create-json-path-extraction doesn't do anything |
| 2480 | + ;; but single quote the compoents for a pg json path |
| 2481 | + ;; lookup, e.g. json->'x'->'y'. If we want null? to work |
| 2482 | + ;; on nested arrays, then we'll need to distinguish, |
| 2483 | + ;; i.e. foo.b'ar[5].baz should become |
| 2484 | + ;; foo->'b''ar'->5->'baz'. |
| 2485 | + ;; cf. https://www.postgresql.org/docs/11/functions-json.html |
| 2486 | + (let [[top & path] (parse/parse-field column-name 0 |
| 2487 | + {:indexes? false |
| 2488 | + :matches? false}) |
| 2489 | + cinfo (get-in query-rec [:projections (:name top)])] |
2479 | 2490 | (if (and (= :queryable-json (:type cinfo)) |
2480 | | - (seq? (rest maybe-dotted-path))) |
| 2491 | + (seq path)) |
2481 | 2492 | (let [field (name (h/extract-sql (:field cinfo))) |
2482 | | - dotted-path (->> maybe-dotted-path rest (str/join ".")) |
2483 | | - json-path (->> (parse/dotted-query->path dotted-path) |
2484 | | - (map parse/maybe-strip-escaped-quotes )) |
2485 | | - path-extraction-field (jdbc/create-json-path-extraction field json-path)] |
2486 | | - (map->NullExpression {:column (assoc cinfo :field (hcore/raw path-extraction-field)) |
| 2493 | + json-path (->> (map :name path) |
| 2494 | + (jdbc/create-json-path-extraction field) |
| 2495 | + hcore/raw)] |
| 2496 | + (map->NullExpression {:column (assoc cinfo :field json-path) |
2487 | 2497 | :null? value})) |
2488 | 2498 | (map->NullExpression {:column cinfo :null? value}))) |
2489 | 2499 |
|
|
0 commit comments