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

New join api #180

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 10 additions & 1 deletion dev/resources/common_unpatched.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{;; scenario 1 migrations
{ ;; scenario 1 migrations
[:duct.migrator.ragtime/sql :walkable-demo.migration.scenario-1/create-house-table]
{:up ["CREATE TABLE `house` (`index` VARCHAR(32) PRIMARY KEY, `color` TEXT)"
"INSERT INTO `house` (`index`, `color`) VALUES ('10', 'black'), ('20', 'brown')"]
Expand Down Expand Up @@ -61,4 +61,13 @@
{:up ["CREATE TABLE `follow` (`human_1` INTEGER REFERENCES `human`(`number`), `human_2` INTEGER REFERENCES `human`(`number`), `year` INTEGER)"
"INSERT INTO `follow` (`human_1`, `human_2`, `year`) VALUES (1, 2, 2015), (1, 3, 2017), (2, 1, 2014), (2, 3, 2015), (1, 4, 2012)"]
:down ["DROP TABLE `follow`"]}
;; scenario 5 migrations
[:duct.migrator.ragtime/sql :walkable-demo.migration.scenario-5/create-article-table]
{:up ["CREATE TABLE `article` (`id` SERIAL PRIMARY KEY, `title` TEXT, `current_revision` INTEGER)"
"INSERT INTO `article` (`id`, `title`, `current_revision`) VALUES (1, 'introduction', 2), (2, 'hello world', 1)" ]
:down ["DROP TABLE `article`"]}
[:duct.migrator.ragtime/sql :walkable-demo.migration.scenario-5/create-revision-table]
{:up ["CREATE TABLE `revision` (`id` INTEGER, `content` TEXT, `revision` INTEGER)"
"INSERT INTO `revision` (`id`, `content`, `revision`) VALUES (1, 'tbd', 1), (1, 'this is sparta', 2), (2, 'welcome to my site', 1)" ]
:down ["DROP TABLE `revision`"]}
}
2 changes: 2 additions & 0 deletions dev/resources/config-mysql.edn
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#ig/ref :walkable-demo.migration.scenario-3/create-person_pet-table
#ig/ref :walkable-demo.migration.scenario-4/create-human-table
#ig/ref :walkable-demo.migration.scenario-4/create-follow-table
#ig/ref :walkable-demo.migration.scenario-5/create-article-table
#ig/ref :walkable-demo.migration.scenario-5/create-revision-table
;; mysql-specific scenarios (starting from 100)
]}
}
Expand Down
2 changes: 2 additions & 0 deletions dev/resources/config-postgres.edn
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#ig/ref :walkable-demo.migration.scenario-3/create-person_pet-table
#ig/ref :walkable-demo.migration.scenario-4/create-human-table
#ig/ref :walkable-demo.migration.scenario-4/create-follow-table
#ig/ref :walkable-demo.migration.scenario-5/create-article-table
#ig/ref :walkable-demo.migration.scenario-5/create-revision-table
;; postgres-specific scenarios (starting from 100)

