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

add alternative type check for auto_increment type validation #7688

Merged
merged 1 commit into from
Apr 3, 2024
Merged
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
15 changes: 14 additions & 1 deletion go/libraries/doltcore/schema/schema_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func ValidateForInsert(allCols *ColCollection) error {
}
colNames[col.Name] = true

if col.AutoIncrement && !isAutoIncrementKind(col.Kind) {
if col.AutoIncrement && !(isAutoIncrementKind(col.Kind) || isAutoIncrementType(col.TypeInfo.ToSqlType().Type())) {
return true, ErrNonAutoIncType
}

Expand Down Expand Up @@ -250,6 +250,19 @@ func isAutoIncrementKind(k types.NomsKind) bool {
return k == types.IntKind || k == types.UintKind || k == types.FloatKind
}

// isAutoIncrementType returns true is |t| is a numeric type.
// This is an alternative way for the numeric type check.
func isAutoIncrementType(t query.Type) bool {
switch t {
case query.Type_INT8, query.Type_INT16, query.Type_INT24, query.Type_INT32, query.Type_INT64,
query.Type_UINT8, query.Type_UINT16, query.Type_UINT24, query.Type_UINT32, query.Type_UINT64,
query.Type_FLOAT32, query.Type_FLOAT64, query.Type_DECIMAL:
return true
default:
return false
}
}

// UnkeyedSchemaFromCols creates a schema without any primary keys to be used for displaying to users, tests, etc. Such
// unkeyed schemas are not suitable to be inserted into storage.
func UnkeyedSchemaFromCols(allCols *ColCollection) Schema {
Expand Down
Loading