Skip to content

P2: ClickHouse SAMPLE clause parsing #454

@ajitpratap0

Description

@ajitpratap0

Problem

ClickHouse's SAMPLE clause (for approximate query processing on large datasets) is marked as TODO in the test suite and not implemented. This is the last significant gap in ClickHouse dialect support added in v1.13.0.

// clickhouse_test.go:88
// TODO: SAMPLE clause parsing not yet implemented

Syntax to Support

-- Sample by ratio
SELECT count() FROM hits SAMPLE 0.1

-- Sample absolute rows
SELECT count() FROM hits SAMPLE 10000

-- Sample with offset
SELECT count() FROM hits SAMPLE 1/3 OFFSET 2/3

-- ARRAY JOIN with SAMPLE
SELECT col FROM table SAMPLE 0.5 ARRAY JOIN arr

AST Changes

type SampleClause struct {
    Ratio  *LiteralValue   // 0.1 or 1/3 form
    Offset *LiteralValue   // OFFSET form (optional)
    IsRows bool            // SAMPLE 10000 ROWS form
}

// Add to SelectStatement (ClickHouse dialect only)
type SelectStatement struct {
    // ...existing fields...
    Sample *SampleClause  // ClickHouse SAMPLE clause
}

Acceptance Criteria

  • SAMPLE ratio parsed (float literal: 0.1, 0.5)
  • SAMPLE n/d parsed (fraction form: 1/3, 2/3)
  • SAMPLE n ROWS parsed (absolute row count)
  • SAMPLE ratio OFFSET offset parsed
  • Only active in ClickHouse dialect mode
  • Formatter renders SAMPLE clause correctly
  • Remove TODO comment from clickhouse_test.go
  • 15+ test cases covering all SAMPLE forms
  • docs/SQL_COMPATIBILITY.md ClickHouse section updated

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium priorityenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions