clauses.go
clauses.go - Overview
-
Overview This file provides helper functions for generating SQL clauses such as
GROUP BY
,ORDER BY
, andSELECT
statements, specifically tailored for ClickHouse queries related to metrics. -
Detailed Documentation
groupingSets(tags ...string) string
- Purpose: Creates a comma-separated string of tags, always including "ts" for use in
GROUP BY
clauses. - Parameters:
tags
: ...string - A variable number of tag strings.
- Returns:
string
: Comma-separated string of tags with "ts" appended.
GroupingSetsByAttributeKeyTags(tags ...v3.AttributeKey) string
- Purpose: Generates a
GROUP BY
clause string from a slice ofAttributeKey
structs, adding backticks to the key for ClickHouse formatting. - Parameters:
tags
: ...v3.AttributeKey - A variable number ofAttributeKey
structs.
- Returns:
string
: Comma-separated string of attribute keys for use inGROUP BY
clause.
GroupByAttributeKeyTags(tags ...v3.AttributeKey) string
- Purpose: Generates a
GROUP BY
clause string including "ts", usingAttributeKey
structs, adding backticks for ClickHouse formatting. - Parameters:
tags
: ...v3.AttributeKey - A variable number ofAttributeKey
structs.
- Returns:
string
: Comma-separated string of attribute keys and "ts" for use inGROUP BY
clause.
OrderByAttributeKeyTags(items []v3.OrderBy, tags []v3.AttributeKey) string
- Purpose: Generates an
ORDER BY
clause string based on providedOrderBy
items andAttributeKey
structs. Defaults toASC
if order is not specified. - Parameters:
items
: []v3.OrderBy - Slice ofOrderBy
structs defining the ordering.tags
: []v3.AttributeKey - Slice ofAttributeKey
structs for the columns to order by.
- Returns:
string
: Comma-separated string for use inORDER BY
clause.
SelectLabelsAny(tags []v3.AttributeKey) string
- Purpose: Creates a string for selecting labels with the
any()
function in ClickHouse, aliasing them with their key. - Parameters:
tags
: []v3.AttributeKey - Slice ofAttributeKey
structs representing labels to select.
- Returns:
string
: String for selecting labels withany()
function.
SelectLabels(tags []v3.AttributeKey) string
- Purpose: Generates a string for selecting labels, adding backticks for ClickHouse formatting.
- Parameters:
tags
: []v3.AttributeKey - Slice ofAttributeKey
structs representing labels to select.
- Returns:
string
: Comma-separated string of labels for use inSELECT
clause.
- Purpose: Creates a comma-separated string of tags, always including "ts" for use in
-
Code Examples
None
-
Clarity and Accuracy
All documented functions have clear descriptions and parameter/return value explanations.
-
Markdown & MDX Perfection
The documentation uses proper markdown syntax for headings, lists, and code blocks.
-
Edge Cases To Avoid Breaking MDX
- No unescaped special characters.
- No broken links or images.
- No raw HTML tags.
- No HTML comments.
- No tables.
- Lists are properly indented.
- Code blocks and headings are properly closed.
-
Getting Started Relevance Include in Getting Started: NO