Parse 字段 新思路

This commit is contained in:
huangsimin 2020-03-12 16:59:56 +08:00
parent 59b0851e5d
commit a0677f2451

View File

@ -4,6 +4,8 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"sync"
"sync/atomic"
"time" "time"
"github.com/tecbot/gorocksdb" "github.com/tecbot/gorocksdb"
@ -51,20 +53,58 @@ type Metadata struct {
tidCount uint32 // int16 tidCount uint32 // int16
} }
type Field struct { type ValueType int
Key string
ValueType int const (
ID int VT_INT ValueType = 10000 + iota
VT_INT8
VT_INT16
VT_INT32
VT_INT64
)
const (
VT_UINT ValueType = 11000 + iota
VT_UINT8
VT_UINT16
VT_UINT32
VT_UINT64
)
const (
VT_CHAR ValueType = 12000 + iota
VT_VARCHAR
VT_TEXT
)
const (
VT_TIMESTAMP ValueType = 13000 + iota
VT_DATE
)
type Field struct {
Key []byte
VT ValueType
ID uint16
IsIndex bool IsIndex bool
IsUnique bool IsUnique bool
} }
// Parse 从字符串中解析 var a int; a = 0; a < 0 && a > 5 ;
func (field *Field) Parse(code string) {
}
// Table 表结构
type Table struct { type Table struct {
tableLock *sync.Mutex
Name string Name string
Type int Type int
ID uint32 // uint16
ID uint32 // uint16
IsAllKey bool IsAllKey bool
Fields []*Field Fields []*Field
@ -75,17 +115,36 @@ type Table struct {
delCount uint64 delCount uint64
} }
func CreateTable(name string, field []*Field) { // CreateField 创建字段
func (table *Table) CreateField(key []byte, vt ValueType, isIndex bool, isUnique bool) *Field {
table.tableLock.Lock()
defer table.tableLock.Unlock()
field := &Field{}
field.ID = table.fidCount
field.IsIndex = isIndex
field.IsUnique = isUnique
field.Key = key
field.VT = vt
table.fidCount++
return field
}
// CreateTable 创建表
func CreateTable(name string, fields []*Field) {
if _, ok := EDB.TableDict[name]; !ok { if _, ok := EDB.TableDict[name]; !ok {
// ntid := atomic.AddUint32(&EDB.Metadata.tidCount, 1) ntid := atomic.AddUint32(&EDB.Metadata.tidCount, 1)
// table := &Table{Name: name, ID: ntid, Type: 1} table := &Table{Name: name, ID: ntid, Type: 1}
table.Fields = fields
} else { } else {
log.Println("table name is exists") log.Println("table name is exists")
} }
} }
// gson
// OpenDataBase (cf-key.{tableid(2)}{fieldid(2)}) {value}{indexid(6)} = {rowid(6)} (cf-row.{tableid(2)} {row-sharding-id}){rowid(6)} = {values} // OpenDataBase (cf-key.{tableid(2)}{fieldid(2)}) {value}{indexid(6)} = {rowid(6)} (cf-row.{tableid(2)} {row-sharding-id}){rowid(6)} = {values}
func OpenDataBase() (*gorocksdb.DB, []*gorocksdb.ColumnFamilyHandle) { func OpenDataBase() (*gorocksdb.DB, []*gorocksdb.ColumnFamilyHandle) {