Skip to content

Instantly share code, notes, and snippets.

View kylebrandt's full-sized avatar
🦥
🛠️

Kyle Brandt kylebrandt

🦥
🛠️
View GitHub Profile
@kylebrandt
kylebrandt / README.md
Last active May 13, 2025 00:49
Audible Dashboard for fun (Sheets and SQL Expressions)

image

The queries

Panel: Main Sheet

SQL:

SELECT title, author, copyright, href, image, rating, series
FROM main
@kylebrandt
kylebrandt / genre.sql
Created May 12, 2025 19:33
Some Wide/Long SQL
/* Long
WITH movie_genre AS (
SELECT
A.title,
A.year,
B.Genre AS genre
FROM A
JOIN B ON A.imdb_id = B.imdb_id
),
genre_totals AS (
@kylebrandt
kylebrandt / screenshots.md
Last active April 30, 2025 15:59
SQL Expression Example Screenshots

Smooth Time Series (PromQL DS)

image

Trend line over Time Series (PromQL DS)

image

Aggregation and Math across Different Queries (Azure Metrics)

Calculate percentage of syn packages against total packets, per direction image

@kylebrandt
kylebrandt / time_funcs.go
Created April 1, 2025 18:33
Can't implement FunctionProvider
package sql
import (
"context"
"time"
mysql "github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/types"
)
@kylebrandt
kylebrandt / sql_expr_basic_usage_chatgpt.md
Created March 27, 2025 14:05
Basic Usage of SQL Expressions in Grafana

📘 Basic Usage of SQL Expressions in Grafana

SQL expressions in Grafana let you perform lightweight SQL-like transformations on the results of other queries — directly within the panel. This is great for reshaping, renaming, filtering, and aggregating data without modifying the original datasource query.


🔧 How SQL Expressions Work

SQL expressions operate on the output of another query in the same panel, referenced by its query letter (e.g., A, B). These expressions are parsed and executed by Grafana — not sent to an external database.

@kylebrandt
kylebrandt / README.md
Last active March 14, 2025 17:02
SQL Expressions and Full Long (Written by ChatGPT)

Why *_full_long Formats Are Essential for Handling Label Sparsity

Overview

In Grafana, data coming from many sources includes sparse labels — meaning some series have label keys that others do not.
This is common in systems like Prometheus, OpenTelemetry, or SQL queries with GROUP BY.

However, traditional long formats (like time_series_long or numeric_long) do not preserve label sparsity correctly, leading to broken behaviors in visualization, alerts, and expressions.


@kylebrandt
kylebrandt / func.go
Created January 26, 2025 15:55
mysql_func
package sql
import (
"fmt"
mysql "github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/types"
)
type SlothFunction struct{}
@kylebrandt
kylebrandt / README.md
Last active January 6, 2025 15:18
SQL Expression Input Conversion Notes

SQL Expressions and Input

  • What do we want to happen to data when read by SQL Expressions?
    • Data from an individual query needs to appear as a single table
      • Raw table data maps directly to single table
      • The "Long" formats of the TimeSeries and Numeric kinds map directly to a table
      • The "Multi" and "wide" formats of the TimeSeries and Numeric kinds need conversion to the kind's "Long" format
      • For now I'm calling this "SQL Conversion Rules"
  • What does SSE currently do for conversion?
  • To generalize, SSE reads TimeSeries and Numeric data in different formats, and converts them to the multi format for their kind. Things like alerting depend on this behavior.
@kylebrandt
kylebrandt / notes.md
Created November 7, 2024 16:20
SQL Expression Notes

SQL Expression Notes

Getting some thoughts down...

PoC Outline (with go-mysql-server)

  • Goals
    • Main Goal: go-mysql-server end-to-end inside SSE over completion for discovery, supporting some subset of cases of combining other datasources
    • Run go-mysql-server without "server"
  • Use SDK for response
@kylebrandt
kylebrandt / README.md
Last active November 21, 2024 15:29
Recorded Query Multi-Dimensions - Dataplane + SSE

Recorded Queries and Multiple Dimensions, The Ugly Details

Docs (https://grafana.com/docs/grafana/latest/administration/recorded-queries/#how-recorded-queries-work):

Recorded queries only work with backend data source plugins. Refer to Backend data source plugin for more information about backend data source plugins. You can recorded four types of queries:

  • single row and column - A query that returns a single row and column.
  • row count - A query that returns meaningful rows to be counted.
  • expression - Any expression. To learn more about creating and using expressions, see Write expression queries.
  • dataplane numeric - A query that returns dataplane numeric kind data.