Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sql row interface #8547

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions go/cmd/dolt/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func patchWorkflow(sqlCtx *sql.Context, queryist cli.Queryist, tables []string)
}

for _, r := range rows {
tbl := r[0].(string)
tbl := r.GetValue(0).(string)
tables = append(tables, tbl)
}
}
Expand Down Expand Up @@ -301,8 +301,8 @@ func queryForUnstagedChanges(sqlCtx *sql.Context, queryist cli.Queryist, tables

changeCounts[tableName] = &tablePatchInfo{}
for _, row := range rows {
diffType := row[0].(string)
count, err := coerceToInt(row[1])
diffType := row.GetValue(0).(string)
count, err := coerceToInt(row.GetValue(1))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -344,12 +344,12 @@ func queryForUnstagedChanges(sqlCtx *sql.Context, queryist cli.Queryist, tables
if len(rows) != 1 {
return nil, errors.New("Expected one row")
}
firstId, err := coerceToInt(rows[0][0])
firstId, err := coerceToInt(rows[0].GetValue(0))
if err != nil {
return nil, err
}
changeCounts[tableName].firstId = firstId
lastId, err := coerceToInt(rows[0][1])
lastId, err := coerceToInt(rows[0].GetValue(1))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -468,7 +468,7 @@ func (ps *patchState) skipRemainingInTable(c *ishell.Context) {
// addRemainingInTable adds all changes in the current table. "a" command.
func (ps *patchState) addRemainingInTable(c *ishell.Context) {
// grab the row id.
id, err := coerceToInt(ps.currentRow[0])
id, err := coerceToInt(ps.currentRow.GetValue(0))
if err != nil {
ps.err = err
c.Stop()
Expand Down Expand Up @@ -609,20 +609,20 @@ func newState(sqlCtx *sql.Context, queryist cli.Queryist, tables []string) (*pat
}

func printSingleChange(sqlCtx *sql.Context, workspaceRow sql.Row, schema sql.Schema) (err error) {
writer := tabular.NewFixedWidthDiffTableWriter(schema, iohelp.NopWrCloser(cli.CliOut), len(workspaceRow)/2)
writer := tabular.NewFixedWidthDiffTableWriter(schema, iohelp.NopWrCloser(cli.CliOut), workspaceRow.Len()/2)
defer writer.Close(sqlCtx.Context)

toRow := workspaceRow[3 : 3+len(schema)]
fromRow := workspaceRow[3+len(schema):]
toRow := workspaceRow.Subslice(3, 3+len(schema))
fromRow := workspaceRow.Subslice(3+len(schema), workspaceRow.Len())

diffType := workspaceRow[2].(string)
diffType := workspaceRow.GetValue(2).(string)
switch diffType {
case "added":
err = writer.WriteRow(sqlCtx.Context, toRow, diff.Added, colDiffType(diff.Added, len(toRow)))
err = writer.WriteRow(sqlCtx.Context, toRow, diff.Added, colDiffType(diff.Added, toRow.Len()))
case "modified":
err = writer.WriteCombinedRow(sqlCtx.Context, fromRow, toRow, diff.ModeContext)
case "removed":
err = writer.WriteRow(sqlCtx.Context, fromRow, diff.Removed, colDiffType(diff.Removed, len(fromRow)))
err = writer.WriteRow(sqlCtx.Context, fromRow, diff.Removed, colDiffType(diff.Removed, fromRow.Len()))
default:
err = errors.New(fmt.Sprintf("Unexpected diff type: %s", diffType))
}
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/dolt/commands/assist.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ func getCreateTableStatements(ctx *sql.Context, sqlEngine *engine.SqlEngine, dEn
return "", err
}

createTable := rows[0][1].(string)
createTable := rows[0].GetValue(1).(string)
sb.WriteString(createTable)
sb.WriteString("\n\n")
}
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/dolt/commands/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func getBranches(sqlCtx *sql.Context, queryEngine cli.Queryist, remote bool) ([]
if err != nil {
return nil, err
}
if len(row) != 2 {
if row.Len() != 2 {
return nil, fmt.Errorf("unexpectedly received multiple columns in '%s': %s", command, row)
}

Expand Down
4 changes: 2 additions & 2 deletions go/cmd/dolt/commands/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,11 @@ func (cmd CheckoutCmd) Exec(ctx context.Context, commandStr string, args []strin
return HandleVErrAndExitCode(errhand.BuildDError("expected 1 row response from %s, got %d", sqlQuery, len(rows)).Build(), usage)
}

if len(rows[0]) < 2 {
if rows[0].Len() < 2 {
return HandleVErrAndExitCode(errhand.BuildDError("no 'message' field in response from %s", sqlQuery).Build(), usage)
}

message, ok := rows[0][1].(string)
message, ok := rows[0].GetValue(1).(string)
if !ok {
return HandleVErrAndExitCode(errhand.BuildDError("expected string value for 'message' field in response from %s ", sqlQuery).Build(), usage)
}
Expand Down
8 changes: 4 additions & 4 deletions go/cmd/dolt/commands/cherry-pick.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,16 @@ hint: commit your changes (dolt commit -am \"<message>\") or reset them (dolt re
succeeded := false
commitHash := ""
for _, row := range rows {
commitHash = row[0].(string)
dataConflicts, err := getInt64ColAsInt64(row[1])
commitHash = row.GetValue(0).(string)
dataConflicts, err := getInt64ColAsInt64(row.GetValue(1))
if err != nil {
return fmt.Errorf("Unable to parse data_conflicts column: %w", err)
}
schemaConflicts, err := getInt64ColAsInt64(row[2])
schemaConflicts, err := getInt64ColAsInt64(row.GetValue(2))
if err != nil {
return fmt.Errorf("Unable to parse schema_conflicts column: %w", err)
}
constraintViolations, err := getInt64ColAsInt64(row[3])
constraintViolations, err := getInt64ColAsInt64(row.GetValue(3))
if err != nil {
return fmt.Errorf("Unable to parse constraint_violations column: %w", err)
}
Expand Down
10 changes: 5 additions & 5 deletions go/cmd/dolt/commands/cnfcmds/cat.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,15 @@ func getMergeStatus(queryist cli.Queryist, sqlCtx *sql.Context) (mergeStatus, er
}

row := rows[0]
ms.isMerging, err = commands.GetTinyIntColAsBool(row[0])
ms.isMerging, err = commands.GetTinyIntColAsBool(row.GetValue(0))
if err != nil {
return ms, fmt.Errorf("error: failed to parse is_merging: %w", err)
}
if ms.isMerging {
ms.source = row[1].(string)
ms.sourceCommit = row[2].(string)
ms.target = row[3].(string)
unmergedTables := row[4].(string)
ms.source = row.GetValue(1).(string)
ms.sourceCommit = row.GetValue(2).(string)
ms.target = row.GetValue(3).(string)
unmergedTables := row.GetValue(4).(string)
ms.unmergedTables = strings.Split(unmergedTables, ", ")
}

Expand Down
12 changes: 6 additions & 6 deletions go/cmd/dolt/commands/cnfcmds/conflictsplitter.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,28 +109,28 @@ type conflictRow struct {
}

func (cs conflictSplitter) splitConflictRow(row sql.Row) ([]conflictRow, error) {
baseRow, ourRow, theirRow := make(sql.Row, len(cs.targetSch)), make(sql.Row, len(cs.targetSch)), make(sql.Row, len(cs.targetSch))
baseRow, ourRow, theirRow := make(sql.UntypedSqlRow, len(cs.targetSch)), make(sql.UntypedSqlRow, len(cs.targetSch)), make(sql.UntypedSqlRow, len(cs.targetSch))

ourDiffType := changeTypeFromString(row[cs.ourDiffTypeIdx].(string))
theirDiffType := changeTypeFromString(row[cs.theirDiffTypeIdx].(string))
ourDiffType := changeTypeFromString(row.GetValue(cs.ourDiffTypeIdx).(string))
theirDiffType := changeTypeFromString(row.GetValue(cs.theirDiffTypeIdx).(string))

for from, to := range cs.baseToTarget {
baseRow[to] = row[from]
baseRow.SetValue(to, row.GetValue(from))
}

if ourDiffType == diff.Removed {
ourRow = baseRow
} else {
for from, to := range cs.ourToTarget {
ourRow[to] = row[from]
ourRow.SetValue(to, row.GetValue(from))
}
}

if theirDiffType == diff.Removed {
theirRow = baseRow
} else {
for from, to := range cs.theirToTarget {
theirRow[to] = row[from]
theirRow.SetValue(to, row.GetValue(from))
}
}

Expand Down
40 changes: 20 additions & 20 deletions go/cmd/dolt/commands/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func performCommit(ctx context.Context, commandStr string, args []string, cliCtx
cli.Println(err.Error())
return 1, false
}
amendStr = row[0].(string)
amendStr = row.GetValue(0).(string)
}
msg, err = getCommitMessageFromEditor(sqlCtx, queryist, "", amendStr, false, cliCtx)
if err != nil {
Expand Down Expand Up @@ -463,7 +463,7 @@ func PrintDiffsNotStaged(
}
var conflictTables []string
for i, _ := range conflictRows {
conflictTables = append(conflictTables, conflictRows[i][0].(string))
conflictTables = append(conflictTables, conflictRows[i].GetValue(0).(string))
}
inCnfSet := set.NewStrSet(conflictTables)

Expand All @@ -478,7 +478,7 @@ func PrintDiffsNotStaged(
}
var schemaConflictTables []string
for i, _ := range schemaConflictRows {
schemaConflictTables = append(schemaConflictTables, schemaConflictRows[i][0].(string))
schemaConflictTables = append(schemaConflictTables, schemaConflictRows[i].GetValue(0).(string))
}
inCnfSet.Add(schemaConflictTables...)

Expand All @@ -493,7 +493,7 @@ func PrintDiffsNotStaged(
}
var constraintViolationTables []string
for i, _ := range constraintViolationRows {
constraintViolationTables = append(constraintViolationTables, constraintViolationRows[i][0].(string))
constraintViolationTables = append(constraintViolationTables, constraintViolationRows[i].GetValue(0).(string))
}
violationSet := set.NewStrSet(constraintViolationTables)

Expand Down Expand Up @@ -532,9 +532,9 @@ func PrintDiffsNotStaged(
added := 0
removeModified := 0
for _, row := range notStagedRows {
if row[1] == "new table" {
if row.GetValue(1) == "new table" {
added++
} else if row[1] == "renamed" {
} else if row.GetValue(1) == "renamed" {
added++
removeModified++
} else {
Expand Down Expand Up @@ -633,17 +633,17 @@ func PrintDiffsNotStaged(
func getModifiedAndRemovedNotStaged(notStagedRows []sql.Row, inCnfSet, violationSet *set.StrSet) (lines []string) {
lines = make([]string, 0, len(notStagedRows))
for _, row := range notStagedRows {
if row[1] == "added" || inCnfSet.Contains(row[0].(string)) || violationSet.Contains(row[0].(string)) {
if row.GetValue(1) == "added" || inCnfSet.Contains(row.GetValue(0).(string)) || violationSet.Contains(row.GetValue(0).(string)) {
continue
}
if row[1] == "deleted" {
lines = append(lines, fmt.Sprintf(statusFmt, tblDiffTypeToLabel[diff.RemovedTable], row[0].(string)))
} else if row[1] == "renamed" {
if row.GetValue(1) == "deleted" {
lines = append(lines, fmt.Sprintf(statusFmt, tblDiffTypeToLabel[diff.RemovedTable], row.GetValue(0).(string)))
} else if row.GetValue(1) == "renamed" {
// per Git, unstaged renames are shown as drop + add
names := strings.Split(row[0].(string), " -> ")
names := strings.Split(row.GetValue(0).(string), " -> ")
lines = append(lines, fmt.Sprintf(statusFmt, tblDiffTypeToLabel[diff.RemovedTable], names[0]))
} else {
lines = append(lines, fmt.Sprintf(statusFmt, tblDiffTypeToLabel[diff.ModifiedTable], row[0].(string)))
lines = append(lines, fmt.Sprintf(statusFmt, tblDiffTypeToLabel[diff.ModifiedTable], row.GetValue(0).(string)))
}
}
return lines
Expand All @@ -652,8 +652,8 @@ func getModifiedAndRemovedNotStaged(notStagedRows []sql.Row, inCnfSet, violation
func getAddedNotStagedTables(notStagedRows []sql.Row) (tables []doltdb.TableName) {
tables = make([]doltdb.TableName, 0, len(notStagedRows))
for _, row := range notStagedRows {
if row[1] == "added" || row[1] == "renamed" {
names := strings.Split(row[0].(string), " -> ")
if row.GetValue(1) == "added" || row.GetValue(1) == "renamed" {
names := strings.Split(row.GetValue(0).(string), " -> ")
// TODO: schema name
tables = append(tables, doltdb.TableName{Name: names[0]})
}
Expand Down Expand Up @@ -713,17 +713,17 @@ func printStagedDiffs(wr io.Writer, stagedRows []sql.Row, printHelp bool) int {

lines := make([]string, 0, len(stagedRows))
for _, row := range stagedRows {
if !doltdb.IsReadOnlySystemTable(doltdb.TableName{Name: row[0].(string)}) {
switch row[1].(string) {
if !doltdb.IsReadOnlySystemTable(doltdb.TableName{Name: row.GetValue(0).(string)}) {
switch row.GetValue(1).(string) {
case "new table":
lines = append(lines, fmt.Sprintf(statusFmt, tblDiffTypeToLabel[diff.AddedTable], row[0].(string)))
lines = append(lines, fmt.Sprintf(statusFmt, tblDiffTypeToLabel[diff.AddedTable], row.GetValue(0).(string)))
case "deleted":
lines = append(lines, fmt.Sprintf(statusFmt, tblDiffTypeToLabel[diff.RemovedTable], row[0].(string)))
lines = append(lines, fmt.Sprintf(statusFmt, tblDiffTypeToLabel[diff.RemovedTable], row.GetValue(0).(string)))
case "renamed":
names := strings.Split(row[0].(string), " -> ")
names := strings.Split(row.GetValue(0).(string), " -> ")
lines = append(lines, fmt.Sprintf(statusRenameFmt, tblDiffTypeToLabel[diff.RenamedTable], names[0], names[1]))
default:
lines = append(lines, fmt.Sprintf(statusFmt, tblDiffTypeToLabel[diff.ModifiedTable], row[0].(string)))
lines = append(lines, fmt.Sprintf(statusFmt, tblDiffTypeToLabel[diff.ModifiedTable], row.GetValue(0).(string)))
}
}
}
Expand Down
Loading
Loading