Giter VIP home page Giter VIP logo

sql2kv's People

Contributors

anxiousmodernman avatar nearhan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

zeropool dulumao

sql2kv's Issues

Profiling tooling

Add this early on so we benefit from it over time. This project pushes a lot of data from network to disk, and holds things in memory to reshape them. Profiling seems worth it.

Build function that maps and builds every MySQL type

We get column types after scanning information_schema. The first place we map those to a go type is here

There are a lot of types to map. We might gather them under a function like:

for _, t := range ts.Columns {
  val, err := mapMySQLType(ts.DataType)
  // check err ...
  newRow = append(newRow, val)
}
rows.Scan(newRow...)

If we encapsulate the different DB's mappings into functions, it will be easier to swap the implementation.

Storing additional metadata

The core function is to dump data, but we might persist additional metadata on a special key path:

/{schema}/{table}/metadata/{something}

Rather than forcing the person querying out k-v store to map a complicated data structure that contains all metadata, we might provide arrays of strings for some things

/{schema}/{table}/metadata/columns - ["id", "name", "age"]
/{schema}/{table}/metadata/types - ["numeric", "string", "numeric"]
//{schema}/{table}/metadata/primary-key - "id"

Set up CI

Travis is free for open source. Does Circle do the same thing?

Function to reflect over newRow and return map[string]interface{}

The JSON serializer knows what to do with a flat map[string]interface{}. We need to switch over the pointer types and dereference the pointers to get values.

Note that we need column names and (optionally) the primary key column name turned into the special __pk key.

Proposed signature:

func derefToMap(cols []string, row []interface{}, pkCol string) map[string]interface{} { /* ... */ }

Document conversion procedures

We have a chain of conversions from SQL to Go types to Key + JSON representation.

MySQL type Go type JSON type Done
text string string YES
binary(n) []byte base64 string NO
varchar(n) string string YES
boolean bool bool YES
timestamp(n) time.Time ISO_8601 string NO
int int64 float64/numeric YES
bigint int64 float64/numeric NO

Nullables

Most regular types, if nullable, will need to map to a custom Go struct that implements the Valuer interface: https://golang.org/pkg/database/sql/driver/#Valuer . There might also be libraries that provide these types.

Edge cases

  • tables without primary keys: what do we do here?

Get Users Table into LevelDB

Still working on the POC.

Take the user table

+----+---------------+-------+
| id | name          | age   |
+----+---------------+-------+
|  1 | Farhan        |    32 |
|  2 | Coleman       |    32 |
|  3 | Jeff May      |    27 |
|  4 | Mr&MissGophie |     1 |
|  5 | Dogs          |   200 |
|  6 | GopherThing   |    20 |
|  7 | Linus Torval  |   100 |
|  8 | Rob Pike      |   100 |
|  9 | NinjaMan      | 23232 |
| 10 | Zack          |    34 |
+----+---------------+-------+

Into a leveldb with something like

<schema>!<table>!<PrimaryKEY>! JSON

Command line interface

We can ship tools under cmd like

sql2kv/cmd/sql2kv  # "real" command line app
sql2kv/cmd/sql2kv-test  # an standalone CLI for benchmarking

Everybody loves the cli framework.

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.