Skip to content

Commit

Permalink
merge main
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmu committed Mar 6, 2025
2 parents 070fac7 + 015deee commit e15ecec
Show file tree
Hide file tree
Showing 11 changed files with 311 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cd-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
run: |
latest=$(git rev-parse HEAD)
echo "commitish=$latest" >> $GITHUB_OUTPUT
GO_BUILD_VERSION=1.23.3 scripts/build_binaries.sh
GO_BUILD_VERSION=1.24.1 scripts/build_binaries.sh
- name: Create Release
id: create_release
uses: dolthub/create-release@v2
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
module github.com/dolthub/doltgresql

go 1.23.3
go 1.24.1

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.20250227000557-ec15fdc1ddc6
github.com/dolthub/dolt/go v0.40.5-0.20250305033733-0565b03abd83
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
github.com/dolthub/go-icu-regex v0.0.0-20250303123116-549b8d7cad00
github.com/dolthub/go-mysql-server v0.19.1-0.20250303225135-c856028387bc
github.com/dolthub/go-mysql-server v0.19.1-0.20250305015716-690400e21e90
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216
github.com/dolthub/vitess v0.0.0-20250228011932-c4f6bba87730
github.com/dolthub/vitess v0.0.0-20250304211657-920ca9ec2b9a
github.com/fatih/color v1.13.0
github.com/goccy/go-json v0.10.2
github.com/gogo/protobuf v1.3.2
Expand Down Expand Up @@ -58,7 +58,7 @@ require (
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/apache/thrift v0.13.1-0.20201008052519-daf620915714 // indirect
github.com/aws/aws-sdk-go v1.34.0 // indirect
github.com/aws/aws-sdk-go v1.55.6 // indirect
github.com/bcicen/jstream v1.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ github.com/aryann/difflib v0.0.0-20170710044230-e206f873d14a/go.mod h1:DAHtR1m6l
github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQwij/eHl5CU=
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.30.19/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.34.0 h1:brux2dRrlwCF5JhTL7MUT3WUwo9zfDHZZp3+g3Mvlmo=
github.com/aws/aws-sdk-go v1.34.0/go.mod h1:5zCpMtNQVjRREroY7sYe8lOMRSxkhG6MZveU8YkpAk0=
github.com/aws/aws-sdk-go v1.55.6 h1:cSg4pvZ3m8dgYcgqB97MrcdjUmZ1BeMYKUxMMB89IPk=
github.com/aws/aws-sdk-go v1.55.6/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/aws/aws-sdk-go-v2 v1.7.1/go.mod h1:L5LuPC1ZgDr2xQS7AmIec/Jlc7O/Y1u2KxJyNVab250=
github.com/aws/aws-sdk-go-v2/config v1.5.0/go.mod h1:RWlPOAW3E3tbtNAqTwvSW54Of/yP3oiZXMI0xfUdjyA=
Expand Down 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.20250227000557-ec15fdc1ddc6 h1:g69dROw+SbOeOiZuPPe5CJ2vzcXdUDL2T9WXmA7uzUQ=
github.com/dolthub/dolt/go v0.40.5-0.20250227000557-ec15fdc1ddc6/go.mod h1:sXPQXJRVGP9iAxcqf7SHZrnYKLnSTL4hKwlo6ELDK10=
github.com/dolthub/dolt/go v0.40.5-0.20250305033733-0565b03abd83 h1:UIKUtU2Hn0R1mAsZNftanHm70t1G9P2HhNh/ogNcR5s=
github.com/dolthub/dolt/go v0.40.5-0.20250305033733-0565b03abd83/go.mod h1:yNlTc3vD2W3cy/CUsHRQBYTzUyi9SQyr3iFBAnNij8E=
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d h1:gO9+wrmNHXukPNCO1tpfCcXIdMlW/qppbUStfLvqz/U=
github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi v0.0.0-20241119094239-f4e529af734d/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-20250303123116-549b8d7cad00 h1:rh2ij2yTYKJWlX+c8XRg4H5OzqPewbU1lPK8pcfVmx8=
github.com/dolthub/go-icu-regex v0.0.0-20250303123116-549b8d7cad00/go.mod h1:ylU4XjUpsMcvl/BKeRRMXSH7e7WBrPXdSLvnRJYrxEA=
github.com/dolthub/go-mysql-server v0.19.1-0.20250303225135-c856028387bc h1:xOGV8hl0l4m5wXXuAE76T7f5hrvN7kiA1+3BukMNqw0=
github.com/dolthub/go-mysql-server v0.19.1-0.20250303225135-c856028387bc/go.mod h1:w0iOhKy+xe00c8MBzJ+j/m54OttZPNRS8U/eAKVxohU=
github.com/dolthub/go-mysql-server v0.19.1-0.20250305015716-690400e21e90 h1:zYtorqYKsm+OFrHeBYklBiNmIc1QbKTdnF0SDH4DarE=
github.com/dolthub/go-mysql-server v0.19.1-0.20250305015716-690400e21e90/go.mod h1:yr+Vv47/YLOKMgiEY+QxHTlbIVpTuiVtkEZ5l+xruY4=
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 All @@ -238,8 +238,8 @@ github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216 h1:JWkKRE4
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216/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-20250228011932-c4f6bba87730 h1:GtlMVB7+Z7fZZj7BHRFd2rzxZ574dJ8cB/EHWdq1kbY=
github.com/dolthub/vitess v0.0.0-20250228011932-c4f6bba87730/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
github.com/dolthub/vitess v0.0.0-20250304211657-920ca9ec2b9a h1:HIH9g4z+yXr4DIFyT6L5qOIEGJ1zVtlj6baPyHAG4Yw=
github.com/dolthub/vitess v0.0.0-20250304211657-920ca9ec2b9a/go.mod h1:1gQZs/byeHLMSul3Lvl3MzioMtOW1je79QYGyi2fd70=
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
1 change: 1 addition & 0 deletions postgres/parser/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2553,6 +2553,7 @@ var unreservedTypeTokens = map[string]*T{
"float4": Float,
"float8": Float,
"inet": INet,
"integer": Int4,
"int2": Int2,
"int4": Int4,
"int8": Int,
Expand Down
2 changes: 1 addition & 1 deletion scripts/run_staticcheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
cd "$(cd -P -- "$(dirname -- "$0")" && pwd -P)"
cd ..

go run honnef.co/go/tools/cmd/staticcheck@2024.1.1 ./...
go run honnef.co/go/tools/cmd/staticcheck@2025.1 ./...
2 changes: 1 addition & 1 deletion server/node/no_op.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func (n noOpRowIter) Next(ctx *sql.Context) (sql.Row, error) {

func (n noOpRowIter) Close(ctx *sql.Context) error {
for _, warning := range n.warnings {
ctx.Warn(0, fmt.Sprintf("%s is unimplemented", warning))
ctx.Warn(0, "%s is unimplemented", warning)
}
return nil
}
Expand Down
23 changes: 22 additions & 1 deletion server/plpgsql/interpreter_logic.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ package plpgsql

import (
"fmt"
"strings"

"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/analyzer"

"github.com/dolthub/doltgresql/core/id"
"github.com/dolthub/doltgresql/core/typecollection"
"github.com/dolthub/doltgresql/postgres/parser/types"
pgtypes "github.com/dolthub/doltgresql/server/types"
)

Expand Down Expand Up @@ -92,7 +94,26 @@ func Call(ctx *sql.Context, iFunc InterpretedFunction, runner analyzer.Statement
if err != nil {
return nil, err
}
resolvedType, exists := typeCollection.GetType(id.NewType("pg_catalog", operation.PrimaryData))

// pg_query_go sets PrimaryData for implicit CASE statement variables to
// `pg_catalog."integer"`, so we remove double-quotes and extract the schema name.
typeName := operation.PrimaryData
typeName = strings.ReplaceAll(typeName, `"`, "")
schemaName := "pg_catalog"
if strings.Contains(typeName, ".") {
parts := strings.Split(typeName, ".")
schemaName = parts[0]
typeName = parts[1]
// Check the NonKeyword type names to see if we're looking at
// an alias of a type if we're in the pg_catalog schema.
if schemaName == "pg_catalog" {
typ, ok, _ := types.TypeForNonKeywordTypeName(typeName)
if ok && typ != nil {
typeName = typ.Name()
}
}
}
resolvedType, exists := typeCollection.GetType(id.NewType(schemaName, typeName))
if !exists {
return nil, pgtypes.ErrTypeDoesNotExist.New(operation.PrimaryData)
}
Expand Down
109 changes: 109 additions & 0 deletions server/plpgsql/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package plpgsql

import (
"fmt"
"strings"

"github.com/cockroachdb/errors"
Expand Down Expand Up @@ -102,6 +103,25 @@ type plpgSQL_stmt_block struct {
LineNumber int32 `json:"lineno"`
}

// plpgSQL_stmt_case exists to match the expected JSON format.
type plpgSQL_stmt_case struct {
LineNumber int32 `json:"lineno"`
Expression expr `json:"t_expr"`
// VarNo indicates the ID for the __Case__Variable_N__ variable that holds the evaluated
// value of the case expression.
VarNo int32 `json:"t_varno"`
WhenList []statement `json:"case_when_list"`
HasElse bool `json:"have_else"`
Else []statement `json:"else_stmts"`
}

// plpgSQL_case_when exists to match the expected JSON format.
type plpgSQL_case_when struct {
LineNumber int32 `json:"lineno"`
Expression expr `json:"expr"`
Body []statement `json:"stmts"`
}

// plpgSQL_stmt_execsql exists to match the expected JSON format.
type plpgSQL_stmt_execsql struct {
SQLStmt sqlstmt `json:"sqlstmt"`
Expand Down Expand Up @@ -175,12 +195,14 @@ type sqlstmt struct {
// having a singular expected implementation.
type statement struct {
Assignment *plpgSQL_stmt_assign `json:"PLpgSQL_stmt_assign"`
Case *plpgSQL_stmt_case `json:"PLpgSQL_stmt_case"`
ExecSQL *plpgSQL_stmt_execsql `json:"PLpgSQL_stmt_execsql"`
Exit *plpgSQL_stmt_exit `json:"PLpgSQL_stmt_exit"`
If *plpgSQL_stmt_if `json:"PLpgSQL_stmt_if"`
Loop *plpgSQL_stmt_loop `json:"PLpgSQL_stmt_loop"`
Perform *plpgSQL_stmt_perform `json:"PLpgSQL_stmt_perform"`
Return *plpgSQL_stmt_return `json:"PLpgSQL_stmt_return"`
When *plpgSQL_case_when `json:"PLpgSQL_case_when"`
While *plpgSQL_stmt_while `json:"PLpgSQL_stmt_while"`
}

Expand All @@ -204,6 +226,93 @@ func (stmt *plpgSQL_stmt_assign) Convert() (Assignment, error) {
}, nil
}

func (stmt *plpgSQL_stmt_case) Convert() (block Block, err error) {
// If the CASE statement has a main expression, start by assigning it to a variable so
// we can evaluate it once and only once.
if stmt.Expression.Expression.Query != "" {
// TODO: pg_query_go creates the definitions for these variables, and
// ideally users shouldn't be able to reference them. We could
// update all the references to them (i.e. declaration, assignment,
// and WHEN block exprs) to change the name to include a \0 char to
// prevent users from referencing them or colliding with them.
block.Body = append(block.Body, Assignment{
VariableName: fmt.Sprintf("__Case__Variable_%d__", stmt.VarNo),
Expression: stmt.Expression.Expression.Query,
})
}

// Record indexes of all the GOTO ops that jump to the very end of the case block so we
// can update them later and plug in the correct offsets after we know the final size.
var gotoEndOpsIndexes []int

// Add operations for each WHEN statement...
for _, stmt := range stmt.WhenList {
when := stmt.When
if when == nil {
return Block{}, fmt.Errorf("case statement WHEN clause is nil")
}

// TODO: The generated expressions from pg_query_go uses double quotes
// around the variable name, which is valid for Postgres, but
// our engine doesn't currently resolve double-quoted strings to
// variables, so for now, we just extract the double quotes.
expressionString := when.Expression.Expression.Query
expressionString = strings.ReplaceAll(expressionString, `"`, "")

convertedWhenBodyStatements, err := jsonConvertStatements(when.Body)
if err != nil {
return Block{}, err
}

block.Body = append(block.Body,
If{
Condition: expressionString,
GotoOffset: 2,
},
Goto{
// This GOTO jumps to the next WHEN block, so step over all the statements
// from this WHEN block, plus 1 for the GOTO op we add at the end of each
// block, and plus 1 more to move to the next statement.
Offset: int32(len(convertedWhenBodyStatements) + 1 + 1),
})
block.Body = append(block.Body, convertedWhenBodyStatements...)

// Add a GOTO op to jump to the end of the entire CASE block, and record its position
// in the statement block so we can update it later.
block.Body = append(block.Body, Goto{})
gotoEndOpsIndexes = append(gotoEndOpsIndexes, len(block.Body)-1)
}

if stmt.HasElse {
convertElseBodyStatements, err := jsonConvertStatements(stmt.Else)
if err != nil {
return Block{}, err
}
block.Body = append(block.Body, convertElseBodyStatements...)
// TODO: If no cases match and there is no ELSE block, then add a RAISE statement
// to return an error.
//} else {
// Sample PostgreSQL error response:
// ERROR: case not found
// HINT: CASE statement is missing ELSE part.
// CONTEXT: PL/pgSQL function interpreted_case(integer) line 5 at CASE
}

// Update all the GOTO ops that jump to the very end of the case block.
for _, gotoEndOpIndex := range gotoEndOpsIndexes {
// Sanity check that we are looking at a GOTO statement
if _, ok := block.Body[gotoEndOpIndex].(Goto); !ok {
return Block{}, fmt.Errorf("expected Goto statement, got %T", block.Body[gotoEndOpIndex])
}

block.Body[gotoEndOpIndex] = Goto{
Offset: int32(len(block.Body) - gotoEndOpIndex),
}
}

return block, nil
}

// Convert converts the JSON statement into its output form.
func (stmt *plpgSQL_stmt_execsql) Convert() (ExecuteSQL, error) {
var target string
Expand Down
2 changes: 2 additions & 0 deletions server/plpgsql/json_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func jsonConvertStatement(stmt statement) (Statement, error) {
switch {
case stmt.Assignment != nil:
return stmt.Assignment.Convert()
case stmt.Case != nil:
return stmt.Case.Convert()
case stmt.ExecSQL != nil:
return stmt.ExecSQL.Convert()
case stmt.Exit != nil:
Expand Down
4 changes: 4 additions & 0 deletions servercfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ func (cfg *DoltgresConfig) LogLevel() servercfg.LogLevel {
}
}

func (cfg *DoltgresConfig) LogFormat() servercfg.LogFormat {
return servercfg.LogFormat_Text
}

func (cfg *DoltgresConfig) MaxConnections() uint64 {
return 0
}
Expand Down
Loading

0 comments on commit e15ecec

Please sign in to comment.