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

use gms engine instead of mysql handler #677

Merged
merged 29 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f525c9a
[WIP] use gms engine instead of mysql handler
jennifersp Sep 4, 2024
cb5360f
merge main
jennifersp Sep 6, 2024
d1fd071
more changes
jennifersp Sep 6, 2024
696cb61
restore
jennifersp Sep 6, 2024
9bcda17
clean up and some fixes
jennifersp Sep 10, 2024
3fcc89f
format
jennifersp Sep 10, 2024
57db66b
Merge branch 'main' into jennifer/handler
jennifersp Sep 10, 2024
f9f5340
test fixes
jennifersp Sep 11, 2024
0e878be
merge main
jennifersp Sep 11, 2024
049c1f4
merge main
jennifersp Sep 11, 2024
b383fe7
clean up
jennifersp Sep 11, 2024
b2e30b5
clean up and fix decimal formatting and fix pgclient node test
jennifersp Sep 12, 2024
aa57f18
merge main and bump dolt
jennifersp Sep 12, 2024
749a098
rm typo
jennifersp Sep 12, 2024
b79cc86
fix
jennifersp Sep 12, 2024
3dffc45
merge main
jennifersp Sep 13, 2024
1cd31fb
fix pgclient node test
jennifersp Sep 13, 2024
216af91
fixed for feedback
jennifersp Sep 17, 2024
d2ace49
merge main and bump dolt
jennifersp Sep 17, 2024
43c98de
Merge branch 'main' into jennifer/handler
jennifersp Sep 18, 2024
b359708
bump dolt and gms
jennifersp Sep 18, 2024
de13c44
merge main
jennifersp Sep 18, 2024
1174b2a
rm usage of gms handler
jennifersp Sep 18, 2024
b8b8038
add comment
jennifersp Sep 18, 2024
b0afa9e
[ga-bump-dep] Bump dependency in Doltgres by jennifersp
jennifersp Sep 18, 2024
ebf5984
add interface
jennifersp Sep 18, 2024
7c41dae
merge jennifersp-88ae8c98
jennifersp Sep 18, 2024
e2c755f
format
jennifersp Sep 18, 2024
043e0bf
add _TEXT
jennifersp Sep 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,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.20240918171330-ae4c8c780fd7
github.com/dolthub/dolt/go v0.40.5-0.20240918195522-7c2cd69829ec
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240827111219-e4bb9ca3442d
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662
github.com/dolthub/go-mysql-server v0.18.2-0.20240918043246-e3846f5468f5
github.com/dolthub/go-mysql-server v0.18.2-0.20240918194055-f75a63f64679
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216
github.com/dolthub/vitess v0.0.0-20240916204416-9d4d4a09b1d9
github.com/fatih/color v1.13.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ 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.20240918171330-ae4c8c780fd7 h1:qdlLYlU0bLqOEi3BDcWzRj31LUjy40B6e2nXkWs8xWo=
github.com/dolthub/dolt/go v0.40.5-0.20240918171330-ae4c8c780fd7/go.mod h1:95aBt3R6EbixJ32k/mYTKj8XekDpgfDItulcz5VpEcU=
github.com/dolthub/dolt/go v0.40.5-0.20240918195522-7c2cd69829ec h1:xuZmCQJrEVSx8Sv3zDkS8dglsLCFV/y90vhgCPSnlH0=
github.com/dolthub/dolt/go v0.40.5-0.20240918195522-7c2cd69829ec/go.mod h1:ezR9KWGkpIWGHEFPk9GgQfaHyF8PcdTlQbqJUah0GM0=
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240827111219-e4bb9ca3442d h1:RZkQeYOrDrOWzCxaP2ttkvg4E2TM9n8lnEsIBLKjqkM=
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20240827111219-e4bb9ca3442d/go.mod h1:L5RDYZbC9BBWmoU2+TjTekeqqhFXX5EqH9ln00O0stY=
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2 h1:u3PMzfF8RkKd3lB9pZ2bfn0qEG+1Gms9599cr0REMww=
Expand All @@ -224,8 +224,8 @@ 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-20240916130659-0118adc6b662 h1:aC17hZD6iwzBwwfO5M+3oBT5E5gGRiQPdn+vzpDXqIA=
github.com/dolthub/go-icu-regex v0.0.0-20240916130659-0118adc6b662/go.mod h1:KPUcpx070QOfJK1gNe0zx4pA5sicIK1GMikIGLKC168=
github.com/dolthub/go-mysql-server v0.18.2-0.20240918043246-e3846f5468f5 h1:m12ohMzoZUQExnXqWeTYziQiSwwtzjoEFBSKzBVHin8=
github.com/dolthub/go-mysql-server v0.18.2-0.20240918043246-e3846f5468f5/go.mod h1:m88EMm9OthVVa6qIhbpnRDpj/eYUXuNpvY/+0YWKVwc=
github.com/dolthub/go-mysql-server v0.18.2-0.20240918194055-f75a63f64679 h1:O6eSicGwVPYnEzE0jgLakX2Ud54p6OGdcaqwBgNB+vU=
github.com/dolthub/go-mysql-server v0.18.2-0.20240918194055-f75a63f64679/go.mod h1:m88EMm9OthVVa6qIhbpnRDpj/eYUXuNpvY/+0YWKVwc=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE=
Expand Down
13 changes: 6 additions & 7 deletions postgres/messages/data_row.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ package messages
import (
"fmt"

"github.com/dolthub/vitess/go/sqltypes"

"github.com/dolthub/doltgresql/postgres/connection"
)

