Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Executor #6

Merged
merged 32 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
26472a5
executor implementation
vahagz Jan 17, 2024
0e39a93
insert parsing and executing
vahagz Jan 18, 2024
8c22d2e
bptree update
vahagz Jan 18, 2024
eb4d0f1
minor
vahagz Jan 19, 2024
34a3fe7
go version 1.21
vahagz Jan 19, 2024
acf1e97
ignore go.work
vahagz Jan 19, 2024
e0aea89
minor
vahagz Jan 19, 2024
061bac0
dep update
vahagz Jan 20, 2024
0f3d8a2
all submodules in pkg folder
vahagz Jan 20, 2024
198a70d
rbree update
vahagz Jan 20, 2024
30730aa
dep update
vahagz Jan 20, 2024
0f8a71d
Merge branch 'master' of github.com:vahagz/go-dbms into executor
vahagz Jan 20, 2024
48af57d
upgrade
vahagz Jan 22, 2024
09cb823
upgrade
vahagz Jan 22, 2024
e94ffce
upgrade
vahagz Jan 22, 2024
b48a6ae
submodules removed
vahagz Jan 23, 2024
1b289ff
submodules added
vahagz Jan 23, 2024
eb79da1
upgrade
vahagz Jan 23, 2024
f23d160
command logs
vahagz Jan 23, 2024
1715cf5
'bptree, disk-allocator/heap, rbtree, pager' dependencies upgrade
vahagz Jan 23, 2024
5e922cb
submodules
vahagz Jan 23, 2024
223556b
minor
vahagz Jan 23, 2024
64fbea2
scan with filter
vahagz Jan 23, 2024
146ac15
minor
vahagz Jan 23, 2024
88cf566
unexported read method
vahagz Jan 23, 2024
15c9bf8
select dml implemented
vahagz Jan 23, 2024
b1a42ea
'bptree, disk-allocator/heap, rbtree, pager' dependencies upgrade
vahagz Jan 24, 2024
386e57c
buf fix
vahagz Jan 25, 2024
d0bf49f
select dml fixed
vahagz Jan 25, 2024
128795c
return primary key after insertion
vahagz Jan 25, 2024
feccd5f
update implemented
vahagz Jan 25, 2024
d918eb3
delete implemented
vahagz Jan 25, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# vendor/

# Go workspace file
go.work
go.work*


df.dat
Expand Down
15 changes: 14 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
[submodule "pkg/pager"]
path = pkg/pager
url = [email protected]:vahagz/pager.git
branch = main
[submodule "pkg/rbtree"]
path = pkg/rbtree
url = [email protected]:vahagz/rbtree.git
branch = main
[submodule "pkg/disk-allocator"]
path = pkg/disk-allocator
url = [email protected]:vahagz/disk-allocator.git
branch = main
[submodule "pkg/bptree"]
path = pkg/bptree
url = https://github.com/vahagz/bptree
url = [email protected]:vahagz/bptree.git
branch = main
25 changes: 9 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,38 +1,31 @@
module go-dbms

go 1.19

replace (
github.com/vahagz/bptree v0.0.4 => ./pkg/bptree
github.com/vahagz/disk-allocator v0.0.2 => ./pkg/bptree/pkg/disk-allocator
github.com/vahagz/disk-allocator/heap => ./pkg/bptree/pkg/disk-allocator/heap
github.com/vahagz/pager v0.0.1 => ./pkg/bptree/pkg/disk-allocator/pkg/rbtree/pkg/pager
)
go 1.21

