Code Monkey home page Code Monkey logo

stellarsql's Introduction

StellarSQL

Build Status codecov

(WIP) A minimal SQL DBMS written in Rust

  • The document is here.
  • There is a slide introduce this project.
  • There is a series of articles introducing about this project: Let's build a DBMS

logo

Setup

Before you start, you need to have Rust(>=1.31) and Cargo.

curl https://sh.rustup.rs -sSf | sh

Then we could get the source code.

git clone https://github.com/tigercosmos/StellarSQL
cd StellarSQL

Run

Server

Open the first window and run server:

cargo run [port]

the default port is 23333, and you can either modify .env or run by argument [port].

Client

Open the another window and run the client by python client/client.py and connect to the server:

command:

> create user <name> <key> # key is our feature, put any number for now
> set user <name> # second time log in
> create database <db_name> # first time create database
> use <db_name> # second time adopt the database
> <query> # now support simple sql

SQL query are not implement very well. A few simple command support for now:

  • create database
  • create table
    • type: int, float, double, varchar, char, url
  • insert into
  • select {fields} from {table} where {predicate}
    • not yet support join, only a table
    • predicate without NULL

The default host and port are 127.0.0.1 and 23333

$ python client/client.py [host] [port]

Connect to 127.0.0.1:23333
== Welcome to StellarSQL Client! ==
StellarSQL> create user Tiger 123
Login OK!

StellarSQL> create database DB1
Query OK!

StellarSQL> create table t1 (a1 int, b1 int, c1 float);
Query OK!

StellarSQL> insert into t1 (a1, b1, c1) values (1, 2, 1.2), (2, 3, 4.5), (4, 1, 0.3);
Query OK!

StellarSQL> select a1, b1, c1 from t1 where a1 > 1;
{"fields":["a1","b1","c1"],"rows":[["2","3","4.5"],["4","1","0.3"]]}

StellarSQL> select a1, b1, c1 from t1 where a1 > 1 and c1 > 2;
{"fields":["a1","b1","c1"],"rows":[["2","3","4.5"]]}

StellarSQL> select a1, b1, c1 from t1 where not (not a1 < 2 and not (not b1 = 3 or c1 > 1.1));
{"fields":["a1","b1","c1"],"rows":[["1","2","1.2"],["2","3","4.5"],["4","1","0.3"]]}

Build

cargo build

Test

Run all tests

cargo test

Debug a test

Add the line at the beginning of the test function.

// init the logger for the test
env_logger::init();

Then run the command to see the debug information:

RUST_LOG=debug cargo test -- --nocapture {test_name}

Pull Request

Install rustfmt, and make sure you could pass:

cargo fmt --all -- --check
cargo build
cargo test

Document

Build and open the document at localhost

cargo rustdoc --open -- --document-private-items

License

MIT

stellarsql's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

stellarsql's Issues

Implement memory pages and write back mechanism

Now we use dirty property to record the status of the SQL object.
The pool stores many SQL, and when the SQL is pop out or the client disconnects the server, the dirty data will write back to storage.

We should rather implement memory pages and manages the pages. Probably use memmap crate.
We should also write back data as soon as possible. The time written back needs discuss.

Use UUID for the key of Field

When there is a join, there might be fields with same name, like t1.a = t2.a. We cannot use field name as the key for hashmap in such condition, so we should replace the key by UUID. Checking the field name only when it needs, and operating data via the UUID.

use uuid

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.