本文整理汇总了Golang中github.com/youtube/vitess/go/vt/schema.Table类的典型用法代码示例。如果您正苦于以下问题:Golang Table类的具体用法?Golang Table怎么用?Golang Table使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Table类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: analyzeSelectExprs
func analyzeSelectExprs(exprs sqlparser.SelectExprs, table *schema.Table) (selects []int, err error) {
selects = make([]int, 0, len(exprs))
for _, expr := range exprs {
switch expr := expr.(type) {
case *sqlparser.StarExpr:
// Append all columns.
for colIndex := range table.Columns {
selects = append(selects, colIndex)
}
case *sqlparser.NonStarExpr:
name := sqlparser.GetColName(expr.Expr)
if name == "" {
// Not a simple column name.
return nil, nil
}
colIndex := table.FindColumn(name)
if colIndex == -1 {
return nil, fmt.Errorf("column %s not found in table %s", name, table.Name)
}
selects = append(selects, colIndex)
default:
panic("unreachable")
}
}
return selects, nil
}
开发者ID:ninqing,项目名称:vitess,代码行数:26,代码来源:select.go
示例2: getInsertPKValues
func getInsertPKValues(pkColumnNumbers []int, rowList *Node, tableInfo *schema.Table) (pkValues []interface{}) {
pkValues = make([]interface{}, len(pkColumnNumbers))
for index, columnNumber := range pkColumnNumbers {
if columnNumber == -1 {
pkValues[index] = tableInfo.GetPKColumn(index).Default
continue
}
values := make([]interface{}, rowList.Len())
for j := 0; j < rowList.Len(); j++ {
if columnNumber >= rowList.At(j).At(0).Len() { // NODE_LIST->'('->NODE_LIST
panic(NewParserError("Column count doesn't match value count"))
}
node := rowList.At(j).At(0).At(columnNumber) // NODE_LIST->'('->NODE_LIST->Value
value := node.execAnalyzeValue()
if value == nil {
log.Warningf("insert is too complex %v", node)
return nil
}
values[j] = asInterface(value)
}
if len(values) == 1 {
pkValues[index] = values[0]
} else {
pkValues[index] = values
}
}
return pkValues
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:28,代码来源:execution.go
示例3: getInsertPKValues
func getInsertPKValues(pkColumnNumbers []int, rowList sqlparser.Values, tableInfo *schema.Table) (pkValues []interface{}, err error) {
pkValues = make([]interface{}, len(pkColumnNumbers))
for index, columnNumber := range pkColumnNumbers {
if columnNumber == -1 {
pkValues[index] = tableInfo.GetPKColumn(index).Default
continue
}
values := make([]interface{}, len(rowList))
for j := 0; j < len(rowList); j++ {
if _, ok := rowList[j].(*sqlparser.Subquery); ok {
return nil, errors.New("row subquery not supported for inserts")
}
row := rowList[j].(sqlparser.ValTuple)
if columnNumber >= len(row) {
return nil, errors.New("column count doesn't match value count")
}
node := row[columnNumber]
if !sqlparser.IsNull(node) && !sqlparser.IsValue(node) {
return nil, nil
}
var err error
values[j], err = sqlparser.AsInterface(node)
if err != nil {
return nil, err
}
}
if len(values) == 1 {
pkValues[index] = values[0]
} else {
pkValues[index] = values
}
}
return pkValues, nil
}
开发者ID:jmptrader,项目名称:vitess,代码行数:34,代码来源:dml.go
示例4: addIndexToTable
// addIndexToTable adds an index named 'indexName' to 'table' with the given 'indexCols'.
// It uses 12345 as the cardinality.
// It returns the new index.
func addIndexToTable(table *schema.Table, indexName string, indexCols ...string) *schema.Index {
index := table.AddIndex(indexName)
for _, indexCol := range indexCols {
index.AddColumn(indexCol, 12345)
}
return index
}
开发者ID:CowLeo,项目名称:vitess,代码行数:10,代码来源:testutils_test.go
示例5: findSplitColumnsInSchema
func findSplitColumnsInSchema(
splitColumnNames []sqlparser.ColIdent, tableSchema *schema.Table,
) ([]*schema.TableColumn, error) {
result := make([]*schema.TableColumn, 0, len(splitColumnNames))
for _, splitColumnName := range splitColumnNames {
i := tableSchema.FindColumn(splitColumnName.Original())
if i == -1 {
return nil, fmt.Errorf("can't find split column: %v", splitColumnName)
}
result = append(result, &tableSchema.Columns[i])
}
return result, nil
}
开发者ID:CowLeo,项目名称:vitess,代码行数:13,代码来源:split_params.go
示例6: execAnalyzeSelectExpressions
func (node *Node) execAnalyzeSelectExpressions(table *schema.Table) (selects []int) {
selects = make([]int, 0, node.Len())
for i := 0; i < node.Len(); i++ {
if name := node.At(i).execAnalyzeSelectExpression(); name != "" {
if name == "*" {
for colIndex := range table.Columns {
selects = append(selects, colIndex)
}
} else if colIndex := table.FindColumn(name); colIndex != -1 {
selects = append(selects, colIndex)
} else {
panic(NewParserError("Column %s not found in table %s", name, table.Name))
}
} else {
// Complex expression
return nil
}
}
return selects
}
开发者ID:rrudduck,项目名称:golang-stuff,代码行数:20,代码来源:execution.go
示例7: execAnalyzeSelectExprs
func execAnalyzeSelectExprs(exprs SelectExprs, table *schema.Table) (selects []int) {
selects = make([]int, 0, len(exprs))
for _, expr := range exprs {
if name := execAnalyzeSelectExpr(expr); name != "" {
if name == "*" {
for colIndex := range table.Columns {
selects = append(selects, colIndex)
}
} else if colIndex := table.FindColumn(name); colIndex != -1 {
selects = append(selects, colIndex)
} else {
panic(NewParserError("column %s not found in table %s", name, table.Name))
}
} else {
// Complex expression
return nil
}
}
return selects
}
开发者ID:kingpro,项目名称:vitess,代码行数:20,代码来源:execution.go
示例8: getTestSchema
// getSchema returns a fake schema object that can be given to SplitParams
func getTestSchema() map[string]*schema.Table {
table := schema.Table{
Name: "test_table",
}
zero, _ := sqltypes.BuildValue(0)
table.AddColumn("id", sqltypes.Int64, zero, "")
table.AddColumn("int32_col", sqltypes.Int32, zero, "")
table.AddColumn("uint32_col", sqltypes.Uint32, zero, "")
table.AddColumn("int64_col", sqltypes.Int64, zero, "")
table.AddColumn("uint64_col", sqltypes.Uint64, zero, "")
table.AddColumn("float32_col", sqltypes.Float32, zero, "")
table.AddColumn("float64_col", sqltypes.Float64, zero, "")
table.AddColumn("user_id", sqltypes.Int64, zero, "")
table.AddColumn("user_id2", sqltypes.Int64, zero, "")
table.AddColumn("id2", sqltypes.Int64, zero, "")
table.AddColumn("count", sqltypes.Int64, zero, "")
table.PKColumns = []int{0, 7}
addIndexToTable(&table, "PRIMARY", "id", "user_id")
addIndexToTable(&table, "idx_id2", "id2")
addIndexToTable(&table, "idx_int64_col", "int64_col")
addIndexToTable(&table, "idx_uint64_col", "uint64_col")
addIndexToTable(&table, "idx_float64_col", "float64_col")
addIndexToTable(&table, "idx_id_user_id", "id", "user_id")
addIndexToTable(&table, "idx_id_user_id_user_id_2", "id", "user_id", "user_id2")
table.SetMysqlStats(
int64Value(1000), /* TableRows */
int64Value(100), /* DataLength */
int64Value(123), /* IndexLength */
int64Value(456), /* DataFree */
)
result := make(map[string]*schema.Table)
result["test_table"] = &table
tableNoPK := schema.Table{
Name: "test_table_no_pk",
}
tableNoPK.AddColumn("id", sqltypes.Int64, zero, "")
tableNoPK.PKColumns = []int{}
result["test_table_no_pk"] = &tableNoPK
return result
}
开发者ID:CowLeo,项目名称:vitess,代码行数:45,代码来源:testutils_test.go
示例9: GetSchema
// GetSchema returns a fake schema object that can be given to SplitParams
func GetSchema() map[string]*schema.Table {
table := schema.Table{
Name: "test_table",
}
zero, _ := sqltypes.BuildValue(0)
table.AddColumn("id", sqltypes.Int64, zero, "")
table.AddColumn("int32_col", sqltypes.Int32, zero, "")
table.AddColumn("uint32_col", sqltypes.Uint32, zero, "")
table.AddColumn("int64_col", sqltypes.Int64, zero, "")
table.AddColumn("uint64_col", sqltypes.Uint64, zero, "")
table.AddColumn("float32_col", sqltypes.Float32, zero, "")
table.AddColumn("float64_col", sqltypes.Float64, zero, "")
table.AddColumn("user_id", sqltypes.Int64, zero, "")
table.AddColumn("user_id2", sqltypes.Int64, zero, "")
table.AddColumn("id2", sqltypes.Int64, zero, "")
table.AddColumn("count", sqltypes.Int64, zero, "")
table.PKColumns = []int{0, 7}
addIndexToTable(&table, "PRIMARY", "id", "user_id")
addIndexToTable(&table, "idx_id2", "id2")
addIndexToTable(&table, "idx_int64_col", "int64_col")
addIndexToTable(&table, "idx_uint64_col", "uint64_col")
addIndexToTable(&table, "idx_float64_col", "float64_col")
addIndexToTable(&table, "idx_id_user_id", "id", "user_id")
addIndexToTable(&table, "idx_id_user_id_user_id_2", "id", "user_id", "user_id2")
result := make(map[string]*schema.Table)
result["test_table"] = &table
tableNoPK := schema.Table{
Name: "test_table_no_pk",
}
tableNoPK.AddColumn("id", sqltypes.Int64, zero, "")
tableNoPK.PKColumns = []int{}
result["test_table_no_pk"] = &tableNoPK
return result
}
开发者ID:aaijazi,项目名称:vitess,代码行数:38,代码来源:testutils_test.go
注:本文中的github.com/youtube/vitess/go/vt/schema.Table类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论