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

Fixed internal index comparisons considering unnecessary parameters #1082

Merged
merged 2 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 54 additions & 0 deletions bats/regression-tests.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env bats
load $BATS_TEST_DIRNAME/helper/common.bash

setup() {
setup_common
}

teardown() {
teardown_common
}

@test "regression-tests: dolt issue #1081" {
dolt sql <<SQL
Hydrocharged marked this conversation as resolved.
Show resolved Hide resolved
CREATE TABLE XA(YW VARCHAR(24) NOT NULL, XB VARCHAR(100), XC VARCHAR(2500),
XD VARCHAR(2500), XE VARCHAR(100), XF VARCHAR(100), XG VARCHAR(100),
XI VARCHAR(100), XJ VARCHAR(100), XK VARCHAR(100), XL VARCHAR(100),
XM VARCHAR(1000), XN TEXT, XO TEXT, PRIMARY KEY (YW));
CREATE TABLE XP(YW VARCHAR(24) NOT NULL, XQ VARCHAR(100) NOT NULL,
XR VARCHAR(1000), PRIMARY KEY (YW));
CREATE TABLE XS(YW VARCHAR(24) NOT NULL, XT VARCHAR(24) NOT NULL,
XU VARCHAR(24), XV VARCHAR(100) NOT NULL, XW DOUBLE NOT NULL,
XX DOUBLE NOT NULL, XY VARCHAR(100), XC VARCHAR(100), XZ VARCHAR(100) NOT NULL,
YA DOUBLE, YB VARCHAR(24) NOT NULL, YC VARCHAR(1000), XO VARCHAR(1000),
YD DOUBLE NOT NULL, YE DOUBLE NOT NULL, PRIMARY KEY (YW));
CREATE TABLE YF(YW VARCHAR(24) NOT NULL, XB VARCHAR(100) NOT NULL, YG VARCHAR(100),
YH VARCHAR(100), XO TEXT, PRIMARY KEY (YW));
CREATE TABLE yp(YW VARCHAR(24) NOT NULL, XJ VARCHAR(100) NOT NULL, XL VARCHAR(100),
XT VARCHAR(24) NOT NULL, YI INT NOT NULL, XO VARCHAR(1000), PRIMARY KEY (YW),
FOREIGN KEY (XT) REFERENCES XP (YW));
INSERT INTO XS VALUES ('', '', NULL, 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC', 0, 0,
NULL, NULL, '', NULL, '', NULL, NULL, 0, 0);
INSERT INTO YF VALUES ('', '', NULL, NULL, NULL);
INSERT INTO XA VALUES ('', '', '', '', '', 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAC',
'', '', '', '', '', '', '', '');
SQL
run dolt sql -r=csv -q "
SELECT DISTINCT YM.YW AS YW, (SELECT YW FROM YF WHERE YF.XB = YM.XB) AS YF_YW,
(SELECT YW FROM yp WHERE yp.XJ = YM.XJ AND (yp.XL = YM.XL OR (yp.XL IS NULL AND
YM.XL IS NULL)) AND yp.XT = nd.XT) AS YJ, XE AS XE, XI AS YO, XK AS XK, XM AS XM,
CASE WHEN YM.XO <> 'Z' THEN YM.XO ELSE NULL END AS XO FROM (SELECT YW, XB, XC, XE,
XF, XI, XJ, XK, CASE WHEN XL = 'Z' OR XL = 'Z' THEN NULL ELSE XL END AS XL, XM,
XO FROM XA) YM INNER JOIN XS nd ON nd.XV = XF WHERE XB IN (SELECT XB FROM YF) AND
(XF IS NOT NULL AND XF <> 'Z') UNION SELECT DISTINCT YL.YW AS YW, (SELECT YW FROM
YF WHERE YF.XB = YL.XB) AS YF_YW, (SELECT YW FROM yp WHERE yp.XJ = YL.XJ AND
(yp.XL = YL.XL OR (yp.XL IS NULL AND YL.XL IS NULL)) AND yp.XT = YN.XT) AS YJ,
XE AS XE, XI AS YO, XK AS XK, XM AS XM, CASE WHEN YL.XO <> 'Z' THEN YL.XO ELSE
NULL END AS XO FROM (SELECT YW, XB, XC, XE, XF, XI, XJ, XK, CASE WHEN XL = 'Z' OR
XL = 'Z' THEN NULL ELSE XL END AS XL, XM, XO FROM XA) YL INNER JOIN XS YN ON
YN.XC = YL.XC WHERE XB IN (SELECT XB FROM YF) AND (XF IS NULL OR XF = 'Z');"
[ "$status" -eq "0" ]
[[ "$output" =~ "YW,YF_YW,YJ,XE,YO,XK,XM,XO" ]] || false
[[ "$output" =~ '"","",,"","","","",""' ]] || false
[[ "${#lines[@]}" = "2" ]] || false
}
5 changes: 5 additions & 0 deletions go/libraries/doltcore/schema/typeinfo/bit.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ func (ti *bitType) ParseValue(str *string) (types.Value, error) {
return nil, fmt.Errorf(`"%v" cannot convert the string "%v" to a value`, ti.String(), str)
}

