Commit graph

891 commits

Author SHA1 Message Date
Richard Newman
70e5759b5f Ensure that variable bindings are used when selecting a table. r=nalexander,etoop
For queries like

```edn
[:find ?x :where [?x _ "hello"]]
[:find [?v ...] :where [_ ?a ?v]]
```

we'll query `all_datoms` to handle fulltext strings, which is expensive.

If `?a` is bound, we can avoid this — resolve any keyword binding,
ensure that the value is an attribute, and use the appropriate table.
2017-03-14 13:47:22 +00:00
Richard Newman
dc6a7a4128 Add a VSCode test configuration for cargo test --all. 2017-03-13 16:56:23 +00:00
Emily Toop
fddc57d548 Use sqlite3_limit instead of hard-coded SQLITE_MAX_VARIABLE_NUMBER (#371) (#288) r=rnewman
* Part 1: added limits feature to rusqlite dependencies.
* Part 2: replace references to SQLITE_MAX_VARIABLE_NUMBER with sqlite3_limit.
* Move assertion check for correct number of variables in repeat_values to before call as this is where the variable is defined.
* Part 3: add tests
2017-03-13 09:39:19 -07:00
Richard Newman
6109a63249 Support input bindings in ConjoiningClauses. r=nalexander 2017-03-10 19:01:56 -08:00
Richard Newman
914902cf9e Ignore build output in VSCode. 2017-03-09 16:36:06 -08:00
Richard Newman
30804e033a Use rusqlite 0.10.1. (#367) r=nalexander 2017-03-09 12:30:36 -08:00
Richard Newman
39440895ab Add basic VSCode file ignore settings. 2017-03-09 11:31:04 -08:00
Richard Newman
77f7fab525 Tweak testing commands. 2017-03-09 09:00:46 -08:00
Richard Newman
bf38105fef (#362) Part 4: handle unknown attributes by expanding type codes. r=nalexander
Also, don't run any SQL at all if an algebrized query is known to return no results.
2017-03-08 17:44:27 -08:00
Richard Newman
b5867e9131 (#362) Part 3: implement querying against simple keywords. r=nalexander 2017-03-08 17:44:19 -08:00
Richard Newman
ce3a9bdf87 (#362) Part 2: use constrain_attribute. r=nalexander 2017-03-08 17:44:11 -08:00
Richard Newman
8935d6a8a5 (#362) Part 1: if a variable's type becomes known, don't extract it. r=nalexander
This is necessary because we process patterns sequentially; a later
pattern might tell us the type of a variable (e.g., by having a
constant attribute), at which point we can do less work.
2017-03-08 17:44:00 -08:00
Richard Newman
1961815acd Pre: add an interpose macro for SQL output. 2017-03-08 17:41:50 -08:00
Richard Newman
7bcf311db9 Pre: move SQLValueType to core, because it's so central.
Yes, this isn't tidy... but in order to be really tidy we'd need to
split up db into parts that don't depend on a particular SQLite library.
2017-03-08 17:41:49 -08:00
Richard Newman
e898df8842 Implement basic query limits. (#361) r=nalexander 2017-03-08 17:41:42 -08:00
Richard Newman
85f3b79f75 Support a limited set of '.'-prefixed non-keyword symbols. (#352) r=nalexander
This commit allows `.` and `...` to parse correctly as `PlainSymbol`.

Tests in edn, query-translator, and the top level have been added.
2017-03-06 15:01:19 -08:00
Richard Newman
70b112801c Implement projection and querying. (#353) r=nalexander
* Add a failing test for EDN parsing '…'.
* Expose a SQLValueType trait to get value_type_tag values out of a ValueType.
* Add accessors to FindSpec.
* Implement querying.
* Implement rudimentary projection.
* Export mentat_db::new_connection.
* Export symbols from mentat.
* Add rudimentary end-to-end query tests.
2017-03-06 14:40:10 -08:00
Nick Alexander
f86b24001f Add top-level Conn. Fixes #296. (#342) r=rnewman
* Add top-level `Conn`. Fixes #296.

This is a little different than the API rnewman and I originally
discussed in https://public.etherpad-mozilla.org/p/db-conn-thoughts.
A few notes:

- I was led to make a `Schema` instance the thing that is shared,
  rather than a `db::DB`.  It's possible that queries will want to
  know the current transaction at some point (to prevent races, or to
  query historical data), but that can be a future consideration.

- The generation number just allows for a cheap comparison.  I don't
  care to handle races to transact just yet; the long term plan might
  be to make embedding applications responsible for avoiding races, or
  we might handle queuing transactions and yielding report futures in
  Mentat itself.

- The sharing of the partition maps is a little more subtle than
  expected.  Partition maps are volatile: a successful Mentat
  transaction always advances the :db.part/tx partition, so it's not
  worth passing references around.  This means that consumers must
  clone in order to maintain just a single clone per transaction.

Clean some cruft.

* Review comments.
2017-03-03 15:03:59 -08:00
Richard Newman
ecf56395b9 Add discussion of storage difficulties. r=nalexander (#344)
* Add discussion of storage difficulties.

* Replace mention of MVP with discussion of initial requirements.
2017-02-27 16:19:23 -08:00
Richard Newman
d7f323d15d Wire in the start of querying and error_chain at top level. (#349) r=nalexander 2017-02-27 16:17:25 -08:00
Richard Newman
48312e1ff0 Rebased conversion of mentat_query_parser to use error-chain. r=nalexander
This is a tiny bit simpler and more consistent.
2017-02-27 16:16:54 -08:00
Richard Newman
b2f22952c1 Convert mentat_sql to use error-chain. r=nalexander 2017-02-27 16:16:49 -08:00
Nick Alexander
dcd9bcb1ce Extract partial storage abstraction; use error-chain throughout. Fixes #328. r=rnewman (#341)
* Pre: Drop unneeded tx0 from search results.

* Pre: Don't require a schema in some of the DB code.

The idea is to separate the transaction applying code, which is
schema-aware, from the concrete storage code, which is just concerned
with getting bits onto disk.

* Pre: Only reference Schema, not DB, in debug module.

This is part of a larger separation of the volatile PartitionMap,
which is modified every transaction, from the stable Schema, which is
infrequently modified.

* Pre: Fix indentation.

* Extract part of DB to new SchemaTypeChecking trait.

* Extract part of DB to new PartitionMapping trait.

* Pre: Don't expect :db.part/tx partition to advance when tx fails.

This fails right now, because we allocate tx IDs even when we shouldn't.

* Sketch a db interface without DB.

* Add ValueParseError; use error-chain in tx-parser.

This can be simplified when
https://github.com/Marwes/combine/issues/86 makes it to a published
release, but this unblocks us for now.  This converts the `combine`
error type `ParseError<&'a [edn::Value]>` to a type with owned
`Vec<edn::Value>` collections, re-using `edn::Value::Vector` for
making them `Display`.

* Pre: Accept Borrow<Schema> instead of just &Schema in debug module.

This makes it easy to use Rc<Schema> or Arc<Schema> without inserting
&* sigils throughout the code.

* Use error-chain in query-parser.

There are a few things to point out here:

- the fine grained error types have been flattened into one crate-wide
  error type; it's pretty easy to regain the granularity as needed.

- edn::ParseError is automatically lifted to
  mentat_query_parser::errors::Error;

- we use mentat_parser_utils::ValueParser to maintain parsing error
  information from `combine`.

* Patch up top-level.

* Review comment: Only `borrow()` once.
2017-02-24 15:33:48 -08:00
Richard Newman
5e3cdd1fc2 Implement query-translator. (#301) r=nalexander 2017-02-23 18:39:49 -08:00
Richard Newman
91c75f26c8 Expand query algebrizer. r=nalexander 2017-02-23 18:39:49 -08:00
Richard Newman
76f51015d9 Support accumulating TypedValue instances into a SQL query. (#339) r=nalexander
These expand into a collection of named variables that should be
passed via bind parameters when the query is executed.

Bind parameters are now only named.
2017-02-23 18:39:43 -08:00
Richard Newman
b0120aa446 Pre: fix query/Cargo.toml indenting. 2017-02-23 18:31:57 -08:00
Richard Newman
14972fa6d7 Pre: use Option::cloned() instead of a cloning closure. 2017-02-23 18:31:54 -08:00
Joe Walker
40bca2df6d Remove most uses of use foo::* 2017-02-23 14:09:54 +00:00
Joe Walker
60b2e6f885 Improve Debug output for ConjoiningClauses; r=rnewman
Fixes #317, and also removes the '::' exploration of rust style
2017-02-23 14:05:56 +00:00
Victor Porof
7fc2a22d68 Implement a basic edn matcher, r=ncalexan (#271) (#338)
Signed-off-by: Victor Porof <victor.porof@gmail.com>
2017-02-23 09:11:34 +01:00
Victor Porof
bf707acbc3 Lint for the clippy gods in the edn crate (#340)
Signed-off-by: Victor Porof <victor.porof@gmail.com>
2017-02-22 18:11:05 +01:00
Victor Porof
0d3b8e4b29 Avoid code duplication for common Value trait implementations, r=ncalexan
Signed-off-by: Victor Porof <victor.porof@gmail.com>
2017-02-22 08:36:45 +01:00
Victor Porof
1b26e23d02 Implement edn pretty printing using pretty.rs. Fixes #195. (#245)
* Implement pretty printing

Signed-off-by: Victor Porof <victor.porof@gmail.com>

* Rewrite pretty printing.

This does a few things.  First, it use pretty.rs directly, without the
layer of macro obfuscation.  The code is significantly simpler as a
result.

Second, it tightens the layout, using pretty.rs to group nested
layouts that fit on a single line.  This is Clojure's EDN style, more
or less.

Third, it drops "special format" support for queries.  This wasn't
completely implemented; if we want it, we can newtype
Query(edn::Value) and figure out how to really implement this idea.

* Rename to reflect functionality.

* Make write interface more Rust-like.

There isn't a clear standard in the stdlib, but a function that takes
ownership of a writer and then returns it back is definitely not
Rust-like.  That's what a (mutable) reference is for.

* Review comment: Use as_ref to avoid cloning strings.

* Post: Fix tests to use `without_spans()`.
2017-02-21 11:48:08 -08:00
Richard Newman
7476d0c0c8 More Rust notes. 2017-02-21 10:45:21 -08:00
Richard Newman
e18a0e9fdc Discuss Rust contributions. 2017-02-21 10:43:36 -08:00
Richard Newman
6fa907d2df Simplify .travis.yml to use cargo test --all. 2017-02-20 11:04:18 -08:00
Richard Newman
a10f68fdb7 Mark every project as being part of the workspace. r=nalexander
This allows `cargo test --all` to work.
2017-02-20 11:04:08 -08:00
Richard Newman
42ae26ab46 Add new stuff to Travis. 2017-02-17 17:54:35 -08:00
Richard Newman
9ecd02ef95 Begin serializing queries to SQL. r=nalexander 2017-02-17 17:54:07 -08:00
Richard Newman
a9cd9b1e87 Export symbols and string helpers from mentat_query_algebrizer. 2017-02-17 17:54:07 -08:00
Richard Newman
f890995202 Add a rudimentary SQL builder, based on parts of Diesel. (#273) r=nalexander
https://github.com/diesel-rs/diesel/
2017-02-17 17:53:50 -08:00
Jordan Santell
bc2b2ec4c8 Change to_namespaced_keyword(s) to return a Result rather than Option to (#333)
reduce error handling throughout db code. Fixes #331. r=nalexander
2017-02-17 16:10:34 -08:00
Jordan Santell
6f67f8563b TypedValue::Keyword now wraps a NamespacedKeyword rather than a String. Fixes #203. r=nalexander" (#329) 2017-02-17 14:07:57 -08:00
Jordan Santell
a59f9583ac Store Idents as NamespacedKeywords, rather than Strings. Fixes #291. (#300)
r=ncalexander
2017-02-17 13:55:36 -08:00
Jordan Santell
ec2bbb8e83 Ensure minimum rustc version in a build script. r=nalexander (#326)
Printing out failure to meet rustc version helps users during
setup with a helpful message if using an older rustc.
Rust version checking from http://stackoverflow.com/a/36607492.
2017-02-17 12:04:45 -08:00
Victor Porof
896d7f8f88 Add a span component to edn::Value, r=ncalexan
Signed-off-by: Victor Porof <victor.porof@gmail.com>
2017-02-17 18:31:26 +01:00
Joe Walker
d9b699b588 Fix the authors entry in Cargo.toml (#322) 2017-02-17 08:03:48 +01:00
Joe Walker
89949fb451 Update README for edn; r=me 2017-02-16 18:32:36 +00:00
Richard Newman
5af7082165 Partly flesh out query algebrizer. (#243) r=nalexander 2017-02-15 16:10:59 -08:00