require (
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.4
github.com/vahagz/bptree v0.0.4
github.com/vahagz/disk-allocator/heap v0.0.2
github.com/vahagz/bptree v0.0.5-0.20240124142002-30dd773c400b
github.com/vahagz/disk-allocator/heap v0.0.0-20240124141934-a045858da972
github.com/x-cray/logrus-prefixed-formatter v0.5.2
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/edsrzf/mmap-go v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.30.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/vahagz/pager v0.0.1 // indirect
github.com/vahagz/rbtree v0.0.1 // indirect
golang.org/x/crypto v0.16.0 // indirect
github.com/vahagz/pager v0.0.2-0.20240124141821-d9a252b6212b // indirect
github.com/vahagz/rbtree v0.0.2-0.20240124141912-f00f8bc1d2fd // indirect
golang.org/x/crypto v0.18.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/term v0.15.0 // indirect
golang.org/x/term v0.16.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
28 changes: 19 additions & 9 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
Expand All @@ -47,18 +49,24 @@ github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/vahagz/rbtree v0.0.1 h1:KzuuylQPmhoVihSloia+rKWaT0/O0F95VE9QVDLNT5E=
github.com/vahagz/rbtree v0.0.1/go.mod h1:NSKjc5Wet1Vte6ABolDPJD+aKycIUK2ds2eiRfbQ2hE=
github.com/vahagz/bptree v0.0.5-0.20240124142002-30dd773c400b h1:Rb5BM1PcOrrmGDzQQBEbZVKtUxfleKkCnKgVgpw/l+A=
github.com/vahagz/bptree v0.0.5-0.20240124142002-30dd773c400b/go.mod h1:TaFmohHkwMKo2KDta8GjO2/9kgXUymLUbMJjLrxYMAM=
github.com/vahagz/disk-allocator/heap v0.0.0-20240124141934-a045858da972 h1:hUqLijsG0gUp1UETryfS8W9kfaLHX9F3vxoJaHZtbU0=
github.com/vahagz/disk-allocator/heap v0.0.0-20240124141934-a045858da972/go.mod h1:ugD049A8lyp3X8pfphM6NX5L3P3Fit6JGjRs6976ihQ=
github.com/vahagz/pager v0.0.2-0.20240124141821-d9a252b6212b h1:lWKnLH6JUoAP6biMhJRiIjK2yZK/9C6qZU1BIvt3DxE=
github.com/vahagz/pager v0.0.2-0.20240124141821-d9a252b6212b/go.mod h1:46G/eN1+gw4I5FgyY2sIFDgAJuQvwNADs49wTKqfyOk=
github.com/vahagz/rbtree v0.0.2-0.20240124141912-f00f8bc1d2fd h1:8w8so/fqPGMCcdi3mTmxLQfk+vdRS9DrVRXZvgGI6uY=
github.com/vahagz/rbtree v0.0.2-0.20240124141912-f00f8bc1d2fd/go.mod h1:GFnDXpvSJ9DDA/GxpGEZYRggiX80jDn+Ku8Y+jJB23M=
github.com/x-cray/logrus-prefixed-formatter v0.5.2 h1:00txxvfBM9muc0jiLIEAkAcIMJzfthRT6usrui8uGmg=
github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a h1:Q8/wZp0KX97QFTc2ywcOE0YRjZPVIx+MXInMzdvQqcA=
golang.org/x/exp v0.0.0-20240119083558-1b970713d09a/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand All @@ -81,13 +89,15 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0=
golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
Expand Down
226 changes: 199 additions & 27 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
r "math/rand"
"os"
"path"
"time"

"go-dbms/pkg/column"
"go-dbms/pkg/types"
"go-dbms/services/executor"
"go-dbms/services/parser"
"go-dbms/util/response"

"github.com/sirupsen/logrus"
)
Expand All @@ -29,39 +34,194 @@ var rand = r.New(r.NewSource(seed))


