-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parser: fix GetTypeFromValidSQLSyntax for collated strings
Previously, `GetTypeFromValidSQLSyntax` would result in an error when attempting to parse a collated string. This is due to an expression like `1::STRING COLLATE en` being parsed as `CollateExpr(CastExpr)` whereas the function expected just `CastExpr`. This is now fixed by having a special case for the collated strings. Additionally, this commit adds a couple of testing improvements around the collated strings: - a representative collated string type is now included into `randgen.SeedTypes` - a new test is introduced that asserts that for all (with a few exceptions) type families at least one representative type is included into `randgen.SeedTypes`. Release note: None
- Loading branch information
1 parent
05d509a
commit 59c8bb3
Showing
10 changed files
with
116 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// Copyright 2023 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package randgen | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/sql/types" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/errors" | ||
) | ||
|
||
// TestSeedTypes verifies that at least one representative type is included into | ||
// SeedTypes for all (with a few exceptions) type families. | ||
func TestSeedTypes(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
|
||
noFamilyRepresentative := make(map[types.Family]struct{}) | ||
loop: | ||
for id := range types.Family_name { | ||
familyID := types.Family(id) | ||
switch familyID { | ||
case types.EnumFamily: | ||
// Enums need to created separately. | ||
continue loop | ||
case types.EncodedKeyFamily: | ||
// It's not a real type. | ||
continue loop | ||
case types.UnknownFamily, types.AnyFamily: | ||
// These are not included on purpose. | ||
continue loop | ||
} | ||
noFamilyRepresentative[familyID] = struct{}{} | ||
} | ||
for _, typ := range SeedTypes { | ||
delete(noFamilyRepresentative, typ.Family()) | ||
} | ||
if len(noFamilyRepresentative) > 0 { | ||
s := "no representative for " | ||
for f := range noFamilyRepresentative { | ||
s += fmt.Sprintf("%s (%d) ", types.Family_name[int32(f)], f) | ||
} | ||
t.Fatal(errors.Errorf("%s", s)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters