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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ func (l *Lexer) NextToken() Item {
if l.ch == '-' && l.peekChar() == '-' {
return l.readLineComment()
}
if l.ch == '#' {
return l.readHashComment()
}
if l.ch == '/' && l.peekChar() == '*' {
return l.readBlockComment()
}
Expand Down Expand Up @@ -280,6 +283,20 @@ func (l *Lexer) readLineComment() Item {
return Item{Token: token.COMMENT, Value: sb.String(), Pos: pos}
}

func (l *Lexer) readHashComment() Item {
pos := l.pos
var sb strings.Builder
// Skip #
sb.WriteRune(l.ch)
l.readChar()

for l.ch != '\n' && l.ch != 0 && !l.eof {
sb.WriteRune(l.ch)
l.readChar()
}
return Item{Token: token.COMMENT, Value: sb.String(), Pos: pos}
}

func (l *Lexer) readBlockComment() Item {
pos := l.pos
var sb strings.Builder
Expand Down
7 changes: 7 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3098,6 +3098,13 @@ func (p *Parser) parseIdentifierName() string {
return name
}

// Handle parameterized identifiers like {CLICKHOUSE_DATABASE:Identifier}
if p.currentIs(token.PARAM) {
name = "{" + p.current.Value + "}"
p.nextToken()
return name
}

// Handle name starting with number (e.g., 03657_test)
if p.currentIs(token.NUMBER) {
name = p.current.Value
Expand Down
2 changes: 1 addition & 1 deletion parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestParser(t *testing.T) {
var queryParts []string
for _, line := range strings.Split(string(queryBytes), "\n") {
trimmed := strings.TrimSpace(line)
if trimmed == "" || strings.HasPrefix(trimmed, "--") {
if trimmed == "" || strings.HasPrefix(trimmed, "--") || strings.HasPrefix(trimmed, "#") {
continue
}
// Remove trailing comment if present (but not inside strings - simple heuristic)
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
2 changes: 1 addition & 1 deletion parser/testdata/01012_show_tables_limit/metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
2 changes: 1 addition & 1 deletion parser/testdata/01084_regexp_empty/metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
2 changes: 1 addition & 1 deletion parser/testdata/01881_negate_formatting/metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"todo": true}
{}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
2 changes: 1 addition & 1 deletion parser/testdata/02192_comment/metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
2 changes: 1 addition & 1 deletion parser/testdata/02233_interpolate_1/metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
2 changes: 1 addition & 1 deletion parser/testdata/02294_system_certificates/metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
2 changes: 1 addition & 1 deletion parser/testdata/02462_distributions/metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
2 changes: 1 addition & 1 deletion parser/testdata/02808_aliases_inside_case/metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
2 changes: 1 addition & 1 deletion parser/testdata/03442_detach_view/metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
2 changes: 1 addition & 1 deletion parser/testdata/03524_sign_argument/metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
2 changes: 1 addition & 1 deletion parser/testdata/03546_leftover_dependencies/metadata.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"explain":false,"todo": true}
{"explain":false}
55 changes: 52 additions & 3 deletions scripts/clickhouse.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,30 @@ CLICKHOUSE_DIR="$PROJECT_DIR/.clickhouse"
CONFIG_FILE="$CLICKHOUSE_DIR/config.xml"
PID_FILE="$CLICKHOUSE_DIR/clickhouse.pid"

# ClickHouse version - use a specific stable version for reproducible test output
# Update this when regenerating test expectations
CLICKHOUSE_VERSION="${CLICKHOUSE_VERSION:-24.8.4.13}"

# Download ClickHouse if not present
download() {
if [ -f "$CLICKHOUSE_BIN" ]; then
echo "ClickHouse binary already exists"
"$CLICKHOUSE_BIN" --version
return 0
fi

echo "Downloading ClickHouse..."
curl -k -L -o "$CLICKHOUSE_BIN" https://builds.clickhouse.com/master/amd64/clickhouse
echo "Downloading ClickHouse v$CLICKHOUSE_VERSION..."

# Use stable release URL format
DOWNLOAD_URL="https://github.com/ClickHouse/ClickHouse/releases/download/v${CLICKHOUSE_VERSION}-stable/clickhouse-linux-amd64"

if ! curl -k -L -f -o "$CLICKHOUSE_BIN" "$DOWNLOAD_URL"; then
echo "Failed to download from releases, trying builds.clickhouse.com..."
# Fallback to builds server with version tag
DOWNLOAD_URL="https://builds.clickhouse.com/master/amd64/clickhouse"
curl -k -L -o "$CLICKHOUSE_BIN" "$DOWNLOAD_URL"
fi

chmod +x "$CLICKHOUSE_BIN"
echo "Downloaded ClickHouse"
"$CLICKHOUSE_BIN" --version
Expand Down Expand Up @@ -150,10 +165,34 @@ client() {
"$CLICKHOUSE_BIN" client "$@"
}

# Force download (remove existing binary first)
force_download() {
if [ -f "$CLICKHOUSE_BIN" ]; then
echo "Removing existing ClickHouse binary..."
rm -f "$CLICKHOUSE_BIN"
fi
download
}

# Show version info
version() {
echo "Configured version: $CLICKHOUSE_VERSION"
echo "Override with: CLICKHOUSE_VERSION=X.Y.Z.W $0 download"
if [ -f "$CLICKHOUSE_BIN" ]; then
echo "Installed:"
"$CLICKHOUSE_BIN" --version
else
echo "Binary not installed yet"
fi
}

case "$1" in
download)
download
;;
force-download)
force_download
;;
init)
init
;;
Expand All @@ -170,12 +209,22 @@ case "$1" in
status)
status
;;
version)
version
;;
client)
shift
client "$@"
;;
*)
echo "Usage: $0 {download|init|start|stop|restart|status|client}"
echo "Usage: $0 {download|force-download|init|start|stop|restart|status|version|client}"
echo ""
echo "Environment variables:"
echo " CLICKHOUSE_VERSION - Override the ClickHouse version (default: $CLICKHOUSE_VERSION)"
echo ""
echo "Examples:"
echo " $0 download # Download default version"
echo " CLICKHOUSE_VERSION=24.3.1.5 $0 force-download # Download specific version"
exit 1
;;
esac