-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #596 from dolthub/zachmu/discard
Implemented DISCARD
- Loading branch information
Showing
5 changed files
with
174 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package node | ||
|
||
import ( | ||
"github.com/dolthub/go-mysql-server/sql" | ||
"github.com/dolthub/vitess/go/vt/sqlparser" | ||
) | ||
|
||
// DiscardStatement is just a marker type, since all functionality is handled by the connection handler, | ||
// rather than the engine. It has to conform to the sql.ExecSourceRel interface to be used in the handler, but this | ||
// functionality is all unused. | ||
type DiscardStatement struct{} | ||
|
||
var _ sqlparser.Injectable = DiscardStatement{} | ||
var _ sql.ExecSourceRel = DiscardStatement{} | ||
|
||
func (d DiscardStatement) Resolved() bool { | ||
return true | ||
} | ||
|
||
func (d DiscardStatement) String() string { | ||
return "DISCARD ALL" | ||
} | ||
|
||
func (d DiscardStatement) Schema() sql.Schema { | ||
return nil | ||
} | ||
|
||
func (d DiscardStatement) Children() []sql.Node { | ||
return nil | ||
} | ||
|
||
func (d DiscardStatement) WithChildren(children ...sql.Node) (sql.Node, error) { | ||
return d, nil | ||
} | ||
|
||
func (d DiscardStatement) CheckPrivileges(ctx *sql.Context, opChecker sql.PrivilegedOperationChecker) bool { | ||
return true | ||
} | ||
|
||
func (d DiscardStatement) IsReadOnly() bool { | ||
return true | ||
} | ||
|
||
func (d DiscardStatement) RowIter(ctx *sql.Context, r sql.Row) (sql.RowIter, error) { | ||
panic("DISCARD ALL should be handled by the connection handler") | ||
} | ||
|
||
func (d DiscardStatement) WithResolvedChildren(children []any) (any, error) { | ||
return d, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package _go | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/dolthub/go-mysql-server/sql" | ||
) | ||
|
||
func TestDiscard(t *testing.T) { | ||
RunScripts(t, []ScriptTest{ | ||
{ | ||
Name: "Test discard", | ||
SetUpScript: []string{ | ||
`CREATE temporary TABLE test (a INT)`, | ||
`insert into test values (1)`, | ||
}, | ||
Assertions: []ScriptTestAssertion{ | ||
{ | ||
Query: "select * from test", | ||
Expected: []sql.Row{ | ||
{1}, | ||
}, | ||
}, | ||
{ | ||
Query: "DISCARD ALL", | ||
Expected: []sql.Row{}, | ||
}, | ||
{ | ||
Query: "select * from test", | ||
ExpectedErr: "table not found", | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "Test discard errors", | ||
SetUpScript: []string{ | ||
`CREATE temporary TABLE test (a INT)`, | ||
`insert into test values (1)`, | ||
}, | ||
Assertions: []ScriptTestAssertion{ | ||
{ | ||
Query: "DISCARD SEQUENCES", | ||
ExpectedErr: "unimplemented", | ||
}, | ||
{ | ||
Query: "select * from test", | ||
Expected: []sql.Row{ | ||
{1}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Name: "Test discard in transaction", | ||
SetUpScript: []string{ | ||
`CREATE temporary TABLE test (a INT)`, | ||
`insert into test values (1)`, | ||
}, | ||
Assertions: []ScriptTestAssertion{ | ||
{ | ||
Query: "BEGIN", | ||
}, | ||
{ | ||
Query: "DISCARD ALL", | ||
ExpectedErr: "DISCARD ALL cannot run inside a transaction block", | ||
Skip: true, // not yet implemented | ||
}, | ||
}, | ||
}, | ||
}) | ||
} |