Skip to content

Commit

Permalink
Merge pull request #131 from dolthub/fulghum/table-function-support
Browse files Browse the repository at this point in the history
Table function support
  • Loading branch information
fulghum authored Mar 15, 2022
2 parents a2f7a61 + 2f8a994 commit 0bb5262
Show file tree
Hide file tree
Showing 5 changed files with 3,081 additions and 3,003 deletions.
46 changes: 46 additions & 0 deletions go/vt/sqlparser/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -3102,6 +3102,7 @@ func (*ParenTableExpr) iTableExpr() {}
func (*JoinTableExpr) iTableExpr() {}
func (*CommonTableExpr) iTableExpr() {}
func (*ValuesStatement) iTableExpr() {}
func (TableFuncExpr) iTableExpr() {}

// AliasedTableExpr represents a table expression
// coupled with an optional alias, AS OF expression, and index hints.
Expand Down Expand Up @@ -5466,6 +5467,51 @@ func (node *ColIdent) UnmarshalJSON(b []byte) error {
return nil
}

type TableFuncExpr struct {
Name string
Exprs SelectExprs
}

// Format formats the node.
func (node TableFuncExpr) Format(buf *TrackedBuffer) {
buf.Myprintf("%s(%v)", node.Name, node.Exprs)
}

// IsEmpty returns true if TableFuncExpr's name is empty.
func (node TableFuncExpr) IsEmpty() bool {
return node.Name == ""
}

// String returns the unescaped table function name. It must
// not be used for SQL generation. Use sqlparser.String
// instead. The Stringer conformance is for usage
// in templates.
func (node TableFuncExpr) String() string {
return node.Name
}

// CompliantName returns a compliant id name
// that can be used for a bind var.
func (node TableFuncExpr) CompliantName() string {
return compliantName(node.Name)
}

// MarshalJSON marshals into JSON.
func (node TableFuncExpr) MarshalJSON() ([]byte, error) {
return json.Marshal(node.Name)
}

// UnmarshalJSON unmarshals from JSON.
func (node *TableFuncExpr) UnmarshalJSON(b []byte) error {
var result string
err := json.Unmarshal(b, &result)
if err != nil {
return err
}
node.Name = result
return nil
}

// TableIdent is a case sensitive SQL identifier. It will be escaped with
// backquotes if necessary.
type TableIdent struct {
Expand Down
12 changes: 12 additions & 0 deletions go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ type parseTest struct {

var (
validSQL = []parseTest{
{
input: "select * from my_table_function()",
output: "select * from my_table_function()",
},
{
input: "select * from my_table_function('foo')",
output: "select * from my_table_function('foo')",
},
{
input: "select * from my_table_function('foo', 'bar')",
output: "select * from my_table_function('foo', 'bar')",
},
{
input: "select 1",
output: "select 1 from dual",
Expand Down
Loading

0 comments on commit 0bb5262

Please sign in to comment.