#ig/ref :walkable-demo.migration.scenario-100/create-land-animal-table
Expand Down
2 changes: 2 additions & 0 deletions dev/resources/config-sqlite.edn
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#ig/ref :walkable-demo.migration.scenario-3/create-person_pet-table
#ig/ref :walkable-demo.migration.scenario-4/create-human-table
#ig/ref :walkable-demo.migration.scenario-4/create-follow-table
#ig/ref :walkable-demo.migration.scenario-5/create-article-table
#ig/ref :walkable-demo.migration.scenario-5/create-revision-table
;; sqlite-specific scenarios (starting from 100)
]}
}
Expand Down
11 changes: 10 additions & 1 deletion dev/resources/core-mysql.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{;; scenario 1 migrations
{ ;; scenario 1 migrations
[:duct.migrator.ragtime/sql :walkable-demo.migration.scenario-1/create-house-table]
{:up ["CREATE TABLE `house` (`index` VARCHAR(32) PRIMARY KEY, `color` TEXT)"
"INSERT INTO `house` (`index`, `color`) VALUES ('10', 'black'), ('20', 'brown')"]
Expand Down Expand Up @@ -61,4 +61,13 @@
{:up ["CREATE TABLE `follow` (`human_1` INTEGER REFERENCES `human`(`number`), `human_2` INTEGER REFERENCES `human`(`number`), `year` INTEGER)"
"INSERT INTO `follow` (`human_1`, `human_2`, `year`) VALUES (1, 2, 2015), (1, 3, 2017), (2, 1, 2014), (2, 3, 2015), (1, 4, 2012)"]
:down ["DROP TABLE `follow`"]}
;; scenario 5 migrations
[:duct.migrator.ragtime/sql :walkable-demo.migration.scenario-5/create-article-table]
{:up ["CREATE TABLE `article` (`id` SERIAL PRIMARY KEY, `title` TEXT, `current_revision` INTEGER)"
"INSERT INTO `article` (`id`, `title`, `current_revision`) VALUES (1, 'introduction', 2), (2, 'hello world', 1)" ]
:down ["DROP TABLE `article`"]}
[:duct.migrator.ragtime/sql :walkable-demo.migration.scenario-5/create-revision-table]
{:up ["CREATE TABLE `revision` (`id` INTEGER, `content` TEXT, `revision` INTEGER)"
"INSERT INTO `revision` (`id`, `content`, `revision`) VALUES (1, 'tbd', 1), (1, 'this is sparta', 2), (2, 'welcome to my site', 1)" ]
:down ["DROP TABLE `revision`"]}
}
11 changes: 10 additions & 1 deletion dev/resources/core-postgres.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{;; scenario 1 migrations
{ ;; scenario 1 migrations
[:duct.migrator.ragtime/sql :walkable-demo.migration.scenario-1/create-house-table]
{:up ["CREATE TABLE \"house\" (\"index\" VARCHAR(32) PRIMARY KEY, \"color\" TEXT)"
"INSERT INTO \"house\" (\"index\", \"color\") VALUES ('10', 'black'), ('20', 'brown')"]
Expand Down Expand Up @@ -61,4 +61,13 @@
{:up ["CREATE TABLE \"follow\" (\"human_1\" INTEGER REFERENCES \"human\"(\"number\"), \"human_2\" INTEGER REFERENCES \"human\"(\"number\"), \"year\" INTEGER)"
"INSERT INTO \"follow\" (\"human_1\", \"human_2\", \"year\") VALUES (1, 2, 2015), (1, 3, 2017), (2, 1, 2014), (2, 3, 2015), (1, 4, 2012)"]
:down ["DROP TABLE \"follow\""]}
;; scenario 5 migrations
[:duct.migrator.ragtime/sql :walkable-demo.migration.scenario-5/create-article-table]
{:up ["CREATE TABLE \"article\" (\"id\" SERIAL PRIMARY KEY, \"title\" TEXT, \"current_revision\" INTEGER)"
"INSERT INTO \"article\" (\"id\", \"title\", \"current_revision\") VALUES (1, 'introduction', 2), (2, 'hello world', 1)" ]
:down ["DROP TABLE \"article\""]}
[:duct.migrator.ragtime/sql :walkable-demo.migration.scenario-5/create-revision-table]
{:up ["CREATE TABLE \"revision\" (\"id\" INTEGER, \"content\" TEXT, \"revision\" INTEGER)"
"INSERT INTO \"revision\" (\"id\", \"content\", \"revision\") VALUES (1, 'tbd', 1), (1, 'this is sparta', 2), (2, 'welcome to my site', 1)" ]
:down ["DROP TABLE \"revision\""]}
}
11 changes: 10 additions & 1 deletion dev/resources/core-sqlite.edn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{;; scenario 1 migrations
{ ;; scenario 1 migrations
[:duct.migrator.ragtime/sql :walkable-demo.migration.scenario-1/create-house-table]
{:up ["CREATE TABLE `house` (`index` VARCHAR(32) PRIMARY KEY, `color` TEXT)"
"INSERT INTO `house` (`index`, `color`) VALUES ('10', 'black'), ('20', 'brown')"]
Expand Down Expand Up @@ -61,4 +61,13 @@
{:up ["CREATE TABLE `follow` (`human_1` INTEGER REFERENCES `human`(`number`), `human_2` INTEGER REFERENCES `human`(`number`), `year` INTEGER)"
"INSERT INTO `follow` (`human_1`, `human_2`, `year`) VALUES (1, 2, 2015), (1, 3, 2017), (2, 1, 2014), (2, 3, 2015), (1, 4, 2012)"]
:down ["DROP TABLE `follow`"]}
;; scenario 5 migrations
[:duct.migrator.ragtime/sql :walkable-demo.migration.scenario-5/create-article-table]
{:up ["CREATE TABLE `article` (`id` SERIAL PRIMARY KEY, `title` TEXT, `current_revision` INTEGER)"
"INSERT INTO `article` (`id`, `title`, `current_revision`) VALUES (1, 'introduction', 2), (2, 'hello world', 1)" ]
:down ["DROP TABLE `article`"]}
[:duct.migrator.ragtime/sql :walkable-demo.migration.scenario-5/create-revision-table]
{:up ["CREATE TABLE `revision` (`id` INTEGER, `content` TEXT, `revision` INTEGER)"
"INSERT INTO `revision` (`id`, `content`, `revision`) VALUES (1, 'tbd', 1), (1, 'this is sparta', 2), (2, 'welcome to my site', 1)" ]
:down ["DROP TABLE `revision`"]}
}
2 changes: 1 addition & 1 deletion dev/src/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
(defn dev
"Load and switch to the 'dev' namespace."
[]
(require 'dev)
(require 'dev :reload-all)
(in-ns 'dev)
:loaded)
55 changes: 43 additions & 12 deletions dev/test/walkable/integration_test/common.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
:output [:farmer/name :farmer/house-plus :farmer/house-count :farmer/house]}
{:key :farmer/house
:type :join
:join-path [:farmer/house-index :house/index]
:join-path [{:farmer/house-index :house/index}]
:output [:house/color]
:cardinality :one}
{:key :house/owner
:type :join
:join-path [:house/index :farmer/house-index]
:join-path [{:house/index :farmer/house-index}]
:output [:farmer/number]
:cardinality :one}])

Expand All @@ -30,12 +30,12 @@
:output [:kid/name]}
{:key :toy/owner
:type :join
:join-path [:toy/owner-number :kid/number]
:join-path [{:toy/owner-number :kid/number}]
:output [:kid/name :kid/number]
:cardinality :one}
{:key :kid/toy
:type :join
:join-path [:kid/number :toy/owner-number]
:join-path [{:kid/number :toy/owner-number}]
:output [:toy/color :toy/index]
:cardinality :one}
{:key :kid/number
Expand All @@ -50,7 +50,8 @@
:output [:human/number :human/name :human/yob :human/age]}
{:key :human/follow
:type :join
:join-path [:human/number :follow/human-1 :follow/human-2 :human/number]
:join-path [{:human/number :follow/human-1}
{:follow/human-2 :human/number}]
:output [:human/number :human/name :human/yob :human/age]}])

(def person-pet-registry
Expand Down Expand Up @@ -82,8 +83,8 @@
{:key :person/pet
:type :join
:join-path
[:person/number :person-pet/person-number
:person-pet/pet-index :pet/index]
[{:person/number :person-pet/person-number}
{:person-pet/pet-index :pet/index}]
:output [:pet/index
:person-pet/adoption-year
:pet/name
Expand All @@ -92,13 +93,14 @@
{:key :pet/owner
:type :join
:join-path
[:pet/index :person-pet/pet-index :person-pet/person-number :person/number]
[{:pet/index :person-pet/pet-index}
{:person-pet/person-number :person/number}]
:output [:person/number]}
{:key :person/pet-count
:type :join
:join-path
[:person/number :person-pet/person-number
:person-pet/pet-index :pet/index]
[{:person/number :person-pet/person-number}
{:person-pet/pet-index :pet/index}]
:aggregate true
:formula [:count-*]}
{:key :pets/by-color
Expand All @@ -111,6 +113,18 @@
:type :pseudo-column
:formula [:count :pet/index]}])

(def article-revision-registry
[{:key :articles/list
:type :root
:table "article"
:output [:article/id :article/title :article/current-revision]}
{:key :article/revision
:type :join
:cardinality :one
:output [:revision/content]
:join-path [{:article/id :revision/id
:article/current-revision :revision/revision}]}])

(def common-scenarios
{:farmer-house
{:registry farmer-house-registry
Expand Down Expand Up @@ -161,7 +175,7 @@
{:farmer/house [:house/index :house/color]}]}]
:expected
#:farmers{:farmers [#:farmer{:number 2, :house #:house {:index "20", :color "brown"}}]}}]}

:kid-toy
{:registry kid-toy-registry
:test-suite
Expand Down Expand Up @@ -418,4 +432,21 @@
:person/age]}]
:expected
#:people {:people [#:person{:number 1, :name "jon", :yob 1980, :age 38}
#:person{:number 2, :name "mary", :yob 1992, :age 26}]}}]}})
#:person{:number 2, :name "mary", :yob 1992, :age 26}]}}]}

:article-revision
{:registry article-revision-registry
:test-suite
[{:message "join with multiple column pairs should work"
:query `[{:articles/list [:article/id :article/title
{:article/revision [:revision/content]}]}]
:expected
#:articles{:list
[#:article{:id 1,
:title "introduction",
:revision
#:revision{:content "this is sparta"}}
#:article{:id 2,
:title "hello world",
:revision
#:revision{:content "welcome to my site"}}]}}]}})
18 changes: 9 additions & 9 deletions src/walkable/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
[build-and-run-query env ast]
(->> ast
(ast-map-loc (fn [loc]
(let [{::ast/keys [prepared-query]} (z/node loc)]
(let [{:keys [::ast/prepared-query]} (z/node loc)]
(if prepared-query
(let [parent (last (z/path loc))
;; TODO: partition entities and concat back
Expand All @@ -54,8 +54,8 @@
(z/root loc)
(recur
(z/next
(let [{:keys [children] :as node} (z/node loc)
{::ast/keys [prepared-merge-sub-entities]} node]
(let [{:keys [:children] :as node} (z/node loc)
{:keys [::ast/prepared-merge-sub-entities]} node]
(if (or (not prepared-merge-sub-entities) ;; node can be nil
(not-empty children))
loc
Expand All @@ -78,25 +78,25 @@

(defn merge-data
[wrap-merge ast]
(loop [{:keys [children] :as root} ast]
(loop [{:keys [:children] :as root} ast]
(if (empty? children)
(:entities root)
(recur (merge-data-in-bottom-branches wrap-merge root)))))

(defn ast-resolver*
[{:keys [build-and-run-query floor-plan env wrap-merge ast]}]
[{:keys [:build-and-run-query :floor-plan :env :wrap-merge :ast]}]
(->> (ast/prepare-ast floor-plan ast)
(fetch-data build-and-run-query env)
(merge-data wrap-merge)))

(defn prepared-ast-resolver*
[{:keys [build-and-run-query env wrap-merge prepared-ast]}]
[{:keys [:build-and-run-query :env :wrap-merge :prepared-ast]}]
(->> prepared-ast
(fetch-data build-and-run-query env)
(merge-data wrap-merge)))

(defn query-resolver*
[{:keys [floor-plan env resolver query]}]
[{:keys [:floor-plan :env :resolver :query]}]
(resolver floor-plan env (p/query->ast query)))

(defn ast-resolver
Expand Down Expand Up @@ -158,7 +158,7 @@
ios))

(defn internalize-indexes
[indexes {::pc/keys [sym] :as dynamic-resolver}]
[indexes {:keys [::pc/sym] :as dynamic-resolver}]
(-> indexes
(update ::pc/index-resolvers
(fn [resolvers]
Expand All @@ -178,7 +178,7 @@
(floor-plan/with-db-type db-type registry)
registry))]
{::p/wrap-parser2
(fn [parser {::p/keys [plugins]}]
(fn [parser {:keys [::p/plugins]}]
(let [resolve-fn (fn [env _]
(resolver compiled-floor-plan query-env env))
all-indexes (-> (compute-indexes resolver-sym inputs-outputs)
Expand Down
Loading