Skip to content

Commit 30b1b91

Browse files
committed
feat(dtables): add dolt_status_ignored system table adapter
Add adapter and test expectations for the new dolt_status_ignored system table from PR dolthub/dolt#10227. This table provides the same information as dolt_status plus an additional ignored column indicating whether unstaged new tables match a pattern in dolt_ignore. Changes: - Add DoltgresDoltStatusIgnoredTableAdapter in status_ignored.go - Register DoltgresDoltStatusIgnoredTableAdapter in init.go - Update pgcatalog_test.go with new dolt_status_ignore table to expected tables - Add new dolt_status_ignore table to sequences_test.go expected tables Refs: dolthub/dolt#5862, dolthub/dolt#10227
1 parent 090d26b commit 30b1b91

4 files changed

Lines changed: 152 additions & 0 deletions

File tree

server/tables/dtables/init.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
// Init handles initialization of all Postgres-specific and Doltgres-specific Dolt system tables.
2727
func Init() {
2828
adapters.DoltTableAdapterRegistry.AddAdapter(doltdb.StatusTableName, DoltgresDoltStatusTableAdapter{}, DoltgresDoltStatusTableName)
29+
adapters.DoltTableAdapterRegistry.AddAdapter(doltdb.StatusIgnoredTableName, DoltgresDoltStatusIgnoredTableAdapter{}, DoltgresDoltStatusIgnoredTableName)
2930

3031
// Table names
3132
doltdb.GetBranchesTableName = getBranchesTableName
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
// Copyright 2026 Dolthub, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package dtables
16+
17+
import (
18+
"fmt"
19+
20+
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
21+
"github.com/dolthub/dolt/go/libraries/doltcore/env"
22+
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/adapters"
23+
doltdtables "github.com/dolthub/dolt/go/libraries/doltcore/sqle/dtables"
24+
"github.com/dolthub/go-mysql-server/sql"
25+
26+
pgtypes "github.com/dolthub/doltgresql/server/types"
27+
)
28+
29+
// DoltgresDoltStatusIgnoredTableAdapter adapts the [doltdtables.StatusIgnoredTable] into a Doltgres-compatible version.
30+
//
31+
// DoltgresDoltStatusIgnoredTableAdapter implements the [adapters.TableAdapter] interface.
32+
type DoltgresDoltStatusIgnoredTableAdapter struct{}
33+
34+
var _ adapters.TableAdapter = DoltgresDoltStatusIgnoredTableAdapter{}
35+
36+
// NewTable returns a new [sql.Table] for Doltgres' version of [doltdtables.StatusIgnoredTable].
37+
func (a DoltgresDoltStatusIgnoredTableAdapter) NewTable(ctx *sql.Context, tableName string, ddb *doltdb.DoltDB, ws *doltdb.WorkingSet, rp env.RootsProvider[*sql.Context]) sql.Table {
38+
doltTable := doltdtables.NewStatusIgnoredTableWithNoAdapter(ctx, tableName, ddb, ws, rp)
39+
return &doltgresDoltStatusIgnoredTable{
40+
srcDoltStatusIgnored: doltTable.(*doltdtables.StatusIgnoredTable),
41+
}
42+
}
43+
44+
// TableName returns the table name for Doltgres' version of [doltdtables.StatusIgnoredTable].
45+
func (a DoltgresDoltStatusIgnoredTableAdapter) TableName() string {
46+
return DoltgresDoltStatusIgnoredTableName
47+
}
48+
49+
// DoltgresDoltStatusIgnoredTableName is the name of Dolt's status_ignored table following Doltgres' naming conventions.
50+
const DoltgresDoltStatusIgnoredTableName = "status_ignored"
51+
52+
// doltgresDoltStatusIgnoredTable translates the [doltdtables.StatusIgnoredTable] into a Doltgres-compatible version.
53+
//
54+
// doltgresDoltStatusIgnoredTable implements the [sql.Table] and [sql.StatisticsTable] interfaces.
55+
type doltgresDoltStatusIgnoredTable struct {
56+
srcDoltStatusIgnored *doltdtables.StatusIgnoredTable
57+
}
58+
59+
var _ sql.Table = (*doltgresDoltStatusIgnoredTable)(nil)
60+
var _ sql.StatisticsTable = (*doltgresDoltStatusIgnoredTable)(nil)
61+
62+
// Name returns the name of Doltgres' version of the Dolt status_ignored table.
63+
func (w *doltgresDoltStatusIgnoredTable) Name() string {
64+
return w.srcDoltStatusIgnored.Name()
65+
}
66+
67+
// Schema returns the schema for Doltgres' version of the Dolt status_ignored table.
68+
func (w *doltgresDoltStatusIgnoredTable) Schema() sql.Schema {
69+
return []*sql.Column{
70+
{Name: "table_name", Type: pgtypes.Text, Source: DoltgresDoltStatusIgnoredTableName, PrimaryKey: true, Nullable: false},
71+
{Name: "staged", Type: pgtypes.Bool, Source: DoltgresDoltStatusIgnoredTableName, PrimaryKey: true, Nullable: false},
72+
{Name: "status", Type: pgtypes.Text, Source: DoltgresDoltStatusIgnoredTableName, PrimaryKey: true, Nullable: false},
73+
{Name: "ignored", Type: pgtypes.Bool, Source: DoltgresDoltStatusIgnoredTableName, PrimaryKey: false, Nullable: false},
74+
}
75+
}
76+
77+
// String returns the string representation of [doltdtables.StatusIgnoredTable].
78+
func (w *doltgresDoltStatusIgnoredTable) String() string {
79+
return w.srcDoltStatusIgnored.String()
80+
}
81+
82+
// Collation returns the [sql.CollationID] from [doltdtables.StatusIgnoredTable].
83+
func (w *doltgresDoltStatusIgnoredTable) Collation() sql.CollationID {
84+
return w.srcDoltStatusIgnored.Collation()
85+
}
86+
87+
// Partitions returns a [sql.PartitionIter] on the partitions of [doltdtables.StatusIgnoredTable].
88+
func (w *doltgresDoltStatusIgnoredTable) Partitions(ctx *sql.Context) (sql.PartitionIter, error) {
89+
return w.srcDoltStatusIgnored.Partitions(ctx)
90+
}
91+
92+
// PartitionRows returns a wrapped [sql.RowIter] for the rows in |partition| from
93+
// [doltdtables.StatusIgnoredTable.PartitionRows] to later apply column transformations that match Doltgres' version of the
94+
// Dolt status_ignored table schema.
95+
func (w *doltgresDoltStatusIgnoredTable) PartitionRows(ctx *sql.Context, partition sql.Partition) (sql.RowIter, error) {
96+
iter, err := w.srcDoltStatusIgnored.PartitionRows(ctx, partition)
97+
if err != nil {
98+
return nil, err
99+
}
100+
return &doltgresDoltStatusIgnoredRowIter{w, iter}, nil
101+
}
102+
103+
// DataLength returns the length of the data in bytes from [doltdtables.StatusIgnoredTable].
104+
func (w *doltgresDoltStatusIgnoredTable) DataLength(ctx *sql.Context) (uint64, error) {
105+
return w.srcDoltStatusIgnored.DataLength(ctx)
106+
}
107+
108+
// RowCount returns exact (true) or estimate (false) number of rows from [doltdtables.StatusIgnoredTable].
109+
func (w *doltgresDoltStatusIgnoredTable) RowCount(ctx *sql.Context) (uint64, bool, error) {
110+
return w.srcDoltStatusIgnored.RowCount(ctx)
111+
}
112+
113+
// doltgresDoltStatusIgnoredRowIter wraps [doltdtables.StatusIgnoredTable] [sql.RowIter] and applies transformations before returning
114+
// its rows to make sure they're compatible with Doltgres' version of Dolt's status_ignored table.
115+
type doltgresDoltStatusIgnoredRowIter struct {
116+
doltStatusIgnoredTable sql.Table
117+
rowIter sql.RowIter
118+
}
119+
120+
var _ sql.RowIter = (*doltgresDoltStatusIgnoredRowIter)(nil)
121+
122+
// Next converts the 'staged' column from [doltdtables.StatusIgnoredTable.Schema] from byte into bool since,
123+
// unlike the MySQL wire protocol, Doltgres has a real bool type.
124+
func (i *doltgresDoltStatusIgnoredRowIter) Next(ctx *sql.Context) (sql.Row, error) {
125+
row, err := i.rowIter.Next(ctx)
126+
if err != nil {
127+
return nil, err
128+
}
129+
130+
// Dolt uses byte to avoid MySQL wire protocol ambiguity on tinyint(1) and bool.
131+
// See: https://github.com/dolthub/dolt/pull/10117
132+
stagedIndex := i.doltStatusIgnoredTable.Schema().IndexOfColName("staged")
133+
stagedVal, ok := row[stagedIndex].(byte)
134+
if !ok {
135+
return nil, fmt.Errorf("expected staged column at index %d to be byte, got %T", stagedIndex, row[stagedIndex])
136+
}
137+
row[stagedIndex] = stagedVal != 0
138+
139+
return row, nil
140+
}
141+
142+
// Close closes the wrapped [doltdtables.StatusIgnoredTable] [sql.RowIter].
143+
func (i *doltgresDoltStatusIgnoredRowIter) Close(ctx *sql.Context) error {
144+
return i.rowIter.Close(ctx)
145+
}

testing/go/pgcatalog_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4318,6 +4318,7 @@ func TestPgTables(t *testing.T) {
43184318
{"public", "dolt_remotes"},
43194319
{"public", "dolt_schema_conflicts"},
43204320
{"public", "dolt_status"},
4321+
{"public", "dolt_status_ignored"},
43214322
{"public", "dolt_tags"},
43224323
{"public", "dolt_workspace_t1"},
43234324
{"public", "dolt_workspace_t2"},
@@ -5711,6 +5712,7 @@ func TestSystemTablesInPgcatalog(t *testing.T) {
57115712
{"public", "dolt_remotes", "postgres", nil, "f", "f", "f", "f"},
57125713
{"public", "dolt_schema_conflicts", "postgres", nil, "f", "f", "f", "f"},
57135714
{"public", "dolt_status", "postgres", nil, "f", "f", "f", "f"},
5715+
{"public", "dolt_status_ignored", "postgres", nil, "f", "f", "f", "f"},
57145716
{"public", "dolt_tags", "postgres", nil, "f", "f", "f", "f"},
57155717
{"s1", "dolt_branches", "postgres", nil, "f", "f", "f", "f"},
57165718
{"s1", "dolt_column_diff", "postgres", nil, "f", "f", "f", "f"},
@@ -5730,6 +5732,7 @@ func TestSystemTablesInPgcatalog(t *testing.T) {
57305732
{"s1", "dolt_remotes", "postgres", nil, "f", "f", "f", "f"},
57315733
{"s1", "dolt_schema_conflicts", "postgres", nil, "f", "f", "f", "f"},
57325734
{"s1", "dolt_status", "postgres", nil, "f", "f", "f", "f"},
5735+
{"s1", "dolt_status_ignored", "postgres", nil, "f", "f", "f", "f"},
57335736
{"s1", "dolt_tags", "postgres", nil, "f", "f", "f", "f"},
57345737
{"s1", "dolt_workspace_t1", "postgres", nil, "f", "f", "f", "f"},
57355738
{"s1", "t1", "postgres", nil, "t", "f", "f", "f"},
@@ -5761,6 +5764,7 @@ func TestSystemTablesInPgcatalog(t *testing.T) {
57615764
{341706375, "dolt_remotes", 2200, "r"},
57625765
{3210116770, "dolt_schema_conflicts", 2200, "r"},
57635766
{1060579466, "dolt_status", 2200, "r"},
5767+
{1523309269, "dolt_status_ignored", 2200, "r"},
57645768
{1807684176, "dolt_tags", 2200, "r"},
57655769
{1763579892, "dolt_branches", 1634633383, "r"},
57665770
{1212681264, "dolt_column_diff", 1634633383, "r"},
@@ -5780,6 +5784,7 @@ func TestSystemTablesInPgcatalog(t *testing.T) {
57805784
{373092098, "dolt_remotes", 1634633383, "r"},
57815785
{225426095, "dolt_schema_conflicts", 1634633383, "r"},
57825786
{3554775706, "dolt_status", 1634633383, "r"},
5787+
{1227149778, "dolt_status_ignored", 1634633383, "r"},
57835788
{3246414078, "dolt_tags", 1634633383, "r"},
57845789
{1640933374, "dolt_workspace_t1", 1634633383, "r"},
57855790
{2849341124, "t1", 1634633383, "r"},

testing/go/sequences_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,7 @@ ORDER BY 1,2;`,
12341234
{"public", "dolt_remotes", "table", "postgres"},
12351235
{"public", "dolt_schema_conflicts", "table", "postgres"},
12361236
{"public", "dolt_status", "table", "postgres"},
1237+
{"public", "dolt_status_ignored", "table", "postgres"},
12371238
{"public", "dolt_tags", "table", "postgres"},
12381239
{"public", "dolt_workspace_call", "table", "postgres"},
12391240
{"public", "dolt_workspace_user", "table", "postgres"},

0 commit comments

Comments
 (0)