Created
September 10, 2018 15:20
-
-
Save Jaretbinford/33f2c2614b5d5204c7e2b3c74b55fa9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Rules I implemented to test. Results show that using any clojure core function in a rule results in an error | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;I created one without any clojure core function. It worked. | |
(def all2 | |
'[[(item-info ?type ?sku ?color ?size) | |
[?item :inv/type ?type] | |
[?item :inv/sku ?sku] | |
[?item :inv/color ?color] | |
[?item :inv/size ?size] | |
[(any? 2)]]]) | |
(defn items-by-cust2* | |
"Testing item matching a sku?" | |
[db type] | |
(d/q '[:find ?sku ?color ?size | |
:in $ % ?type | |
:where | |
(item-info ?type ?sku ?color ?size)] | |
db all2 type)) | |
(defn items-by-cust2 | |
"Lambda ion that returns sample database items matching type." | |
[{:keys [input]}] | |
(-> (items-by-cust2* (d/db (get-connection)) | |
(-> input json/read-str keyword)) | |
pp-str)) | |
(def all | |
'[[(item-info ?type ?sku ?color ?size ?sort ?prefix) | |
[?item :inv/type ?type] | |
[?item :inv/sku ?sku] | |
[?item :inv/color ?color] | |
[?item :inv/size ?size] | |
[?item ?sort ?n] | |
[(clojure.string/starts-with? ?n ?prefix)]]]) | |
(defn items-by-cust* | |
"Testing item matching a sku?" | |
[db type] | |
(d/q '[:find ?sku ?color ?size | |
:in $ % ?type | |
:where | |
(item-info ?type ?sku ?color ?size ?sort ?prefix)] | |
db all type)) | |
(defn items-by-cust | |
"Lambda ion that returns sample database items matching type." | |
[{:keys [input]}] | |
(-> (items-by-cust* (d/db (get-connection)) | |
(-> input json/read-str keyword)) | |
pp-str)) | |
(def rules | |
'[[(item-info ?type ?sku ?color ?size) | |
[?item :inv/type ?type] | |
[?item :inv/sku ?sku] | |
[?item :inv/color ?color] | |
[?item :inv/size ?size]]]) | |
(defn items-by-rule* | |
"returns info about items matching a type and using a rule" | |
[db type] | |
(d/q '[:find ?sku ?color ?size | |
:in $ % ?type | |
:where | |
(item-info ?type ?sku ?color ?size)] | |
db rules type)) | |
(defn items-by-rule | |
"Lambda ion that returns sample database items matching type." | |
[{:keys [input]}] | |
(-> (items-by-rule* (d/db (get-connection)) | |
(-> input json/read-str keyword)) | |
pp-str)) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;; Results invoked directly from ION: | |
jbin at Jarets-MacBook-Pro in ~/Desktop/Jaret/Tools/releasetest/lambda-rule-test/ion-starter on master* | |
$ aws lambda invoke --function-name jaret-lambda-test-compute-items-by-cust2 --payload \"hat\" /dev/stdout | |
{"errorMessage":"clojure.lang.ExceptionInfo: :db.error/invalid-rule-fn The following forms do not name predicates or fns: (any?) {:cognitect.anomalies/category :cognitect.anomalies/incorrect, :cognitect.anomalies/message \"The following forms do not name predicates or fns: (any?)\", :symbols (any?), :db/error :db.error/invalid-rule-fn}","errorType":"datomic.ion.lambda.handler.exceptions.Incorrect","stackTrace":["datomic.ion.lambda.handler$throw_anomaly.invokeStatic(handler.clj:24)","datomic.ion.lambda.handler$throw_anomaly.invoke(handler.clj:20)","datomic.ion.lambda.handler.Handler.on_anomaly(handler.clj:139)","datomic.ion.lambda.handler.Handler.handle_request(handler.clj:155)","datomic.ion.lambda.handler$fn__4075$G__4011__4080.invoke(handler.clj:70)","datomic.ion.lambda.handler$fn__4075$G__4010__4086.invoke(handler.clj:70)","clojure.lang.Var.invoke(Var.java:396)","datomic.ion.lambda.handler.Thunk.handleRequest(Thunk.java:35)"]}{ | |
"FunctionError": "Unhandled", | |
"StatusCode": 200 | |
} | |
jbin at Jarets-MacBook-Pro in ~/Desktop/Jaret/Tools/releasetest/lambda-rule-test/ion-starter on master* | |
$ aws lambda invoke --function-name jaret-lambda-test-compute-items-by-cust --payload \"hat\" /dev/stdout | |
{"errorMessage":"clojure.lang.ExceptionInfo: :db.error/invalid-rule-fn The following forms do not name predicates or fns: (clojure.string/starts-with?) {:cognitect.anomalies/category :cognitect.anomalies/incorrect, :cognitect.anomalies/message \"The following forms do not name predicates or fns: (clojure.string/starts-with?)\", :symbols (clojure.string/starts-with?), :db/error :db.error/invalid-rule-fn}","errorType":"datomic.ion.lambda.handler.exceptions.Incorrect","stackTrace":["datomic.ion.lambda.handler$throw_anomaly.invokeStatic(handler.clj:24)","datomic.ion.lambda.handler$throw_anomaly.invoke(handler.clj:20)","datomic.ion.lambda.handler.Handler.on_anomaly(handler.clj:139)","datomic.ion.lambda.handler.Handler.handle_request(handler.clj:155)","datomic.ion.lambda.handler$fn__4075$G__4011__4080.invoke(handler.clj:70)","datomic.ion.lambda.handler$fn__4075$G__4010__4086.invoke(handler.clj:70)","clojure.lang.Var.invoke(Var.java:396)","datomic.ion.lambda.handler.Thunk.handleRequest(Thunk.java:35)"]}{ | |
"FunctionError": "Unhandled", | |
"StatusCode": 200 | |
} | |
jbin at Jarets-MacBook-Pro in ~/Desktop/Jaret/Tools/releasetest/lambda-rule-test/ion-starter on master* | |
$ aws lambda invoke --function-name jaret-lambda-test-compute-items-by-rule --payload \"hat\" /dev/stdout | |
#{["SKU-12246" 32330039903125571 28499341391953988] ["SKU-12256" 32330039903125571 19087521858191430] ["SKU-15" 44499434599350336 29304183903486023] ["SKU-7" 44499434599350336 46139905947992133] ["SKU-3" 44499434599350336 28499341391953988] ["LOG-MEi2" 44499434599350336 28499341391953988] ["SKU-11" 44499434599350336 19087521858191430] ["SKU-51" 32330039903125571 28499341391953988] ["SKU-55" 32330039903125571 46139905947992133] ["SKU-43" 24198051904094274 19087521858191430] ["SKU-47" 24198051904094274 29304183903486023] ["SKU-35" 24198051904094274 28499341391953988] ["LOG-ME" 44499434599350336 28499341391953988] ["SKU-13256" 24198051904094274 46139905947992133] ["SKU-31" 23934169113428033 29304183903486023] ["SKU-63" 32330039903125571 29304183903486023] ["SKU-12345" 24198051904094274 28499341391953988] ["SKU-23" 23934169113428033 46139905947992133] ["SKU-59" 32330039903125571 19087521858191430] ["SKU-39" 24198051904094274 46139905947992133] ["SKU-19" 23934169113428033 28499341391953988] ["SKU-27" 23934169113428033 19087521858191430]} | |
{ | |
"StatusCode": 200 | |
} | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;; Results directly from a client | |
(d/q '[:find ?sku ?color ?size | |
:in $ % ?type | |
:where | |
(item-info ?type ?sku ?color ?size)] | |
db rules :hat) | |
=> | |
[["SKU-12246" 32330039903125571 28499341391953988] | |
["SKU-12256" 32330039903125571 19087521858191430] | |
["SKU-15" 44499434599350336 29304183903486023] | |
["SKU-7" 44499434599350336 46139905947992133] | |
["SKU-3" 44499434599350336 28499341391953988] | |
["LOG-MEi2" 44499434599350336 28499341391953988] | |
["SKU-11" 44499434599350336 19087521858191430] | |
["SKU-51" 32330039903125571 28499341391953988] | |
["SKU-55" 32330039903125571 46139905947992133] | |
["SKU-43" 24198051904094274 19087521858191430] | |
["SKU-47" 24198051904094274 29304183903486023] | |
["SKU-35" 24198051904094274 28499341391953988] | |
["LOG-ME" 44499434599350336 28499341391953988] | |
["SKU-13256" 24198051904094274 46139905947992133] | |
["SKU-31" 23934169113428033 29304183903486023] | |
["SKU-63" 32330039903125571 29304183903486023] | |
["SKU-12345" 24198051904094274 28499341391953988] | |
["SKU-23" 23934169113428033 46139905947992133] | |
["SKU-59" 32330039903125571 19087521858191430] | |
["SKU-39" 24198051904094274 46139905947992133] | |
["SKU-19" 23934169113428033 28499341391953988] | |
["SKU-27" 23934169113428033 19087521858191430]] | |
(d/q '[:find ?sku ?color ?size | |
:in $ % ?type | |
:where | |
(item-info ?type ?sku ?color ?size)] | |
db all2 :hat) | |
=> | |
[["SKU-12246" 32330039903125571 28499341391953988] | |
["SKU-12256" 32330039903125571 19087521858191430] | |
["SKU-15" 44499434599350336 29304183903486023] | |
["SKU-7" 44499434599350336 46139905947992133] | |
["SKU-3" 44499434599350336 28499341391953988] | |
["LOG-MEi2" 44499434599350336 28499341391953988] | |
["SKU-11" 44499434599350336 19087521858191430] | |
["SKU-51" 32330039903125571 28499341391953988] | |
["SKU-55" 32330039903125571 46139905947992133] | |
["SKU-43" 24198051904094274 19087521858191430] | |
["SKU-47" 24198051904094274 29304183903486023] | |
["SKU-35" 24198051904094274 28499341391953988] | |
["LOG-ME" 44499434599350336 28499341391953988] | |
["SKU-13256" 24198051904094274 46139905947992133] | |
["SKU-31" 23934169113428033 29304183903486023] | |
["SKU-63" 32330039903125571 29304183903486023] | |
["SKU-12345" 24198051904094274 28499341391953988] | |
["SKU-23" 23934169113428033 46139905947992133] | |
["SKU-59" 32330039903125571 19087521858191430] | |
["SKU-39" 24198051904094274 46139905947992133] | |
["SKU-19" 23934169113428033 28499341391953988] | |
["SKU-27" 23934169113428033 19087521858191430]] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment