Skip to content

Commit

Permalink
More testing
Browse files Browse the repository at this point in the history
  • Loading branch information
tbantle22 committed May 2, 2024
1 parent b028262 commit c7ab70a
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 210 deletions.
22 changes: 11 additions & 11 deletions server/cast/bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,17 @@ func boolExplicit() {
return handleCharExplicitCast(str, targetType)
},
})
framework.MustAddExplicitTypeCast(framework.TypeCast{
FromType: pgtypes.Bool,
ToType: pgtypes.Xid,
Function: func(ctx framework.Context, val any, targetType pgtypes.DoltgresType) (any, error) {
if val.(bool) {
return uint32(1), nil
} else {
return uint32(0), nil
}
},
})
// framework.MustAddExplicitTypeCast(framework.TypeCast{
// FromType: pgtypes.Bool,
// ToType: pgtypes.Xid,
// Function: func(ctx framework.Context, val any, targetType pgtypes.DoltgresType) (any, error) {
// if val.(bool) {
// return uint32(1), nil
// } else {
// return uint32(0), nil
// }
// },
// })
}

// boolImplicit registers all implicit casts. This comprises only the "From" types.
Expand Down
44 changes: 22 additions & 22 deletions server/cast/float32.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ func float32Explicit() {
return handleCharExplicitCast(str, targetType)
},
})
framework.MustAddExplicitTypeCast(framework.TypeCast{
FromType: pgtypes.Float32,
ToType: pgtypes.Xid,
Function: func(ctx framework.Context, valInterface any, targetType pgtypes.DoltgresType) (any, error) {
val := float32(math.RoundToEven(float64(valInterface.(float32))))
if val > 2147483647 || val < 0 {
return nil, fmt.Errorf("XID out of range")
}
return uint32(val), nil
},
})
// framework.MustAddExplicitTypeCast(framework.TypeCast{
// FromType: pgtypes.Float32,
// ToType: pgtypes.Xid,
// Function: func(ctx framework.Context, valInterface any, targetType pgtypes.DoltgresType) (any, error) {
// val := float32(math.RoundToEven(float64(valInterface.(float32))))
// if val > 2147483647 || val < 0 {
// return nil, fmt.Errorf("XID out of range")
// }
// return uint32(val), nil
// },
// })
}

// float32Implicit registers all implicit casts. This comprises only the "From" types.
Expand Down Expand Up @@ -218,15 +218,15 @@ func float32Implicit() {
return handleCharImplicitCast(str, targetType)
},
})
framework.MustAddImplicitTypeCast(framework.TypeCast{
FromType: pgtypes.Float32,
ToType: pgtypes.Xid,
Function: func(ctx framework.Context, valInterface any, targetType pgtypes.DoltgresType) (any, error) {
val := float32(math.RoundToEven(float64(valInterface.(float32))))
if val > 2147483647 || val < 0 {
return nil, fmt.Errorf("XID out of range")
}
return uint32(val), nil
},
})
// framework.MustAddImplicitTypeCast(framework.TypeCast{
// FromType: pgtypes.Float32,
// ToType: pgtypes.Xid,
// Function: func(ctx framework.Context, valInterface any, targetType pgtypes.DoltgresType) (any, error) {
// val := float32(math.RoundToEven(float64(valInterface.(float32))))
// if val > 2147483647 || val < 0 {
// return nil, fmt.Errorf("XID out of range")
// }
// return uint32(val), nil
// },
// })
}
44 changes: 22 additions & 22 deletions server/cast/float64.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,17 @@ func float64Explicit() {
return handleCharExplicitCast(str, targetType)
},
})
framework.MustAddExplicitTypeCast(framework.TypeCast{
FromType: pgtypes.Float64,
ToType: pgtypes.Xid,
Function: func(ctx framework.Context, valInterface any, targetType pgtypes.DoltgresType) (any, error) {
val := math.RoundToEven(valInterface.(float64))
if val > 2147483647 || val < 0 {
return nil, fmt.Errorf("XID out of range")
}
return uint32(val), nil
},
})
// framework.MustAddExplicitTypeCast(framework.TypeCast{
// FromType: pgtypes.Float64,
// ToType: pgtypes.Xid,
// Function: func(ctx framework.Context, valInterface any, targetType pgtypes.DoltgresType) (any, error) {
// val := math.RoundToEven(valInterface.(float64))
// if val > 2147483647 || val < 0 {
// return nil, fmt.Errorf("XID out of range")
// }
// return uint32(val), nil
// },
// })
}

