Skip to content

Commit

Permalink
PR Feedback & Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Hydrocharged committed Nov 29, 2023
1 parent 52cfaf5 commit 9e82020
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 47 deletions.
8 changes: 4 additions & 4 deletions 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")
}

typeParams, err := nodeResolvableTypeReference(node.Type)
convertType, err := nodeResolvableTypeReference(node.Type)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -104,13 +104,13 @@ func nodeColumnTableDef(node *tree.ColumnTableDef) (_ *vitess.ColumnDefinition,
return &vitess.ColumnDefinition{
Name: vitess.NewColIdent(string(node.Name)),
Type: vitess.ColumnType{
Type: typeParams.name,
Type: convertType.Type,
Null: isNull,
NotNull: isNotNull,
Autoincrement: vitess.BoolVal(node.IsSerial),
Default: defaultExpr,
Length: typeParams.length,
Scale: typeParams.scale,
Length: convertType.Length,
Scale: convertType.Scale,
KeyOpt: keyOpt,
ForeignKeyDef: fkDef,
GeneratedExpr: generated,
Expand Down
9 changes: 2 additions & 7 deletions server/ast/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,15 @@ func nodeExpr(node tree.Expr) (vitess.Expr, error) {
return nil, fmt.Errorf("unknown cast syntax")
}

params, err := nodeResolvableTypeReference(node.Type)
convertType, err := nodeResolvableTypeReference(node.Type)
if err != nil {
return nil, err
}

return &vitess.ConvertExpr{
Name: "CAST",
Expr: expr,
Type: &vitess.ConvertType{
Type: params.name,
Length: params.length,
Scale: params.scale,
Charset: "", // TODO
},
Type: convertType,
}, nil
case *tree.CoalesceExpr:
return nil, fmt.Errorf("COALESCE is not yet supported")
Expand Down
18 changes: 7 additions & 11 deletions server/ast/resolvable_type_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,8 @@ import (
"github.com/dolthub/doltgresql/postgres/parser/types"
)

type typeParams struct {
name string
length *vitess.SQLVal
scale *vitess.SQLVal
}

func nodeResolvableTypeReference(typ tree.ResolvableTypeReference) (*typeParams, error) {
// nodeResolvableTypeReference handles tree.ResolvableTypeReference nodes.
func nodeResolvableTypeReference(typ tree.ResolvableTypeReference) (*vitess.ConvertType, error) {
if typ == nil {
return nil, nil
}
Expand Down Expand Up @@ -62,9 +57,10 @@ func nodeResolvableTypeReference(typ tree.ResolvableTypeReference) (*typeParams,
}
}

return &typeParams{
name: columnTypeName,
length: columnTypeLength,
scale: columnTypeScale,
return &vitess.ConvertType{
Type: columnTypeName,
Length: columnTypeLength,
Scale: columnTypeScale,
Charset: "", // TODO
}, nil
}
54 changes: 29 additions & 25 deletions testing/generation/command_docs/create_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,33 @@ import (
"github.com/dolthub/doltgresql/server/ast"
)

const TestHeader = `// Copyright %d Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package output
import "testing"
func Test%s(t *testing.T) {
tests := []QueryParses{
`

const TestFooter = ` }
RunTests(t, tests)
}
`

// GenerateTestsFromSynopses generates a test file in the output directory for each file in the synopses directory.
func GenerateTestsFromSynopses() (err error) {
parentFolder, err := GetCommandDocsFolder()
Expand Down Expand Up @@ -93,27 +120,7 @@ FileLoop:
continue FileLoop
}
sb := strings.Builder{}
sb.WriteString(fmt.Sprintf(`// Copyright %d Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package output
import "testing"
func Test%s(t *testing.T) {
tests := []QueryParses{
`, time.Now().Year(), strings.ReplaceAll(strings.Title(strings.ToLower(prefix)), " ", "")))
sb.WriteString(fmt.Sprintf(TestHeader, time.Now().Year(), strings.ReplaceAll(strings.Title(strings.ToLower(prefix)), " ", "")))

result, nErr := GetQueryResult(stmtGen.String())
if nErr != nil {
Expand All @@ -130,10 +137,7 @@ func Test%s(t *testing.T) {
sb.WriteString(result)
}

sb.WriteString(` }
RunTests(t, tests)
}
`)
sb.WriteString(TestFooter)
outputFileName := strings.ToLower(strings.ReplaceAll(prefix, " ", "_"))
if nErr = os.WriteFile(fmt.Sprintf("%s/output/%s_test.go", parentFolder, outputFileName), []byte(sb.String()), 0644); nErr != nil {
err = errors.Join(err, nErr)
Expand Down

0 comments on commit 9e82020

Please sign in to comment.