Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
137 changes: 137 additions & 0 deletions cmd/sync-tests/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
// Command sync-tests copies ClickHouse's stateless SQL tests into
// parser/testdata.
//
// Usage:
//
// go run ./cmd/sync-tests -src ~/ClickHouse/tests/queries/0_stateless
//
// For every <name>.sql in the source directory it writes
// parser/testdata/<name>/query.sql. New tests get an empty metadata.json.
// Existing tests whose query changed have their explain files removed and
// their explain_todo cleared, since statement numbers may have shifted. Tests that no longer exist upstream are
// left alone.
//
// Afterwards, regenerate the explain files and record the statements that
// don't pass yet:
//
// go run ./cmd/regenerate-explain
// go test ./parser/... -mark-todo
package main

import (
"bytes"
"encoding/json"
"flag"
"fmt"
"os"
"path/filepath"
"sort"
"strings"
)

func main() {
src := flag.String("src", "", "path to ClickHouse's tests/queries/0_stateless directory")
dst := flag.String("dst", "parser/testdata", "testdata directory to update")
newOnly := flag.Bool("new-only", false, "only add tests that don't exist yet")
flag.Parse()

if *src == "" {
fmt.Fprintln(os.Stderr, "-src is required")
os.Exit(2)
}

files, err := filepath.Glob(filepath.Join(*src, "*.sql"))
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
sort.Strings(files)

var added, updated, unchanged int
for _, f := range files {
name := strings.TrimSuffix(filepath.Base(f), ".sql")
query, err := os.ReadFile(f)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
dir := filepath.Join(*dst, name)
queryPath := filepath.Join(dir, "query.sql")
existing, err := os.ReadFile(queryPath)
switch {
case os.IsNotExist(err):
if err := os.MkdirAll(dir, 0o755); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if err := os.WriteFile(queryPath, query, 0o644); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if err := os.WriteFile(filepath.Join(dir, "metadata.json"), []byte("{}\n"), 0o644); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
added++
case err != nil:
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
case bytes.Equal(existing, query) || *newOnly:
unchanged++
default:
if err := os.WriteFile(queryPath, query, 0o644); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
if err := removeExplainFiles(dir); err != nil {
fmt.Fprintf(os.Stderr, "%s: %v\n", name, err)
os.Exit(1)
}
if err := clearExplainTodo(filepath.Join(dir, "metadata.json")); err != nil {
fmt.Fprintf(os.Stderr, "%s: %v\n", name, err)
os.Exit(1)
}
updated++
}
}
fmt.Printf("added %d, updated %d, unchanged %d\n", added, updated, unchanged)
}

// clearExplainTodo removes explain_todo from a metadata.json file, keeping
// every other key.
func clearExplainTodo(path string) error {
data, err := os.ReadFile(path)
if os.IsNotExist(err) {
return os.WriteFile(path, []byte("{}\n"), 0o644)
}
if err != nil {
return err
}
var m map[string]json.RawMessage
if err := json.Unmarshal(data, &m); err != nil {
return err
}
if _, ok := m["explain_todo"]; !ok {
return nil
}
delete(m, "explain_todo")
out, err := json.MarshalIndent(m, "", " ")
if err != nil {
return err
}
return os.WriteFile(path, append(out, '\n'), 0o644)
}

// removeExplainFiles deletes the explain*.txt files in a test directory.
func removeExplainFiles(dir string) error {
files, err := filepath.Glob(filepath.Join(dir, "explain*.txt"))
if err != nil {
return err
}
for _, f := range files {
if err := os.Remove(f); err != nil {
return err
}
}
return nil
}
5 changes: 5 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ func TestParser(t *testing.T) {
}
t.Skipf("Marked explain_todo[%s]: %s", stmtKey, fmt.Sprintf(format, args...))
}
defer func() {
if r := recover(); r != nil {
fail("panic: %v\nQuery: %s", r, stmt)
}
}()

