repo fmt and table name check

This commit is contained in:
Andy Arthur
2020-05-05 19:59:58 -07:00
parent 8119935e74
commit 18e6bcaad8
17 changed files with 38 additions and 34 deletions

View File

@@ -137,7 +137,6 @@ teardown() {
run dolt table import -c --pk=pk1,pk2 test `batshelper 2pk5col-ints.csv`
[ "$status" -eq 0 ]
[[ "$output" =~ "Import completed successfully." ]] || false
dolt sql -q 'select count(*) from test'
run dolt sql -q 'select count(*) from test'
[ "$status" -eq 0 ]
[[ "$output" =~ "4" ]] || false
@@ -290,7 +289,6 @@ SQL
run dolt ls
[ "$status" -eq 0 ]
[[ "$output" =~ "empty_strings_null_values" ]] || false
dolt sql -q "select * from empty_strings_null_values"
run dolt sql -q "select * from empty_strings_null_values"
[ "$status" -eq 0 ]
[ "${#lines[@]}" -eq 11 ]

View File

@@ -174,7 +174,7 @@ func printSystemTables(ctx context.Context, root *doltdb.RootValue, ddb *doltdb.
}
cli.Println("System tables:")
for _, tbl := range perSysTbls{
for _, tbl := range perSysTbls {
if verbose {
ls, verr := listTableVerbose(ctx, tbl, root)
if verr != nil {

View File

@@ -17,19 +17,18 @@ package schcmds
import (
"context"
"fmt"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/sqle/sqlfmt"
"io"
"os"
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
"github.com/liquidata-inc/dolt/go/cmd/dolt/commands"
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
eventsapi "github.com/liquidata-inc/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/env"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/sqle/sqlfmt"
"github.com/liquidata-inc/dolt/go/libraries/utils/argparser"
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
)
var schExportDocs = cli.CommandDocumentationContent{
@@ -41,7 +40,7 @@ var schExportDocs = cli.CommandDocumentationContent{
}
const (
//exportAllSchFlag = "all"
//exportAllSchFlag = "all"
)
type ExportCmd struct{}
@@ -94,7 +93,7 @@ func exportSchemas(ctx context.Context, apr *argparser.ArgParseResults, root *do
var tblName string
var fileName string
switch apr.NArg() {
case 0: // write all tables to stdout
case 0: // write all tables to stdout
case 1:
if doltdb.IsValidTableName(apr.Arg(0)) {
tblName = apr.Arg(0)
@@ -145,7 +144,7 @@ func exportTblSchema(ctx context.Context, tblName string, root *doltdb.RootValue
if has, err := root.HasTable(ctx, tblName); err != nil {
return errhand.BuildDError("unable to read from database").AddCause(err).Build()
} else if !has {
return errhand.BuildDError( "table %s not found", tblName).Build()
return errhand.BuildDError("table %s not found", tblName).Build()
}
tbl, _, err := root.GetTable(ctx, tblName)

View File

@@ -140,6 +140,7 @@ func (cmd CpCmd) Exec(ctx context.Context, commandStr string, args []string, dEn
mvOpts := &mvdata.MoveOptions{
Operation: mvdata.OverwriteOp,
TableName: newTbl,
ContOnErr: true,
Force: force,
Src: mvdata.TableDataLocation{Name: oldTbl},

View File

@@ -106,7 +106,7 @@ func parseExportArgs(ap *argparser.ArgParser, commandStr string, args []string)
return &mvdata.MoveOptions{
Operation: mvdata.OverwriteOp,
ContOnErr: apr.Contains(contOnErrParam),
Force: apr.Contains(forceParam),
Force: apr.Contains(forceParam),
TableName: tableName,
SchFile: schemaFile,
MappingFile: mappingFile,

View File

@@ -333,7 +333,6 @@ func executeMove(ctx context.Context, dEnv *env.DoltEnv, mvOpts *mvdata.MoveOpti
return errhand.BuildDError("Unable to get the working root value for this data repository.").AddCause(err).Build()
}
if mvOpts.WillOverwrite() {
destExists, err := mvOpts.Dest.Exists(ctx, root, dEnv.FS)
if err != nil {

View File

@@ -17,10 +17,11 @@ package doltdb
import (
"context"
"errors"
"github.com/liquidata-inc/dolt/go/libraries/utils/funcitr"
"sort"
"strings"
"github.com/liquidata-inc/dolt/go/libraries/utils/funcitr"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/schema"
"github.com/liquidata-inc/dolt/go/libraries/utils/set"
)

View File

@@ -17,12 +17,13 @@ package doltdb
import (
"context"
"errors"
"regexp"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/row"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/schema"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/schema/encoding"
"github.com/liquidata-inc/dolt/go/store/hash"
"github.com/liquidata-inc/dolt/go/store/types"
"regexp"
)
const (
@@ -37,7 +38,6 @@ const (
TableNameRegexStr = `^[a-zA-Z]{1}$|^[a-zA-Z]+[-_0-9a-zA-Z]*[0-9a-zA-Z]+$`
)
var tableNameRegex, _ = regexp.Compile(TableNameRegexStr)
// IsValidTableName returns true if the name matches the regular expression TableNameRegexStr.

View File

@@ -35,9 +35,9 @@ import (
)
const (
testTableName = "test_table"
testTableName = "test_table"
testSchemaFileName = "schema.sql"
testSchema = `
testSchema = `
CREATE TABLE test_table (
a VARCHAR(120) COMMENT 'tag:0',
b VARCHAR(120) COMMENT 'tag:1',

View File

@@ -18,17 +18,16 @@ import (
"context"
"errors"
"fmt"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/rowconv"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/sqle"
"strings"
"sync/atomic"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/table/typed/noms"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/rowconv"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/schema"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/sqle"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/table"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/table/pipeline"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/table/typed/noms"
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
"github.com/liquidata-inc/dolt/go/libraries/utils/funcitr"
"github.com/liquidata-inc/dolt/go/libraries/utils/set"
@@ -90,7 +89,7 @@ func (m MoveOptions) isExport() bool {
func (m MoveOptions) WillOverwrite() bool {
if _, isStdOut := m.Dest.(StreamDataLocation); isStdOut {
return false // can't overwrite StdOut
return false // can't overwrite StdOut
}
return m.Operation == OverwriteOp && !m.Force
}
@@ -144,7 +143,7 @@ func NewDataMover(ctx context.Context, root *doltdb.RootValue, fs filesys.Filesy
outSch, err := outSchemaFromInSchema(ctx, inSch, root, fs, mvOpts)
if err != nil {
return nil, &DataMoverCreationError{ SchemaErr, err}
return nil, &DataMoverCreationError{SchemaErr, err}
}
transforms, dmce := maybeMapFields(inSch, outSch, fs, mvOpts)
@@ -213,7 +212,7 @@ func (imp *DataMover) Move(ctx context.Context) (badRowCount int64, err error) {
return badCount, nil
}
func maybeMapFields(inSch schema.Schema, outSch schema.Schema, fs filesys.Filesys, mvOpts *MoveOptions) (*pipeline.TransformCollection, *DataMoverCreationError) {
func maybeMapFields(inSch schema.Schema, outSch schema.Schema, fs filesys.Filesys, mvOpts *MoveOptions) (*pipeline.TransformCollection, *DataMoverCreationError) {
var mapping *rowconv.FieldMapping
var err error
if mvOpts.MappingFile != "" {
@@ -252,7 +251,7 @@ func outSchemaFromInSchema(ctx context.Context, inSch schema.Schema, root *doltd
var outSch schema.Schema
var err error
if mvOpts.isExport() {
if mvOpts.isExport() {
outSch = inSch
return outSch, nil
}
@@ -351,6 +350,10 @@ func addPrimaryKey(sch schema.Schema, explicitKey string) (schema.Schema, error)
}
func MakeTagsUnique(ctx context.Context, root *doltdb.RootValue, tblName string, sch schema.Schema) (schema.Schema, error) {
if !doltdb.IsValidTableName(tblName) {
return nil, fmt.Errorf("invalid table name '%s'", tblName)
}
var colNames []string
var colKinds []types.NomsKind
_ = sch.GetAllCols().Iter(func(_ uint64, col schema.Column) (stop bool, err error) {

View File

@@ -42,6 +42,7 @@ func TestDataMover(t *testing.T) {
"",
&MoveOptions{
Operation: OverwriteOp,
TableName: "testable",
ContOnErr: false,
SchFile: "",
MappingFile: "",
@@ -78,6 +79,7 @@ func TestDataMover(t *testing.T) {
"",
&MoveOptions{
Operation: OverwriteOp,
TableName: "table-name",
ContOnErr: false,
SchFile: "",
MappingFile: "",
@@ -86,7 +88,7 @@ func TestDataMover(t *testing.T) {
Dest: NewDataLocation("table-name", "")},
},
{
`CREATE TABLE table_name (
`CREATE TABLE table_name (
pk VARCHAR(120) COMMENT 'tag:0',
value INT COMMENT 'tag:1',
PRIMARY KEY (pk)

View File

@@ -18,6 +18,9 @@ import (
"context"
"errors"
"fmt"
"os"
"strings"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/schema"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/table"
@@ -27,8 +30,6 @@ import (
"github.com/liquidata-inc/dolt/go/libraries/doltcore/table/untyped/sqlexport"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/table/untyped/xlsx"
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"
"os"
"strings"
)
// DFFromString returns a data object from a string.

View File

@@ -66,7 +66,7 @@ func (tt TaggedValues) NomsTupleForPKCols(nbf *types.NomsBinFormat, pkCols *sche
return tt.nomsTupleForTags(nbf, pkCols.Tags, true)
}
func (tt TaggedValues) NomsTupleForNonPKCols(nbf *types.NomsBinFormat, nonPKCols *schema.ColCollection) TupleVals {
func (tt TaggedValues) NomsTupleForNonPKCols(nbf *types.NomsBinFormat, nonPKCols *schema.ColCollection) TupleVals {
return tt.nomsTupleForTags(nbf, nonPKCols.SortedTags, false)
}

View File

@@ -18,9 +18,10 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/liquidata-inc/dolt/go/libraries/utils/set"
"strconv"
"github.com/liquidata-inc/dolt/go/libraries/utils/set"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/schema"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/table/untyped"
"github.com/liquidata-inc/dolt/go/libraries/utils/filesys"

View File

@@ -33,8 +33,8 @@ import (
)
const (
toCommit = "to_commit"
fromCommit = "from_commit"
toCommit = "to_commit"
fromCommit = "from_commit"
diffTypeColName = "diff_type"
diffTypeAdded = "added"

View File

@@ -1049,7 +1049,6 @@ func TestAlterSystemTables(t *testing.T) {
})
}
func TestParseCreateTableStatement(t *testing.T) {
tests := []struct {
name string

View File

@@ -46,7 +46,7 @@ func TestFilterStrings(t *testing.T) {
inputs := []string{"this", "THAT", "The", "oThEr"}
outputs := FilterStrings(inputs, func(s string) bool { return !strings.Contains(s, "T") })
if !reflect.DeepEqual(outputs, []string{ "this" }) {
if !reflect.DeepEqual(outputs, []string{"this"}) {
t.Error("Failed to filter strings")
}
}