Skip to content
This repository was archived by the owner on Jan 28, 2021. It is now read-only.

Commit af59652

Browse files
Modify VIEW-related comments to adhere to Go conventions
Signed-off-by: Alejandro García Montoro <alejandro.garciamontoro@gmail.com>
1 parent d27b3d3 commit af59652

File tree

6 files changed

+30
-35
lines changed

6 files changed

+30
-35
lines changed

sql/analyzer/resolve_tables_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,27 +115,23 @@ func TestResolveViews(t *testing.T) {
115115
subqueryAlias := plan.NewSubqueryAlias("myview", subquery)
116116
view := sql.NewView("myview", subqueryAlias)
117117

118-
// Register the view in the catalog
119118
catalog := sql.NewCatalog()
120119
catalog.AddDatabase(db)
121120
err := catalog.ViewRegistry.Register(db.Name(), view)
122121
require.NoError(err)
123122

124123
a := NewBuilder(catalog).AddPostAnalyzeRule(f.Name, f.Apply).Build()
125124

126-
// Check whether the view is resolved and replaced with the subquery
127125
var notAnalyzed sql.Node = plan.NewUnresolvedTable("myview", "")
128126
analyzed, err := f.Apply(sql.NewEmptyContext(), a, notAnalyzed)
129127
require.NoError(err)
130128
require.Equal(subqueryAlias, analyzed)
131129

132-
// Ensures that the resolution is case-insensitive
133130
notAnalyzed = plan.NewUnresolvedTable("MyVieW", "")
134131
analyzed, err = f.Apply(sql.NewEmptyContext(), a, notAnalyzed)
135132
require.NoError(err)
136133
require.Equal(subqueryAlias, analyzed)
137134

138-
// Ensures that the resolution is idempotent
139135
analyzed, err = f.Apply(sql.NewEmptyContext(), a, subqueryAlias)
140136
require.NoError(err)
141137
require.Equal(subqueryAlias, analyzed)

sql/parse/util.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ func skipSpaces(r *bufio.Reader) error {
8080
}
8181
}
8282

