add flags

main
Ziyang Hu 2 years ago
parent 412c39e764
commit be78a8d3e5

20
Cargo.lock generated

@ -1466,9 +1466,9 @@ dependencies = [
[[package]] [[package]]
name = "pyo3" name = "pyo3"
version = "0.17.2" version = "0.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "201b6887e5576bf2f945fe65172c1fcbf3fcf285b23e4d71eb171d9736e38d32" checksum = "268be0c73583c183f2b14052337465768c07726936a260f480f0857cb95ba543"
dependencies = [ dependencies = [
"cfg-if 1.0.0", "cfg-if 1.0.0",
"indoc", "indoc",
@ -1483,9 +1483,9 @@ dependencies = [
[[package]] [[package]]
name = "pyo3-build-config" name = "pyo3-build-config"
version = "0.17.2" version = "0.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf0708c9ed01692635cbf056e286008e5a2927ab1a5e48cdd3aeb1ba5a6fef47" checksum = "28fcd1e73f06ec85bf3280c48c67e731d8290ad3d730f8be9dc07946923005c8"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"target-lexicon", "target-lexicon",
@ -1493,9 +1493,9 @@ dependencies = [
[[package]] [[package]]
name = "pyo3-ffi" name = "pyo3-ffi"
version = "0.17.2" version = "0.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90352dea4f486932b72ddf776264d293f85b79a1d214de1d023927b41461132d" checksum = "0f6cb136e222e49115b3c51c32792886defbfb0adead26a688142b346a0b9ffc"
dependencies = [ dependencies = [
"libc", "libc",
"pyo3-build-config", "pyo3-build-config",
@ -1503,9 +1503,9 @@ dependencies = [
[[package]] [[package]]
name = "pyo3-macros" name = "pyo3-macros"
version = "0.17.2" version = "0.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7eb24b804a2d9e88bfcc480a5a6dd76f006c1e3edaf064e8250423336e2cd79d" checksum = "94144a1266e236b1c932682136dc35a9dee8d3589728f68130c7c3861ef96b28"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"pyo3-macros-backend", "pyo3-macros-backend",
@ -1515,9 +1515,9 @@ dependencies = [
[[package]] [[package]]
name = "pyo3-macros-backend" name = "pyo3-macros-backend"
version = "0.17.2" version = "0.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f22bb49f6a7348c253d7ac67a6875f2dc65f36c2ae64a82c381d528972bea6d6" checksum = "c8df9be978a2d2f0cdebabb03206ed73b11314701a5bfe71b0d753b81997777f"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",

@ -5,33 +5,37 @@
# `cozo` # `cozo`
A general-purpose, transactional, relational database A general-purpose, transactional, relational database
that uses Datalog for query and focuses on graph data and algorithms. that uses Datalog for query, is embeddable, and focuses on graph data and algorithms.
## Features ## Features
* Relational database with [Datalog](https://en.wikipedia.org/wiki/Datalog) as the query language * Relational database with [Datalog](https://en.wikipedia.org/wiki/Datalog) as the query language
* Recursive queries, especially recursion through (safe) aggregation, capable of expressing complex graph operations and algorithms * Recursive queries, recursion through (safe) aggregations, capable of expressing complex graph operations and
* Fixed rules providing efficient whole-graph algorithms which integrate seamlessly with Datalog algorithms
* Rich set of built-in functions and aggregations * Fixed rules for efficient whole-graph algorithms which integrate seamlessly with Datalog
* Only a single executable, trivial to deploy and run * Rich set of built-in functions and aggregations
* [Embeddable](https://cozodb.github.io/current/manual/setup.html#embedding-cozo), can run in the same process as the application * Easy to use from any programming language, or as a standalone program
* Easy to use from any programming language * [Embeddable](https://cozodb.github.io/current/manual/setup.html#embedding-cozo), with ready-to-use bindings for
* Special support for [Jupyter](https://jupyter.org/) notebooks for integration with the Python DataScience ecosystem Python, NodeJS and Java
* Single executable, trivial to deploy and run
* [Jupyter](https://jupyter.org/) notebooks integration, plays well with the DataScience ecosystem
* Modern, clean, flexible syntax, informative error messages * Modern, clean, flexible syntax, informative error messages
## Teasers ## Teasers
Here `*route` is a relation with two columns `src` and `dst`, Here `*route` is a relation with two columns `src` and `dst`,
representing a route between those airports. representing a route between those airports.
Find airports reachable by one stop from Frankfurt Airport (code `FRA`): Find airports reachable by one stop from Frankfurt Airport (code `FRA`):
TODO replace with images
```js ```js
?[dst] := *route{src: 'FRA', dst: stop}, ?[dst] := *route{src: 'FRA', dst: stop},
*route{src: stop, dst} *route{src: stop, dst}
``` ```
Find airports reachable from Frankfurt with any number of stops Find airports reachable from Frankfurt with any number of stops
with code starting with the letter `A`: with code starting with the letter `A`:
```js ```js
@ -58,15 +62,35 @@ starting[airport] := airport = 'FRA'
?[src, dst, cost, path] <~ ShortestPathDijkstra(*route[], starting[]) ?[src, dst, cost, path] <~ ShortestPathDijkstra(*route[], starting[])
``` ```
## Learning Cozo Nice error messages when things go wrong:
xxx
## Getting started
First we need to get Cozo installed on the local machine. As Cozo is embeddable,
there are lots of options for how we run Cozo. Follow one of the following guides that suits you best:
* Start with the [Tutorial](https://nbviewer.org/github/cozodb/cozo/blob/main/docs/tutorial/tutorial.ipynb) to learn the basics; * Embedded in Python with JupyterLab (best interactive experience, recommended if you are comfortable with the Python
* Continue with the [Manual](https://cozodb.github.io/current/manual/) to understand the fine points. ecosystem)
* Embedded in Python
* Embedded in NodeJS (Javascript)
* Embedded in Java (or any JVM language)
* Embedded in Rust
* Client/server with HTTP API
* Embedded in C/C++, or any language that has a C FFI
(Golang, R, Haskell, CommonLisp, Julia, Fortran, C#, Swift, ...)
After you have it installed, you can start learning CozoScript:
* Start with the [Tutorial](https://nbviewer.org/github/cozodb/cozo/blob/main/docs/tutorial/tutorial.ipynb) to learn the
basics;
* Continue with the [Manual](https://cozodb.github.io/current/manual/) for the fine points.
## Bug reports, discussions ## Bug reports, discussions
If you encounter a bug, first search for [past issues](https://github.com/cozodb/cozo/issues) to see If you encounter a bug, first search for [past issues](https://github.com/cozodb/cozo/issues) to see
if it has already been reported. If not, open a new issue. if it has already been reported. If not, open a new issue.
Please provide sufficient information so that we can diagnose the problem faster. Please provide sufficient information so that we can diagnose the problem faster.
Other discussions about Cozo should be in [GitHub discussions](https://github.com/cozodb/cozo/discussions). Other discussions about Cozo should be in [GitHub discussions](https://github.com/cozodb/cozo/discussions).
@ -84,67 +108,68 @@ in specific situations:
* You have a lot of interconnected relations * You have a lot of interconnected relations
and the usual queries need to relate many relations together. and the usual queries need to relate many relations together.
In other words, you need to query a complex graph. In other words, you need to query a complex graph.
* An example is a system granting permissions to users for specific tasks. * An example is a system granting permissions to users for specific tasks.
In this case, users may have roles, In this case, users may have roles,
belong to an organization hierarchy, and tasks similarly have organizations belong to an organization hierarchy, and tasks similarly have organizations
and special provisions associated with them. and special provisions associated with them.
The granting process itself may also be a complicated rule encoded as data The granting process itself may also be a complicated rule encoded as data
within the database. within the database.
* With a traditional database, * With a traditional database,
the corresponding SQL tend to become the corresponding SQL tend to become
an entangled web of nested queries, with many tables joined together, an entangled web of nested queries, with many tables joined together,
and maybe even with some recursive CTE thrown in. This is hard to maintain, and maybe even with some recursive CTE thrown in. This is hard to maintain,
and worse, the performance is unpredictable since query optimizers in general and worse, the performance is unpredictable since query optimizers in general
fail when you have over twenty tables joined together. fail when you have over twenty tables joined together.
* With Cozo, on the other hand, [Horn clauses](https://en.wikipedia.org/wiki/Horn_clause) * With Cozo, on the other hand, [Horn clauses](https://en.wikipedia.org/wiki/Horn_clause)
make it easy to break make it easy to break
the logic into smaller pieces and write clear, easily testable queries. the logic into smaller pieces and write clear, easily testable queries.
Furthermore, the deterministic evaluation order makes identifying and solving Furthermore, the deterministic evaluation order makes identifying and solving
performance problems easier. performance problems easier.
* Your data may be simple, even a single table, but it is inherently a graph. * Your data may be simple, even a single table, but it is inherently a graph.
* We have seen an example in the [Tutorial](https://nbviewer.org/github/cozodb/cozo/blob/main/docs/tutorial/tutorial.ipynb): * We have seen an example in
the air route dataset, where the key relation contains the routes connecting airports. the [Tutorial](https://nbviewer.org/github/cozodb/cozo/blob/main/docs/tutorial/tutorial.ipynb):
* In traditional databases, when you are given a new relation, the air route dataset, where the key relation contains the routes connecting airports.
you try to understand it by running aggregations on it to collect statistics: * In traditional databases, when you are given a new relation,
what is the distribution of values, how are the columns correlated, etc. you try to understand it by running aggregations on it to collect statistics:
* In Cozo you can do the same exploratory analysis, what is the distribution of values, how are the columns correlated, etc.
except now you also have graph algorithms that you can * In Cozo you can do the same exploratory analysis,
easily apply to understand things such as: what is the most _connected_ entity, except now you also have graph algorithms that you can
how are the nodes connected, and what are the _communities_ structure within the nodes. easily apply to understand things such as: what is the most _connected_ entity,
how are the nodes connected, and what are the _communities_ structure within the nodes.
* Your data contains hidden structures that only become apparent when you * Your data contains hidden structures that only become apparent when you
identify the _scales_ of the relevant structures. identify the _scales_ of the relevant structures.
* Examples are most real networks, such as social networks, * Examples are most real networks, such as social networks,
which have a very rich hierarchy of structures which have a very rich hierarchy of structures
* In a traditional database, you are limited to doing nested aggregations and filtering, * In a traditional database, you are limited to doing nested aggregations and filtering,
i.e. a form of multifaceted data analysis. For example, you can analyze by gender, geography, i.e. a form of multifaceted data analysis. For example, you can analyze by gender, geography,
job or combinations of them. For structures hidden in other ways, job or combinations of them. For structures hidden in other ways,
or if such categorizing tags are not already present in your data, or if such categorizing tags are not already present in your data,
you are out of luck. you are out of luck.
* With Cozo, you can now deal with emergent and fuzzy structures by using e.g. * With Cozo, you can now deal with emergent and fuzzy structures by using e.g.
community detection algorithms, and collapse the original graph into a coarse-grained community detection algorithms, and collapse the original graph into a coarse-grained
graph consisting of super-nodes and super-edges. graph consisting of super-nodes and super-edges.
The process can be iterated to gain insights into even higher-order emergent structures. The process can be iterated to gain insights into even higher-order emergent structures.
This is possible in a social network with only edges and _no_ categorizing tags This is possible in a social network with only edges and _no_ categorizing tags
associated with nodes at all, associated with nodes at all,
and the discovered structures almost always have meanings correlated to real-world events and and the discovered structures almost always have meanings correlated to real-world events and
organizations, for example, forms of collusion and crime rings. organizations, for example, forms of collusion and crime rings.
Also, from a performance perspective, Also, from a performance perspective,
coarse-graining is a required step in analyzing the so-called big data, coarse-graining is a required step in analyzing the so-called big data,
since many graph algorithms have high complexity and are only applicable to since many graph algorithms have high complexity and are only applicable to
the coarse-grained small or medium networks. the coarse-grained small or medium networks.
* You want to understand your live business data better by augmenting it into a _knowledge graph_. * You want to understand your live business data better by augmenting it into a _knowledge graph_.
* For example, your sales database contains product, buyer, inventory, and invoice tables. * For example, your sales database contains product, buyer, inventory, and invoice tables.
The augmentation is external data about the entities in your data in the form of _taxonomies_ The augmentation is external data about the entities in your data in the form of _taxonomies_
and _ontologies_ in layers. and _ontologies_ in layers.
* This is inherently a graph-theoretic undertaking and traditional databases are not suitable. * This is inherently a graph-theoretic undertaking and traditional databases are not suitable.
Usually, a dedicated graph processing engine is used, separate from the main database. Usually, a dedicated graph processing engine is used, separate from the main database.
* With Cozo, it is possible to keep your live data and knowledge graph analysis together, * With Cozo, it is possible to keep your live data and knowledge graph analysis together,
and importing new external data and doing analysis is just a few lines of code away. and importing new external data and doing analysis is just a few lines of code away.
This ease of use means that you will do the analysis much more often, with a perhaps much wider scope. This ease of use means that you will do the analysis much more often, with a perhaps much wider scope.
## Status of the project ## Status of the project
Cozo is very young and **not** production-ready yet, Cozo is very young and **not** production-ready yet,
but we encourage you to try it out for your use case. but we encourage you to try it out for your use case.
Any feedback is welcome. Any feedback is welcome.
@ -165,26 +190,29 @@ Further down the road:
* More tuning options * More tuning options
* Streaming/reactive data * Streaming/reactive data
* Extension system * Extension system
* The core of Cozo should be kept small at all times. Additional functionalities should be in extensions for the user to choose from. * The core of Cozo should be kept small at all times. Additional functionalities should be in extensions for the
* What can be extended: datatypes, functions, aggregations, and fixed algorithms. user to choose from.
* Extensions should be written in a compiled language such as Rust or C++ and compiled into a dynamic library, to be loaded by Cozo at runtime. * What can be extended: datatypes, functions, aggregations, and fixed algorithms.
* There will probably be a few "official" extension bundles, such as * Extensions should be written in a compiled language such as Rust or C++ and compiled into a dynamic library, to be
* arbitrary precision arithmetic loaded by Cozo at runtime.
* full-text "indexing" and searching * There will probably be a few "official" extension bundles, such as
* relations that can emulate spatial and other types of non-lexicographic indices * arbitrary precision arithmetic
* reading from external databases directly * full-text "indexing" and searching
* more exotic graph algorithms * relations that can emulate spatial and other types of non-lexicographic indices
* reading from external databases directly
* more exotic graph algorithms
Ideas and discussions are welcome. Ideas and discussions are welcome.
## Storage engine ## Storage engine
Cozo is written in Rust, with [RocksDB](http://rocksdb.org/) as the storage engine Cozo is written in Rust, with [RocksDB](http://rocksdb.org/) as the storage engine
(this may change in the future). (this may change in the future).
We manually wrote the C++/Rust bindings for RocksDB with [cxx](https://cxx.rs/). We manually wrote the C++/Rust bindings for RocksDB with [cxx](https://cxx.rs/).
## Licensing ## Licensing
The contents of this project are licensed under AGPL-3.0 or later, except: The contents of this project are licensed under AGPL-3.0 or later, except:
* Files under `cozorocks/` are licensed under MIT, or Apache-2.0, or BSD-3-Clause;
* Files under `cozorocks/`, `python/`, `nodejs/`, `java/` and `c/` are licensed under MIT, or Apache-2.0, or BSD-3-Clause;
* Files under `docs/` are licensed under CC BY-SA 4.0. * Files under `docs/` are licensed under CC BY-SA 4.0.

@ -6,6 +6,10 @@ edition = "2021"
[lib] [lib]
crate-type = ["cdylib", "staticlib"] crate-type = ["cdylib", "staticlib"]
[features]
jemalloc = ["cozo/jemalloc"]
io-uring = ["cozo/io-uring"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]

@ -39,7 +39,7 @@ bool cozo_close_db(int32_t id);
/** /**
* Run query against a database. * Run query against a database.
* *
* `db_id`: the ID representing the database to run the query. * `db_id`: the ID representing the database to run the query.
* `script_raw`: a UTF-8 encoded C-string for the CozoScript to execute. * `script_raw`: a UTF-8 encoded C-string for the CozoScript to execute.
* `params_raw`: a UTF-8 encoded C-string for the params of the query, * `params_raw`: a UTF-8 encoded C-string for the params of the query,
* in JSON format. You must always pass in a valid JSON map, * in JSON format. You must always pass in a valid JSON map,

@ -6,6 +6,10 @@ edition = "2021"
[lib] [lib]
crate-type = ["cdylib"] crate-type = ["cdylib"]
[features]
jemalloc = ["cozo/jemalloc"]
io-uring = ["cozo/io-uring"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]

Binary file not shown.

After

Width:  |  Height:  |  Size: 107 KiB

@ -10,6 +10,10 @@ exclude = ["index.node"]
[lib] [lib]
crate-type = ["cdylib"] crate-type = ["cdylib"]
[features]
jemalloc = ["cozo/jemalloc"]
io-uring = ["cozo/io-uring"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]

@ -8,8 +8,12 @@ edition = "2021"
name = "cozo_py_module" name = "cozo_py_module"
crate-type = ["cdylib"] crate-type = ["cdylib"]
[features]
jemalloc = ["cozo/jemalloc"]
io-uring = ["cozo/io-uring"]
[dependencies] [dependencies]
pyo3 = { version = "0.17.1", features = ["extension-module"] } pyo3 = { version = "0.17.1", features = ["extension-module", "abi3", "abi3-py37"] }
cozo = { version = "0.1.1", path = ".." } cozo = { version = "0.1.1", path = ".." }
miette = { version = "=5.3.0", features = ["fancy"] } miette = { version = "=5.3.0", features = ["fancy"] }
serde_json = "1.0.81" serde_json = "1.0.81"

@ -10,8 +10,6 @@ use pyo3::prelude::*;
use cozo::Db; use cozo::Db;
#[pyclass(extends=PyException)]
struct ErrorBridge(cozo::Error);
trait PyResultExt<T> { trait PyResultExt<T> {
fn into_py_res(self) -> PyResult<T>; fn into_py_res(self) -> PyResult<T>;
} }
@ -50,6 +48,5 @@ impl CozoDbPy {
#[pymodule] #[pymodule]
fn cozo_py_module(_py: Python<'_>, m: &PyModule) -> PyResult<()> { fn cozo_py_module(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
m.add_class::<CozoDbPy>()?; m.add_class::<CozoDbPy>()?;
m.add_class::<ErrorBridge>()?;
Ok(()) Ok(())
} }

Loading…
Cancel
Save