mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Add Table.Description, Table.CreatedAt, Field.CreatedAt support to SchemaAPI (#2340)
* Thread Table.Description through SchemaAPI * Thread Table.CreatedAt through SchemaAPI * Thread Field.CreatedAt through SchemaAPI
This commit is contained in:
parent
aa2a62fda0
commit
734477aaee
5 changed files with 37 additions and 8 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/molecula/featurebase/v3/dax"
|
||||
"github.com/molecula/featurebase/v3/dax/boltdb"
|
||||
|
|
@ -61,6 +62,18 @@ func (s *Schemar) CreateTable(ctx context.Context, qtbl *dax.QualifiedTable) err
|
|||
return schemar.NewErrInvalidPrimaryKey()
|
||||
}
|
||||
|
||||
// Set the CreateAt value for the table.
|
||||
// TODO(tlt): We may want to consider erroring here if the value is != 0.
|
||||
if qtbl.CreatedAt == 0 {
|
||||
now := timestamp()
|
||||
qtbl.CreatedAt = now
|
||||
|
||||
// Set CreatedAt for all of the fields as well.
|
||||
for i := range qtbl.Fields {
|
||||
qtbl.Fields[i].CreatedAt = now
|
||||
}
|
||||
}
|
||||
|
||||
//////////// end validation
|
||||
|
||||
tx, err := s.db.BeginTx(ctx, true)
|
||||
|
|
@ -384,3 +397,7 @@ func (s *Schemar) TableID(ctx context.Context, qual dax.TableQualifier, name dax
|
|||
|
||||
return s.tableIDByName(tx, qual, name)
|
||||
}
|
||||
|
||||
func timestamp() int64 {
|
||||
return time.Now().UnixNano()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -162,6 +162,9 @@ type Table struct {
|
|||
Name TableName `json:"name,omitempty"`
|
||||
Fields []*Field `json:"fields"`
|
||||
PartitionN int `json:"partitionN"`
|
||||
|
||||
Description string `json:"description,omitempty"`
|
||||
CreatedAt int64 `json:"createdAt,omitempty"`
|
||||
}
|
||||
|
||||
// CreateID generates a unique identifier for Table. If Table has already been
|
||||
|
|
@ -518,6 +521,8 @@ type Field struct {
|
|||
Name FieldName `json:"name"`
|
||||
Type BaseType `json:"type"`
|
||||
Options FieldOptions `json:"options"`
|
||||
|
||||
CreatedAt int64 `json:"createdAt,omitempty"`
|
||||
}
|
||||
|
||||
// String returns the field name as a string.
|
||||
|
|
|
|||
16
schema.go
16
schema.go
|
|
@ -72,6 +72,7 @@ func (s *onPremSchema) CreateTable(ctx context.Context, tbl *dax.Table) error {
|
|||
Keys: keyed,
|
||||
TrackExistence: true,
|
||||
PartitionN: tbl.PartitionN,
|
||||
Description: tbl.Description,
|
||||
}
|
||||
|
||||
// Add the index.
|
||||
|
|
@ -135,6 +136,9 @@ func IndexInfoToTable(ii *IndexInfo) *dax.Table {
|
|||
Name: dax.TableName(ii.Name),
|
||||
Fields: make([]*dax.Field, 0, len(ii.Fields)+1), // +1 to account for the _id field
|
||||
PartitionN: dax.DefaultPartitionN,
|
||||
|
||||
Description: ii.Options.Description,
|
||||
CreatedAt: ii.CreatedAt,
|
||||
}
|
||||
|
||||
// // sortedFields will contain the sorted list of fields from IndexInfo.
|
||||
|
|
@ -154,8 +158,9 @@ func IndexInfoToTable(ii *IndexInfo) *dax.Table {
|
|||
idType = dax.BaseTypeString
|
||||
}
|
||||
tbl.Fields = append(tbl.Fields, &dax.Field{
|
||||
Name: "_id",
|
||||
Type: idType,
|
||||
Name: "_id",
|
||||
Type: idType,
|
||||
CreatedAt: ii.CreatedAt,
|
||||
})
|
||||
|
||||
// Populate the rest of the fields.
|
||||
|
|
@ -243,6 +248,8 @@ func FieldInfoToField(fi *FieldInfo) *dax.Field {
|
|||
TTL: fo.TTL,
|
||||
ForeignIndex: foreignIndex,
|
||||
},
|
||||
|
||||
CreatedAt: fi.CreatedAt,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -271,10 +278,11 @@ func TablesToIndexInfos(tbls []*dax.Table) []*IndexInfo {
|
|||
func TableToIndexInfo(tbl *dax.Table) *IndexInfo {
|
||||
ii := &IndexInfo{
|
||||
Name: string(tbl.Name), // TODO(tlt): this should be TableKey i think
|
||||
CreatedAt: 0,
|
||||
CreatedAt: tbl.CreatedAt,
|
||||
Options: IndexOptions{
|
||||
Keys: tbl.StringKeys(),
|
||||
TrackExistence: true,
|
||||
Description: tbl.Description,
|
||||
},
|
||||
ShardWidth: ShardWidth,
|
||||
}
|
||||
|
|
@ -320,7 +328,7 @@ func FieldToFieldInfo(fld *dax.Field) *FieldInfo {
|
|||
|
||||
return &FieldInfo{
|
||||
Name: string(fld.Name),
|
||||
CreatedAt: 0, // TODO(tlt): we need to handle this on MDS schemar
|
||||
CreatedAt: fld.CreatedAt,
|
||||
Options: FieldOptions{
|
||||
Type: fieldToFieldType(fld),
|
||||
Base: base,
|
||||
|
|
|
|||
|
|
@ -128,10 +128,10 @@ func (i *createTableRowIter) Next(ctx context.Context) (types.Row, error) {
|
|||
// TODO(tlt): once we can support different partitionN's per table,
|
||||
// replace dax.DefaultPartitionN with i.keyPartitions.
|
||||
PartitionN: dax.DefaultPartitionN,
|
||||
// TODO(tlt): add Description to dax.Table; = i.description
|
||||
|
||||
Description: i.description,
|
||||
}
|
||||
|
||||
// TODO (pok) add ability to add description here
|
||||
if err := i.planner.schemaAPI.CreateTable(ctx, tbl); err != nil {
|
||||
if _, ok := errors.Cause(err).(pilosa.ConflictError); ok {
|
||||
if i.failIfExists {
|
||||
|
|
|
|||
|
|
@ -154,8 +154,7 @@ func (i *showColumnsRowIter) Next(ctx context.Context) (types.Row, error) {
|
|||
if i.rowIndex < len(i.tbl.Fields) {
|
||||
fields := i.tbl.Fields
|
||||
|
||||
//tm := time.Unix(0, fields[i.rowIndex].CreatedAt)
|
||||
tm := time.Unix(0, 0)
|
||||
tm := time.Unix(0, fields[i.rowIndex].CreatedAt)
|
||||
|
||||
row := []interface{}{
|
||||
fields[i.rowIndex].Name,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue