Hello CrateΒΆ

To get started let’s have a quick look on how Crate can be used. This tutorial uses the crash command-line SQL shell shipped with the Crate distribution.

sh$ ./bin/crash

First let’s connect to a running node:

cr> \connect 127.0.0.1:4200;
+------------------------+-----------+---------+-----------+---------+
| server_url             | node_name | version | connected | message |
+------------------------+-----------+---------+-----------+---------+
| http://127.0.0.1:...   | crate     | ...     | TRUE      | OK      |
+------------------------+-----------+---------+-----------+---------+
CONNECT OK
...

In this guide we want to create a database for Twitter tweets. Let’s create the table tweets with all columns we need:

cr> create table tweets (
...   created_at timestamp,
...   id string primary key,
...   retweeted boolean,
...   source string INDEX using fulltext,
...   text string INDEX using fulltext,
...   user_id string
... );
CREATE OK (... sec)

Now we are ready to insert our first tweet:

cr> insert into tweets
... values (1394182937, '1', true, 'web', 'Don''t panic', 'Douglas');
INSERT OK, 1 row affected (... sec)

And another:

cr> insert into tweets
... values (
...     1394182938,
...     '2',
...     true,
...    'web',
...    'Time is an illusion. Lunchtime doubly so',
...    'Ford'
... );
INSERT OK, 1 row affected (... sec)

In order to query the inserted tweets the SELECT statement can be used. Here it is used with a filter to only lookup Ford’s tweets:

cr> select * from tweets where id = '2';
+------------+----+-----------+--------+-------------------------...-+---------+
| created_at | id | retweeted | source | text                        | user_id |
+------------+----+-----------+--------+-------------------------...-+---------+
| 1394182938 | 2  | TRUE      | web    | Time is an illusion. Lun... | Ford    |
+------------+----+-----------+--------+-------------------------...-+---------+
SELECT 1 row in set (... sec)

See also

Data Definition - To see what options the create table statement supports and to learn more about sharding and replication.

Data Manipulation - In order to learn how to import, export, insert, update or delete records.

Querying Crate - Filtering, ordering, grouping and powerful fulltext search. Learn how to find your data.

Configuration - After you’re done trying out Crate and before you go into production you should take a look at this section. Especially the CRATE_HEAP_SIZE environment variable is very important!