Skip to content

Commit

Permalink
fix: RESET ALL is not supported yet
Browse files Browse the repository at this point in the history
  • Loading branch information
VWagen1989 committed Nov 27, 2024
1 parent 92d2b42 commit a7ea129
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 34 deletions.
13 changes: 11 additions & 2 deletions pgserver/connection_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ var showVariablesRegex = regexp.MustCompile(`(?i)^\s*SHOW\s+(ALL|[a-zA-Z_][a-zA-
var setStmtRegex = regexp.MustCompile(`(?i)^\s*SET\s+(SESSION|LOCAL)?\s*([a-zA-Z_][a-zA-Z0-9_]+)\s*(TO|=)\s*(DEFAULT|'([^']*)'|"([^"]*)"|[^'"\s;]+)\s*;?\s*$`)

// precompile a regex to match "RESET xxx;".
var resetStmtRegex = regexp.MustCompile(`(?i)^\s*RESET\s+([a-zA-Z_][a-zA-Z0-9_]+)\s*;?\s*$`)
var resetStmtRegex = regexp.MustCompile(`(?i)^\s*RESET\s+(ALL|[a-zA-Z_][a-zA-Z0-9_]+)\s*;?\s*$`)

// precompile a regex to match any "from pg_catalog.xxx" in the query.
var pgCatalogRegex = regexp.MustCompile(`(?i)\s+from\s+pg_catalog\.`)
Expand Down Expand Up @@ -764,7 +764,16 @@ var pgCatalogHandlers = map[*regexp.Regexp]PGCatalogHandler{
// This is a configuration of DuckDB, it should be bypassed to DuckDB
return false, nil
}
return h.setPgSessionVar(key, nil, true, "RESET")
if key != "all" {
return h.setPgSessionVar(key, nil, true, "RESET")
}
// TODO(sean): Implement RESET ALL
_ = h.send(&pgproto3.ErrorResponse{
Severity: string(ErrorResponseSeverity_Error),
Code: "0A000",
Message: "Statement 'RESET ALL' is not supported yet.",
})
return true, nil
},
},
pgCatalogRegex: {
Expand Down
75 changes: 43 additions & 32 deletions pgserver/sess_params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,25 +173,25 @@ func TestSessParam(t *testing.T) {
executions: []Execution{
// Set the application_name to 'myDUCK'
{
SQL: "SET application_name TO 'myDUCK';",
SQL: " \t\r\nSET application_name TO 'myDUCK'; \t\r\n",
Expected: nil,
WantErr: false,
},
// Get the value of application_name, it should be 'myDUCK'
{
SQL: "SELECT CURRENT_SETTING('application_name');",
SQL: " \t\r\nSELECT CURRENT_SETTING('application_name'); \t\r\n",
Expected: [][]string{{"myDUCK"}},
WantErr: false,
},
// Set the application_name to "MYduck"
{
SQL: "SET application_NAME TO \"MYduck\";",
SQL: " \t\r\nSET application_NAME TO \"MYduck\"; \t\r\n",
Expected: nil,
WantErr: false,
},
// Get the value of application_name, it should be 'MYduck'
{
SQL: "SELECT CURRENT_SETTING('application_name');",
SQL: " \t\r\nSELECT CURRENT_SETTING('application_name'); \t\r\n",
Expected: [][]string{{"MYduck"}},
WantErr: false,
},
Expand All @@ -202,25 +202,25 @@ func TestSessParam(t *testing.T) {
executions: []Execution{
// Set the application_name to 'myDUCK'
{
SQL: "SET application_name TO 'myDUCK';",
SQL: " \t\r\nSET application_name TO 'myDUCK'; \t\r\n",
Expected: nil,
WantErr: false,
},
// Get the value of application_name, it should be 'myDUCK'
{
SQL: "SELECT CURRENT_SETTING('application_name');",
SQL: " \t\r\nSELECT CURRENT_SETTING('application_name'); \t\r\n",
Expected: [][]string{{"myDUCK"}},
WantErr: false,
},
// Set the application_name to 'default'
{
SQL: "SET application_NAME TO 'default';",
SQL: " \t\r\nSET application_NAME TO 'default'; \t\r\n",
Expected: nil,
WantErr: false,
},
// Get the value of application_name, it should be 'default'
{
SQL: "SELECT CURRENT_SETTING('application_name');",
SQL: " \t\r\nSELECT CURRENT_SETTING('application_name'); \t\r\n",
Expected: [][]string{{"default"}},
WantErr: false,
},
Expand All @@ -231,25 +231,25 @@ func TestSessParam(t *testing.T) {
executions: []Execution{
// Set the application_name to myDUCK
{
SQL: "SET application_name TO myDUCK;",
SQL: " \t\r\nSET application_name TO myDUCK; \t\r\n",
Expected: nil,
WantErr: false,
},
// Get the value of application_name, it should be 'myDUCK'
{
SQL: "SELECT CURRENT_SETTING('application_name');",
SQL: " \t\r\nSELECT CURRENT_SETTING('application_name'); \t\r\n",
Expected: [][]string{{"myDUCK"}},
WantErr: false,
},
// Set the application_name to default
{
SQL: "SET application_NAME TO default;",
SQL: " \t\r\nSET application_NAME TO default; \t\r\n",
Expected: nil,
WantErr: false,
},
// Get the value of application_name, it should be default value 'psql'
{
SQL: "SELECT CURRENT_SETTING('application_name');",
SQL: " \t\r\nSELECT CURRENT_SETTING('application_name'); \t\r\n",
Expected: [][]string{{"psql"}},
WantErr: false,
},
Expand All @@ -262,25 +262,25 @@ func TestSessParam(t *testing.T) {
executions: []Execution{
// Set the application_name to 'myDUCK'
{
SQL: "SET http_proxy_username TO 'myDUCK';",
SQL: " \t\r\nSET http_proxy_username TO 'myDUCK'; \t\r\n",
Expected: nil,
WantErr: false,
},
// Get the value of http_proxy_username, it should be 'myDUCK'
{
SQL: "SELECT CURRENT_SETTING('http_proxy_username');",
SQL: " \t\r\nSELECT CURRENT_SETTING('http_proxy_username'); \t\r\n",
Expected: [][]string{{"myDUCK"}},
WantErr: false,
},
// Set the application_name to "MYduck"
{
SQL: "SET http_proxy_USERNAME TO \"MYduck\";",
SQL: " \t\r\nSET http_proxy_USERNAME TO \"MYduck\"; \t\r\n",
Expected: nil,
WantErr: false,
},
// Get the value of http_proxy_username, it should be 'myDUCK'
{
SQL: "SELECT CURRENT_SETTING('http_proxy_username');",
SQL: " \t\r\nSELECT CURRENT_SETTING('http_proxy_username'); \t\r\n",
Expected: [][]string{{"MYduck"}},
WantErr: false,
},
Expand All @@ -291,25 +291,25 @@ func TestSessParam(t *testing.T) {
executions: []Execution{
// Set the application_name to myDUCK
{
SQL: "SET http_proxy_username TO myDUCK;",
SQL: " \t\r\nSET http_proxy_username TO myDUCK; \t\r\n",
Expected: nil,
WantErr: false,
},
// Get the value of http_proxy_username, it should be 'myDUCK'
{
SQL: "SELECT CURRENT_SETTING('http_proxy_username');",
SQL: " \t\r\nSELECT CURRENT_SETTING('http_proxy_username'); \t\r\n",
Expected: [][]string{{"myDUCK"}},
WantErr: false,
},
// Set the application_name to 'default'
{
SQL: "SET http_proxy_USERNAME TO 'default';",
SQL: " \t\r\nSET http_proxy_USERNAME TO 'default'; \t\r\n",
Expected: nil,
WantErr: false,
},
// Get the value of http_proxy_username, it should be 'default'
{
SQL: "SELECT CURRENT_SETTING('http_proxy_username');",
SQL: " \t\r\nSELECT CURRENT_SETTING('http_proxy_username'); \t\r\n",
Expected: [][]string{{"default"}},
WantErr: false,
},
Expand All @@ -320,25 +320,25 @@ func TestSessParam(t *testing.T) {
executions: []Execution{
// Set the application_name to myDUCK
{
SQL: "SET http_proxy_username TO myDUCK;",
SQL: " \t\r\nSET http_proxy_username TO myDUCK; \t\r\n",
Expected: nil,
WantErr: false,
},
// Get the value of http_proxy_username, it should be 'myDUCK'
{
SQL: "SELECT CURRENT_SETTING('http_proxy_username');",
SQL: " \t\r\nSELECT CURRENT_SETTING('http_proxy_username'); \t\r\n",
Expected: [][]string{{"myDUCK"}},
WantErr: false,
},
// Set the application_name to default
{
SQL: "SET http_proxy_USERNAME TO default;",
SQL: " \t\r\nSET http_proxy_USERNAME TO default; \t\r\n",
Expected: nil,
WantErr: false,
},
// Get the value of http_proxy_username, it should be ''
{
SQL: "SELECT CURRENT_SETTING('http_proxy_username');",
SQL: " \t\r\nSELECT CURRENT_SETTING('http_proxy_username'); \t\r\n",
Expected: [][]string{{"<nil>"}},
WantErr: false,
},
Expand All @@ -351,25 +351,25 @@ func TestSessParam(t *testing.T) {
executions: []Execution{
// Set the application_name to myDUCK
{
SQL: "SET application_name TO myDUCK;",
SQL: " \t\r\nSET application_name TO myDUCK; \t\r\n",
Expected: nil,
WantErr: false,
},
// Get the value of application_name, it should be 'myDUCK'
{
SQL: "SELECT CURRENT_SETTING('application_name');",
SQL: " \t\r\nSELECT CURRENT_SETTING('application_name'); \t\r\n",
Expected: [][]string{{"myDUCK"}},
WantErr: false,
},
// Reset the application_name to default
{
SQL: "reSET application_NAME;",
SQL: " \t\r\nreSET application_NAME; \t\r\n",
Expected: nil,
WantErr: false,
},
// Get the value of application_name, it should be default value 'psql'
{
SQL: "SELECT CURRENT_SETTING('application_name');",
SQL: " \t\r\nSELECT CURRENT_SETTING('application_name'); \t\r\n",
Expected: [][]string{{"psql"}},
WantErr: false,
},
Expand All @@ -382,30 +382,41 @@ func TestSessParam(t *testing.T) {
executions: []Execution{
// Set the application_name to myDUCK
{
SQL: "SET http_proxy_username TO myDUCK;",
SQL: " \t\r\nSET http_proxy_username TO myDUCK; \t\r\n",
Expected: nil,
WantErr: false,
},
// Get the value of http_proxy_username, it should be 'myDUCK'
{
SQL: "SELECT CURRENT_SETTING('http_proxy_username');",
SQL: " \t\r\nSELECT CURRENT_SETTING('http_proxy_username'); \t\r\n",
Expected: [][]string{{"myDUCK"}},
WantErr: false,
},
// Reset the application_name to default
{
SQL: "reSET http_proxy_USERNAME;",
SQL: " \t\r\nreSET http_proxy_USERNAME; \t\r\n",
Expected: nil,
WantErr: false,
},
// Get the value of http_proxy_username, it should be ''
{
SQL: "SELECT CURRENT_SETTING('http_proxy_username');",
SQL: " \t\r\nSELECT CURRENT_SETTING('http_proxy_username'); \t\r\n",
Expected: [][]string{{"<nil>"}},
WantErr: false,
},
},
},
{
name: "Reset ALL",
executions: []Execution{
{
// RESET ALL is not supported yet.
SQL: "RESET ALL;",
Expected: nil,
WantErr: true,
},
},
},
}

// Setup MyDuck Server
Expand Down

0 comments on commit a7ea129

Please sign in to comment.