github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/plan/generate_series.go (about) 1 // Copyright 2022 Matrix Origin 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 plan 16 17 import ( 18 "github.com/matrixorigin/matrixone/pkg/container/types" 19 "github.com/matrixorigin/matrixone/pkg/pb/plan" 20 "github.com/matrixorigin/matrixone/pkg/sql/parsers/tree" 21 ) 22 23 var ( 24 GSColDefs = [3][]*plan.ColDef{} 25 ) 26 27 func init() { 28 retTyp := types.T_int64.ToType() 29 GSColDefs[0] = []*plan.ColDef{ 30 { 31 Name: "result", 32 Typ: makePlan2Type(&retTyp), 33 }, 34 } 35 retTyp = types.T_datetime.ToType() 36 GSColDefs[1] = []*plan.ColDef{ 37 { 38 Name: "result", 39 Typ: makePlan2Type(&retTyp), 40 }, 41 } 42 retTyp = types.T_varchar.ToType() 43 GSColDefs[2] = []*plan.ColDef{ 44 { 45 Name: "result", 46 Typ: makePlan2Type(&retTyp), 47 }, 48 } 49 } 50 51 func (builder *QueryBuilder) buildGenerateSeries(tbl *tree.TableFunction, ctx *BindContext, exprs []*plan.Expr, childId int32) int32 { 52 var retsIdx int 53 if types.T(exprs[0].Typ.Id).IsInteger() { 54 retsIdx = 0 55 } else if types.T(exprs[0].Typ.Id).IsDateRelate() { 56 retsIdx = 1 57 } else { 58 retsIdx = 2 59 } 60 node := &plan.Node{ 61 NodeType: plan.Node_FUNCTION_SCAN, 62 Stats: &plan.Stats{}, 63 TableDef: &plan.TableDef{ 64 TableType: "func_table", //test if ok 65 //Name: tbl.String(), 66 TblFunc: &plan.TableFunction{ 67 Name: "generate_series", 68 }, 69 Cols: GSColDefs[retsIdx], 70 }, 71 BindingTags: []int32{builder.genNewTag()}, 72 Children: []int32{childId}, 73 TblFuncExprList: exprs, 74 } 75 return builder.appendNode(node, ctx) 76 }