mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Thread Owner, UpdatedAt, UpdatedBy through SchemaAPI (#2351)
* Fix "qualifer" misspellings
* Remove `track_existence` and `shard_width` from SHOW TABLES output
* Thread Owner, UpdatedAt, UpdatedBy through SchemaAPI
I took the liberty of renaming "LastUpdatedUser" to "UpdateBy" to align
with "UpdatedAt".
(cherry picked from commit 63cfdb5078)
This commit is contained in:
parent
17188b7a7b
commit
0127147d69
6 changed files with 24 additions and 41 deletions
|
|
@ -13,7 +13,7 @@ import (
|
|||
var _ pilosa.SchemaAPI = (*qualifiedSchemaAPI)(nil)
|
||||
|
||||
// qualifiedSchemaAPI is a wrapper around schemaAPI. It is initialized with a
|
||||
// TableQualifer, and it uses this qualifer to convert between, for example,
|
||||
// TableQualifier, and it uses this qualifer to convert between, for example,
|
||||
// FeatureBase index name (a string) and TableKey. It requires a Schemar to do
|
||||
// that lookup/conversion.
|
||||
type qualifiedSchemaAPI struct {
|
||||
|
|
|
|||
17
dax/table.go
17
dax/table.go
|
|
@ -27,7 +27,7 @@ import (
|
|||
// Table - base Table struct; includes a TableID and a TableName
|
||||
// TableQualifier - combination of OrganizationID and DatabaseID
|
||||
// QualifiedTable - TableQualifier plus a Table
|
||||
// QualifiedTableID - TableQualifer plus a TableID
|
||||
// QualifiedTableID - TableQualifier plus a TableID
|
||||
// TableKey - a string representation of OrganizationID, DatabaseID, and
|
||||
// TableID, which is safe to use as a FeatureBase index name.
|
||||
//
|
||||
|
|
@ -44,7 +44,7 @@ import (
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// TableKeyDelimiter is used to delimit the qualifer elements in the TableKey.
|
||||
// TableKeyDelimiter is used to delimit the qualifier elements in the TableKey.
|
||||
// While it might make more sense to use a pipe ("|") here, we instead use a
|
||||
// double underscore because underscore is one of the few characters allowed by
|
||||
// the FeatureBase index name restrictions, and we double it in a lame attempt
|
||||
|
|
@ -181,7 +181,10 @@ type Table struct {
|
|||
PartitionN int `json:"partitionN"`
|
||||
|
||||
Description string `json:"description,omitempty"`
|
||||
Owner string `json:"owner,omitempty"`
|
||||
CreatedAt int64 `json:"createdAt,omitempty"`
|
||||
UpdatedAt int64 `json:"updatedAt,omitempty"`
|
||||
UpdatedBy string `json:"updatedBy,omitempty"`
|
||||
}
|
||||
|
||||
func (t *Table) Key() TableKey {
|
||||
|
|
@ -219,7 +222,7 @@ func (t *Table) CreateID() (TableID, error) {
|
|||
}
|
||||
|
||||
// NewTable returns a new instance of table with a pseudo-random ID which is
|
||||
// assumed to be unique within the scope of a TableQualifer.
|
||||
// assumed to be unique within the scope of a TableQualifier.
|
||||
func NewTable(name TableName) *Table {
|
||||
return &Table{
|
||||
Name: name,
|
||||
|
|
@ -310,7 +313,7 @@ func (o Tables) Len() int { return len(o) }
|
|||
func (o Tables) Less(i, j int) bool { return o[i].Name < o[j].Name }
|
||||
func (o Tables) Swap(i, j int) { o[i], o[j] = o[j], o[i] }
|
||||
|
||||
// TableQualifierKey is the unique TableQualifer values encoded as a string. The
|
||||
// TableQualifierKey is the unique TableQualifier values encoded as a string. The
|
||||
// current encoding is delimited as `prefix|OrganizationID|DatabaseID` (where
|
||||
// the pipe may be some other delimiter) by the TableQualifier.Key() method.
|
||||
type TableQualifierKey string
|
||||
|
|
@ -360,7 +363,7 @@ type TableQualifier struct {
|
|||
DatabaseID DatabaseID `json:"db-id"`
|
||||
}
|
||||
|
||||
// NewTableQualifier is a helper function used to create a TableQualifer from
|
||||
// NewTableQualifier is a helper function used to create a TableQualifier from
|
||||
// the provided arguments.
|
||||
func NewTableQualifier(orgID OrganizationID, dbID DatabaseID) TableQualifier {
|
||||
return TableQualifier{
|
||||
|
|
@ -454,7 +457,7 @@ func (qtid QualifiedTableID) Key() TableKey {
|
|||
}
|
||||
|
||||
// Equals returns true if `other` is the same as qtid. Note: the `Name` value is
|
||||
// ignored in this comparison; only `TableQualifer` and `ID` are considered.
|
||||
// ignored in this comparison; only `TableQualifier` and `ID` are considered.
|
||||
func (qtid QualifiedTableID) Equals(other QualifiedTableID) bool {
|
||||
if qtid.TableQualifier == other.TableQualifier && qtid.ID == other.ID {
|
||||
return true
|
||||
|
|
@ -491,7 +494,7 @@ func (qt QualifiedTable) String() string {
|
|||
return fmt.Sprintf("%s (%s)", qt.QualifiedID(), qt.Name)
|
||||
}
|
||||
|
||||
// Qualifier returns the TableQualifer portion of the QualifiedTable.
|
||||
// Qualifier returns the TableQualifier portion of the QualifiedTable.
|
||||
func (qt *QualifiedTable) Qualifier() TableQualifier {
|
||||
return qt.TableQualifier
|
||||
}
|
||||
|
|
|
|||
10
schema.go
10
schema.go
|
|
@ -138,7 +138,10 @@ func IndexInfoToTable(ii *IndexInfo) *dax.Table {
|
|||
PartitionN: dax.DefaultPartitionN,
|
||||
|
||||
Description: ii.Options.Description,
|
||||
Owner: ii.Owner,
|
||||
CreatedAt: ii.CreatedAt,
|
||||
UpdatedAt: ii.UpdatedAt,
|
||||
UpdatedBy: ii.LastUpdateUser,
|
||||
}
|
||||
|
||||
// Sort ii.Fields by CreatedAt before adding them to sortedFields.
|
||||
|
|
@ -271,8 +274,11 @@ func TablesToIndexInfos(tbls []*dax.Table) []*IndexInfo {
|
|||
// TableToIndexInfo converts a dax.Table to a featurease.IndexInfo.
|
||||
func TableToIndexInfo(tbl *dax.Table) *IndexInfo {
|
||||
ii := &IndexInfo{
|
||||
Name: string(tbl.Name), // TODO(tlt): this should be TableKey i think
|
||||
CreatedAt: tbl.CreatedAt,
|
||||
Name: string(tbl.Name),
|
||||
Owner: tbl.Owner,
|
||||
CreatedAt: tbl.CreatedAt,
|
||||
UpdatedAt: tbl.UpdatedAt,
|
||||
LastUpdateUser: tbl.UpdatedBy,
|
||||
Options: IndexOptions{
|
||||
Keys: tbl.StringKeys(),
|
||||
TrackExistence: true,
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ func (p *ExecutionPlanner) compileShowTablesStatement(stmt parser.Statement) (ty
|
|||
},
|
||||
&qualifiedRefPlanExpression{
|
||||
tableName: "fb_tables",
|
||||
columnName: "last_updated_user",
|
||||
columnName: "updated_by",
|
||||
columnIndex: 3,
|
||||
dataType: parser.NewDataTypeString(),
|
||||
},
|
||||
|
|
@ -53,26 +53,14 @@ func (p *ExecutionPlanner) compileShowTablesStatement(stmt parser.Statement) (ty
|
|||
},
|
||||
&qualifiedRefPlanExpression{
|
||||
tableName: "fb_tables",
|
||||
columnName: "track_existence",
|
||||
columnName: "keys",
|
||||
columnIndex: 5,
|
||||
dataType: parser.NewDataTypeBool(),
|
||||
},
|
||||
&qualifiedRefPlanExpression{
|
||||
tableName: "fb_tables",
|
||||
columnName: "keys",
|
||||
columnIndex: 6,
|
||||
dataType: parser.NewDataTypeBool(),
|
||||
},
|
||||
&qualifiedRefPlanExpression{
|
||||
tableName: "fb_tables",
|
||||
columnName: "shard_width",
|
||||
columnIndex: 7,
|
||||
dataType: parser.NewDataTypeInt(),
|
||||
},
|
||||
&qualifiedRefPlanExpression{
|
||||
tableName: "fb_tables",
|
||||
columnName: "description",
|
||||
columnIndex: 8,
|
||||
columnIndex: 6,
|
||||
dataType: parser.NewDataTypeString(),
|
||||
}}
|
||||
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ func (p *PlanOpFeatureBaseTables) Schema() types.Schema {
|
|||
},
|
||||
&types.PlannerColumn{
|
||||
RelationName: "fb_tables",
|
||||
ColumnName: "last_updated_user",
|
||||
ColumnName: "updated_by",
|
||||
Type: parser.NewDataTypeString(),
|
||||
},
|
||||
&types.PlannerColumn{
|
||||
|
|
@ -76,21 +76,11 @@ func (p *PlanOpFeatureBaseTables) Schema() types.Schema {
|
|||
ColumnName: "created_at",
|
||||
Type: parser.NewDataTypeTimestamp(),
|
||||
},
|
||||
&types.PlannerColumn{
|
||||
RelationName: "fb_tables",
|
||||
ColumnName: "track_existence",
|
||||
Type: parser.NewDataTypeBool(),
|
||||
},
|
||||
&types.PlannerColumn{
|
||||
RelationName: "fb_tables",
|
||||
ColumnName: "keys",
|
||||
Type: parser.NewDataTypeBool(),
|
||||
},
|
||||
&types.PlannerColumn{
|
||||
RelationName: "fb_tables",
|
||||
ColumnName: "shard_width",
|
||||
Type: parser.NewDataTypeInt(),
|
||||
},
|
||||
&types.PlannerColumn{
|
||||
RelationName: "fb_tables",
|
||||
ColumnName: "description",
|
||||
|
|
@ -129,9 +119,7 @@ func (i *showTablesRowIter) Next(ctx context.Context) (types.Row, error) {
|
|||
i.indexInfo[i.rowIndex].Owner,
|
||||
i.indexInfo[i.rowIndex].LastUpdateUser,
|
||||
tm.Format(time.RFC3339),
|
||||
i.indexInfo[i.rowIndex].Options.TrackExistence,
|
||||
i.indexInfo[i.rowIndex].Options.Keys,
|
||||
i.indexInfo[i.rowIndex].ShardWidth,
|
||||
i.indexInfo[i.rowIndex].Options.Description,
|
||||
}
|
||||
i.rowIndex += 1
|
||||
|
|
|
|||
|
|
@ -172,11 +172,9 @@ func TestPlanner_Show(t *testing.T) {
|
|||
wireQueryFieldString("_id"),
|
||||
wireQueryFieldString("name"),
|
||||
wireQueryFieldString("owner"),
|
||||
wireQueryFieldString("last_updated_user"),
|
||||
wireQueryFieldString("updated_by"),
|
||||
wireQueryFieldTimestamp("created_at"),
|
||||
wireQueryFieldBool("track_existence"),
|
||||
wireQueryFieldBool("keys"),
|
||||
wireQueryFieldInt("shard_width"),
|
||||
wireQueryFieldString("description"),
|
||||
}, columns); diff != "" {
|
||||
t.Fatal(diff)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue