Skip to content

Commit

Permalink
Add further testing to CountStar formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <[email protected]>
  • Loading branch information
timvaillancourt committed Jun 19, 2024
1 parent ae6c966 commit 92cd529
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 10 deletions.
8 changes: 4 additions & 4 deletions go/vt/sqlparser/ast_format.go
Original file line number Diff line number Diff line change
Expand Up @@ -2656,12 +2656,12 @@ func (node *Count) Format(buf *TrackedBuffer) {
}

func (node *CountStar) Format(buf *TrackedBuffer) {
name := node.AggrName()
if node.Name != "" {
buf.astPrintf(node, "%s(*)", node.Name)
} else {
buf.astPrintf(node, "%s(", node.AggrName())
buf.WriteString("*)")
name = node.Name
}
buf.astPrintf(node, "%s(", name)
buf.WriteString("*)")
}

func (node *Avg) Format(buf *TrackedBuffer) {
Expand Down
11 changes: 5 additions & 6 deletions go/vt/sqlparser/ast_format_fast.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 28 additions & 0 deletions go/vt/sqlparser/ast_format_fast_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package sqlparser

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestCountStarFormatFast(t *testing.T) {
{
buf := NewTrackedBuffer(nil)
node := &CountStar{}
node.formatFast(buf)
assert.Equal(t, &ParsedQuery{Query: "count(*)"}, buf.ParsedQuery())
}
{
buf := NewTrackedBuffer(nil)
node := &CountStar{Name: "Count"}
node.formatFast(buf)
assert.Equal(t, &ParsedQuery{Query: "Count(*)"}, buf.ParsedQuery())
}
{
buf := NewTrackedBuffer(nil)
node := &CountStar{Name: "COUNT"}
node.formatFast(buf)
assert.Equal(t, &ParsedQuery{Query: "COUNT(*)"}, buf.ParsedQuery())
}
}
28 changes: 28 additions & 0 deletions go/vt/sqlparser/ast_format_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package sqlparser

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestCountStarFormat(t *testing.T) {
{
buf := NewTrackedBuffer(nil)
node := &CountStar{}
node.Format(buf)
assert.Equal(t, &ParsedQuery{Query: "count(*)"}, buf.ParsedQuery())
}
{
buf := NewTrackedBuffer(nil)
node := &CountStar{Name: "Count"}
node.Format(buf)
assert.Equal(t, &ParsedQuery{Query: "Count(*)"}, buf.ParsedQuery())
}
{
buf := NewTrackedBuffer(nil)
node := &CountStar{Name: "COUNT"}
node.Format(buf)
assert.Equal(t, &ParsedQuery{Query: "COUNT(*)"}, buf.ParsedQuery())
}
}

0 comments on commit 92cd529

Please sign in to comment.