Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor aggregation AST structs #10347

Merged
merged 27 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8dbb5f1
SQLParser:Refactoring Add count struct
rsajwani May 19, 2022
934fa96
SQLParser:Refactoring Add countStar struct
rsajwani May 19, 2022
d96a6df
SQLParser:Refactoring Add avg struct
rsajwani May 19, 2022
f79aa19
SQLParser:Refactoring Add max struct
rsajwani May 20, 2022
28def9a
SQLParser:Refactoring Add min struct
rsajwani May 20, 2022
3005af2
SQLParser:Refactoring Add sum struct
rsajwani May 20, 2022
0bbb68c
SQLParser:Refactoring Fixing Parser Aggr Function
rsajwani May 20, 2022
4cb77cb
fix: the return type of count was wrong
systay May 24, 2022
baca564
Refacotring code
rsajwani May 24, 2022
e50f583
More refactoring and unit test cases fix
rsajwani May 27, 2022
67d9ad6
removing getarg from aggregate interface
rsajwani May 30, 2022
f1d013b
Merge branch main into Issue#10113
systay May 31, 2022
9df4f67
Merge branch 'Issue#10113' of github.com:planetscale/vitess into Issu…
rsajwani May 31, 2022
9a1e265
Fixing bugs after merge
rsajwani Jun 1, 2022
c73de21
Optimizing code
rsajwani Jun 2, 2022
e448a03
Fixing planBuilder test cases`
rsajwani Jun 2, 2022
c6ffbf7
Merge branch 'main' into Issue#10113
rsajwani Jun 4, 2022
d5e2b49
Adding more aggregate functions
rsajwani Jun 5, 2022
b1db216
Fixing parser errors
rsajwani Jun 6, 2022
09ce53d
Merge branch 'main' into Issue#10113
rsajwani Jun 7, 2022
792331d
fixing feedback , code review
rsajwani Jun 9, 2022
a16e3a6
Merge branch 'main' into Issue#10113
rsajwani Jun 9, 2022
d801e2e
Fix regression which making changes in previous commit
rsajwani Jun 9, 2022
ab9d821
Fixing vdiff tests
rsajwani Jun 9, 2022
cb7d5c7
Fixing replication test
rsajwani Jun 9, 2022
46a485f
Fixing vstreamer planbuilder test
rsajwani Jun 9, 2022
b895d13
remove redundant code
rsajwani Jun 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions go/test/endtoend/backup/vtbackup/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ func TestMain(m *testing.M) {
tablet.MysqlctlProcess = *cluster.MysqlCtlProcessInstance(tablet.TabletUID, tablet.MySQLPort, localCluster.TmpDirectory)
tablet.MysqlctlProcess.InitDBFile = newInitDBFile
tablet.MysqlctlProcess.ExtraArgs = extraArgs
if proc, err := tablet.MysqlctlProcess.StartProcess(); err != nil {
proc, err := tablet.MysqlctlProcess.StartProcess()
if err != nil {
return 1, err
} else {
// ignore golint warning, we need the else block to use proc
mysqlProcs = append(mysqlProcs, proc)
}
// ignore golint warning, we need the else block to use proc
mysqlProcs = append(mysqlProcs, proc)
}
for _, proc := range mysqlProcs {
if err := proc.Wait(); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions go/test/endtoend/vault/vault_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ const (
vaultSetupScript = "vault-setup.sh"
)

// VaultServer : Basic parameters for the running the Vault server
type VaultServer struct {
// Server : Basic parameters for the running the Vault server
type Server struct {
address string
port1 int
port2 int
Expand All @@ -56,7 +56,7 @@ type VaultServer struct {
}

// Start the Vault server in dev mode
func (vs *VaultServer) start() error {
func (vs *Server) start() error {
// Download and unpack vault binary
vs.execPath = path.Join(os.Getenv("EXTRA_BIN"), vaultExecutableName)
fileStat, err := os.Stat(vs.execPath)
Expand Down Expand Up @@ -126,7 +126,7 @@ func (vs *VaultServer) start() error {
return nil
}

func (vs *VaultServer) stop() error {
func (vs *Server) stop() error {
if vs.proc == nil || vs.exit == nil {
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions go/test/endtoend/vault/vault_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ func TestVaultAuth(t *testing.T) {
require.True(t, bytes.Contains(logContents, []byte(tokenRenewalString)))
}

func startVaultServer(t *testing.T) *VaultServer {
vs := &VaultServer{
func startVaultServer(t *testing.T) *Server {
vs := &Server{
address: hostname,
port1: clusterInstance.GetAndReservePort(),
port2: clusterInstance.GetAndReservePort(),
Expand All @@ -167,7 +167,7 @@ func startVaultServer(t *testing.T) *VaultServer {
}

// Setup everything we need in the Vault server
func setupVaultServer(t *testing.T, vs *VaultServer) (string, string) {
func setupVaultServer(t *testing.T, vs *Server) (string, string) {
// The setup script uses these environment variables
// We also reuse VAULT_ADDR and VAULT_CACERT later on
os.Setenv("VAULT", vs.execPath)
Expand Down
202 changes: 192 additions & 10 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -2325,15 +2325,6 @@ type (
Exprs SelectExprs
}

// GroupConcatExpr represents a call to GROUP_CONCAT
GroupConcatExpr struct {
Distinct bool
Exprs SelectExprs
OrderBy OrderBy
Separator string
Limit *Limit
}

// ValuesFuncExpr represents a function call.
ValuesFuncExpr struct {
Name *ColName
Expand Down Expand Up @@ -2640,6 +2631,108 @@ type (
JSONValue Expr
}

AggrFunc interface {
Expr
AggrName() string
GetArg() Expr
IsDistinct() bool
GetArgs() Exprs
}

Count struct {
Args Exprs
Distinct bool
Name string
}

CountStar struct {
Name string
}

Comment on lines +2652 to +2658
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does name represents alias here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does name represents alias here?

Name represent (in this case) either 'count' or 'Count' or 'COUNT' etc ... given what I made out of test cases we preserve case sensitivity of keywords in query. Hence this field preserved what has been keyed by user.

Avg struct {
Arg Expr
Distinct bool
Name string
}

Max struct {
Arg Expr
Distinct bool
Name string
}

Min struct {
Arg Expr
Distinct bool
Name string
}

Sum struct {
Arg Expr
Distinct bool
Name string
}

BitAnd struct {
Arg Expr
Name string
}

BitOr struct {
Arg Expr
Name string
}

BitXor struct {
Arg Expr
Name string
}

Std struct {
Arg Expr
Name string
}

StdDev struct {
Arg Expr
Name string
}

StdPop struct {
Arg Expr
Name string
}

StdSamp struct {
Arg Expr
Name string
}

VarPop struct {
Arg Expr
Name string
}

VarSamp struct {
Arg Expr
Name string
}

Variance struct {
Arg Expr
Name string
}

// GroupConcatExpr represents a call to GROUP_CONCAT
GroupConcatExpr struct {
Distinct bool
Exprs Exprs
OrderBy OrderBy
Separator string
Limit *Limit
Name string
}

// RegexpInstrExpr represents REGEXP_INSTR()
// For more information, visit https://dev.mysql.com/doc/refman/8.0/en/regexp.html#function_regexp-instr
RegexpInstrExpr struct {
Expand Down Expand Up @@ -2758,6 +2851,96 @@ type (
)

// iExpr ensures that only expressions nodes can be assigned to a Expr
func (*Sum) iExpr() {}
func (*Min) iExpr() {}
func (*Max) iExpr() {}
func (*Avg) iExpr() {}
func (*CountStar) iExpr() {}
func (*Count) iExpr() {}
func (*GroupConcatExpr) iExpr() {}
func (*BitAnd) iExpr() {}
func (*BitOr) iExpr() {}
func (*BitXor) iExpr() {}
func (*Std) iExpr() {}
func (*StdDev) iExpr() {}
func (*StdPop) iExpr() {}
func (*StdSamp) iExpr() {}
func (*VarPop) iExpr() {}
func (*VarSamp) iExpr() {}
func (*Variance) iExpr() {}

func (sum *Sum) GetArg() Expr { return sum.Arg }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this breaks the pattern this file had before. I think it's nice to keep all the iExpr() together. maybe we could move the GetArg, IsDistinct and AggrName to after the iExprs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will do it in next PR .. I have already have a clean up PR following this as discussed offline ..

func (min *Min) GetArg() Expr { return min.Arg }
func (max *Max) GetArg() Expr { return max.Arg }
func (avg *Avg) GetArg() Expr { return avg.Arg }
func (*CountStar) GetArg() Expr { return nil }
func (count *Count) GetArg() Expr { return count.Args[0] }
func (grpConcat *GroupConcatExpr) GetArg() Expr { return grpConcat.Exprs[0] }
func (bAnd *BitAnd) GetArg() Expr { return bAnd.Arg }
func (bOr *BitOr) GetArg() Expr { return bOr.Arg }
func (bXor *BitXor) GetArg() Expr { return bXor.Arg }
func (std *Std) GetArg() Expr { return std.Arg }
func (stdD *StdDev) GetArg() Expr { return stdD.Arg }
func (stdP *StdPop) GetArg() Expr { return stdP.Arg }
func (stdS *StdSamp) GetArg() Expr { return stdS.Arg }
func (varP *VarPop) GetArg() Expr { return varP.Arg }
func (varS *VarSamp) GetArg() Expr { return varS.Arg }
func (variance *Variance) GetArg() Expr { return variance.Arg }

func (sum *Sum) GetArgs() Exprs { return Exprs{sum.Arg} }
func (min *Min) GetArgs() Exprs { return Exprs{min.Arg} }
func (max *Max) GetArgs() Exprs { return Exprs{max.Arg} }
func (avg *Avg) GetArgs() Exprs { return Exprs{avg.Arg} }
func (*CountStar) GetArgs() Exprs { return nil }
func (count *Count) GetArgs() Exprs { return count.Args }
func (grpConcat *GroupConcatExpr) GetArgs() Exprs { return grpConcat.Exprs }
func (bAnd *BitAnd) GetArgs() Exprs { return Exprs{bAnd.Arg} }
func (bOr *BitOr) GetArgs() Exprs { return Exprs{bOr.Arg} }
func (bXor *BitXor) GetArgs() Exprs { return Exprs{bXor.Arg} }
func (std *Std) GetArgs() Exprs { return Exprs{std.Arg} }
func (stdD *StdDev) GetArgs() Exprs { return Exprs{stdD.Arg} }
func (stdP *StdPop) GetArgs() Exprs { return Exprs{stdP.Arg} }
func (stdS *StdSamp) GetArgs() Exprs { return Exprs{stdS.Arg} }
func (varP *VarPop) GetArgs() Exprs { return Exprs{varP.Arg} }
func (varS *VarSamp) GetArgs() Exprs { return Exprs{varS.Arg} }
func (variance *Variance) GetArgs() Exprs { return Exprs{variance.Arg} }

func (sum *Sum) IsDistinct() bool { return sum.Distinct }
func (min *Min) IsDistinct() bool { return min.Distinct }
func (max *Max) IsDistinct() bool { return max.Distinct }
func (avg *Avg) IsDistinct() bool { return avg.Distinct }
func (cStar *CountStar) IsDistinct() bool { return false }
func (count *Count) IsDistinct() bool { return count.Distinct }
func (grpConcat *GroupConcatExpr) IsDistinct() bool { return grpConcat.Distinct }
func (bAnd *BitAnd) IsDistinct() bool { return false }
func (bOr *BitOr) IsDistinct() bool { return false }
func (bXor *BitXor) IsDistinct() bool { return false }
func (std *Std) IsDistinct() bool { return false }
func (stdD *StdDev) IsDistinct() bool { return false }
func (stdP *StdPop) IsDistinct() bool { return false }
func (stdS *StdSamp) IsDistinct() bool { return false }
func (varP *VarPop) IsDistinct() bool { return false }
func (varS *VarSamp) IsDistinct() bool { return false }
func (variance *Variance) IsDistinct() bool { return false }

func (sum *Sum) AggrName() string { return sum.Name }
func (min *Min) AggrName() string { return min.Name }
func (max *Max) AggrName() string { return max.Name }
func (avg *Avg) AggrName() string { return avg.Name }
func (cStar *CountStar) AggrName() string { return cStar.Name }
func (count *Count) AggrName() string { return count.Name }
func (grpConcat *GroupConcatExpr) AggrName() string { return grpConcat.Name }
func (bAnd *BitAnd) AggrName() string { return bAnd.Name }
func (bOr *BitOr) AggrName() string { return bOr.Name }
func (bXor *BitXor) AggrName() string { return bXor.Name }
func (std *Std) AggrName() string { return std.Name }
func (stdD *StdDev) AggrName() string { return stdD.Name }
func (stdP *StdPop) AggrName() string { return stdP.Name }
func (stdS *StdSamp) AggrName() string { return stdS.Name }
func (varP *VarPop) AggrName() string { return varP.Name }
func (varS *VarSamp) AggrName() string { return varS.Name }
func (variance *Variance) AggrName() string { return variance.Name }

func (*AndExpr) iExpr() {}
func (*OrExpr) iExpr() {}
func (*XorExpr) iExpr() {}
Expand Down Expand Up @@ -2790,7 +2973,6 @@ func (*ConvertExpr) iExpr() {}
func (*SubstrExpr) iExpr() {}
func (*ConvertUsingExpr) iExpr() {}
func (*MatchExpr) iExpr() {}
func (*GroupConcatExpr) iExpr() {}
func (*Default) iExpr() {}
func (*ExtractedSubquery) iExpr() {}
func (*TrimFuncExpr) iExpr() {}
Expand Down
Loading