// Determine explain file path: explain.txt for first, explain_N.txt for N >= 2
var explainPath string
Expand Down
2 changes: 1 addition & 1 deletion parser/testdata/00011_array_join_alias/query.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
SELECT x, a FROM (SELECT arrayJoin(['Hello', 'Goodbye']) AS x, [1, 2, 3] AS arr) ARRAY JOIN; -- { serverError NUMBER_OF_ARGUMENTS_DOESNT_MATCH }
SELECT x, a FROM (SELECT arrayJoin(['Hello', 'Goodbye']) AS x, [1, 2, 3] AS arr) ARRAY JOIN; -- { clientError SYNTAX_ERROR }
SELECT x, a FROM (SELECT arrayJoin(['Hello', 'Goodbye']) AS x, [1, 2, 3] AS arr) ARRAY JOIN arr AS a;
4 changes: 2 additions & 2 deletions parser/testdata/00024_random_counters/query.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- Tags: stateful, no-parallel
-- Tags: stateful, no-parallel, no-msan
-- no-parallel: Heavy
SELECT uniq(UserID), sum(Sign) FROM test.visits WHERE CounterID = 32152608;
SELECT uniq(UserID), sum(Sign) FROM test.visits WHERE CounterID = 9627212;
Expand Down Expand Up @@ -1001,7 +1001,7 @@ SELECT uniq(UserID), sum(Sign) FROM test.visits WHERE CounterID = 6308405;
SELECT uniq(UserID), sum(Sign) FROM test.visits WHERE CounterID = 20762370;
SELECT uniq(UserID), sum(Sign) FROM test.visits WHERE CounterID = 14121177;

SYSTEM DROP UNCOMPRESSED CACHE;
SYSTEM CLEAR UNCOMPRESSED CACHE;

