Code Monkey home page Code Monkey logo

sqlness's Introduction

HoraeDB

License CI OpenIssue HoraeDB Docker HoraeMeta Docker

δΈ­ζ–‡

Apache HoraeDB (incubating) is a high-performance, distributed, cloud native time-series database.

Important

Apache HoraeDB (incubating) is an effort undergoing incubation at the Apache Software Foundation (ASF), sponsored by the Apache Incubator PMC.

Please read the DISCLAIMER and a full explanation of "incubating".

Documentation

Quick Start

Run with Docker

Run HoraeDB standalone Server

docker run -d --name horaedb-server \
  -p 8831:8831 \
  -p 3307:3307 \
  -p 5440:5440 \
  ghcr.io/apache/horaedb-server:nightly-20231222-f57b3827

Run HoraeDB cluster with two horaedb-server node and one horaemeta-server node.

docker compose -f docker/docker-compose.yaml up

Run from source code

See details here.

Create Table and Write/Read data

Create Table.

curl --location --request POST 'http://127.0.0.1:5440/sql' \
-d '
CREATE TABLE `demo` (
    `name` string TAG,
    `value` double NOT NULL,
    `t` timestamp NOT NULL,
    timestamp KEY (t))
ENGINE=Analytic
  with
(enable_ttl="false")
'

Write data with SQL.

curl --location --request POST 'http://127.0.0.1:5440/sql' \
-d '
INSERT INTO demo (t, name, value)
    VALUES (1702224000000, "horaedb", 100)
'

Read data with SQL.

curl --location --request POST 'http://127.0.0.1:5440/sql' \
-d '
SELECT * FROM `demo`
'

Drop table.

curl --location --request POST 'http://127.0.0.1:5440/sql' \
-d '
Drop TABLE `demo`
'

Community

Thrive together in Apache HoraeDB (incubating) community with users and developers from all around the world.

Read our Contributing Guide and make your first contribution!

Acknowledgment

When develop we benefit a lot from several other open source projects, such as influxdb_iox, tikv etc, thanks for their awesome work.

License

Apache License 2.0

sqlness's People

Contributors

dependabot[bot] avatar dust1 avatar jiacai2050 avatar lilit0x avatar michaelscofield avatar rishav1707 avatar waynexia avatar

Stargazers

 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

sqlness's Issues

Add default database implementation

Describe This Problem

Target of Sqlness is to ensure SQL's correction of one database, so if a database want to use sqlness, it need to implement Database trait, although this works as expected, this seems a tedious work.

In SQL world, there are only a few wire protocols, such as MySQL or PostgreSQL. If we can supply a default database with MySQL protocols, then any MySQL-compatible databases can use sqlness with less work.

Proposal

Add one default database implementation: MySQL

Additional Context

No response

Support multiple case directories for one environment

Describe This Problem

In current implementation, there is only one case directory allowed for one environment, although this works, but this makes it awkward to share cases between multiple environment.

Proposal

Support multiple case directories

Additional Context

Another solution to this is symlinks, although this works, but I think it's a little ugly.

prettytable-rs: Force cast a &Vec<T> to &[T] may lead to undefined behavior

Describe this problem

Detected by GitHub Dependabot

The earliest fixed version is 0.10.0.

Steps to reproduce

None

Expected behavior

No response

Additional Information

In function Table::as_ref, a reference of vector is force cast to slice. There are multiple problems here:

To guarantee the size is correct, we have to first do Vec::shrink_to_fit. The function requires a mutable reference, so we have to force cast from immutable to mutable, which is undefined behavior (UB).
Even if (1) is sound, &Vec and &[T] still might not have the same layout. Treating them equally may lead to undefinted behavior (UB).

The earliest fixed version is 0.10.0.

Support to variables inside test cases

Describe This Problem

We have a scenario like this:

CREATE EXTERNAL TABLE WITH (LOCATION='/home/data/tests/data/csv/taxi_zone_lookup.csv', FORMAT='csv');

It's trying to create an external file table from an absolute path, specifying the absolute path in the local development environment is acceptable. However, Using the same absolute path in other environments (i.g., CI) will be problematic.

Proposal

Therefore, we can treat the test cases as templates and inject the environment variables at runtime.

I propose a template syntax:

