GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Why Go
  • Case Studies
  • Use Cases
  • Security
  • Learn
  • Effective Go
  • Go User Manual
  • Standard library
  • Release Notes
  • API
  • Packages
  • Recorded Talks
  • Meetups
  • Conferences

This view

  • Original page
  • New address

GeezerVison is showing pkg.go.dev — doubleclick module - github.com/sqlc-dev/doubleclick - Go Packages

Details

  • checked Valid go.mod file

    The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.

  • checked Redistributable license

    Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.

  • checked Tagged version

    Modules with tagged versions give importers more predictable builds.

  • checked Stable version

    When a project reaches major version v1 it is considered stable.

  • Learn more about best practices

Repository

github.com/sqlc-dev/doubleclick

Links

  • Open Source Insights Logo Open Source Insights

README ¶

doubleclick

Go Reference

A ClickHouse SQL parser written in Go. Parses ClickHouse SQL syntax into an Abstract Syntax Tree (AST) and generates EXPLAIN output matching ClickHouse's format.

Installation

go get github.com/sqlc-dev/doubleclick

Usage

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"strings"

	"github.com/sqlc-dev/doubleclick/parser"
)

func main() {
	sql := `SELECT id, name FROM users WHERE active = 1 ORDER BY created_at DESC LIMIT 10`

	stmts, err := parser.Parse(context.Background(), strings.NewReader(sql))
	if err != nil {
		panic(err)
	}

	// Serialize to JSON
	jsonBytes, _ := json.MarshalIndent(stmts[0], "", "  ")
	fmt.Println(string(jsonBytes))

	// Or print EXPLAIN AST output (matches ClickHouse format)
	fmt.Println(parser.Explain(stmts[0]))
}

JSON output:

{
  "selects": [
    {
      "columns": [
        { "parts": ["id"] },
        { "parts": ["name"] }
      ],
      "from": {
        "tables": [
          { "table": { "table": { "table": "users" } } }
        ]
      },
      "where": {
        "left": { "parts": ["active"] },
        "op": "=",
        "right": { "type": "Integer", "value": 1 }
      },
      "order_by": [
        {
          "expression": { "parts": ["created_at"] },
          "descending": true
        }
      ],
      "limit": { "type": "Integer", "value": 10 }
    }
  ]
}

EXPLAIN output:

SelectWithUnionQuery (children 1)
 ExpressionList (children 1)
  SelectQuery (children 4)
   ExpressionList (children 2)
    Identifier id
    Identifier name
   TablesInSelectQuery (children 1)
    TablesInSelectQueryElement (children 1)
     TableExpression (children 1)
      TableIdentifier (children 1)
       Identifier users
   Function equals (children 1)
    ExpressionList (children 2)
     Identifier active
     Literal UInt64_1
   ExpressionList (children 1)
    OrderByElement (children 1)
     Identifier created_at
   Literal UInt64_10

Features

  • Parses SELECT, INSERT, CREATE, DROP, ALTER, and other ClickHouse statements
  • Handles ClickHouse-specific syntax (Array types, PREWHERE, SAMPLE, etc.)
  • Supports JOINs, subqueries, CTEs, window functions, and complex expressions
  • Generates JSON-serializable AST nodes
  • Produces EXPLAIN AST output matching ClickHouse's format

Directories ¶

Path Synopsis
ast
Package ast defines the abstract syntax tree for ClickHouse SQL.
Package ast defines the abstract syntax tree for ClickHouse SQL.
cmd
next-test command
regenerate-explain command
internal
explain
Package explain provides EXPLAIN AST output functionality for ClickHouse SQL.
Package explain provides EXPLAIN AST output functionality for ClickHouse SQL.
lexer
Package lexer implements a lexer for ClickHouse SQL.
Package lexer implements a lexer for ClickHouse SQL.
parser
Package parser implements a parser for ClickHouse SQL.
Package parser implements a parser for ClickHouse SQL.
token
Package token defines constants representing the lexical tokens of ClickHouse SQL.
Package token defines constants representing the lexical tokens of ClickHouse SQL.
Click to show internal directories.
Click to hide internal directories.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.