Skip to content

Commit a4a0222

Browse files
authored
Merge pull request #1495 from dolthub/jennifer/column-name
fix displaying correct column name for dolt_ tables
2 parents da46cc1 + ef2b034 commit a4a0222

File tree

6 files changed

+143
-135
lines changed

6 files changed

+143
-135
lines changed

server/expression/gms_cast.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"github.com/cockroachdb/errors"
2323
"github.com/dolthub/dolt/go/store/prolly/tree"
2424
"github.com/dolthub/go-mysql-server/sql"
25+
"github.com/dolthub/go-mysql-server/sql/expression"
2526
"github.com/dolthub/go-mysql-server/sql/types"
2627
"github.com/dolthub/vitess/go/vt/proto/query"
2728
"github.com/shopspring/decimal"
@@ -205,6 +206,9 @@ func (c *GMSCast) Resolved() bool {
205206

206207
// String implements the sql.Expression interface.
207208
func (c *GMSCast) String() string {
209+
if gf, ok := c.sqlChild.(*expression.GetField); ok {
210+
return gf.Name()
211+
}
208212
return c.sqlChild.String()
209213
}
210214

testing/go/dolt_tables_test.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,24 @@ func TestUserSpaceDoltTables(t *testing.T) {
2626
Name: "dolt branches",
2727
Assertions: []ScriptTestAssertion{
2828
{
29-
Query: `SELECT name FROM dolt.branches`,
30-
Expected: []sql.Row{{"main"}},
29+
Query: `SELECT name FROM dolt.branches`,
30+
ExpectedColNames: []string{"name"},
31+
Expected: []sql.Row{{"main"}},
3132
},
3233
{
33-
Query: `SELECT name FROM dolt_branches`,
34-
Expected: []sql.Row{{"main"}},
34+
Query: `SELECT name FROM dolt_branches`,
35+
ExpectedColNames: []string{"name"},
36+
Expected: []sql.Row{{"main"}},
3537
},
3638
{
37-
Query: `SELECT branches.name FROM dolt.branches`,
38-
Expected: []sql.Row{{"main"}},
39+
Query: `SELECT branches.name FROM dolt.branches`,
40+
ExpectedColNames: []string{"name"},
41+
Expected: []sql.Row{{"main"}},
3942
},
4043
{
41-
Query: `SELECT dolt.branches.name FROM dolt.branches`,
42-
Expected: []sql.Row{{"main"}},
44+
Query: `SELECT dolt.branches.name FROM dolt.branches`,
45+
ExpectedColNames: []string{"name"},
46+
Expected: []sql.Row{{"main"}},
4347
},
4448
{
4549
Query: `SELECT dolt_branches.name FROM dolt_branches`,

testing/go/framework.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ type ScriptTestAssertion struct {
112112
// This is checked only if no Expected is defined
113113
ExpectedTag string
114114

115-
// Cols is used to check the column names returned from the server.
116-
Cols []string
115+
// ExpectedColNames is used to check the column names returned from the server.
116+
ExpectedColNames []string
117117

118118
// CopyFromSTDIN is used to test the COPY FROM STDIN command.
119119
CopyFromStdInFile string
@@ -224,10 +224,10 @@ func runScript(t *testing.T, ctx context.Context, script ScriptTest, conn *Conne
224224
readRows, err := ReadRows(rows, normalizeRows)
225225
require.NoError(t, err)
226226

227-
if assertion.Cols != nil {
227+
if assertion.ExpectedColNames != nil {
228228
fields := rows.FieldDescriptions()
229-
if assert.Len(t, fields, len(assertion.Cols), "expected length of columns") {
230-
for i, col := range assertion.Cols {
229+
if assert.Len(t, fields, len(assertion.ExpectedColNames), "expected length of columns") {
230+
for i, col := range assertion.ExpectedColNames {
231231
assert.Equal(t, col, fields[i].Name)
232232
}
233233
}

0 commit comments

Comments
 (0)