83-
// Reads every contiguous space from the reader, populating numSpacesRead with
84-
// the number of spaces read.
83+
// readSpaces reads every contiguous space from the reader, populating
84+
// numSpacesRead with the number of spaces read.
8585
func readSpaces(r *bufio.Reader, numSpacesRead *int) error {
8686
*numSpacesRead = 0
8787
for {
@@ -148,8 +148,8 @@ func readLetter(r *bufio.Reader, buf *bytes.Buffer) error {
148148
return nil
149149
}
150150

151-
// Parses a single rune from the reader and consumes it, copying it to the
152-
// buffer, if it is either a letter or a point
151+
// readLetterOrPoint parses a single rune from the reader and consumes it,
152+
// copying it to the buffer, if it is either a letter or a point
153153
func readLetterOrPoint(r *bufio.Reader, buf *bytes.Buffer) error {
154154
ru, _, err := r.ReadRune()
155155
if err != nil {
@@ -188,8 +188,9 @@ func readValidIdentRune(r *bufio.Reader, buf *bytes.Buffer) error {
188188
return nil
189189
}
190190

191-
// Parses a single rune from the reader and consumes it, copying it to the
192-
// buffer, if is a letter, a digit, an underscore or the specified separator.
191+
// readValidScopedIdentRune parses a single rune from the reader and consumes
192+
// it, copying it to the buffer, if is a letter, a digit, an underscore or the
193+
// specified separator.
193194
func readValidScopedIdentRune(r *bufio.Reader, separator rune, buf *bytes.Buffer) error {
194195
ru, _, err := r.ReadRune()
195196
if err != nil {
@@ -404,8 +405,8 @@ func expectQuote(r *bufio.Reader) error {
404405
return nil
405406
}
406407

407-
// Tries to read the specified string, consuming the reader if the string is
408-
// found. The `matched` boolean is set to true if the string is found
408+
// maybe tries to read the specified string, consuming the reader if the string
409+
// is found. The `matched` boolean is set to true if the string is found
409410
func maybe(matched *bool, str string) parseFunc {
410411
return func(rd *bufio.Reader) error {
411412
*matched = false
@@ -436,9 +437,9 @@ func maybe(matched *bool, str string) parseFunc {
436437
}
437438
}
438439

439-
// Tries to read the specified strings, one after the other, separated by an
440-
// arbitrary number of spaces. It consumes the reader if and only if all the
441-
// strings are found.
440+
// multiMaybe tries to read the specified strings, one after the other,
441+
// separated by an arbitrary number of spaces. It consumes the reader if and
442+
// only if all the strings are found.
442443
func multiMaybe(matched *bool, strings ...string) parseFunc {
443444
return func(rd *bufio.Reader) error {
444445
*matched = false
@@ -468,8 +469,9 @@ func multiMaybe(matched *bool, strings ...string) parseFunc {
468469
}
469470
}
470471

471-
// Reads a list of strings separated by the specified separator, with a rune
472-
// indicating the opening of the list and another one specifying its closing.
472+
// maybeList reads a list of strings separated by the specified separator, with
473+
// a rune indicating the opening of the list and another one specifying its
474+
// closing.
473475
// For example, readList('(', ',', ')', list) parses "(uno, dos,tres)" and
474476
// populates list with the array of strings ["uno", "dos", "tres"]
475477
// If the opening is not found, this does not consumes any rune from the

sql/parse/views.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
var ErrMalformedViewName = errors.NewKind("the view name '%s' is not correct")
1515
var ErrMalformedCreateView = errors.NewKind("view definition %#v is not a SELECT query")
1616

17-
// Parses
17+
// parseCreateView parses
1818
// CREATE [OR REPLACE] VIEW [db_name.]view_name AS select_statement
1919
// and returns a NewCreateView node in case of success
2020
func parseCreateView(ctx *sql.Context, s string) (sql.Node, error) {

sql/plan/create_view_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ func TestCreateExistingView(t *testing.T) {
6060

6161
createView := mockCreateView(false)
6262

63-
// Register a view with the same name
6463
view := createView.View()
6564
err := createView.Catalog.ViewRegistry.Register(createView.database.Name(), view)
6665
require.NoError(err)
@@ -78,12 +77,10 @@ func TestReplaceExistingView(t *testing.T) {
7877

7978
createView := mockCreateView(true)
8079

81-
// Register a view with the same name but no child
8280
view := sql.NewView(createView.Name, nil)
8381
err := createView.Catalog.ViewRegistry.Register(createView.database.Name(), view)
8482
require.NoError(err)
8583

86-
// Set the IsReplace flag to true
8784
createView.IsReplace = true
8885

8986
ctx := sql.NewEmptyContext()

sql/viewregistry.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,23 @@ var (
1212
ErrNonExistingView = errors.NewKind("the view %s.%s does not exist in the registry")
1313
)
1414

15-
// A View is defined by a Node and has a name.
15+
// View is defined by a Node and has a name.
1616
type View struct {
1717
name string
1818
definition Node
1919
}
2020

21-
// Creates a View with the specified name and definition.
21+
// NewView creates a View with the specified name and definition.
2222
func NewView(name string, definition Node) View {
2323
return View{name, definition}
2424
}
2525

26-
// Returns the name of the view.
26+
// Name returns the name of the view.
2727
func (view *View) Name() string {
2828
return view.name
2929
}
3030

31-
// Returns the definition of the view.
31+
// Definition returns the definition of the view.
3232
func (view *View) Definition() Node {
3333
return view.definition
3434
}
@@ -39,7 +39,7 @@ type viewKey struct {
3939
dbName, viewName string
4040
}
4141

42-
// Creates a viewKey ensuring both names are lowercase.
42+
// newViewKey creates a viewKey ensuring both names are lowercase.
4343
func newViewKey(databaseName, viewName string) viewKey {
4444
return viewKey{strings.ToLower(databaseName), strings.ToLower(viewName)}
4545
}
@@ -51,15 +51,15 @@ type ViewRegistry struct {
5151
views map[viewKey]View
5252
}
5353

54-
// Creates an empty ViewRegistry.
54+
// NewViewRegistry creates an empty ViewRegistry.
5555
func NewViewRegistry() *ViewRegistry {
5656
return &ViewRegistry{
5757
views: make(map[viewKey]View),
5858
}
5959
}
6060

61-
// Adds the view specified by the pair {database, view.Name()}, returning
62-
// an error if there is already an element with that key.
61+
// Register adds the view specified by the pair {database, view.Name()},
62+
// returning an error if there is already an element with that key.
6363
func (registry *ViewRegistry) Register(database string, view View) error {
6464
registry.mutex.Lock()
6565
defer registry.mutex.Unlock()
@@ -74,8 +74,8 @@ func (registry *ViewRegistry) Register(database string, view View) error {
7474
return nil
7575
}
7676

77-
// Deletes the view specified by the pair {databaseName, viewName}, returning
78-
// an error if it does not exist.
77+
// Delete deletes the view specified by the pair {databaseName, viewName},
78+
// returning an error if it does not exist.
7979
func (registry *ViewRegistry) Delete(databaseName, viewName string) error {
8080
registry.mutex.Lock()
8181
defer registry.mutex.Unlock()
@@ -90,7 +90,7 @@ func (registry *ViewRegistry) Delete(databaseName, viewName string) error {
9090
return nil
9191
}
9292

93-
// Returns a pointer to the view specified by the pair {databaseName,
93+
// View returns a pointer to the view specified by the pair {databaseName,
9494
// viewName}, returning an error if it does not exist.
9595
func (registry *ViewRegistry) View(databaseName, viewName string) (*View, error) {
9696
registry.mutex.RLock()
@@ -105,15 +105,16 @@ func (registry *ViewRegistry) View(databaseName, viewName string) (*View, error)
105105
return nil, ErrNonExistingView.New(databaseName, viewName)
106106
}
107107

108-
// Returns the map of all views in the registry.
108+
// AllViews returns the map of all views in the registry.
109109
func (registry *ViewRegistry) AllViews() map[viewKey]View {
110110
registry.mutex.RLock()
111111
defer registry.mutex.RUnlock()
112112

113113
return registry.views
114114
}
115115

116-
// Returns an array of all the views registered under the specified database.
116+
// ViewsInDatabase returns an array of all the views registered under the
117+
// specified database.
117118
func (registry *ViewRegistry) ViewsInDatabase(databaseName string) (views []View) {
118119
registry.mutex.RLock()
119120
defer registry.mutex.RUnlock()

sql/viewregistry_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ func TestRegisterExistingVIew(t *testing.T) {
4545
require.NoError(err)
4646
require.Equal(1, len(registry.AllViews()))
4747

48-
// Try to register the same view once again
4948
err = registry.Register(dbName, mockView)
5049
require.Error(err)
5150
require.True(ErrExistingView.Is(err))

0 commit comments

Comments
 (0)