func main() {
ps := &parser.ParserServiceT{}
q, err := ps.ParseQuery([]byte(`
{
"type": "SELECT",
"columns": ["c1","c2","c3","c4"],
"db": "test_db",
"table": "test_table",
"where": {
"and": [
{
"statement": {
"column": "c1",
"operator": "=",
"value": "dddd"
}
},
{
"statement": {
"column": "c2",
"operator": ">=",
"value": 100
}
pwd, _ := os.Getwd()
ps := parser.New()
es, err := executor.New(path.Join(pwd, "test/tables"))
if err != nil {
logrus.Fatal(err)
}

defer func() {
if err := es.Close(); err != nil {
fmt.Println(err)
}
}()

q, err := ps.ParseQuery([]byte(`{
"type": "CREATE",
"target": "TABLE",
"name": "testtable",
"columns": [
{
"name": "id",
"type": 0,
"meta": {
"signed": false,
"bit_size": 4,
"auto_increment": {
"enabled": true
}
]
}
},
{
"name": "firstname",
"type": 2,
"meta": {
"cap": 32
}
},
{
"name": "lastname",
"type": 2,
"meta": {
"cap": 32
}
}
],
"indexes": [
{
"name": "id_1",
"columns": [ "id" ],
"primary": true,
"auto_increment": true
},
{
"name": "firstname_lastname_1",
"columns": [ "firstname", "lastname" ]
}
]
}`))
if err != nil {
logrus.Fatal(err)
}
res, err := es.Exec(q)
if err != nil {
logrus.Fatal(err)
}
printResponse(res)


q, err = ps.ParseQuery([]byte(`{
"type": "INSERT",
"table": "testtable",
"columns": [ "firstname", "lastname" ],
"values": [
[ "Vahag", "Zargaryan" ],
[ "Ruben", "Manandyan" ],
[ "Sergey", "Zargaryan" ],
[ "Arman", "Sargsyan" ],
[ "Mery", "Voskanyan" ],
[ "David", "Harutyunyan" ],
[ "Alexader", "Bakunc" ]
]
}`))
if err != nil {
logrus.Fatal(err)
}

res, err = es.Exec(q)
if err != nil {
logrus.Fatal(err)
}
printResponse(res)


q, err = ps.ParseQuery([]byte(`{
"type": "SELECT",
"table": "testtable",
"columns": [ "id", "firstname", "lastname" ]
}`))
if err != nil {
logrus.Fatal(err)
}

res, err = es.Exec(q)
if err != nil {
logrus.Fatal(err)
}
printResponse(res)


q, err = ps.ParseQuery([]byte(`{
"type": "UPDATE",
"table": "testtable",
"values": {
"firstname": "dddddd"
},
"where_index": {
"name": "id_1",
"filter_start": {
"operator": ">=",
"value": {
"id": 4
}
},
"filter_end": {
"operator": "<=",
"value": {
"id": 6
}
}
},
"where": {
"or": [
{
"statement": {
"column": "firstname",
"operator": "=",
"value": "Arman"
}
},
{
"statement": {
"column": "lastname",
"operator": "=",
"value": "Harutyunyan"
}
}
]
}
`))
}`))
if err != nil {
logrus.Fatal(err)
}

res, err = es.Exec(q)
if err != nil {
logrus.Fatal(err)
logrus.Fatal(err)
}
printResponse(res)

b, _ := json.Marshal(q)
fmt.Println(string(b))

q, err = ps.ParseQuery([]byte(`{
"type": "SELECT",
"table": "testtable",
"columns": [ "id", "firstname", "lastname" ]
}`))
if err != nil {
logrus.Fatal(err)
}

res, err = es.Exec(q)
if err != nil {
logrus.Fatal(err)
}
printResponse(res)


q, err = ps.ParseQuery([]byte(`{
"type": "DELETE",
"table": "testtable"
}`))
if err != nil {
logrus.Fatal(err)
}

res, err = es.Exec(q)
if err != nil {
logrus.Fatal(err)
}
printResponse(res)


// logrus.SetLevel(logrus.DebugLevel)
Expand Down Expand Up @@ -727,3 +887,15 @@ func randomString(length int) string {
}
return string(bytes)
}

func printResponse(res io.Reader) {
rr := response.NewReader(res)
for {
msg, err := rr.ReadLine()
fmt.Printf("%v '%s'\n", len(msg), string(msg))
if err != nil {
fmt.Println("error =>", err)
break
}
}
}
2 changes: 1 addition & 1 deletion pkg/bptree
Submodule bptree updated 4 files
+25 −0 .gitignore
+4 −11 go.mod
+6 −0 go.sum
+1 −1 pkg/disk-allocator
1 change: 1 addition & 0 deletions pkg/disk-allocator
Submodule disk-allocator added at a04585
Loading
Loading