Skip to content

Commit

Permalink
Formatting and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zachmu committed Jan 28, 2025
1 parent ac100d7 commit 078b10c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion server/analyzer/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
ruleId_ResolveType // resolveType
ruleId_ReplaceArithmeticExpressions // replaceArithmeticExpressions
ruleId_OptimizeFunctions // optimizeFunctions
ruleId_ValidateColumnDefaults // validateColumnDefaults
ruleId_ValidateColumnDefaults // validateColumnDefaults
)

// Init adds additional rules to the analyzer to handle Doltgres-specific functionality.
Expand Down
5 changes: 3 additions & 2 deletions server/analyzer/validate_column_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
package analyzer

import (
pgnode "github.com/dolthub/doltgresql/server/node"
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/analyzer"
"github.com/dolthub/go-mysql-server/sql/expression"
"github.com/dolthub/go-mysql-server/sql/plan"
"github.com/dolthub/go-mysql-server/sql/transform"

pgnode "github.com/dolthub/doltgresql/server/node"
)

// validateColumnDefaults ensures that newly created column defaults from a DDL statement are legal for the type of
Expand Down Expand Up @@ -198,4 +199,4 @@ func getResolvedTable(node sql.Node) *plan.ResolvedTable {
return true
})
return table
}
}
9 changes: 5 additions & 4 deletions server/functions/gen_random_uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
package functions

import (
"github.com/dolthub/go-mysql-server/sql"

"github.com/dolthub/doltgresql/postgres/parser/uuid"
"github.com/dolthub/doltgresql/server/functions/framework"
pgtypes "github.com/dolthub/doltgresql/server/types"
"github.com/dolthub/go-mysql-server/sql"
)

// initRadians registers the functions to the catalog.
Expand All @@ -27,9 +28,9 @@ func initGenRandomUuid() {
}

var gen_random_uuid = framework.Function0{
Name: "gen_random_uuid",
Return: pgtypes.Uuid,
Strict: true,
Name: "gen_random_uuid",
Return: pgtypes.Uuid,
Strict: true,
Callable: func(ctx *sql.Context) (any, error) {
return uuid.NewV4()
},
Expand Down
4 changes: 2 additions & 2 deletions server/node/create_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func (c CreateTable) WithTargetSchema(schema sql.Schema) (sql.Node, error) {
if err != nil {
return nil, err
}

c.gmsCreateTable = n.(*plan.CreateTable)

return &c, nil
}
18 changes: 17 additions & 1 deletion testing/go/alter_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,24 @@ func TestAlterTable(t *testing.T) {
created_at timestamp with time zone DEFAULT now() NOT NULL,
updated_at timestamp with time zone DEFAULT now() NOT NULL
);`,
"INSERT INTO t1 (id, uid) VALUES (1, '00000000-0000-0000-0000-000000000001');",
"INSERT INTO t1 (id, uid) VALUES (1, '00000000-0000-0000-0000-000000000001');",
},
Assertions: []ScriptTestAssertion{
{
Query: "ALTER TABLE ONLY public.t1 ADD CONSTRAINT t1_pkey PRIMARY KEY (id);",
},
{
Query: "select created_at is not null from t1 where id = 1;",
Expected: []sql.Row{{"t"}},
},
{
Query: "select updated_at is not null from t1 where id = 1;",
Expected: []sql.Row{{"t"}},
},
{
Query: "select created_at = updated_at from t1 where id = 1;",
Expected: []sql.Row{{"t"}},
},
},
},
{
Expand All @@ -458,6 +470,10 @@ func TestAlterTable(t *testing.T) {
{
Query: "ALTER TABLE ONLY public.t1 ADD CONSTRAINT t1_pkey PRIMARY KEY (id);",
},
{
Query: "select uid is not null from t1 where id = 1;",
Expected: []sql.Row{{"t"}},
},
},
},
})
Expand Down

0 comments on commit 078b10c

Please sign in to comment.