Eugen Stan eugen.stan@netdava.com
@ieugen
on internet (mostly)
Apache Calcite Online Meetup
2022-01-19
A quick introduction to calcite-clj
.
A library for using Apache Calcite with Clojure language.
Links:
The foundation for your next high-performance database.
Use Calcite + add persistence to build your database.
Apache Calcite is a Java library for:
(Also see Calcite adapters)
Use a clojure function as a Calcite schema factory.
Implement Calcite adapters in Clojure.
Follow these easy steps ...
calcite-clj
to your projectdeps.edn
io.github.ieugen/calcite-clj {:mvn/version "0.1.2"}
Gradle
implementation("io.github.ieugen:calcite-clj:0.1.2")
(See https://clojars.org/io.github.ieugen/calcite-clj)
Define a function that builds your schema
(ns calcite-clj.simple
(:require [com.rpl.proxy-plus :refer [proxy+]]])
(:import (org.apache.calcite.schema Schema)
(org.apache.calcite.schema.impl AbstractSchema)))
(defn create-tables [] ... )
(defn my-schema
[parent-schema name operand]
(let [tables (create-tables)]
(proxy+
[]
AbstractSchema
(getTableMap [this] tables))))
Build you model.json
file.
{
"version": "1.0",
"defaultSchema": "SALES",
"schemas": [{
"name": "SALES",
"type": "custom",
"factory": "ro.ieugen.calcite.clj.SchemaFactory",
"operand": {
"clojure-clj.schema-factory":
"calcite-clj.simple/my-schema"
} } ] }
Notice ro.ieugen.calcite.clj.SchemaFactory
and
"clojure-clj.schema-factory": "calcite-clj.simple/my-schema"
Reference the model and let Calcite and Clojure do the magic.
(let [db {:jdbcUrl "jdbc:calcite:model=resources/model.json"
:user "admin"
:password "admin"}
ds (jdbc/get-datasource db)
query "select * from emps where age
is null or age >= 40"]
(jdbc/execute! ds [query]))
Main work is done by ro.ieugen.calcite.clj.SchemaFactory
public Schema create(SchemaPlus parentSchema,
String name, Map<String, Object> operand) {
final String sfqn =
(String) operand.get("clojure-clj.schema-factory");
IFn ifn = Clojure.var(sfqn);
Schema s = (Schema) ifn.invoke(parentSchema,
name, operand);
return s;
}
calcite-clj
so users can write idiomatic ClojureDemo time!
@ieugen
on internet (mostly)Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close