Expand All @@ -28,7 +26,7 @@ func init() {

// DataRow represents a row of data.
type DataRow struct {
Values []sqltypes.Value
Values [][]byte
jennifersp marked this conversation as resolved.
Show resolved Hide resolved
}

var dataRowDefault = connection.MessageFormat{
Expand Down Expand Up @@ -75,12 +73,13 @@ var _ connection.Message = DataRow{}
func (m DataRow) Encode() (connection.MessageFormat, error) {
outputMessage := m.DefaultMessage().Copy()
for i := 0; i < len(m.Values); i++ {
if m.Values[i].IsNull() {
if m.Values[i] == nil {
outputMessage.Field("Columns").Child("ColumnLength", i).MustWrite(-1)
} else {
value := []byte(m.Values[i].ToString())
outputMessage.Field("Columns").Child("ColumnLength", i).MustWrite(len(value))
outputMessage.Field("Columns").Child("ColumnData", i).MustWrite(value)
value := m.Values[i]
valLen := len(value)
outputMessage.Field("Columns").Child("ColumnLength", i).MustWrite(valLen)
outputMessage.Field("Columns").Child("ColumnData", i).MustWrite(value[:valLen])
}
}
return outputMessage, nil
Expand Down
150 changes: 8 additions & 142 deletions postgres/messages/row_description.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package messages
import (
"fmt"

"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/vitess/go/vt/proto/query"
"github.com/jackc/pgx/v5/pgproto3"

"github.com/dolthub/doltgresql/postgres/connection"
)
Expand Down Expand Up @@ -110,7 +110,7 @@ func init() {

// RowDescription represents a RowDescription message intended for the client.
type RowDescription struct {
Fields []*query.Field
Fields []pgproto3.FieldDescription
}

var rowDescriptionDefault = connection.MessageFormat{
Expand Down Expand Up @@ -182,22 +182,11 @@ func (m RowDescription) Encode() (connection.MessageFormat, error) {
outputMessage := m.DefaultMessage().Copy()
for i := 0; i < len(m.Fields); i++ {
field := m.Fields[i]
dataTypeObjectID, err := VitessFieldToDataTypeObjectID(field)
if err != nil {
return connection.MessageFormat{}, err
}
dataTypeSize, err := VitessFieldToDataTypeSize(field)
if err != nil {
return connection.MessageFormat{}, err
}
dataTypeModifier, err := VitessFieldToDataTypeModifier(field)
if err != nil {
return connection.MessageFormat{}, err
}
outputMessage.Field("Fields").Child("ColumnName", i).MustWrite(field.Name)
outputMessage.Field("Fields").Child("DataTypeObjectID", i).MustWrite(dataTypeObjectID)
outputMessage.Field("Fields").Child("DataTypeSize", i).MustWrite(dataTypeSize)
outputMessage.Field("Fields").Child("DataTypeModifier", i).MustWrite(dataTypeModifier)
outputMessage.Field("Fields").Child("ColumnName", i).MustWrite(string(field.Name))
outputMessage.Field("Fields").Child("DataTypeObjectID", i).MustWrite(field.DataTypeOID)
outputMessage.Field("Fields").Child("DataTypeSize", i).MustWrite(field.DataTypeSize)
outputMessage.Field("Fields").Child("DataTypeModifier", i).MustWrite(field.TypeModifier)
outputMessage.Field("Fields").Child("FormatCode", i).MustWrite(field.Format)
}
return outputMessage, nil
}
Expand All @@ -215,13 +204,7 @@ func (m RowDescription) DefaultMessage() *connection.MessageFormat {
return &rowDescriptionDefault
}

// VitessFieldToDataTypeObjectID returns the type of a vitess Field into a type as defined by Postgres.
// OIDs can be obtained with the following query: `SELECT oid, typname FROM pg_type ORDER BY 1;`
func VitessFieldToDataTypeObjectID(field *query.Field) (uint32, error) {
return VitessTypeToObjectID(field.Type)
}

// VitessFieldToDataTypeObjectID returns a type, as defined by Vitess, into a type as defined by Postgres.
// VitessTypeToObjectID returns a type, as defined by Vitess, into a type as defined by Postgres.
// OIDs can be obtained with the following query: `SELECT oid, typname FROM pg_type ORDER BY 1;`
func VitessTypeToObjectID(typ query.Type) (uint32, error) {
switch typ {
Expand Down Expand Up @@ -272,10 +255,8 @@ func VitessTypeToObjectID(typ query.Type) (uint32, error) {
case query.Type_JSON:
return OidJson, nil
case query.Type_TIMESTAMP, query.Type_DATETIME:
const OidTimestamp = 1114
return OidTimestamp, nil
case query.Type_DATE:
const OidDate = 1082
return OidDate, nil
case query.Type_NULL_TYPE:
return OidText, nil // NULL is treated as TEXT on the wire
Expand All @@ -285,118 +266,3 @@ func VitessTypeToObjectID(typ query.Type) (uint32, error) {
return 0, fmt.Errorf("unsupported type: %s", typ)
}
}

// VitessFieldToDataTypeSize returns the type's size, as defined by Vitess, into the size as defined by Postgres.
func VitessFieldToDataTypeSize(field *query.Field) (int16, error) {
switch field.Type {
case query.Type_INT8:
return 1, nil
case query.Type_INT16:
return 2, nil
case query.Type_INT24:
return 4, nil
case query.Type_INT32:
return 4, nil
case query.Type_INT64:
return 8, nil
case query.Type_UINT8:
return 4, nil
case query.Type_UINT16:
return 4, nil
case query.Type_UINT24:
return 4, nil
case query.Type_UINT32:
return 4, nil
case query.Type_UINT64:
// Since this has an upperbound greater than `INT64`, we'll treat it as `NUMERIC`
return -1, nil
case query.Type_FLOAT32:
return 4, nil
case query.Type_FLOAT64:
return 8, nil
case query.Type_DECIMAL:
return -1, nil
case query.Type_CHAR:
return -1, nil
case query.Type_VARCHAR:
return -1, nil
case query.Type_TEXT:
return -1, nil
case query.Type_BLOB:
return -1, nil
case query.Type_JSON:
return -1, nil
case query.Type_TIMESTAMP, query.Type_DATETIME:
return 8, nil
case query.Type_DATE:
return 4, nil
case query.Type_NULL_TYPE:
return -1, nil // NULL is treated as TEXT on the wire
case query.Type_ENUM:
return -1, nil // TODO: temporary solution until we support CREATE TYPE
default:
return 0, fmt.Errorf("unsupported type returned from engine: %s", field.Type)
}
}

// VitessFieldToDataTypeModifier returns the field's data type modifier as defined by Postgres.
func VitessFieldToDataTypeModifier(field *query.Field) (int32, error) {
switch field.Type {
case query.Type_INT8:
return -1, nil
case query.Type_INT16:
return -1, nil
case query.Type_INT24:
return -1, nil
case query.Type_INT32:
return -1, nil
case query.Type_INT64:
return -1, nil
case query.Type_UINT8:
return -1, nil
case query.Type_UINT16:
return -1, nil
case query.Type_UINT24:
return -1, nil
case query.Type_UINT32:
return -1, nil
case query.Type_UINT64:
// Since we're encoding this as `NUMERIC`, we emulate a `NUMERIC` type with a precision of 19 and a scale of 0
return (19 << 16) + 4, nil
case query.Type_FLOAT32:
return -1, nil
case query.Type_FLOAT64:
return -1, nil
case query.Type_DECIMAL:
// This is how we encode the precision and scale for some reason
precision := int32(field.ColumnLength - 1)
scale := int32(field.Decimals)
if scale > 0 {
precision--
}
// PostgreSQL adds 4 to the length for an unknown reason
return (precision<<16 + scale) + 4, nil
case query.Type_CHAR:
// PostgreSQL adds 4 to the length for an unknown reason
return int32(int64(field.ColumnLength)/sql.CharacterSetID(field.Charset).MaxLength()) + 4, nil
case query.Type_VARCHAR:
// PostgreSQL adds 4 to the length for an unknown reason
return int32(int64(field.ColumnLength)/sql.CharacterSetID(field.Charset).MaxLength()) + 4, nil
case query.Type_TEXT:
return -1, nil
case query.Type_BLOB:
return -1, nil
case query.Type_JSON:
return -1, nil
case query.Type_TIMESTAMP, query.Type_DATETIME:
return -1, nil
case query.Type_DATE:
return -1, nil
case query.Type_NULL_TYPE:
return -1, nil // NULL is treated as TEXT on the wire
case query.Type_ENUM:
return -1, nil // TODO: temporary solution until we support CREATE TYPE
default:
return 0, fmt.Errorf("unsupported type returned from engine: %s", field.Type)
}
}
Loading
Loading