// Promote implements TypeInfo interface.
func (ti *bitType) Promote() TypeInfo {
return &bitType{ti.sqlBitType.Promote().(sql.BitType)}
}

// String implements TypeInfo interface.
func (ti *bitType) String() string {
return fmt.Sprintf("Bit(%v)", ti.sqlBitType.NumberOfBits())
Expand Down
5 changes: 5 additions & 0 deletions go/libraries/doltcore/schema/typeinfo/bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ func (ti *boolType) ParseValue(str *string) (types.Value, error) {
return ti.ConvertValueToNomsValue(*str)
}

// Promote implements TypeInfo interface.
func (ti *boolType) Promote() TypeInfo {
return ti
}

// String implements TypeInfo interface.
func (ti *boolType) String() string {
return "Bool"
Expand Down
5 changes: 5 additions & 0 deletions go/libraries/doltcore/schema/typeinfo/datetime.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ func (ti *datetimeType) ParseValue(str *string) (types.Value, error) {
return nil, fmt.Errorf(`"%v" cannot convert the string "%v" to a value`, ti.String(), str)
}

// Promote implements TypeInfo interface.
func (ti *datetimeType) Promote() TypeInfo {
return &datetimeType{ti.sqlDatetimeType.Promote().(sql.DatetimeType)}
}

// String implements TypeInfo interface.
func (ti *datetimeType) String() string {
return fmt.Sprintf(`Datetime(SQL: "%v")`, ti.sqlDatetimeType.String())
Expand Down
5 changes: 5 additions & 0 deletions go/libraries/doltcore/schema/typeinfo/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ func (ti *decimalType) ParseValue(str *string) (types.Value, error) {
return ti.ConvertValueToNomsValue(*str)
}

// Promote implements TypeInfo interface.
func (ti *decimalType) Promote() TypeInfo {
return &decimalType{ti.sqlDecimalType.Promote().(sql.DecimalType)}
}

// String implements TypeInfo interface.
func (ti *decimalType) String() string {
return fmt.Sprintf("Decimal(%v, %v)", ti.sqlDecimalType.Precision(), ti.sqlDecimalType.Scale())
Expand Down
5 changes: 5 additions & 0 deletions go/libraries/doltcore/schema/typeinfo/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ func (ti *enumType) ParseValue(str *string) (types.Value, error) {
return types.Uint(val), nil
}

// Promote implements TypeInfo interface.
func (ti *enumType) Promote() TypeInfo {
return &enumType{ti.sqlEnumType.Promote().(sql.EnumType)}
}

// String implements TypeInfo interface.
func (ti *enumType) String() string {
return fmt.Sprintf(`Enum(Collation: %v, Values: %v)`, ti.sqlEnumType.Collation().String(), strings.Join(ti.sqlEnumType.Values(), ", "))
Expand Down
5 changes: 5 additions & 0 deletions go/libraries/doltcore/schema/typeinfo/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ func (ti *floatType) ParseValue(str *string) (types.Value, error) {
return ti.ConvertValueToNomsValue(*str)
}

// Promote implements TypeInfo interface.
func (ti *floatType) Promote() TypeInfo {
return &floatType{ti.sqlFloatType.Promote().(sql.NumberType)}
}

// String implements TypeInfo interface.
func (ti *floatType) String() string {
switch ti.sqlFloatType.Type() {
Expand Down
5 changes: 5 additions & 0 deletions go/libraries/doltcore/schema/typeinfo/inlineblob.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ func (ti *inlineBlobType) ParseValue(str *string) (types.Value, error) {
return nil, fmt.Errorf(`"%v" cannot convert the string "%v" to a value`, ti.String(), str)
}

// Promote implements TypeInfo interface.
func (ti *inlineBlobType) Promote() TypeInfo {
return &inlineBlobType{ti.sqlBinaryType.Promote().(sql.StringType)}
}

// String implements TypeInfo interface.
func (ti *inlineBlobType) String() string {
return "InlineBlob"
Expand Down
5 changes: 5 additions & 0 deletions go/libraries/doltcore/schema/typeinfo/int.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ func (ti *intType) ParseValue(str *string) (types.Value, error) {
return ti.ConvertValueToNomsValue(*str)
}

// Promote implements TypeInfo interface.
func (ti *intType) Promote() TypeInfo {
return &intType{ti.sqlIntType.Promote().(sql.NumberType)}
}

// String implements TypeInfo interface.
func (ti *intType) String() string {
switch ti.sqlIntType.Type() {
Expand Down
5 changes: 5 additions & 0 deletions go/libraries/doltcore/schema/typeinfo/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ func (ti *setType) ParseValue(str *string) (types.Value, error) {
return types.Uint(val), nil
}

// Promote implements TypeInfo interface.
func (ti *setType) Promote() TypeInfo {
return &setType{ti.sqlSetType.Promote().(sql.SetType)}
}

// String implements TypeInfo interface.
func (ti *setType) String() string {
return fmt.Sprintf(`Set(Collation: %v, Values: %v)`, ti.sqlSetType.Collation().String(), strings.Join(ti.sqlSetType.Values(), ","))
Expand Down
5 changes: 5 additions & 0 deletions go/libraries/doltcore/schema/typeinfo/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ func (ti *timeType) ParseValue(str *string) (types.Value, error) {
return types.Int(val), nil
}

// Promote implements TypeInfo interface.
func (ti *timeType) Promote() TypeInfo {
return &timeType{ti.sqlTimeType.Promote().(sql.TimeType)}
}

// String implements TypeInfo interface.
func (ti *timeType) String() string {
return "Time"
Expand Down
5 changes: 5 additions & 0 deletions go/libraries/doltcore/schema/typeinfo/tuple.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ func (ti *tupleType) ParseValue(str *string) (types.Value, error) {
return nil, fmt.Errorf(`"%v" cannot parse strings`, ti.String())
}

// Promote implements TypeInfo interface.
func (ti *tupleType) Promote() TypeInfo {
return ti
}

// String implements TypeInfo interface.
func (ti *tupleType) String() string {
return "Tuple"
Expand Down
3 changes: 3 additions & 0 deletions go/libraries/doltcore/schema/typeinfo/typeinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ type TypeInfo interface {
// ParseValue parses a string and returns a go value that represents it according to this type.
ParseValue(str *string) (types.Value, error)

// Promote will promote the current TypeInfo to the largest representing TypeInfo of the same kind, such as Int8 to Int64.
Promote() TypeInfo

// ToSqlType returns the TypeInfo as a sql.Type. If an exact match is able to be made then that is
// the one returned, otherwise the sql.Type is the closest match possible.
ToSqlType() sql.Type
Expand Down
5 changes: 5 additions & 0 deletions go/libraries/doltcore/schema/typeinfo/uint.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,11 @@ func (ti *uintType) ParseValue(str *string) (types.Value, error) {
return ti.ConvertValueToNomsValue(*str)
}

// Promote implements TypeInfo interface.
func (ti *uintType) Promote() TypeInfo {
return &uintType{ti.sqlUintType.Promote().(sql.NumberType)}
}

// String implements TypeInfo interface.
func (ti *uintType) String() string {
switch ti.sqlUintType.Type() {
Expand Down
5 changes: 5 additions & 0 deletions go/libraries/doltcore/schema/typeinfo/unknown.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ func (ti *unknownImpl) ParseValue(*string) (types.Value, error) {
return nil, fmt.Errorf(`"Unknown" cannot convert any strings to a Noms value`)
}

// Promote implements TypeInfo interface.
func (ti *unknownImpl) Promote() TypeInfo {
return ti
}

// String implements TypeInfo interface.
func (ti *unknownImpl) String() string {
return "Unknown"
Expand Down
5 changes: 5 additions & 0 deletions go/libraries/doltcore/schema/typeinfo/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ func (ti *uuidType) ParseValue(str *string) (types.Value, error) {
return types.UUID(uuidVal), nil
}

// Promote implements TypeInfo interface.
func (ti *uuidType) Promote() TypeInfo {
return ti
}

// String implements TypeInfo interface.
func (ti *uuidType) String() string {
return "Uuid"
Expand Down
5 changes: 5 additions & 0 deletions go/libraries/doltcore/schema/typeinfo/varbinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,11 @@ func (ti *varBinaryType) ParseValue(str *string) (types.Value, error) {
return nil, fmt.Errorf(`"%v" cannot convert the string "%v" to a value`, ti.String(), str)
}

// Promote implements TypeInfo interface.
func (ti *varBinaryType) Promote() TypeInfo {
return &varBinaryType{ti.sqlBinaryType.Promote().(sql.StringType)}
}

// String implements TypeInfo interface.
func (ti *varBinaryType) String() string {
sqlType := ""
Expand Down
5 changes: 5 additions & 0 deletions go/libraries/doltcore/schema/typeinfo/varstring.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,11 @@ func (ti *varStringType) ParseValue(str *string) (types.Value, error) {
return ti.ConvertValueToNomsValue(*str)
}

// Promote implements TypeInfo interface.
func (ti *varStringType) Promote() TypeInfo {
return &varStringType{ti.sqlStringType.Promote().(sql.StringType)}
}

// String implements TypeInfo interface.
func (ti *varStringType) String() string {
sqlType := ""
Expand Down
5 changes: 5 additions & 0 deletions go/libraries/doltcore/schema/typeinfo/year.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ func (ti *yearType) ParseValue(str *string) (types.Value, error) {
return nil, fmt.Errorf(`"%v" cannot convert the string "%v" to a value`, ti.String(), str)
}

// Promote implements TypeInfo interface.
func (ti *yearType) Promote() TypeInfo {
return &yearType{ti.sqlYearType.Promote().(sql.YearType)}
}

// String implements TypeInfo interface.
func (ti *yearType) String() string {
return "Year"
Expand Down
4 changes: 3 additions & 1 deletion go/libraries/doltcore/sqle/dolt_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ func (di *doltIndex) keysToTuple(keys []interface{}) (types.Tuple, error) {
}
var vals []types.Value
for i, col := range di.cols {
val, err := col.TypeInfo.ConvertValueToNomsValue(keys[i])
// As an example, if our TypeInfo is Int8, we should not fail to create a tuple if we are returning all keys
// that have a value of less than 9001, thus we promote the TypeInfo to the widest type.
val, err := col.TypeInfo.Promote().ConvertValueToNomsValue(keys[i])
if err != nil {
return types.EmptyTuple(nbf), err
}
Expand Down