-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧪 Connecting to ClickHouse Cloud (#167)
* :test-tube: Connecting to ClickHouse Cloud Signed-off-by: Julio Jimenez <[email protected]> * testing complete Signed-off-by: Julio Jimenez <[email protected]> * link to nyc taxi dataset Signed-off-by: Julio Jimenez <[email protected]> --------- Signed-off-by: Julio Jimenez <[email protected]>
- Loading branch information
1 parent
3bc412f
commit 8485869
Showing
8 changed files
with
162 additions
and
26 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
:description "clickhouse Tests" | ||
:author "[email protected]" | ||
:license "Apache-2.0" | ||
:version "0.0.26" | ||
:version "0.0.27" | ||
:depends-on (#:clickhouse | ||
#:fiveam) | ||
:components ((:module "t" | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
:description "Common Lisp ClickHouse Client Library" | ||
:author "[email protected]" | ||
:license "Apache-2.0" | ||
:version "0.41.0" | ||
:version "0.42.0" | ||
:depends-on (#:boost-json | ||
#:dexador | ||
#:lexer | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
(defpackage :clickhouse | ||
(:nicknames :ch) | ||
(:use :cl) | ||
(:import-from :clickhouse.ch-sql-parser | ||
:make-query) | ||
(:import-from :clickhouse.http | ||
:http-get | ||
:http-post) | ||
(:import-from :clickhouse.utils | ||
:prettify | ||
:ver) | ||
(:import-from :cl-ppcre | ||
:regex-replace) | ||
(:export :database | ||
:input-parameters | ||
:jget | ||
:ping | ||
:query | ||
:replicas-status)) | ||
|
||
(in-package :clickhouse) | ||
|
||
(defclass database () | ||
((host | ||
:initarg :host | ||
:initform "localhost" | ||
:accessor host | ||
:documentation "ClickHouse database hostname.") | ||
(port | ||
:initarg :port | ||
:initform 8123 | ||
:accessor port | ||
:documentation "ClickHouse database port, i.e. 8443 or 8123.") | ||
(ssl | ||
:initarg :ssl | ||
:initform nil | ||
:accessor ssl | ||
:documentation "SSL option, t or nil.") | ||
(username | ||
:initarg :username | ||
:initform "default" | ||
:accessor username | ||
:documentation "ClickHouse database username, default username is default.") | ||
(password | ||
:initarg :password | ||
:initform nil | ||
:accessor password | ||
:documentation "Clickhouse database password."))) | ||
|
||
(defgeneric ping (obj &key) | ||
(:documentation "Pings the database server.")) | ||
|
||
(defmethod ping ((obj database) &key ping console) | ||
"Pings the database server." | ||
(with-slots ((h host) (p port) (s ssl)) obj | ||
(prettify | ||
(if (ver ping) | ||
(http-get h p s "/ping") | ||
(http-get h p s "/")) | ||
:console console))) | ||
|
||
(defgeneric replicas-status (obj &key) | ||
(:documentation "Get replicas status.")) | ||
|
||
(defmethod replicas-status ((obj database) &key console verbose) | ||
"Get replicas status." | ||
(with-slots ((h host) (p port) (s ssl)) obj | ||
(prettify | ||
(cond (verbose (http-get h p s "/replicas_status?verbose=1")) | ||
(t (http-get h p s "/replicas_status"))) | ||
:console console))) | ||
|
||
(defgeneric query (obj query &key) | ||
(:documentation "Execute a query.")) | ||
|
||
(defmethod query ((obj database) query &key console no-format timeout) | ||
"Execute a query." | ||
(with-slots ((h host) (p port) (s ssl) (u username) (w password)) obj | ||
(prettify | ||
(http-post h p s u w (make-query query) timeout) | ||
:console console :formatting (if no-format nil clickhouse.ch-sql-parser:*format*)))) | ||
|
||
(defmacro jget (obj key) | ||
"Get JSON value." | ||
`(boost-json:json-getf ,obj ,key)) | ||
|
||
(defun input-parameters (query &rest input) | ||
(let ((new-query query)) | ||
(dolist (in input) | ||
(setf new-query (regex-replace "\\$i" new-query in))) | ||
(values new-query))) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[email protected]:1678404309 |
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
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
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