Skip to content

Commit

Permalink
Merge pull request #7 from vahagz/aggregate_feature
Browse files Browse the repository at this point in the history
Aggregate feature
  • Loading branch information
vahagz authored Feb 11, 2024
2 parents 59ba56d + 84468b2 commit ba01966
Show file tree
Hide file tree
Showing 27 changed files with 1,065 additions and 250 deletions.
233 changes: 122 additions & 111 deletions client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func main() {
// id UInt32 AUTO INCREMENT,
// firstname VARCHAR(32),
// lastname VARCHAR(32),
// amount UInt32,
// )
// PRIMARY KEY(id) id,
// INDEX(firstname, lastname) firstname_lastname;
Expand All @@ -106,118 +107,118 @@ func main() {
// setInterval(time.Second, func() {
// fmt.Println(insertId)
// })
// for i := 0; i < 10000; i++ {
// for i := 0; i < 1; i++ {
// rows, err = client.Query([]byte(`
// INSERT INTO testtable (firstname, lastname) VALUES
// ("Vahag", "Zargaryan"),
// ("Ruben", "Manandyan"),
// ("Sergey", "Zargaryan"),
// ("Arman", "Sargsyan"),
// ("Mery", "Voskanyan"),
// ("David", "Harutyunyan"),
// ("Alexader", "Bakunc"),
// ("Hayk", "Vardanyan"),
// ("Serob", "Gevorgyan"),
// ("Gevorg", "Aznauryan"),
// INSERT INTO testtable (firstname, lastname, amount) VALUES
// ("Vahag", "Zargaryan", 10),
// ("Ruben", "Manandyan", 30),
// ("Sergey", "Zargaryan", 50),
// ("Arman", "Sargsyan", 20),
// ("Mery", "Voskanyan", 40),
// ("David", "Harutyunyan", 60),
// ("Alexader", "Bakunc", 30),
// ("Hayk", "Vardanyan", 80),
// ("Serob", "Gevorgyan", 70),
// ("Gevorg", "Aznauryan", 20),

// ("Vahag", "Zargaryan"),
// ("Ruben", "Manandyan"),
// ("Sergey", "Zargaryan"),
// ("Arman", "Sargsyan"),
// ("Mery", "Voskanyan"),
// ("David", "Harutyunyan"),
// ("Alexader", "Bakunc"),
// ("Hayk", "Vardanyan"),
// ("Serob", "Gevorgyan"),
// ("Gevorg", "Aznauryan"),
// ("Vahag", "Zargaryan", 10),
// ("Ruben", "Manandyan", 30),
// ("Sergey", "Zargaryan", 50),
// ("Arman", "Sargsyan", 20),
// ("Mery", "Voskanyan", 40),
// ("David", "Harutyunyan", 60),
// ("Alexader", "Bakunc", 30),
// ("Hayk", "Vardanyan", 80),
// ("Serob", "Gevorgyan", 70),
// ("Gevorg", "Aznauryan", 20),

// ("Vahag", "Zargaryan"),
// ("Ruben", "Manandyan"),
// ("Sergey", "Zargaryan"),
// ("Arman", "Sargsyan"),
// ("Mery", "Voskanyan"),
// ("David", "Harutyunyan"),
// ("Alexader", "Bakunc"),
// ("Hayk", "Vardanyan"),
// ("Serob", "Gevorgyan"),
// ("Gevorg", "Aznauryan"),
// ("Vahag", "Zargaryan", 10),
// ("Ruben", "Manandyan", 30),
// ("Sergey", "Zargaryan", 50),
// ("Arman", "Sargsyan", 20),
// ("Mery", "Voskanyan", 40),
// ("David", "Harutyunyan", 60),
// ("Alexader", "Bakunc", 30),
// ("Hayk", "Vardanyan", 80),
// ("Serob", "Gevorgyan", 70),
// ("Gevorg", "Aznauryan", 20),

// ("Vahag", "Zargaryan"),
// ("Ruben", "Manandyan"),
// ("Sergey", "Zargaryan"),
// ("Arman", "Sargsyan"),
// ("Mery", "Voskanyan"),
// ("David", "Harutyunyan"),
// ("Alexader", "Bakunc"),
// ("Hayk", "Vardanyan"),
// ("Serob", "Gevorgyan"),
// ("Gevorg", "Aznauryan"),
// ("Vahag", "Zargaryan", 10),
// ("Ruben", "Manandyan", 30),
// ("Sergey", "Zargaryan", 50),
// ("Arman", "Sargsyan", 20),
// ("Mery", "Voskanyan", 40),
// ("David", "Harutyunyan", 60),
// ("Alexader", "Bakunc", 30),
// ("Hayk", "Vardanyan", 80),
// ("Serob", "Gevorgyan", 70),
// ("Gevorg", "Aznauryan", 20),

// ("Vahag", "Zargaryan"),
// ("Ruben", "Manandyan"),
// ("Sergey", "Zargaryan"),
// ("Arman", "Sargsyan"),
// ("Mery", "Voskanyan"),
// ("David", "Harutyunyan"),
// ("Alexader", "Bakunc"),
// ("Hayk", "Vardanyan"),
// ("Serob", "Gevorgyan"),
// ("Gevorg", "Aznauryan"),
// ("Vahag", "Zargaryan", 10),
// ("Ruben", "Manandyan", 30),
// ("Sergey", "Zargaryan", 50),
// ("Arman", "Sargsyan", 20),
// ("Mery", "Voskanyan", 40),
// ("David", "Harutyunyan", 60),
// ("Alexader", "Bakunc", 30),
// ("Hayk", "Vardanyan", 80),
// ("Serob", "Gevorgyan", 70),
// ("Gevorg", "Aznauryan", 20),

// ("Vahag", "Zargaryan"),
// ("Ruben", "Manandyan"),
// ("Sergey", "Zargaryan"),
// ("Arman", "Sargsyan"),
// ("Mery", "Voskanyan"),
// ("David", "Harutyunyan"),
// ("Alexader", "Bakunc"),
// ("Hayk", "Vardanyan"),
// ("Serob", "Gevorgyan"),
// ("Gevorg", "Aznauryan"),
// ("Vahag", "Zargaryan", 10),
// ("Ruben", "Manandyan", 30),
// ("Sergey", "Zargaryan", 50),
// ("Arman", "Sargsyan", 20),
// ("Mery", "Voskanyan", 40),
// ("David", "Harutyunyan", 60),
// ("Alexader", "Bakunc", 30),
// ("Hayk", "Vardanyan", 80),
// ("Serob", "Gevorgyan", 70),
// ("Gevorg", "Aznauryan", 20),

// ("Vahag", "Zargaryan"),
// ("Ruben", "Manandyan"),
// ("Sergey", "Zargaryan"),
// ("Arman", "Sargsyan"),
// ("Mery", "Voskanyan"),
// ("David", "Harutyunyan"),
// ("Alexader", "Bakunc"),
// ("Hayk", "Vardanyan"),
// ("Serob", "Gevorgyan"),
// ("Gevorg", "Aznauryan"),
// ("Vahag", "Zargaryan", 10),
// ("Ruben", "Manandyan", 30),
// ("Sergey", "Zargaryan", 50),
// ("Arman", "Sargsyan", 20),
// ("Mery", "Voskanyan", 40),
// ("David", "Harutyunyan", 60),
// ("Alexader", "Bakunc", 30),
// ("Hayk", "Vardanyan", 80),
// ("Serob", "Gevorgyan", 70),
// ("Gevorg", "Aznauryan", 20),

// ("Vahag", "Zargaryan"),
// ("Ruben", "Manandyan"),
// ("Sergey", "Zargaryan"),
// ("Arman", "Sargsyan"),
// ("Mery", "Voskanyan"),
// ("David", "Harutyunyan"),
// ("Alexader", "Bakunc"),
// ("Hayk", "Vardanyan"),
// ("Serob", "Gevorgyan"),
// ("Gevorg", "Aznauryan"),
// ("Vahag", "Zargaryan", 10),
// ("Ruben", "Manandyan", 30),
// ("Sergey", "Zargaryan", 50),
// ("Arman", "Sargsyan", 20),
// ("Mery", "Voskanyan", 40),
// ("David", "Harutyunyan", 60),
// ("Alexader", "Bakunc", 30),
// ("Hayk", "Vardanyan", 80),
// ("Serob", "Gevorgyan", 70),
// ("Gevorg", "Aznauryan", 20),

// ("Vahag", "Zargaryan"),
// ("Ruben", "Manandyan"),
// ("Sergey", "Zargaryan"),
// ("Arman", "Sargsyan"),
// ("Mery", "Voskanyan"),
// ("David", "Harutyunyan"),
// ("Alexader", "Bakunc"),
// ("Hayk", "Vardanyan"),
// ("Serob", "Gevorgyan"),
// ("Gevorg", "Aznauryan"),
// ("Vahag", "Zargaryan", 10),
// ("Ruben", "Manandyan", 30),
// ("Sergey", "Zargaryan", 50),
// ("Arman", "Sargsyan", 20),
// ("Mery", "Voskanyan", 40),
// ("David", "Harutyunyan", 60),
// ("Alexader", "Bakunc", 30),
// ("Hayk", "Vardanyan", 80),
// ("Serob", "Gevorgyan", 70),
// ("Gevorg", "Aznauryan", 20),

// ("Vahag", "Zargaryan"),
// ("Ruben", "Manandyan"),
// ("Sergey", "Zargaryan"),
// ("Arman", "Sargsyan"),
// ("Mery", "Voskanyan"),
// ("David", "Harutyunyan"),
// ("Alexader", "Bakunc"),
// ("Hayk", "Vardanyan"),
// ("Serob", "Gevorgyan"),
// ("Gevorg", "Aznauryan");
// ("Vahag", "Zargaryan", 10),
// ("Ruben", "Manandyan", 30),
// ("Sergey", "Zargaryan", 50),
// ("Arman", "Sargsyan", 20),
// ("Mery", "Voskanyan", 40),
// ("David", "Harutyunyan", 60),
// ("Alexader", "Bakunc", 30),
// ("Hayk", "Vardanyan", 80),
// ("Serob", "Gevorgyan", 70),
// ("Gevorg", "Aznauryan", 20);
// `))
// exitIfErr(errors.Wrap(err, "query failed"))
// for rows.Next() {
Expand All @@ -228,26 +229,27 @@ func main() {

t = time.Now()
rows, err = client.Query([]byte(`
SELECT id, firstname, lastname
SELECT id, COUNT() AS cnt, SUM(amount) AS sumAmount
FROM testtable
WHERE_INDEX id id >= 450000 AND id <= 460000;
WHERE_INDEX id id >= 1 AND id <= 11;
`))
exitIfErr(errors.Wrap(err, "query failed"))
var (
id int
id, cnt, sumAmount int
firstname, lastname string
)
setInterval(time.Second, func() {
fmt.Println(id, firstname, lastname)
})
_, _, _, _, _ = id, cnt, sumAmount, firstname, lastname
// setInterval(time.Second, func() {
// fmt.Println(id, firstname, lastname)
// })
for rows.Next() {
if err := rows.Scan(&id, &firstname, &lastname); err != nil {
if err := rows.Scan(&id, &cnt, &sumAmount); err != nil {
exitIfErr(errors.Wrap(err, "scan failed"))
}
// fmt.Println(id, firstname, lastname)
fmt.Println(id, cnt, sumAmount)
}
fmt.Printf("[select] %v\n", time.Since(t))
fmt.Println(id, firstname, lastname)
// fmt.Println(id, firstname, lastname)

// t = time.Now()
// rows, err = client.Query([]byte(`
Expand Down Expand Up @@ -286,3 +288,12 @@ func setInterval(duration time.Duration, f func()) *time.Ticker {
}()
return t
}

func setTimeout(duration time.Duration, f func()) *time.Ticker {
var t *time.Ticker
t = setInterval(duration, func() {
f()
t.Stop()
})
return t
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/stretchr/testify v1.8.4
github.com/vahagz/bptree v0.0.5-0.20240205141316-d1d09c506382
github.com/vahagz/disk-allocator/heap v0.0.0-20240205141248-c01371e7d1cb
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3
)

require (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ github.com/vahagz/pager v0.0.2-0.20240129094313-d2b541b095ee h1:EDUZbxLxCq9JaPmf
github.com/vahagz/pager v0.0.2-0.20240129094313-d2b541b095ee/go.mod h1:vgo8Osl+QDlL5Ond4RzWHiKPHCo1QAWtj3/gLKMTNrI=
github.com/vahagz/rbtree v0.0.2-0.20240205141227-c534914c07ca h1:/SvNdJfGTO1oxL7WjHdpuAtZXjnY1OZ0D3OcLxLpvVY=
github.com/vahagz/rbtree v0.0.2-0.20240205141227-c534914c07ca/go.mod h1:SXwIaaQV0O5UYbnE0H3rH1HyRjSUO3Ncv40mJDdiJxI=
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 h1:/RIbNt/Zr7rVhIkQhooTxCxFcdWLGIKnZA4IXNFSrvo=
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3/go.mod h1:idGWGoKP1toJGkd5/ig9ZLuPcZBC3ewk7SzmH0uou08=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
Expand Down
30 changes: 26 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,32 @@ var seed = time.Now().UnixMilli()
var rand = r.New(r.NewSource(seed))

func main() {
// pw, _ := os.Getwd()

// p := parser.New()
// e, err := executor.New(path.Join(pw, "test/tables"))
// fatalIfErr(err)

// q, err := p.ParseQuery([]byte(`
// SELECT id, firstname, lastname, COUNT() AS cnt, SUM(amount) AS sumAmount
// FROM testtable
// WHERE_INDEX id id >= 0 AND id <= 11
// GROUP BY id, firstname, lastname;
// `))
// fatalIfErr(err)
// fmt.Println(q)

// r, err := e.Exec(q)
// fatalIfErr(err)
// fmt.Println(r.WriteTo(os.Stdout))

// return

pwd, _ := os.Getwd()
as := auth.New()
ps := parser.New()
es, err := executor.New(path.Join(pwd, "test/tables"))
if err != nil {
fatal(err)
}
fatalIfErr(err)

defer func() {
if err := es.Close(); err != nil {
Expand All @@ -51,7 +70,10 @@ func main() {
}
}

func fatal(val interface{}) {
func fatalIfErr(val interface{}) {
if val == nil {
return
}
fmt.Println(val)
os.Exit(1)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/types/integer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
)

func init() {
numericTypes[TYPE_INTEGER] = struct{}{}

typesMap[TYPE_INTEGER] = newable{
newInstance: func(meta DataTypeMeta) DataType {
m := meta.(*DataTypeINTEGERMeta)
Expand Down
7 changes: 6 additions & 1 deletion pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type newable struct {
}

var typesMap = map[TypeCode]newable{}
var numericTypes = map[TypeCode]struct{}{}

type DataTypeMeta interface {
GetCode() TypeCode
Expand All @@ -34,7 +35,6 @@ type DataType interface {
DataTypeMeta

Bytes() []byte

Value() interface{}
Set(value interface{}) DataType
Fill() DataType
Expand Down Expand Up @@ -69,3 +69,8 @@ func ParseJSONValue(item interface{}) DataType {
}
}
}

func IsNumeric(code TypeCode) bool {
_, ok := numericTypes[code]
return ok
}
Loading

0 comments on commit ba01966

Please sign in to comment.