Skip to content

Commit

Permalink
updated for v0.10
Browse files Browse the repository at this point in the history
  • Loading branch information
brennanjl committed Oct 13, 2024
1 parent 04813cb commit ddce74a
Show file tree
Hide file tree
Showing 15 changed files with 696 additions and 1,451 deletions.
33 changes: 17 additions & 16 deletions core/types/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ type DataType struct {
// IsArray is true if the type is an array.
IsArray bool `json:"is_array"`
// Metadata is the metadata of the type.
Metadata [2]uint16 `json:"metadata"`
Metadata *[2]uint16 `json:"metadata"`
}

// String returns the string representation of the type.
Expand All @@ -1121,8 +1121,6 @@ func (c *DataType) String() string {
return str.String()
}

var ZeroMetadata = [2]uint16{}

// PGString returns the string representation of the type in Postgres.
func (c *DataType) PGString() (string, error) {
var scalar string
Expand All @@ -1140,11 +1138,11 @@ func (c *DataType) PGString() (string, error) {
case uint256Str:
scalar = "UINT256"
case DecimalStr:
if c.Metadata == ZeroMetadata {
return "", fmt.Errorf("decimal type must have metadata")
if c.Metadata == nil {
scalar = "NUMERIC"
} else {
scalar = fmt.Sprintf("NUMERIC(%d,%d)", c.Metadata[0], c.Metadata[1])
}

scalar = fmt.Sprintf("NUMERIC(%d,%d)", c.Metadata[0], c.Metadata[1])
case nullStr:
return "", fmt.Errorf("cannot have null column type")
case unknownStr:
Expand All @@ -1164,14 +1162,15 @@ func (c *DataType) Clean() error {
c.Name = strings.ToLower(c.Name)
switch c.Name {
case intStr, textStr, boolStr, blobStr, uuidStr, uint256Str: // ok
if c.Metadata != ZeroMetadata {
if c.Metadata != nil {
return fmt.Errorf("type %s cannot have metadata", c.Name)
}

return nil
case DecimalStr:
if c.Metadata == ZeroMetadata {
return fmt.Errorf("decimal type must have metadata")
if c.Metadata == nil {
// numeric can have unspecified precision and scale
return nil
}

err := decimal.CheckPrecisionAndScale(c.Metadata[0], c.Metadata[1])
Expand All @@ -1185,7 +1184,7 @@ func (c *DataType) Clean() error {
return fmt.Errorf("type %s cannot be an array", c.Name)
}

if c.Metadata != ZeroMetadata {
if c.Metadata != nil {
return fmt.Errorf("type %s cannot have metadata", c.Name)
}

Expand Down Expand Up @@ -1219,10 +1218,10 @@ func (c *DataType) EqualsStrict(other *DataType) bool {
return false
}

if (c.Metadata == ZeroMetadata) != (other.Metadata == ZeroMetadata) {
if (c.Metadata == nil) != (other.Metadata == nil) {
return false
}
if c.Metadata != ZeroMetadata {
if c.Metadata != nil {
if c.Metadata[0] != other.Metadata[0] || c.Metadata[1] != other.Metadata[1] {
return false
}
Expand Down Expand Up @@ -1275,8 +1274,8 @@ var (
// For type detection, users should prefer compare a datatype
// name with the DecimalStr constant.
DecimalType = &DataType{
Name: DecimalStr,
Metadata: [2]uint16{1, 0}, // the minimum precision and scale
Name: DecimalStr,
// unspecified precision and scale
}
DecimalArrayType = ArrayType(DecimalType)
Uint256Type = &DataType{
Expand Down Expand Up @@ -1332,8 +1331,10 @@ func NewDecimalType(precision, scale uint16) (*DataType, error) {
return nil, err
}

met := [2]uint16{precision, scale}

return &DataType{
Name: DecimalStr,
Metadata: [2]uint16{precision, scale},
Metadata: &met,
}, nil
}
2 changes: 1 addition & 1 deletion core/types/transactions/payload_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ type DataType struct {
// IsArray is true if the type is an array.
IsArray bool
// Metadata is the metadata of the type.
Metadata [2]uint16 `rlp:"optional"`
Metadata *[2]uint16 `rlp:"optional"`
}

// ForeignProcedure is a foreign procedure call in a database
Expand Down
3 changes: 2 additions & 1 deletion parse/antlr.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ func (s *schemaVisitor) VisitType(ctx *gen.TypeContext) any {
return types.UnknownType
}

dt.Metadata = [2]uint16{uint16(prec), uint16(scale)}
met := [2]uint16{uint16(prec), uint16(scale)}
dt.Metadata = &met
}

if ctx.LBRACKET() != nil {
Expand Down
2 changes: 2 additions & 0 deletions parse/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ func literalToString(value any) (string, error) {
return str.String(), nil
}

// TODO: we can remove this interface since in v0.10, we are getting rid of foreign calls
// this means that there will be only 1 implementation of ExpressionCall
type ExpressionCall interface {
Expression
Cast(*types.DataType)
Expand Down
85 changes: 0 additions & 85 deletions parse/common/datetime.go

This file was deleted.

108 changes: 0 additions & 108 deletions parse/common/datetime_test.go

This file was deleted.

7 changes: 2 additions & 5 deletions parse/common/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package common
import "errors"

var (
ErrTypeMismatch = errors.New("type mismatch")
ErrNotArray = errors.New("not an array")
ErrArithmeticOnArray = errors.New("cannot perform arithmetic operation on array")
ErrIndexOutOfBounds = errors.New("index out of bounds")
ErrNegativeSubstringLength = errors.New("negative substring length not allowed")
ErrTypeMismatch = errors.New("type mismatch")
ErrIndexOutOfBounds = errors.New("index out of bounds")
)
Loading

0 comments on commit ddce74a

Please sign in to comment.