Skip to content

Commit

Permalink
Merge pull request #120 from dolthub/daylon/super-type
Browse files Browse the repository at this point in the history
Added BOOLEAN and BOOLEAN[] types
  • Loading branch information
Hydrocharged authored Feb 7, 2024
2 parents ede7e39 + a805a51 commit 35d9c85
Show file tree
Hide file tree
Showing 13 changed files with 847 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ These are automatically included when releasing a new version of DoltgreSQL, so
3. `scripts`: Contains all of the non-build scripts and tools.
4. `server`: The interface between the `postgres` directory and the underlying [GMS](/~https://github.com/dolthub/go-mysql-server) and [Dolt](/~https://github.com/dolthub/dolt) backends.
1. `ast`: Specifically houses all transformations from the `postgres` AST to the [`vitess`](/~https://github.com/dolthub/vitess) AST.
2. `functions`: Contains all implementations of [PostgreSQL functions](https://www.postgresql.org/docs/15/functions.html).
3. `types`: Contains the implementations of all PostgreSQL types.
5. `testing`: Contains all integration tests, and all things related to testing.
This will not contain _all_ tests within the repository, as functions within other directories may declare their own unit tests.
1. `bats`: Contains all of our [Bats](/~https://github.com/bats-core/bats-core) tests.
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ require (
github.com/PuerkitoBio/goquery v1.8.1
github.com/cockroachdb/apd/v2 v2.0.3-0.20200518165714-d020e156310a
github.com/cockroachdb/errors v1.7.5
github.com/dolthub/dolt/go v0.40.5-0.20240118214900-3cbb73cafa3c
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20231213233028-64c353bf920f
github.com/dolthub/go-mysql-server v0.17.1-0.20240118213933-3c0fb56900df
github.com/dolthub/dolt/go v0.40.5-0.20240207142355-cbe6b0ce7f01
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240205125942-fc7c3429f29c
github.com/dolthub/go-mysql-server v0.17.1-0.20240207124505-c0f397a6aaca
github.com/dolthub/sqllogictest/go v0.0.0-20240118211725-a52e3f5697e3
github.com/dolthub/vitess v0.0.0-20240117231546-55b8c7b39462
github.com/dolthub/vitess v0.0.0-20240207121055-c057d2347007
github.com/fatih/color v1.13.0
github.com/gogo/protobuf v1.3.2
github.com/golang/geo v0.0.0-20200730024412-e86565bf3f35
Expand Down Expand Up @@ -61,7 +61,7 @@ require (
github.com/dolthub/fslock v0.0.3 // indirect
github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e // indirect
github.com/dolthub/ishell v0.0.0-20221214210346-d7db0b066488 // indirect
github.com/dolthub/jsonpath v0.0.2-0.20230525180605-8dc13778fd72 // indirect
github.com/dolthub/jsonpath v0.0.2-0.20240201003050-392940944c15 // indirect
github.com/dolthub/maphash v0.0.0-20221220182448-74e1e1ea1577 // indirect
github.com/dolthub/swiss v0.1.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -214,30 +214,30 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.4.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/dolthub/dolt/go v0.40.5-0.20240118214900-3cbb73cafa3c h1:gEvvX3cUMEOW0UyIO3klXaohXzJmJ0ls0jZKAgTdWJE=
github.com/dolthub/dolt/go v0.40.5-0.20240118214900-3cbb73cafa3c/go.mod h1:n4qCXkCLlIFbR8PuXB0WG1JV5s8SZLK4sa/dEVx420o=
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20231213233028-64c353bf920f h1:f250FTgZ/OaCql9G6WJt46l9VOIBF1mI81hW9cnmBNM=
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20231213233028-64c353bf920f/go.mod h1:gHeHIDGU7em40EhFTliq62pExFcc1hxDTIZ9g5UqXYM=
github.com/dolthub/dolt/go v0.40.5-0.20240207142355-cbe6b0ce7f01 h1:r/1CAcbUpAHR0jG15YqMgoribkfOURNqH60M8lITN2M=
github.com/dolthub/dolt/go v0.40.5-0.20240207142355-cbe6b0ce7f01/go.mod h1:F/oS2i85PyQgoKG4ay4joe/iv2HR9njLbyYaqJ2FSyU=
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240205125942-fc7c3429f29c h1:AVAqyKKv6UVOcKr9anIe1VQItJEIcZENMtU0FF8bycM=
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240205125942-fc7c3429f29c/go.mod h1:gHeHIDGU7em40EhFTliq62pExFcc1hxDTIZ9g5UqXYM=
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 h1:u3PMzfF8RkKd3lB9pZ2bfn0qEG+1Gms9599cr0REMww=
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2/go.mod h1:mIEZOHnFx4ZMQeawhw9rhsj+0zwQj7adVsnBX7t+eKY=
github.com/dolthub/fslock v0.0.3 h1:iLMpUIvJKMKm92+N1fmHVdxJP5NdyDK5bK7z7Ba2s2U=
github.com/dolthub/fslock v0.0.3/go.mod h1:QWql+P17oAAMLnL4HGB5tiovtDuAjdDTPbuqx7bYfa0=
github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e h1:kPsT4a47cw1+y/N5SSCkma7FhAPw7KeGmD6c9PBZW9Y=
github.com/dolthub/go-icu-regex v0.0.0-20230524105445-af7e7991c97e/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168=
github.com/dolthub/go-mysql-server v0.17.1-0.20240118213933-3c0fb56900df h1:OmR6U3UvCMEguh1UaXCiK4qasA/tHH3+Ls2NRiEQfjU=
github.com/dolthub/go-mysql-server v0.17.1-0.20240118213933-3c0fb56900df/go.mod h1:hS8Snuzg+nyTDjv4NI9jiXQ2lJJOd3O0ylhVPQlHySw=
github.com/dolthub/go-mysql-server v0.17.1-0.20240207124505-c0f397a6aaca h1:tI3X4fIUTOT0N8n+GYkPNa384WlJoOBcztK5c5mBzjU=
github.com/dolthub/go-mysql-server v0.17.1-0.20240207124505-c0f397a6aaca/go.mod h1:ANK0a6tyjrZ2cOzDJT3nFsDp80xksI4UfeijFlvnjwE=
github.com/dolthub/ishell v0.0.0-20221214210346-d7db0b066488 h1:0HHu0GWJH0N6a6keStrHhUAK5/o9LVfkh44pvsV4514=
github.com/dolthub/ishell v0.0.0-20221214210346-d7db0b066488/go.mod h1:ehexgi1mPxRTk0Mok/pADALuHbvATulTh6gzr7NzZto=
github.com/dolthub/jsonpath v0.0.2-0.20230525180605-8dc13778fd72 h1:NfWmngMi1CYUWU4Ix8wM+USEhjc+mhPlT9JUR/anvbQ=
github.com/dolthub/jsonpath v0.0.2-0.20230525180605-8dc13778fd72/go.mod h1:ZWUdY4iszqRQ8OcoXClkxiAVAoWoK3cq0Hvv4ddGRuM=
github.com/dolthub/jsonpath v0.0.2-0.20240201003050-392940944c15 h1:sfTETOpsrNJPDn2KydiCtDgVu6Xopq8k3JP8PjFT22s=
github.com/dolthub/jsonpath v0.0.2-0.20240201003050-392940944c15/go.mod h1:2/2zjLQ/JOOSbbSboojeg+cAwcRV0fDLzIiWch/lhqI=
github.com/dolthub/maphash v0.0.0-20221220182448-74e1e1ea1577 h1:SegEguMxToBn045KRHLIUlF2/jR7Y2qD6fF+3tdOfvI=
github.com/dolthub/maphash v0.0.0-20221220182448-74e1e1ea1577/go.mod h1:gkg4Ch4CdCDu5h6PMriVLawB7koZ+5ijb9puGMV50a4=
github.com/dolthub/sqllogictest/go v0.0.0-20240118211725-a52e3f5697e3 h1:+eDpuEJ9t8aag943P27VS5PFNhp5l+6NIJ/Rc3b164o=
github.com/dolthub/sqllogictest/go v0.0.0-20240118211725-a52e3f5697e3/go.mod h1:e/FIZVvT2IR53HBCAo41NjqgtEnjMJGKca3Y/dAmZaA=
github.com/dolthub/swiss v0.1.0 h1:EaGQct3AqeP/MjASHLiH6i4TAmgbG/c4rA6a1bzCOPc=
github.com/dolthub/swiss v0.1.0/go.mod h1:BeucyB08Vb1G9tumVN3Vp/pyY4AMUnr9p7Rz7wJ7kAQ=
github.com/dolthub/vitess v0.0.0-20240117231546-55b8c7b39462 h1:So1KO202cb047yWg5X27xRso6tkSYmU0Yu96JIVsaEU=
github.com/dolthub/vitess v0.0.0-20240117231546-55b8c7b39462/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw=
github.com/dolthub/vitess v0.0.0-20240207121055-c057d2347007 h1:MvFoe0FnHhxQLyp4Ldw0HRj1yu83YErbtbr7XxhaIFk=
github.com/dolthub/vitess v0.0.0-20240207121055-c057d2347007/go.mod h1:IwjNXSQPymrja5pVqmfnYdcy7Uv7eNJNBPK/MEh9OOw=
github.com/dustin/go-humanize v0.0.0-20171111073723-bb3d318650d4/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
Expand Down
3 changes: 2 additions & 1 deletion server/ast/column_table_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func nodeColumnTableDef(node *tree.ColumnTableDef) (_ *vitess.ColumnDefinition,
return nil, fmt.Errorf("FAMILY is not yet supported")
}

convertType, err := nodeResolvableTypeReference(node.Type)
convertType, resolvedType, err := nodeResolvableTypeReference(node.Type)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -105,6 +105,7 @@ func nodeColumnTableDef(node *tree.ColumnTableDef) (_ *vitess.ColumnDefinition,
Name: vitess.NewColIdent(string(node.Name)),
Type: vitess.ColumnType{
Type: convertType.Type,
ResolvedType: resolvedType,
Null: isNull,
NotNull: isNotNull,
Autoincrement: vitess.BoolVal(node.IsSerial),
Expand Down
26 changes: 24 additions & 2 deletions server/ast/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ import (
"go/constant"
"strings"

"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/expression"
vitess "github.com/dolthub/vitess/go/vt/sqlparser"

"github.com/dolthub/doltgresql/postgres/parser/sem/tree"
"github.com/dolthub/doltgresql/postgres/parser/types"
pgtypes "github.com/dolthub/doltgresql/server/types"
)

// nodeExprs handles tree.Exprs nodes.
Expand Down Expand Up @@ -96,7 +99,26 @@ func nodeExpr(node tree.Expr) (vitess.Expr, error) {
case *tree.AnnotateTypeExpr:
return nil, fmt.Errorf("ANNOTATE_TYPE is not yet supported")
case *tree.Array:
return nil, fmt.Errorf("arrays are not yet supported")
//TODO: right now, this only works with boolean array values for the sake of demonstration
var gmsExpr sql.Expression
if len(node.Exprs) == 0 {
if node.ResolvedType().Family() == types.ArrayFamily && node.ResolvedType().ArrayContents().Family() == types.BoolFamily {
gmsExpr = expression.NewLiteral([]bool{}, pgtypes.BoolArray)
} else {
return nil, fmt.Errorf("arrays are generally not yet supported")
}
} else {
vals := make([]bool, len(node.Exprs))
for i, arrayExpr := range node.Exprs {
if arrayVal, ok := arrayExpr.(*tree.DBool); ok && arrayVal != nil {
vals[i] = bool(*arrayVal)
} else {
return nil, fmt.Errorf("array value is not yet supported")
}
}
gmsExpr = expression.NewLiteral(vals, pgtypes.BoolArray)
}
return vitess.InjectedExpr{Expression: gmsExpr}, nil
case *tree.ArrayFlatten:
return nil, fmt.Errorf("flattening arrays is not yet supported")
case *tree.BinaryExpr:
Expand Down Expand Up @@ -199,7 +221,7 @@ func nodeExpr(node tree.Expr) (vitess.Expr, error) {
return nil, fmt.Errorf("unknown cast syntax")
}

convertType, err := nodeResolvableTypeReference(node.Type)
convertType, _, err := nodeResolvableTypeReference(node.Type)
if err != nil {
return nil, err
}
Expand Down
25 changes: 18 additions & 7 deletions server/ast/resolvable_type_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,44 @@ import (
"fmt"
"strconv"

"github.com/dolthub/go-mysql-server/sql"
vitess "github.com/dolthub/vitess/go/vt/sqlparser"

"github.com/dolthub/doltgresql/postgres/parser/sem/tree"
"github.com/dolthub/doltgresql/postgres/parser/types"
pgtypes "github.com/dolthub/doltgresql/server/types"
)

// nodeResolvableTypeReference handles tree.ResolvableTypeReference nodes.
func nodeResolvableTypeReference(typ tree.ResolvableTypeReference) (*vitess.ConvertType, error) {
func nodeResolvableTypeReference(typ tree.ResolvableTypeReference) (*vitess.ConvertType, sql.Type, error) {
if typ == nil {
return nil, nil
return nil, nil, nil
}

var columnTypeName string
var columnTypeLength *vitess.SQLVal
var columnTypeScale *vitess.SQLVal
var resolvedType sql.Type
switch columnType := typ.(type) {
case *tree.ArrayTypeReference:
return nil, fmt.Errorf("array types are not yet supported")
return nil, nil, fmt.Errorf("the given array type is not yet supported")
case *tree.OIDTypeReference:
return nil, fmt.Errorf("referencing types by their OID is not yet supported")
return nil, nil, fmt.Errorf("referencing types by their OID is not yet supported")
case *tree.UnresolvedObjectName:
return nil, fmt.Errorf("type declaration format is not yet supported")
return nil, nil, fmt.Errorf("type declaration format is not yet supported")
case *types.GeoMetadata:
return nil, fmt.Errorf("geometry types are not yet supported")
return nil, nil, fmt.Errorf("geometry types are not yet supported")
case *types.T:
columnTypeName = columnType.SQLStandardName()
switch columnType.Family() {
case types.ArrayFamily:
if columnType.ArrayContents().Family() == types.BoolFamily {
resolvedType = pgtypes.BoolArray
} else {
return nil, nil, fmt.Errorf("the given array type is not yet supported")
}
case types.BoolFamily:
resolvedType = pgtypes.Bool
case types.DecimalFamily:
columnTypeName = "decimal"
columnTypeLength = vitess.NewIntVal([]byte(strconv.Itoa(int(columnType.Precision()))))
Expand All @@ -63,5 +74,5 @@ func nodeResolvableTypeReference(typ tree.ResolvableTypeReference) (*vitess.Conv
Length: columnTypeLength,
Scale: columnTypeScale,
Charset: "", // TODO
}, nil
}, resolvedType, nil
}
Loading

0 comments on commit 35d9c85

Please sign in to comment.