mirror of
https://github.com/dolthub/dolt.git
synced 2026-01-06 08:50:04 -06:00
Merge pull request #1041 from dolthub/vinai/1023-remove-tag-info
Vinai/1023 remove tag info
This commit is contained in:
@@ -43,6 +43,20 @@ SQL
|
||||
[[ "$output" =~ "new_name,c1,8201" ]] || false
|
||||
}
|
||||
|
||||
@test "Schema tags should be case insensitive to tables" {
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE TeSt (
|
||||
pk BIGINT NOT NULL,
|
||||
c1 BIGINT,
|
||||
PRIMARY KEY (pk));
|
||||
SQL
|
||||
run dolt schema tags test -r=csv
|
||||
[ $status -eq 0 ]
|
||||
[[ "$output" =~ "TeSt,pk,3228" ]] || false
|
||||
[[ "$output" =~ "TeSt,c1,8201" ]] || false
|
||||
}
|
||||
|
||||
|
||||
@test "Merging two branches that added same tag, name, type, and constraints" {
|
||||
dolt sql <<SQL
|
||||
CREATE TABLE test (
|
||||
|
||||
@@ -16,19 +16,18 @@ package schcmds
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/dolthub/go-mysql-server/sql"
|
||||
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/cli"
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/commands"
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/errhand"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/schema"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/argparser"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/filesys"
|
||||
)
|
||||
|
||||
//SELECT table_name AS 'table', column_name AS 'column', SUBSTR(extra, 5) AS tag FROM information_schema.columns WHERE table_name = 'XXX';
|
||||
|
||||
var tblTagsDocs = cli.CommandDocumentationContent{
|
||||
ShortDesc: "Shows the column tags of one or more tables.",
|
||||
LongDesc: `{{.EmphasisLeft}}dolt schema tags{{.EmphasisRight}} displays the column tags of tables on the working set.
|
||||
@@ -69,11 +68,13 @@ func (cmd TagsCmd) Exec(ctx context.Context, commandStr string, args []string, d
|
||||
apr := cli.ParseArgs(ap, args, help)
|
||||
|
||||
tables := apr.Args()
|
||||
|
||||
root, verr := commands.GetWorkingWithVErr(dEnv)
|
||||
if verr != nil {
|
||||
return commands.HandleVErrAndExitCode(verr, usage)
|
||||
}
|
||||
|
||||
if len(tables) == 0 {
|
||||
root, verr := commands.GetWorkingWithVErr(dEnv)
|
||||
if verr != nil {
|
||||
return commands.HandleVErrAndExitCode(verr, usage)
|
||||
}
|
||||
var err error
|
||||
tables, err = root.GetTableNames(ctx)
|
||||
|
||||
@@ -87,24 +88,63 @@ func (cmd TagsCmd) Exec(ctx context.Context, commandStr string, args []string, d
|
||||
return 0
|
||||
}
|
||||
}
|
||||
for i := 0; i < len(tables); i++ {
|
||||
tables[i] = fmt.Sprintf("'%s'", tables[i])
|
||||
|
||||
var headerSchema = sql.Schema{
|
||||
{Name: "table", Type: sql.Text, Default: nil},
|
||||
{Name: "column", Type: sql.Text, Default: nil},
|
||||
{Name: "tag", Type: sql.Uint64, Default: nil},
|
||||
}
|
||||
|
||||
//TODO: implement REGEXP_SUBSTR in go-mysql-server and use it here instead of SUBSTR, as this will eventually break
|
||||
queryStr := fmt.Sprintf("SELECT table_name AS 'table', column_name AS 'column', "+
|
||||
"SUBSTR(extra, 5) AS tag FROM information_schema.columns WHERE table_name IN (%s)", strings.Join(tables, ","))
|
||||
rows := make([]sql.Row, 0)
|
||||
|
||||
for _, tableName := range tables {
|
||||
table, foundTableKey, ok, err := root.GetTableInsensitive(ctx, tableName)
|
||||
|
||||
// Return an error if table is not found
|
||||
if !ok {
|
||||
return commands.HandleVErrAndExitCode(errhand.BuildDError("Can't find table %s.", tableName).AddCause(err).Build(), usage)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return commands.HandleVErrAndExitCode(errhand.BuildDError("Could not load table %s.", tableName).AddCause(err).Build(), usage)
|
||||
}
|
||||
|
||||
sch, err := table.GetSchema(ctx)
|
||||
|
||||
if err != nil {
|
||||
return commands.HandleVErrAndExitCode(errhand.BuildDError("Could not load %s schema.", tableName).AddCause(err).Build(), usage)
|
||||
}
|
||||
|
||||
_ = sch.GetAllCols().Iter(func(tag uint64, col schema.Column) (stop bool, err error) {
|
||||
rows = append(rows, sql.NewRow(foundTableKey, col.Name, tag))
|
||||
|
||||
return false, err
|
||||
})
|
||||
|
||||
if formatStr, ok := apr.GetValue(commands.FormatFlag); ok {
|
||||
return commands.SqlCmd{}.Exec(ctx, "", []string{
|
||||
fmt.Sprintf(`--%s=%s`, commands.FormatFlag, formatStr),
|
||||
fmt.Sprintf(`--%s`, commands.QueryFlag),
|
||||
queryStr + ";",
|
||||
}, dEnv)
|
||||
} else {
|
||||
return commands.SqlCmd{}.Exec(ctx, "", []string{
|
||||
fmt.Sprintf(`--%s`, commands.QueryFlag),
|
||||
queryStr + ";",
|
||||
}, dEnv)
|
||||
}
|
||||
|
||||
outputFmt, verr := commands.GetResultFormat("tabular")
|
||||
|
||||
if verr != nil {
|
||||
return commands.HandleVErrAndExitCode(errhand.VerboseErrorFromError(verr), usage)
|
||||
}
|
||||
|
||||
formatSr, ok := apr.GetValue(commands.FormatFlag)
|
||||
|
||||
var err error
|
||||
if ok {
|
||||
outputFmt, verr = commands.GetResultFormat(formatSr)
|
||||
|
||||
if verr != nil {
|
||||
return commands.HandleVErrAndExitCode(errhand.VerboseErrorFromError(verr), usage)
|
||||
}
|
||||
}
|
||||
|
||||
err = commands.PrettyPrintResults(ctx, outputFmt, headerSchema, sql.RowsToRowIter(rows...))
|
||||
|
||||
if err != nil {
|
||||
return commands.HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -164,7 +164,7 @@ func (cmd SqlCmd) Exec(ctx context.Context, commandStr string, args []string, dE
|
||||
var verr errhand.VerboseError
|
||||
format := formatTabular
|
||||
if formatSr, ok := apr.GetValue(FormatFlag); ok {
|
||||
format, verr = getFormat(formatSr)
|
||||
format, verr = GetResultFormat(formatSr)
|
||||
if verr != nil {
|
||||
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(verr), usage)
|
||||
}
|
||||
@@ -483,7 +483,7 @@ func formatQueryError(message string, err error) errhand.VerboseError {
|
||||
}
|
||||
}
|
||||
|
||||
func getFormat(format string) (resultFormat, errhand.VerboseError) {
|
||||
func GetResultFormat(format string) (resultFormat, errhand.VerboseError) {
|
||||
switch strings.ToLower(format) {
|
||||
case "tabular":
|
||||
return formatTabular, nil
|
||||
|
||||
@@ -70,7 +70,6 @@ func TestQueryErrors(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestInfoSchema(t *testing.T) {
|
||||
t.Skip("Info schema is broken by presence of tags in EXTRA")
|
||||
enginetest.TestInfoSchema(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
@@ -195,7 +194,6 @@ func TestInnerNestedInNaturalJoins(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestColumnDefaults(t *testing.T) {
|
||||
t.Skip("Broken by tag info in EXTRA")
|
||||
enginetest.TestColumnDefaults(t, newDoltHarness(t))
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,6 @@ func FromDoltSchema(tableName string, sch schema.Schema) (sql.Schema, error) {
|
||||
PrimaryKey: col.IsPartOfPK,
|
||||
AutoIncrement: col.AutoIncrement,
|
||||
Comment: col.Comment,
|
||||
Extra: fmt.Sprintf("tag:%d", tag),
|
||||
},
|
||||
Default: col.Default,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user