SET local_filesystem_read_method = 'pread_threadpool';
SET min_bytes_to_use_direct_io = 1;
Expand Down
3 changes: 2 additions & 1 deletion parser/testdata/00061_storage_buffer/query.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
-- Tags: stateful
-- Tags: stateful, no-parallel
-- no-parallel: the synchronous OPTIMIZE buffer flush is slow under parallel CI load and can hit the 300s client receive_timeout.
DROP TABLE IF EXISTS hits_dst;
DROP TABLE IF EXISTS hits_buffer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
DescribeQuery (children 1)
TableExpression (children 1)
TableIdentifier replicated_alter2
ShowCreateTableQuery replicated_alter1 (children 1)
Identifier replicated_alter1
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ShowCreateTableQuery replicated_alter2 (children 1)
Identifier replicated_alter2
DescribeQuery (children 1)
TableExpression (children 1)
TableIdentifier replicated_alter2
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
SelectWithUnionQuery (children 1)
ExpressionList (children 1)
SelectQuery (children 3)
ExpressionList (children 1)
Asterisk
TablesInSelectQuery (children 1)
TablesInSelectQueryElement (children 1)
TableExpression (children 1)
TableIdentifier replicated_alter1
ExpressionList (children 1)
OrderByElement (children 1)
Identifier k
ShowCreateTableQuery replicated_alter2 (children 1)
Identifier replicated_alter2
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
AlterQuery replicated_alter1 (children 2)
SelectWithUnionQuery (children 1)
ExpressionList (children 1)
AlterCommand ADD_COLUMN (children 1)
ColumnDeclaration dt (children 1)
DataType DateTime (children 1)
ExpressionList (children 1)
Literal \'UTC\'
Identifier replicated_alter1
SelectQuery (children 3)
ExpressionList (children 1)
Asterisk
TablesInSelectQuery (children 1)
TablesInSelectQueryElement (children 1)
TableExpression (children 1)
TableIdentifier replicated_alter1
ExpressionList (children 1)
OrderByElement (children 1)
Identifier k
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
InsertQuery (children 1)
AlterQuery replicated_alter1 (children 2)
ExpressionList (children 1)
AlterCommand ADD_COLUMN (children 1)
ColumnDeclaration dt (children 1)
DataType DateTime (children 1)
ExpressionList (children 1)
Literal \'UTC\'
Identifier replicated_alter1
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
DescribeQuery (children 1)
TableExpression (children 1)
TableIdentifier replicated_alter1
InsertQuery (children 1)
Identifier replicated_alter1
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ShowCreateTableQuery replicated_alter1 (children 1)
Identifier replicated_alter1
DescribeQuery (children 1)
TableExpression (children 1)
TableIdentifier replicated_alter1
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
DescribeQuery (children 1)
TableExpression (children 1)
TableIdentifier replicated_alter2
ShowCreateTableQuery replicated_alter1 (children 1)
Identifier replicated_alter1
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ShowCreateTableQuery replicated_alter2 (children 1)
Identifier replicated_alter2
DescribeQuery (children 1)
TableExpression (children 1)
TableIdentifier replicated_alter2
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
SelectWithUnionQuery (children 1)
ExpressionList (children 1)
SelectQuery (children 3)
ExpressionList (children 1)
Asterisk
TablesInSelectQuery (children 1)
TablesInSelectQueryElement (children 1)
TableExpression (children 1)
TableIdentifier replicated_alter1
ExpressionList (children 1)
OrderByElement (children 1)
Identifier k
ShowCreateTableQuery replicated_alter2 (children 1)
Identifier replicated_alter2
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
AlterQuery replicated_alter1 (children 2)
SelectWithUnionQuery (children 1)
ExpressionList (children 1)
AlterCommand ADD_COLUMN (children 1)
ColumnDeclaration n (children 1)
DataType Nested (children 1)
ExpressionList (children 2)
NameTypePair ui8 (children 1)
DataType UInt8
NameTypePair s (children 1)
DataType String
Identifier replicated_alter1
SelectQuery (children 3)
ExpressionList (children 1)
Asterisk
TablesInSelectQuery (children 1)
TablesInSelectQueryElement (children 1)
TableExpression (children 1)
TableIdentifier replicated_alter1
ExpressionList (children 1)
OrderByElement (children 1)
Identifier k
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
InsertQuery (children 1)
AlterQuery replicated_alter1 (children 2)
ExpressionList (children 1)
AlterCommand ADD_COLUMN (children 1)
ColumnDeclaration n (children 1)
DataType Nested (children 1)
ExpressionList (children 2)
NameTypePair ui8 (children 1)
DataType UInt8
NameTypePair s (children 1)
DataType String
Identifier replicated_alter1
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
DescribeQuery (children 1)
TableExpression (children 1)
TableIdentifier replicated_alter1
InsertQuery (children 1)
Identifier replicated_alter1
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ShowCreateTableQuery replicated_alter1 (children 1)
Identifier replicated_alter1
DescribeQuery (children 1)
TableExpression (children 1)
TableIdentifier replicated_alter1
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
DescribeQuery (children 1)
TableExpression (children 1)
TableIdentifier replicated_alter2
ShowCreateTableQuery replicated_alter1 (children 1)
Identifier replicated_alter1
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ShowCreateTableQuery replicated_alter2 (children 1)
Identifier replicated_alter2
DescribeQuery (children 1)
TableExpression (children 1)
TableIdentifier replicated_alter2
Original file line number Diff line number Diff line change
@@ -1,12 +1,2 @@
SelectWithUnionQuery (children 1)
ExpressionList (children 1)
SelectQuery (children 3)
ExpressionList (children 1)
Asterisk
TablesInSelectQuery (children 1)
TablesInSelectQueryElement (children 1)
TableExpression (children 1)
TableIdentifier replicated_alter1
ExpressionList (children 1)
OrderByElement (children 1)
Identifier k
ShowCreateTableQuery replicated_alter2 (children 1)
Identifier replicated_alter2
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
AlterQuery replicated_alter1 (children 2)
SelectWithUnionQuery (children 1)
ExpressionList (children 1)
AlterCommand ADD_COLUMN (children 1)
ColumnDeclaration n.d (children 1)
DataType Array (children 1)
ExpressionList (children 1)
DataType Date
Identifier replicated_alter1
SelectQuery (children 3)
ExpressionList (children 1)
Asterisk
TablesInSelectQuery (children 1)
TablesInSelectQueryElement (children 1)
TableExpression (children 1)
TableIdentifier replicated_alter1
ExpressionList (children 1)
OrderByElement (children 1)
Identifier k
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
InsertQuery (children 1)
AlterQuery replicated_alter1 (children 2)
ExpressionList (children 1)
AlterCommand ADD_COLUMN (children 1)
ColumnDeclaration n.d (children 1)
DataType Array (children 1)
ExpressionList (children 1)
DataType Date
Identifier replicated_alter1
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
DescribeQuery (children 1)
TableExpression (children 1)
TableIdentifier replicated_alter1
InsertQuery (children 1)
Identifier replicated_alter1
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ShowCreateTableQuery replicated_alter1 (children 1)
Identifier replicated_alter1
DescribeQuery (children 1)
TableExpression (children 1)
TableIdentifier replicated_alter1
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
DescribeQuery (children 1)
TableExpression (children 1)
TableIdentifier replicated_alter2
ShowCreateTableQuery replicated_alter1 (children 1)
Identifier replicated_alter1
Loading
Loading