// float64Implicit registers all implicit casts. This comprises only the "From" types.
Expand Down Expand Up @@ -218,15 +218,15 @@ func float64Implicit() {
return handleCharImplicitCast(str, targetType)
},
})
framework.MustAddImplicitTypeCast(framework.TypeCast{
FromType: pgtypes.Float64,
ToType: pgtypes.Xid,
Function: func(ctx framework.Context, valInterface any, targetType pgtypes.DoltgresType) (any, error) {
val := math.RoundToEven(valInterface.(float64))
if val > 2147483647 || val < 0 {
return nil, fmt.Errorf("XID out of range")
}
return uint32(val), nil
},
})
// framework.MustAddImplicitTypeCast(framework.TypeCast{
// FromType: pgtypes.Float64,
// ToType: pgtypes.Xid,
// Function: func(ctx framework.Context, valInterface any, targetType pgtypes.DoltgresType) (any, error) {
// val := math.RoundToEven(valInterface.(float64))
// if val > 2147483647 || val < 0 {
// return nil, fmt.Errorf("XID out of range")
// }
// return uint32(val), nil
// },
// })
}
2 changes: 1 addition & 1 deletion server/cast/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ func Init() {
initText()
initUuid()
initVarChar()
initXid()
// initXid()
}
25 changes: 11 additions & 14 deletions server/cast/int16.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ func int16Explicit() {
FromType: pgtypes.Int16,
ToType: pgtypes.Xid,
Function: func(ctx framework.Context, val any, targetType pgtypes.DoltgresType) (any, error) {
if val.(int16) < 0 {
return nil, fmt.Errorf("XID out of range")
}
return uint32(val.(int16)), nil
return nil, fmt.Errorf("cannot cast type %s to %s", pgtypes.Int16.String(), pgtypes.Xid.String())

Check failure on line 118 in server/cast/int16.go

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

undefined: fmt

Check failure on line 118 in server/cast/int16.go

View workflow job for this annotation

GitHub Actions / Run Staticcheck

undefined: fmt (compile)

Check failure on line 118 in server/cast/int16.go

View workflow job for this annotation

GitHub Actions / Bats tests (ubuntu-22.04)

undefined: fmt

Check failure on line 118 in server/cast/int16.go

View workflow job for this annotation

GitHub Actions / test (macos-latest)

undefined: fmt

Check failure on line 118 in server/cast/int16.go

View workflow job for this annotation

GitHub Actions / test (windows-latest)

undefined: fmt

Check failure on line 118 in server/cast/int16.go

View workflow job for this annotation

GitHub Actions / Bats tests (macos-latest)

undefined: fmt
},
})
}
Expand Down Expand Up @@ -205,14 +202,14 @@ func int16Implicit() {
return handleCharImplicitCast(str, targetType)
},
})
framework.MustAddImplicitTypeCast(framework.TypeCast{
FromType: pgtypes.Int16,
ToType: pgtypes.Xid,
Function: func(ctx framework.Context, val any, targetType pgtypes.DoltgresType) (any, error) {
if val.(int16) < 0 {
return nil, fmt.Errorf("XID out of range")
}
return uint32(val.(int16)), nil
},
})
// framework.MustAddImplicitTypeCast(framework.TypeCast{
// FromType: pgtypes.Int16,
// ToType: pgtypes.Xid,
// Function: func(ctx framework.Context, val any, targetType pgtypes.DoltgresType) (any, error) {
// if val.(int16) < 0 {
// return nil, fmt.Errorf("XID out of range")
// }
// return uint32(val.(int16)), nil
// },
// })
}
25 changes: 11 additions & 14 deletions server/cast/int32.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,7 @@ func int32Explicit() {
FromType: pgtypes.Int32,
ToType: pgtypes.Xid,
Function: func(ctx framework.Context, val any, targetType pgtypes.DoltgresType) (any, error) {
if val.(int32) < 0 {
return nil, fmt.Errorf("XID out of range")
}
return uint32(val.(int32)), nil
return nil, fmt.Errorf("cannot cast type %s to %s", pgtypes.Int32.String(), pgtypes.Xid.String())
},
})
}
Expand Down Expand Up @@ -212,14 +209,14 @@ func int32Implicit() {
return handleCharImplicitCast(str, targetType)
},
})
framework.MustAddImplicitTypeCast(framework.TypeCast{
FromType: pgtypes.Int32,
ToType: pgtypes.Xid,
Function: func(ctx framework.Context, val any, targetType pgtypes.DoltgresType) (any, error) {
if val.(int32) < 0 {
return nil, fmt.Errorf("XID out of range")
}
return uint32(val.(int32)), nil
},
})
// framework.MustAddImplicitTypeCast(framework.TypeCast{
// FromType: pgtypes.Int32,
// ToType: pgtypes.Xid,
// Function: func(ctx framework.Context, val any, targetType pgtypes.DoltgresType) (any, error) {
// if val.(int32) < 0 {
// return nil, fmt.Errorf("XID out of range")
// }
// return uint32(val.(int32)), nil
// },
// })
}
25 changes: 11 additions & 14 deletions server/cast/int64.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,7 @@ func int64Explicit() {
FromType: pgtypes.Int64,
ToType: pgtypes.Xid,
Function: func(ctx framework.Context, val any, targetType pgtypes.DoltgresType) (any, error) {
if val.(int64) > 2147483647 || val.(int64) < 0 {
return nil, fmt.Errorf("XID out of range")
}
return uint32(val.(int64)), nil
return nil, fmt.Errorf("cannot cast type %s to %s", pgtypes.Int64.String(), pgtypes.Xid.String())
},
})
}
Expand Down Expand Up @@ -224,14 +221,14 @@ func int64Implicit() {
return handleCharImplicitCast(str, targetType)
},
})
framework.MustAddImplicitTypeCast(framework.TypeCast{
FromType: pgtypes.Int64,
ToType: pgtypes.Xid,
Function: func(ctx framework.Context, val any, targetType pgtypes.DoltgresType) (any, error) {
if val.(int64) > 2147483647 || val.(int64) < 0 {
return nil, fmt.Errorf("XID out of range")
}
return uint32(val.(int64)), nil
},
})
// framework.MustAddImplicitTypeCast(framework.TypeCast{
// FromType: pgtypes.Int64,
// ToType: pgtypes.Xid,
// Function: func(ctx framework.Context, val any, targetType pgtypes.DoltgresType) (any, error) {
// if val.(int64) > 2147483647 || val.(int64) < 0 {
// return nil, fmt.Errorf("XID out of range")
// }
// return uint32(val.(int64)), nil
// },
// })
}
44 changes: 22 additions & 22 deletions server/cast/numeric.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,17 @@ func numericExplicit() {
return handleCharExplicitCast(val.(decimal.Decimal).String(), targetType)
},
})
framework.MustAddExplicitTypeCast(framework.TypeCast{
FromType: pgtypes.Numeric,
ToType: pgtypes.Xid,
Function: func(ctx framework.Context, val any, targetType pgtypes.DoltgresType) (any, error) {
d := val.(decimal.Decimal)
if d.LessThan(decimal.NewFromInt(0)) || d.GreaterThan(pgtypes.NumericValueMaxInt32) {
return nil, fmt.Errorf("XID out of range")
}
return uint32(d.IntPart()), nil
},
})
// framework.MustAddExplicitTypeCast(framework.TypeCast{
// FromType: pgtypes.Numeric,
// ToType: pgtypes.Xid,
// Function: func(ctx framework.Context, val any, targetType pgtypes.DoltgresType) (any, error) {
// d := val.(decimal.Decimal)
// if d.LessThan(decimal.NewFromInt(0)) || d.GreaterThan(pgtypes.NumericValueMaxInt32) {
// return nil, fmt.Errorf("XID out of range")
// }
// return uint32(d.IntPart()), nil
// },
// })
}

