Skip to main content

clauses.go

clauses.go - Overview

  1. Overview This file provides helper functions for generating SQL clauses such as GROUP BY, ORDER BY, and SELECT statements, specifically tailored for ClickHouse queries related to metrics.

  2. 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 of AttributeKey structs, adding backticks to the key for ClickHouse formatting.
    • Parameters:
      • tags: ...v3.AttributeKey - A variable number of AttributeKey structs.
    • Returns:
      • string: Comma-separated string of attribute keys for use in GROUP BY clause.

    GroupByAttributeKeyTags(tags ...v3.AttributeKey) string

    • Purpose: Generates a GROUP BY clause string including "ts", using AttributeKey structs, adding backticks for ClickHouse formatting.
    • Parameters:
      • tags: ...v3.AttributeKey - A variable number of AttributeKey structs.
    • Returns:
      • string: Comma-separated string of attribute keys and "ts" for use in GROUP BY clause.

    OrderByAttributeKeyTags(items []v3.OrderBy, tags []v3.AttributeKey) string

    • Purpose: Generates an ORDER BY clause string based on provided OrderBy items and AttributeKey structs. Defaults to ASC if order is not specified.
    • Parameters:
      • items: []v3.OrderBy - Slice of OrderBy structs defining the ordering.
      • tags: []v3.AttributeKey - Slice of AttributeKey structs for the columns to order by.
    • Returns:
      • string: Comma-separated string for use in ORDER 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 of AttributeKey structs representing labels to select.
    • Returns:
      • string: String for selecting labels with any() function.

    SelectLabels(tags []v3.AttributeKey) string

    • Purpose: Generates a string for selecting labels, adding backticks for ClickHouse formatting.
    • Parameters:
      • tags: []v3.AttributeKey - Slice of AttributeKey structs representing labels to select.
    • Returns:
      • string: Comma-separated string of labels for use in SELECT clause.
  3. Code Examples

    None

  4. Clarity and Accuracy

    All documented functions have clear descriptions and parameter/return value explanations.

  5. Markdown & MDX Perfection

    The documentation uses proper markdown syntax for headings, lists, and code blocks.

  6. 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.
  7. Getting Started Relevance Include in Getting Started: NO