interpret 0 value tag as a non-empty value (#4592)

This commit is contained in:
Dhruv Sringari
2022-10-20 16:43:46 -07:00
committed by GitHub
parent f6acf21637
commit 739f090ba4
2 changed files with 24 additions and 6 deletions

View File

@@ -408,7 +408,7 @@ func (root *RootValue) GenerateTagsForNewColumns(
return nil, fmt.Errorf("error generating tags, newColNames and newColKinds must be of equal length")
}
newTags := make([]uint64, len(newColNames))
newTags := make([]*uint64, len(newColNames))
// Get existing columns from the current root, or the head root if the table doesn't exist in the current root. The
// latter case is to support reusing table tags in the case of drop / create in the same session, which is common
@@ -420,12 +420,13 @@ func (root *RootValue) GenerateTagsForNewColumns(
// If we found any existing columns set them in the newTags list.
for _, col := range existingCols {
col := col
for i := range newColNames {
// Only re-use tags if the noms kind didn't change
// TODO: revisit this when new storage format is further along
if strings.ToLower(newColNames[i]) == strings.ToLower(col.Name) &&
newColKinds[i] == col.TypeInfo.NomsKind() {
newTags[i] = col.Tag
newTags[i] = &col.Tag
break
}
}
@@ -441,17 +442,19 @@ func (root *RootValue) GenerateTagsForNewColumns(
return nil, err
}
outputTags := make([]uint64, len(newTags))
for i := range newTags {
if newTags[i] > 0 {
if newTags[i] != nil {
outputTags[i] = *newTags[i]
continue
}
newTags[i] = schema.AutoGenerateTag(existingTags, tableName, existingColKinds, newColNames[i], newColKinds[i])
outputTags[i] = schema.AutoGenerateTag(existingTags, tableName, existingColKinds, newColNames[i], newColKinds[i])
existingColKinds = append(existingColKinds, newColKinds[i])
existingTags.Add(newTags[i], tableName)
existingTags.Add(outputTags[i], tableName)
}
return newTags, nil
return outputTags, nil
}
func getExistingColumns(

View File

@@ -397,3 +397,18 @@ SQL
[ "$status" -eq 1 ]
[[ "$output" =~ "table not found: test" ]] || false
}
@test "drop-create: regression test for 0 value tags" {
dolt sql -q "CREATE TABLE clan_home_level (level INTEGER NOT NULL, price_teleport JSON NOT NULL);"
run dolt schema tags
[ $status -eq 0 ]
[[ $output =~ "clan_home_level | price_teleport | 0" ]] || false
dolt commit -Am "add table"
dolt sql -q "DROP TABLE clan_home_level;"
dolt sql -q "CREATE TABLE clan_home_level (level INTEGER NOT NULL, price_teleport JSON NOT NULL);"
run dolt schema tags
[ $status -eq 0 ]
[[ $output =~ "clan_home_level | price_teleport | 0" ]] || false
}