From 0127147d693bad4d1b49bb25c084298af5016d3b Mon Sep 17 00:00:00 2001 From: Travis Turner Date: Mon, 12 Dec 2022 12:36:37 -0600 Subject: [PATCH] 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 63cfdb5078c6739564dc08d7e00bd7291a6d7e20) --- dax/queryer/schema_api.go | 2 +- dax/table.go | 17 ++++++++++------- schema.go | 10 ++++++++-- sql3/planner/compileshow.go | 18 +++--------------- sql3/planner/opfeaturebasetables.go | 14 +------------- sql3/sql_complex_test.go | 4 +--- 6 files changed, 24 insertions(+), 41 deletions(-) diff --git a/dax/queryer/schema_api.go b/dax/queryer/schema_api.go index b3f39acd6..8faee90d2 100644 --- a/dax/queryer/schema_api.go +++ b/dax/queryer/schema_api.go @@ -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 { diff --git a/dax/table.go b/dax/table.go index 0494d15ac..3c23f511d 100644 --- a/dax/table.go +++ b/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 } diff --git a/schema.go b/schema.go index 5e7d0d677..9c9a4a426 100644 --- a/schema.go +++ b/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, diff --git a/sql3/planner/compileshow.go b/sql3/planner/compileshow.go index ae9d8d7ed..14fb27eeb 100644 --- a/sql3/planner/compileshow.go +++ b/sql3/planner/compileshow.go @@ -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(), }} diff --git a/sql3/planner/opfeaturebasetables.go b/sql3/planner/opfeaturebasetables.go index 64373af16..8a2c0d3cb 100644 --- a/sql3/planner/opfeaturebasetables.go +++ b/sql3/planner/opfeaturebasetables.go @@ -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 diff --git a/sql3/sql_complex_test.go b/sql3/sql_complex_test.go index 5169e5ae4..d5af2102e 100644 --- a/sql3/sql_complex_test.go +++ b/sql3/sql_complex_test.go @@ -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)