// numericImplicit registers all implicit casts. This comprises only the "From" types.
Expand Down Expand Up @@ -214,15 +214,15 @@ func numericImplicit() {
return handleCharImplicitCast(val.(decimal.Decimal).String(), targetType)
},
})
framework.MustAddImplicitTypeCast(framework.TypeCast{
FromType: pgtypes.Numeric,
ToType: pgtypes.Xid,
Function: func(ctx framework.Context, val any, targetType pgtypes.DoltgresType) (any, error) {
d := val.(decimal.Decimal)
if d.LessThan(decimal.NewFromInt(0)) || d.GreaterThan(pgtypes.NumericValueMaxInt32) {
return nil, fmt.Errorf("XID out of range")
}
return uint32(d.IntPart()), nil
},
})
// framework.MustAddImplicitTypeCast(framework.TypeCast{
// FromType: pgtypes.Numeric,
// ToType: pgtypes.Xid,
// Function: func(ctx framework.Context, val any, targetType pgtypes.DoltgresType) (any, error) {
// d := val.(decimal.Decimal)
// if d.LessThan(decimal.NewFromInt(0)) || d.GreaterThan(pgtypes.NumericValueMaxInt32) {
// return nil, fmt.Errorf("XID out of range")
// }
// return uint32(d.IntPart()), nil
// },
// })
}
28 changes: 14 additions & 14 deletions server/cast/oid.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ func oidExplicit() {
return handleCharExplicitCast(str, targetType)
},
})
framework.MustAddExplicitTypeCast(framework.TypeCast{
FromType: pgtypes.Oid,
ToType: pgtypes.Xid,
Function: func(ctx framework.Context, val any, targetType pgtypes.DoltgresType) (any, error) {
return val, nil
},
})
// framework.MustAddExplicitTypeCast(framework.TypeCast{
// FromType: pgtypes.Oid,
// ToType: pgtypes.Xid,
// Function: func(ctx framework.Context, val any, targetType pgtypes.DoltgresType) (any, error) {
// return val, nil
// },
// })
}

// oidImplicit registers all implicit casts. This comprises only the "From" types.
Expand Down Expand Up @@ -146,11 +146,11 @@ func oidImplicit() {
return handleCharImplicitCast(str, targetType)
},
})
framework.MustAddImplicitTypeCast(framework.TypeCast{
FromType: pgtypes.Oid,
ToType: pgtypes.Xid,
Function: func(ctx framework.Context, val any, targetType pgtypes.DoltgresType) (any, error) {
return val, nil
},
})
// framework.MustAddImplicitTypeCast(framework.TypeCast{
// FromType: pgtypes.Oid,
// ToType: pgtypes.Xid,
// Function: func(ctx framework.Context, val any, targetType pgtypes.DoltgresType) (any, error) {
// return val, nil
// },
// })
}
Loading

0 comments on commit c7ab70a

Please sign in to comment.