func convertColumnsToValExpr(columns []*schema.TableColumn) []sqlparser.ValExpr { valExprs := make([]sqlparser.ValExpr, 0, len(columns)) for _, column := range columns { valExprs = append(valExprs, &sqlparser.ColName{Name: sqlparser.ColIdent(column.Name)}) } return valExprs }
func buildOrderByClause(splitColumns []*schema.TableColumn) sqlparser.OrderBy { result := make(sqlparser.OrderBy, 0, len(splitColumns)) for _, splitColumn := range splitColumns { result = append(result, &sqlparser.Order{ Expr: &sqlparser.ColName{Name: sqlparser.ColIdent(splitColumn.Name)}, Direction: sqlparser.AscScr, }, ) } return result }
func convertColumnsToSelectExprs(columns []*schema.TableColumn) sqlparser.SelectExprs { result := make([]sqlparser.SelectExpr, 0, len(columns)) for _, column := range columns { result = append(result, &sqlparser.NonStarExpr{ Expr: &sqlparser.ColName{ Name: sqlparser.ColIdent(column.Name), }, }) } return result }
// getWhereClause returns a whereClause based on desired upper and lower // bounds for primary key. func (qs *QuerySplitter) getWhereClause(whereClause *sqlparser.Where, bindVars map[string]interface{}, start, end sqltypes.Value) *sqlparser.Where { var startClause *sqlparser.ComparisonExpr var endClause *sqlparser.ComparisonExpr var clauses sqlparser.BoolExpr // No upper or lower bound, just return the where clause of original query if start.IsNull() && end.IsNull() { return whereClause } pk := &sqlparser.ColName{ Name: sqlparser.ColIdent(qs.splitColumn), } if !start.IsNull() { startClause = &sqlparser.ComparisonExpr{ Operator: sqlparser.GreaterEqualStr, Left: pk, Right: sqlparser.ValArg([]byte(":" + startBindVarName)), } bindVars[startBindVarName] = start.ToNative() } // splitColumn < end if !end.IsNull() { endClause = &sqlparser.ComparisonExpr{ Operator: sqlparser.LessThanStr, Left: pk, Right: sqlparser.ValArg([]byte(":" + endBindVarName)), } bindVars[endBindVarName] = end.ToNative() } if startClause == nil { clauses = endClause } else { if endClause == nil { clauses = startClause } else { // splitColumn >= start AND splitColumn < end clauses = &sqlparser.AndExpr{ Left: startClause, Right: endClause, } } } if whereClause != nil { clauses = &sqlparser.AndExpr{ Left: &sqlparser.ParenBoolExpr{Expr: whereClause.Expr}, Right: &sqlparser.ParenBoolExpr{Expr: clauses}, } } return &sqlparser.Where{ Type: sqlparser.WhereStr, Expr: clauses, } }
func findOrInsertPos(ins *sqlparser.Insert, col cistring.CIString, rowNum int) (row sqlparser.ValTuple, pos int) { pos = -1 for i, column := range ins.Columns { if col.Equal(cistring.CIString(column)) { pos = i break } } if pos == -1 { pos = len(ins.Columns) ins.Columns = append(ins.Columns, sqlparser.ColIdent(col)) } if pos == -1 || pos >= len(ins.Rows.(sqlparser.Values)[rowNum].(sqlparser.ValTuple)) { ins.Rows.(sqlparser.Values)[rowNum] = append(ins.Rows.(sqlparser.Values)[rowNum].(sqlparser.ValTuple), &sqlparser.NullVal{}) } return ins.Rows.(sqlparser.Values)[rowNum].(sqlparser.ValTuple), pos }
func nameMatch(node sqlparser.ValExpr, col cistring.CIString) bool { colname, ok := node.(*sqlparser.ColName) return ok && colname.Name.Equal(sqlparser.ColIdent(col)) }