CREATE EXTERNAL TABLE WITH (location='{{$PWD}}/tests/data/csv/taxi_zone_lookup.csv', FORMAT='csv');

it will replace all {{\$.*}} with Env(.*) in a test case file.

Additional Context

No response

Refactor UI to use structured output util

Describe This Problem

Currently sqlness outputs everything with println!. This is hard to maintain.

Proposal

Consider a structured way to organize our outputs. Either using existing util like TestReporter from nextest or wrap our own.

Additional Context

No response

Another way to compare result file

Describe This Problem

In current usage pattern, sqlness will write query response to .out file, and it's used to be compared with corresponding .result, while this works for basic case, it becomes verbose when we change some behaviors of server, and lots of .result file need to be updated ONE AFTER ONE.

Proposal

I suggest another pattern to compare result:

Write query result directly to result file

It works like this

  • When a SQL test file is first added, write result file directly can save us one mv command
  • When execute testcases next time, save original result file in Vec or tempfile before write query response, then compare it with result file,
    • If updated result file is what we expected, just check into git with git add ...
    • if wrong, discard result file with git checkout ..., update testcase and run again

I think this usage pattern is more efficient than before.

Additional Context

No response

Remove tokio dependency

Describe This Problem

In current implementation, sqlness use tokio to do file IO, which is not a requirement, and this cause sqlness to depend on a heavy dependency.

Proposal

Use std to do file IO, and remove hard requirement of tokio.

Additional Context

No response

Implement `TEMPLATE` interceptor

Describe This Problem

It's a bit frustrating when we want to repeat SQL several times. Like insert 100 rows

INSERT INTO t (c) VALUES
(1),
(2),
...
(100);

or query with all the aggregators

SELECT count(c) FROM t;
SELECT avg(c) FROM t;
...

Proposal

Implement a query interceptor that can do this for us. It can automatically replace variables from the given value set. It will looks like

-- SQLNESS TEMPLATE i=0..100
INSERT INTO t (c) VALUES {{i}};
-- SQLNESS TEMPLATE aggr={avg, count, stddev, stdvar, sum}
SELECT {{aggr}}(c) from t;

Additional Context

As @jiacai2050 mentioned in #50 (comment), crate minijinja may help to implement this

Some initial interceptor implementations

Describe This Problem

"Interceptor" is a hook point in sqlness, which allows people to write tests with extra functionality. E.g., provide per-case config, parameterized SQL or resource limitation etc.

Proposal

Some interceptable points I can think of are:

  • before query execution
  • after query execution
  • before one .sql file start

And I plan to add one simple interceptor implementation for each point as an example, and to see if this mechanism actually works.

Interceptor Name Stage Description
parameter before execution Allow to pass K-V like parameters as execution context to DB. Some pre-query setting can be done in this way, like query mode (e.g., whether oracle-compatible in MySQL) or current user.
replace-result after execution Allow to modify the query result with sed-like grammar. This is useful when you only care about some parts of the result, or your query will generate some random values.
time-limit file level Limit the total execution time for a .sql case

Additional Context

No response

Add sqlness-cli to run cases for supported database implementation

          https://crates.io/crates/mysql is a popular crates, so we can go with it first.

We can add a feature gate to enable this feature.

By doing this, we can make it easier to get started with sqlness, user only needs to handle the start/stop of their services.

I think we can go further, we can provide a cli for this default server, and let user start/stop service all by themselves, users can execute this cli against their servers directly, something like

sqlness-cli -t mysql -h localhost -p 3306 --case-dir some-directory

We can implement this in two steps, first to add default database implementation, then to add this cli.

Originally posted by @jiacai2050 in #15 (comment)

Support run testcase for only one env

Describe This Problem

In CeresDB, we use docker-compose to setup integration tests for cluster mode, and it requires some additional step to run it correctly.

In local dev, setup those steps is non-trivial, so I prefer to add an option to support run test for only one env.

Proposal

See above

Additional Context

No response

Return RunFailed error

Describe this problem

When cases fail to run, sqlness return 0as the result which means success.
run_env needs to return errors up instead of logging.
Refer to

if let Err(e) = self.run_env(&env, &db).await {
.

Steps to reproduce

  1. Define a wrong case, run sqlness.
  2. echo $? will return 0 while the correct result should be 1.

Expected behavior

No response

Additional Information

No response

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.