本文整理汇总了Golang中github.com/pingcap/tidb/expression.Schema.GetIndex方法的典型用法代码示例。如果您正苦于以下问题:Golang Schema.GetIndex方法的具体用法?Golang Schema.GetIndex怎么用?Golang Schema.GetIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/expression.Schema
的用法示例。
在下文中一共展示了Schema.GetIndex方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: makeUsedList
func makeUsedList(usedCols []*expression.Column, schema expression.Schema) []bool {
used := make([]bool, len(schema))
for _, col := range usedCols {
idx := schema.GetIndex(col)
used[idx] = true
}
return used
}
示例2: initColumnIndexInExpr
func initColumnIndexInExpr(expr expression.Expression, schema expression.Schema) {
switch assign := expr; assign.(type) {
case (*expression.Column):
assign.(*expression.Column).Index = schema.GetIndex(assign.(*expression.Column))
case (*expression.ScalarFunction):
for i, args := 0, assign.(*expression.ScalarFunction).Args; i < len(args); i++ {
initColumnIndexInExpr(args[i], schema)
}
}
}
示例3: getUsedList
func getUsedList(usedCols []*expression.Column, schema expression.Schema) []bool {
used := make([]bool, len(schema))
for _, col := range usedCols {
idx := schema.GetIndex(col)
if idx == -1 {
log.Errorf("Can't find column %s from schema %s.", col, schema)
}
used[idx] = true
}
return used
}
示例4: columnSubstitute
// columnSubstitute substitutes the columns in filter to expressions in select fields.
// e.g. select * from (select b as a from t) k where a < 10 => select * from (select b as a from t where b < 10) k.
func columnSubstitute(expr expression.Expression, schema expression.Schema, newExprs []expression.Expression) expression.Expression {
switch v := expr.(type) {
case *expression.Column:
id := schema.GetIndex(v)
return newExprs[id]
case *expression.ScalarFunction:
for i, arg := range v.Args {
v.Args[i] = columnSubstitute(arg, schema, newExprs)
}
}
return expr
}
示例5: columnSubstitute
// columnSubstitute substitutes the columns in filter to expressions in select fields.
// e.g. select * from (select b as a from t) k where a < 10 => select * from (select b as a from t where b < 10) k.
func columnSubstitute(expr expression.Expression, schema expression.Schema, newExprs []expression.Expression) expression.Expression {
switch v := expr.(type) {
case *expression.Column:
id := schema.GetIndex(v)
if id == -1 {
log.Errorf("Can't find columns %s in schema %s", v.ToString(), schema.ToString())
}
return newExprs[id]
case *expression.ScalarFunction:
for i, arg := range v.Args {
v.Args[i] = columnSubstitute(arg, schema, newExprs)
}
}
return expr
}
示例6: replaceColsInPropBySchema
// replaceColsInPropBySchema replaces the columns in original prop with the columns in schema.
func replaceColsInPropBySchema(prop *requiredProperty, schema expression.Schema) *requiredProperty {
newProps := make([]*columnProp, 0, len(prop.props))
for _, p := range prop.props {
idx := schema.GetIndex(p.col)
if idx == -1 {
log.Errorf("Can't find column %s in schema", p.col)
}
newProps = append(newProps, &columnProp{col: schema[idx], desc: p.desc})
}
return &requiredProperty{
props: newProps,
sortKeyLen: prop.sortKeyLen,
limit: prop.limit,
}
}
示例7: getAggFuncChildIdx
// getAggFuncChildIdx gets which children it belongs to, 0 stands for left, 1 stands for right, -1 stands for both.
func (a *aggPushDownSolver) getAggFuncChildIdx(aggFunc expression.AggregationFunction, schema expression.Schema) int {
fromLeft, fromRight := false, false
var cols []*expression.Column
for _, arg := range aggFunc.GetArgs() {
cols = append(cols, expression.ExtractColumns(arg)...)
}
for _, col := range cols {
if schema.GetIndex(col) != -1 {
fromLeft = true
} else {
fromRight = true
}
}
if fromLeft && fromRight {
return -1
} else if fromLeft {
return 0
}
return 1
}
示例8: calculateResultOfExpression
// calculateResultOfExpression set inner table columns in a expression as null and calculate the finally result of the scalar function.
func calculateResultOfExpression(schema expression.Schema, expr expression.Expression) (expression.Expression, error) {
switch x := expr.(type) {
case *expression.ScalarFunction:
var err error
args := make([]expression.Expression, len(x.Args))
for i, arg := range x.Args {
args[i], err = calculateResultOfExpression(schema, arg)
}
if err != nil {
return nil, errors.Trace(err)
}
return expression.NewFunction(x.FuncName.L, types.NewFieldType(mysql.TypeTiny), args...)
case *expression.Column:
if schema.GetIndex(x) == -1 {
return x, nil
}
constant := &expression.Constant{Value: types.Datum{}}
constant.Value.SetNull()
return constant, nil
default:
return x.DeepCopy(), nil
}
}