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

feat: Add TIME keyword #56

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions resources/inferenceql/query/base.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ relation-expr ::= '(' ws? relation-expr ws? ')'
| join-expr
| rename-expr
| with-expr
| time-expr

(* commands *)

Expand Down Expand Up @@ -61,6 +62,10 @@ with-expr ::= #'(?i)WITH' ws binding (ws? ',' ws? binding)* ws? ':' ws? relation
binding ::= expr ws alias-clause
<expr> ::= relation-expr | model-expr | scalar-expr

(* time-expr *)

time-expr ::= #'(?i)TIME' ws relation-expr

(* select *)

select-expr ::= select-clause
Expand Down
49 changes: 48 additions & 1 deletion src/inferenceql/query/plan.cljc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns inferenceql.query.plan
(:refer-clojure :exclude [alias alter distinct distinct? eval sort type update])
(:refer-clojure :exclude [alias alter distinct distinct? eval sort time type update])
(:require [clojure.core :as core]
[clojure.core.match :as match]
[clojure.math.combinatorics :as combinatorics]
Expand Down Expand Up @@ -133,6 +133,11 @@
::plan-2 op2
::condition condition})

(defn time
[op]
{::type :inferenceql.query.plan.type/time
::plan op})

(defn with
[bindings op]
{::type :inferenceql.query.plan.type/with
Expand Down Expand Up @@ -416,6 +421,10 @@
[node]
(plan-impl (tree/only-child-node node)))

(defmethod plan-impl :time-expr
[node]
(time (plan (tree/only-child-node node))))

(defmethod plan-impl :join-expr-group
[node]
(plan-impl (tree/only-child-node node)))
Expand Down Expand Up @@ -673,3 +682,41 @@
(rest binding-plans)))
bindings))]
(eval plan env bindings)))

(defmethod eval :inferenceql.query.plan.type/time
[plan env bindings]
(let [{::keys [plan]} plan
start (. System (nanoTime))]
(eval plan env bindings)
(let [elapsed (/ (double (- (. System (nanoTime)) start))
1.0E9)]
(relation/relation [{:seconds elapsed}]
:name :time
:attrs [:seconds]))))


(comment

(-> "TIME SELECT * FROM data"
(parser/parse))

(core/time (+ 1 1))


(-> [:query
[:relation-expr
[:time-expr
"TIME"
[:ws " "]
[:relation-expr
[:select-expr
[:select-clause "SELECT" [:ws " "] [:select-list [:star "*"]]]
[:ws " "]
[:from-clause
"FROM"
[:ws " "]
[:relation-expr [:simple-symbol "data"]]]]]]]]
tree/only-child-node
plan)

,)