github.com/matrixorigin/matrixone@v0.7.0/pkg/sql/plan/meta_scan.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/catalog" 19 "github.com/matrixorigin/matrixone/pkg/common/moerr" 20 "github.com/matrixorigin/matrixone/pkg/container/batch" 21 "github.com/matrixorigin/matrixone/pkg/container/types" 22 "github.com/matrixorigin/matrixone/pkg/container/vector" 23 "github.com/matrixorigin/matrixone/pkg/pb/plan" 24 "github.com/matrixorigin/matrixone/pkg/sql/colexec" 25 "github.com/matrixorigin/matrixone/pkg/sql/parsers/tree" 26 ) 27 28 var ( 29 MetaColDefs = []*plan.ColDef{ 30 { 31 Name: catalog.MetaColNames[catalog.QUERY_ID_IDX], 32 Typ: &plan.Type{ 33 Id: int32(catalog.MetaColTypes[catalog.QUERY_ID_IDX].Oid), 34 NotNullable: false, 35 }, 36 }, 37 { 38 Name: catalog.MetaColNames[catalog.STATEMENT_IDX], 39 Typ: &plan.Type{ 40 Id: int32(catalog.MetaColTypes[catalog.STATEMENT_IDX].Oid), 41 NotNullable: false, 42 }, 43 }, 44 { 45 Name: catalog.MetaColNames[catalog.ACCOUNT_ID_IDX], 46 Typ: &plan.Type{ 47 Id: int32(catalog.MetaColTypes[catalog.ACCOUNT_ID_IDX].Oid), 48 NotNullable: false, 49 }, 50 }, 51 { 52 Name: catalog.MetaColNames[catalog.ROLE_ID_IDX], 53 Typ: &plan.Type{ 54 Id: int32(catalog.MetaColTypes[catalog.ROLE_ID_IDX].Oid), 55 NotNullable: false, 56 }, 57 }, 58 { 59 Name: catalog.MetaColNames[catalog.RESULT_PATH_IDX], 60 Typ: &plan.Type{ 61 Id: int32(catalog.MetaColTypes[catalog.RESULT_PATH_IDX].Oid), 62 NotNullable: false, 63 Width: 4, 64 }, 65 }, 66 { 67 Name: catalog.MetaColNames[catalog.CREATE_TIME_IDX], 68 Typ: &plan.Type{ 69 Id: int32(catalog.MetaColTypes[catalog.CREATE_TIME_IDX].Oid), 70 NotNullable: false, 71 }, 72 }, 73 { 74 Name: catalog.MetaColNames[catalog.RESULT_SIZE_IDX], 75 Typ: &plan.Type{ 76 Id: int32(catalog.MetaColTypes[catalog.RESULT_SIZE_IDX].Oid), 77 NotNullable: false, 78 }, 79 }, 80 { 81 Name: catalog.MetaColNames[catalog.TABLES_IDX], 82 Typ: &plan.Type{ 83 Id: int32(catalog.MetaColTypes[catalog.TABLES_IDX].Oid), 84 NotNullable: false, 85 }, 86 }, 87 { 88 Name: catalog.MetaColNames[catalog.USER_ID_IDX], 89 Typ: &plan.Type{ 90 Id: int32(catalog.MetaColTypes[catalog.USER_ID_IDX].Oid), 91 NotNullable: false, 92 }, 93 }, 94 { 95 Name: catalog.MetaColNames[catalog.EXPIRED_TIME_IDX], 96 Typ: &plan.Type{ 97 Id: int32(catalog.MetaColTypes[catalog.EXPIRED_TIME_IDX].Oid), 98 NotNullable: false, 99 }, 100 }, 101 { 102 Name: catalog.MetaColNames[catalog.COLUMN_MAP_IDX], 103 Typ: &plan.Type{ 104 Id: int32(catalog.MetaColTypes[catalog.COLUMN_MAP_IDX].Oid), 105 NotNullable: false, 106 }, 107 }, 108 } 109 ) 110 111 func (builder *QueryBuilder) buildMetaScan(tbl *tree.TableFunction, ctx *BindContext, exprs []*plan.Expr, childId int32) (int32, error) { 112 var err error 113 val, err := builder.compCtx.ResolveVariable("save_query_result", true, true) 114 if err == nil { 115 if v, _ := val.(int8); v == 0 { 116 return 0, moerr.NewNoConfig(builder.GetContext(), "save query result") 117 } 118 } 119 exprs[0], err = appendCastBeforeExpr(builder.GetContext(), exprs[0], &plan.Type{ 120 Id: int32(types.T_uuid), 121 NotNullable: true, 122 }) 123 if err != nil { 124 return 0, err 125 } 126 // calculate uuid 127 bat := batch.NewWithSize(0) 128 bat.Zs = []int64{1} 129 vec, err := colexec.EvalExpr(bat, builder.compCtx.GetProcess(), exprs[0]) 130 if err != nil { 131 return 0, err 132 } 133 uuid := vector.MustTCols[types.Uuid](vec)[0] 134 node := &plan.Node{ 135 NodeType: plan.Node_FUNCTION_SCAN, 136 Stats: &plan.Stats{}, 137 TableDef: &plan.TableDef{ 138 Name: uuid.ToString(), 139 TableType: "func_table", 140 TblFunc: &plan.TableFunction{ 141 Name: "meta_scan", 142 }, 143 Cols: MetaColDefs, 144 }, 145 BindingTags: []int32{builder.genNewTag()}, 146 Children: []int32{childId}, 147 TblFuncExprList: exprs, 148 } 149 return builder.appendNode(node, ctx), nil 150 }