diff --git a/node/engine/parse/parse_test.go b/node/engine/parse/parse_test.go index 89d706e42..c5cd4ff45 100644 --- a/node/engine/parse/parse_test.go +++ b/node/engine/parse/parse_test.go @@ -14,7 +14,7 @@ func assertPositionsAreSet(t *testing.T, v any) { RecursivelyVisitPositions(v, func(gp GetPositioner) { pos := gp.GetPosition() // if not set, this will tell us the struct - assert.True(t, pos.IsSet, "position is not set. struct type: %T", gp) + assert.True(t, pos.isSet, "position is not set. struct type: %T", gp) }) } diff --git a/node/engine/parse/postgres/doc.go b/node/engine/parse/postgres/doc.go deleted file mode 100644 index a8baf50f2..000000000 --- a/node/engine/parse/postgres/doc.go +++ /dev/null @@ -1,19 +0,0 @@ -/* -Package postgres provides a CheckSyntax function wraps the parser for the -PostgreSQL dialect of SQL, which will return an error if the query is not -syntactically valid. - -This package includes a default implementation of CheckSyntax that does nothing, -and a cgo implementation that uses the pg_query_go library to check the syntax -of the query. - -This cgo implementation is only built when the CGO_ENABLED=1. -By doing this, we keep pg_query_go as a cgo dependency, which is not required in -the default build. - -pg_query_go is a cgo wrapper around the libpg_query C library, which is used in -kwil-db to simply check the syntax of SQL queries we generated. - -TO run tests using pg_query_go, run `CGO_ENABLED=1 go test ./...` -*/ -package postgres diff --git a/node/engine/parse/postgres/parse.go b/node/engine/parse/postgres/parse.go deleted file mode 100644 index 29f66c206..000000000 --- a/node/engine/parse/postgres/parse.go +++ /dev/null @@ -1,25 +0,0 @@ -package postgres - -import ( - "regexp" -) - -type CheckSyntaxFunc func(query string) error - -var CheckSyntax CheckSyntaxFunc = doNothing - -// doNothing is a placeholder for the CheckSyntaxFunc when cgo is disabled. -func doNothing(_ string) error { - return nil -} - -// CheckSyntaxReplaceDollar replaces all bind parameters($x) with 1 to bypass -// syntax check errors. -// () method doesn't convert bind parameters to $1, $2, etc. so we need to -// replace them manually, just so we can do the syntax check. -func CheckSyntaxReplaceDollar(query string) error { - // Replace all bind parameters($x) with 1 to bypass syntax check errors - re := regexp.MustCompile(`\$([a-zA-Z_])+`) - sql := re.ReplaceAllString(query, "1") - return CheckSyntax(sql) -} diff --git a/node/engine/parse/postgres/parse_cgo.go b/node/engine/parse/postgres/parse_cgo.go deleted file mode 100644 index 8a4338d3e..000000000 --- a/node/engine/parse/postgres/parse_cgo.go +++ /dev/null @@ -1,22 +0,0 @@ -//go:build cgo - -package postgres - -import ( - "fmt" - - pg_query "github.com/pganalyze/pg_query_go/v5" -) - -func init() { - // package-level variable is initialized before init() is called - CheckSyntax = checkSyntaxCgo -} - -func checkSyntaxCgo(query string) error { - if query == "select 'printme';" { - fmt.Println("Checking postgres syntax with pg_query_go") - } - _, err := pg_query.Parse(query) - return err -} diff --git a/node/engine/parse/postgres/parse_test.go b/node/engine/parse/postgres/parse_test.go deleted file mode 100644 index 6076f4254..000000000 --- a/node/engine/parse/postgres/parse_test.go +++ /dev/null @@ -1,12 +0,0 @@ -package postgres_test - -import ( - "testing" - - "github.com/kwilteam/kwil-db/node/engine/parse/postgres" - "github.com/stretchr/testify/assert" -) - -func TestCheckSyntax(t *testing.T) { - assert.NoError(t, postgres.CheckSyntax("select 'printme';")) -} diff --git a/node/engine/parse/types.go b/node/engine/parse/types.go index 771e90b5d..2d0feedbb 100644 --- a/node/engine/parse/types.go +++ b/node/engine/parse/types.go @@ -9,16 +9,16 @@ import ( type Position struct { // Set is true if the position of the Position has been set. // This is useful for testing parsers. - IsSet bool `json:"-"` - StartLine int `json:"start_line"` - StartCol int `json:"start_col"` - EndLine int `json:"end_line"` - EndCol int `json:"end_col"` + isSet bool + StartLine int `json:"start_line"` + StartCol int `json:"start_col"` + EndLine int `json:"end_line"` + EndCol int `json:"end_col"` } // Set sets the position of the Position based on the given parser rule context. func (n *Position) Set(r antlr.ParserRuleContext) { - n.IsSet = true + n.isSet = true n.StartLine = r.GetStart().GetLine() n.StartCol = r.GetStart().GetColumn() n.EndLine = r.GetStop().GetLine() @@ -27,7 +27,7 @@ func (n *Position) Set(r antlr.ParserRuleContext) { // SetToken sets the position of the Position based on the given token. func (n *Position) SetToken(t antlr.Token) { - n.IsSet = true + n.isSet = true n.StartLine = t.GetLine() n.StartCol = t.GetColumn() n.EndLine = t.GetLine() @@ -42,7 +42,7 @@ func (n *Position) GetPosition() *Position { // Clear clears the position of the Position. func (n *Position) Clear() { - n.IsSet = false + n.isSet = false n.StartLine = 0 n.StartCol = 0 n.EndLine = 0