github.com/dolthub/go-mysql-server@v0.18.0/sql/rowexec/builder_gen_test.go (about) 1 // Copyright 2023 Dolthub, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package rowexec 16 17 import ( 18 "bufio" 19 "fmt" 20 "os" 21 "os/user" 22 "path/filepath" 23 "testing" 24 25 "github.com/stretchr/testify/require" 26 ) 27 28 func TestGenBuilder(t *testing.T) { 29 t.Skip() 30 nodes := map[string]string{ 31 "Releaser": "*plan.Releaser", 32 "dummyNode": "plan.dummyNode", 33 "UnresolvedTableFunction": "*plan.UnresolvedTableFunction", 34 "AlterAutoIncrement": "*plan.AlterAutoIncrement", 35 "CreateCheck": "*plan.CreateCheck", 36 "DropCheck": "*plan.DropCheck", 37 "DropConstraint": "*plan.DropConstraint", 38 "AlterDefaultSet": "*plan.AlterDefaultSet", 39 "AlterDefaultDrop": "*plan.AlterDefaultDrop", 40 "CreateForeignKey": "*plan.CreateForeignKey", 41 "DropForeignKey": "*plan.DropForeignKey", 42 "AlterIndex": "*plan.AlterIndex", 43 "AlterPK": "*plan.AlterPK", 44 "RenameTable": "*plan.RenameTable", 45 "AddColumn": "*plan.AddColumn", 46 "DropColumn": "*plan.DropColumn", 47 "RenameColumn": "*plan.RenameColumn", 48 "ModifyColumn": "*plan.ModifyColumn", 49 "AlterTableCollation": "*plan.AlterTableCollation", 50 "AnalyzeTable": "*plan.AnalyzeTable", 51 "BeginEndBlock": "*plan.BeginEndBlock", 52 "Block": "*plan.Block", 53 "CachedResults": "*plan.CachedResults", 54 "Call": "*plan.Call", 55 "CaseStatement": "*plan.CaseStatement", 56 "elseCaseError": "plan.elseCaseError", 57 "Close": "*plan.Close", 58 "Concat": "*plan.Concat", 59 "CreateIndex": "*plan.CreateIndex", 60 "CreateRole": "*plan.CreateRole", 61 "CreateUser": "*plan.CreateUser", 62 "CreateView": "*plan.CreateView", 63 "CreateDB": "*plan.CreateDB", 64 "DropDB": "*plan.DropDB", 65 "AlterDB": "*plan.AlterDB", 66 "CreateTable": "*plan.CreateTable", 67 "DropTable": "*plan.DropTable", 68 "CreateProcedure": "*plan.CreateProcedure", 69 "CreateTrigger": "*plan.CreateTrigger", 70 "DeclareCondition": "*plan.DeclareCondition", 71 "DeclareCursor": "*plan.DeclareCursor", 72 "DeclareHandler": "*plan.DeclareHandler", 73 "DeclareVariables": "*plan.DeclareVariables", 74 "DeleteFrom": "*plan.DeleteFrom", 75 "Describe": "*plan.Describe", 76 "DescribeQuery": "*plan.DescribeQuery", 77 "Distinct": "*plan.Distinct", 78 "OrderedDistinct": "*plan.OrderedDistinct", 79 "DropIndex": "*plan.DropIndex", 80 "DropProcedure": "*plan.DropProcedure", 81 "DropRole": "*plan.DropRole", 82 "DropTrigger": "*plan.DropTrigger", 83 "DropUser": "*plan.DropUser", 84 "SingleDropView": "*plan.SingleDropView", 85 "DropView": "*plan.DropView", 86 "EmptyTable": "*plan.EmptyTable", 87 "Exchange": "*plan.Exchange", 88 "exchangePartition": "*plan.exchangePartition", 89 "ExternalProcedure": "*plan.ExternalProcedure", 90 "Fetch": "*plan.Fetch", 91 "Filter": "*plan.Filter", 92 "FlushPrivileges": "*plan.FlushPrivileges", 93 "ForeignKeyHandler": "*plan.ForeignKeyHandler", 94 "Grant": "*plan.Grant", 95 "GrantRole": "*plan.GrantRole", 96 "GrantProxy": "*plan.GrantProxy", 97 "GroupBy": "*plan.GroupBy", 98 "HashLookup": "*plan.HashLookup", 99 "Having": "*plan.Having", 100 "IfConditional": "*plan.IfConditional", 101 "IfElseBlock": "*plan.IfElseBlock", 102 "IndexedInSubqueryFilter": "*plan.IndexedInSubqueryFilter", 103 "IndexedTableAccess": "*plan.IndexedTableAccess", 104 "InsertInto": "*plan.InsertInto", 105 "InsertDestination": "*plan.InsertDestination", 106 "Into": "*plan.Into", 107 "Iterate": "*plan.Iterate", 108 "JoinNode": "*plan.JoinNode", 109 "JSONTable": "plan.JSONTable", 110 "Kill": "*plan.Kill", 111 "Leave": "*plan.Leave", 112 "Limit": "*plan.Limit", 113 "LoadData": "*plan.LoadData", 114 "LockTables": "*plan.LockTables", 115 "UnlockTables": "*plan.UnlockTables", 116 "Loop": "*plan.Loop", 117 "NamedWindows": "*plan.NamedWindows", 118 "nothing": "plan.nothing", 119 "Offset": "*plan.Offset", 120 "Open": "*plan.Open", 121 "PrepareQuery": "*plan.PrepareQuery", 122 "ExecuteQuery": "*plan.ExecuteQuery", 123 "DeallocateQuery": "*plan.DeallocateQuery", 124 "Procedure": "*plan.Procedure", 125 "ProcedureResolvedTable": "*plan.ProcedureResolvedTable", 126 "QueryProcess": "*plan.QueryProcess", 127 "ShowProcessList": "*plan.ShowProcessList", 128 "Project": "*plan.Project", 129 "RecursiveCte": "*plan.RecursiveCte", 130 "RecursiveTable": "*plan.RecursiveTable", 131 "RenameUser": "*plan.RenameUser", 132 "Repeat": "*plan.Repeat", 133 "ChangeReplicationSource": "*plan.ChangeReplicationSource", 134 "ChangeReplicationFilter": "*plan.ChangeReplicationFilter", 135 "StartReplica": "*plan.StartReplica", 136 "StopReplica": "*plan.StopReplica", 137 "ResetReplica": "*plan.ResetReplica", 138 "TableNode": "*plan.TableNode", 139 "Revoke": "*plan.Revoke", 140 "RevokeAll": "*plan.RevokeAll", 141 "RevokeRole": "*plan.RevokeRole", 142 "RevokeProxy": "*plan.RevokeProxy", 143 "RowUpdateAccumulator": "plan.RowUpdateAccumulator", 144 "Set": "*plan.Set", 145 "ShowCharset": "*plan.ShowCharset", 146 "ShowCreateDatabase": "*plan.ShowCreateDatabase", 147 "ShowCreateProcedure": "*plan.ShowCreateProcedure", 148 "ShowCreateTable": "*plan.ShowCreateTable", 149 "ShowCreateTrigger": "*plan.ShowCreateTrigger", 150 "ShowGrants": "*plan.ShowGrants", 151 "ShowIndexes": "*plan.ShowIndexes", 152 "ShowPrivileges": "*plan.ShowPrivileges", 153 "ShowReplicaStatus": "*plan.ShowReplicaStatus", 154 "ShowStatus": "*plan.ShowStatus", 155 "ShowTriggers": "*plan.ShowTriggers", 156 "ShowColumns": "*plan.ShowColumns", 157 "ShowDatabases": "*plan.ShowDatabases", 158 "ShowTableStatus": "*plan.ShowTableStatus", 159 "ShowVariables": "*plan.ShowVariables", 160 "ShowWarnings": "*plan.ShowWarnings", 161 "Signal": "*plan.Signal", 162 "SignalName": "*plan.SignalName", 163 "Sort": "*plan.Sort", 164 "TopN": "*plan.TopN", 165 "StripRowNode": "*plan.StripRowNode", 166 "prependNode": "*plan.prependNode", 167 "Max1Row": "*plan.Max1Row", 168 "SubqueryAlias": "*plan.SubqueryAlias", 169 "TableCopier": "*plan.TableCopier", 170 "StartTransaction": "*plan.StartTransaction", 171 "Commit": "*plan.Commit", 172 "Rollback": "*plan.Rollback", 173 "CreateSavepoint": "*plan.CreateSavepoint", 174 "RollbackSavepoint": "*plan.RollbackSavepoint", 175 "ReleaseSavepoint": "*plan.ReleaseSavepoint", 176 "TransactionCommittingNode": "*plan.TransactionCommittingNode", 177 "TransformedNamedNode": "*plan.TransformedNamedNode", 178 "TriggerExecutor": "*plan.TriggerExecutor", 179 "TriggerRollback": "*plan.TriggerRollback", 180 "NoopTriggerRollback": "*plan.NoopTriggerRollback", 181 "TriggerBeginEndBlock": "*plan.TriggerBeginEndBlock", 182 "Truncate": "*plan.Truncate", 183 "SetOp": "*plan.SetOp", 184 "UnresolvedTable": "*plan.UnresolvedTable", 185 "DeferredAsOfTable": "*plan.DeferredAsOfTable", 186 "DeferredFilteredTable": "*plan.DeferredFilteredTable", 187 "Update": "*plan.Update", 188 "UpdateJoin": "*plan.UpdateJoin", 189 "UpdateSource": "*plan.UpdateSource", 190 "Use": "*plan.Use", 191 "Values": "*plan.Values", 192 "ValueDerivedTable": "*plan.ValueDerivedTable", 193 "While": "*plan.While", 194 "Window": "*plan.Window", 195 "With": "*plan.With", 196 "nodeA": "*plan.nodeA", 197 "testNode": "*plan.testNode", 198 } 199 200 expressions := map[string]string{ 201 "customFunc": "*expression.customFunc", 202 "AliasReference": "*expression.AliasReference", 203 "Alias": "*expression.Alias", 204 "UnaryMinus": "*expression.UnaryMinus", 205 "AutoIncrement": "*expression.AutoIncrement", 206 "Between": "*expression.Between", 207 "Binary": "*expression.Binary", 208 "BindVar": "*expression.BindVar", 209 "BitOp": "*expression.BitOp", 210 "Not": "*expression.Not", 211 "Case": "*expression.Case", 212 "CollatedExpression": "*expression.CollatedExpression", 213 "Equals": "*expression.Equals", 214 "NullSafeEquals": "*expression.NullSafeEquals", 215 "Regexp": "*expression.Regexp", 216 "GreaterThan": "*expression.GreaterThan", 217 "LessThan": "*expression.LessThan", 218 "GreaterThanOrEqual": "*expression.GreaterThanOrEqual", 219 "LessThanOrEqual": "*expression.LessThanOrEqual", 220 "Convert": "*expression.Convert", 221 "DefaultColumn": "*expression.DefaultColumn", 222 "DistinctExpression": "*expression.DistinctExpression", 223 "Rand": "*expression.Rand", 224 "Time": "*expression.Time", 225 "GetField": "*expression.GetField", 226 "Interval": "*expression.Interval", 227 "IsNull": "*expression.IsNull", 228 "IsTrue": "*expression.IsTrue", 229 "Like": "*expression.Like", 230 "Literal": "expression.Literal", 231 "And": "*expression.And", 232 "Or": "*expression.Or", 233 "Xor": "*expression.Xor", 234 "NamedLiteral": "expression.NamedLiteral", 235 "ProcedureParam": "*expression.ProcedureParam", 236 "UnresolvedProcedureParam": "*expression.UnresolvedProcedureParam", 237 "SetField": "*expression.SetField", 238 "Star": "*expression.Star", 239 "UnresolvedColumn": "*expression.UnresolvedColumn", 240 "UnresolvedFunction": "*expression.UnresolvedFunction", 241 "SystemVar": "*expression.SystemVar", 242 "UserVar": "*expression.UserVar", 243 "Wrapper": "*expression.Wrapper", 244 "colDefaultExpression": "colDefaultExpression", 245 "ExistsSubquery": "*expression.ExistsSubquery", 246 "InSubquery": "*expression.InSubquery", 247 } 248 249 genBuilder(t, "Node", "plan", "node_builder.gen.go", nodes) 250 genBuilder(t, "Expr", "expression", "expr_builder.gen.go", expressions) 251 } 252 253 func genBuilder(t *testing.T, typ, pack, fileName string, objects map[string]string) { 254 usr, _ := user.Current() 255 dir := usr.HomeDir 256 257 f, err := os.Create(filepath.Join(dir, "go/src/github.com/dolthub/go-mysql-server/sql/rowexec", fileName)) 258 require.NoError(t, err) 259 260 w := bufio.NewWriter(f) 261 fmt.Fprintf(w, `// Copyright 2021 Dolthub, Inc. 262 // 263 // GENERATED 264 // 265 // Licensed under the Apache License, Version 2.0 (the "License"); 266 // you may not use this file except in compliance with the License. 267 // You may obtain a copy of the License at 268 // 269 // http://www.apache.org/licenses/LICENSE-2.0 270 // 271 // Unless required by applicable law or agreed to in writing, software 272 // distributed under the License is distributed on an "AS IS" BASIS, 273 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 274 // See the License for the specific language governing permissions and 275 // limitations under the License. 276 277 package rowexec 278 279 import ( 280 "fmt" 281 "github.com/dolthub/go-mysql-server/sql" 282 "github.com/dolthub/go-mysql-server/sql/%s" 283 ) 284 285 `, pack) 286 fmt.Fprintf(w, "func (b *builder) build%sExec(n sql.%s, row sql.Row) (sql.RowIter, error) {\n", typ, typ) 287 fmt.Fprintf(w, " switch n := n.(type) {\n") 288 289 for name, obj := range objects { 290 fmt.Fprintf(w, " case %s:\n", obj) 291 fmt.Fprintf(w, " return build%s(n, row)\n", name) 292 } 293 294 fmt.Fprintf(w, " default:\n") 295 fmt.Fprintf(w, " return nil, fmt.Errorf(\"Unknown %s type\")\n", typ) 296 fmt.Fprintf(w, " }\n") 297 fmt.Fprintf(w, "}\n\n") 298 w.Flush() 299 }