Skip to content

Commit

Permalink
sql/coltypes: remove the field Name in TArray
Browse files Browse the repository at this point in the history
It was not needed. This simplifies.

Release note: None
  • Loading branch information
knz committed Aug 23, 2018
1 parent f7708e9 commit 59d7bd1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/coltypes/aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func ArrayOf(colType T, bounds []int32) (T, error) {
if !canBeInArrayColType(colType) {
return nil, pgerror.NewErrorf(pgerror.CodeFeatureNotSupportedError, "arrays of %s not allowed", colType)
}
return &TArray{Name: colType.String() + "[]", ParamType: colType, Bounds: bounds}, nil
return &TArray{ParamType: colType, Bounds: bounds}, nil
}

var typNameLiterals map[string]T
Expand Down
16 changes: 12 additions & 4 deletions pkg/sql/coltypes/arrays.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,29 @@ import (

// TArray represents an ARRAY column type.
type TArray struct {
Name string
// ParamTyp is the type of the elements in this array.
ParamType T
Bounds []int32
}

// TypeName implements the ColTypeFormatter interface.
func (node *TArray) TypeName() string { return node.Name }
func (node *TArray) TypeName() string {
return node.ParamType.TypeName() + "[]"
}

// Format implements the ColTypeFormatter interface.
func (node *TArray) Format(buf *bytes.Buffer, f lex.EncodeFlags) {
buf.WriteString(node.Name)
if collation, ok := node.ParamType.(*TCollatedString); ok {
buf.WriteString(" COLLATE ")
// We cannot use node.ParamType.Format() directly here (and DRY
// across the two branches of the if) because if we have an array
// of collated strings, the COLLATE string must appear after the
// square brackets.
collation.TString.Format(buf, f)
buf.WriteString("[] COLLATE ")
lex.EncodeUnrestrictedSQLIdent(buf, collation.Locale, f)
} else {
node.ParamType.Format(buf, f)
buf.WriteString("[]")
}
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ func TestParse(t *testing.T) {
{`CREATE TABLE a AS SELECT * FROM b UNION VALUES ('one', 1) ORDER BY c LIMIT 5`},
{`CREATE TABLE IF NOT EXISTS a AS SELECT * FROM b UNION VALUES ('one', 1) ORDER BY c LIMIT 5`},
{`CREATE TABLE a (b STRING COLLATE "DE")`},
{`CREATE TABLE a (b STRING(3) COLLATE "DE")`},
{`CREATE TABLE a (b STRING[] COLLATE "DE")`},
{`CREATE TABLE a (b STRING(3)[] COLLATE "DE")`},

{`CREATE VIEW a AS SELECT * FROM b`},
{`CREATE VIEW a AS SELECT b.* FROM b LIMIT 5`},
Expand Down

0 comments on commit 59d7bd1

Please sign in to comment.