{"id":31646774,"url":"https://github.com/victoriametrics/sql-to-logsql","last_synced_at":"2025-10-29T03:42:55.601Z","repository":{"id":317775580,"uuid":"1068003892","full_name":"VictoriaMetrics/sql-to-logsql","owner":"VictoriaMetrics","description":"Simple UI that provides SQL support for VictoriaLogs and VictoriaTraces","archived":false,"fork":false,"pushed_at":"2025-10-02T23:17:55.000Z","size":400,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-03T01:21:58.053Z","etag":null,"topics":["distributed-tracing","logging","logs","logsql","sql","traces","tracing","victorialogs","victoriametrics","victoriatraces"],"latest_commit_sha":null,"homepage":"https://victoriametrics.com/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VictoriaMetrics.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-01T17:54:10.000Z","updated_at":"2025-10-02T23:17:58.000Z","dependencies_parsed_at":"2025-10-06T08:02:31.057Z","dependency_job_id":null,"html_url":"https://github.com/VictoriaMetrics/sql-to-logsql","commit_stats":null,"previous_names":["victoriametrics/sql-to-logsql"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/VictoriaMetrics/sql-to-logsql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictoriaMetrics%2Fsql-to-logsql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictoriaMetrics%2Fsql-to-logsql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictoriaMetrics%2Fsql-to-logsql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictoriaMetrics%2Fsql-to-logsql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VictoriaMetrics","download_url":"https://codeload.github.com/VictoriaMetrics/sql-to-logsql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictoriaMetrics%2Fsql-to-logsql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278924143,"owners_count":26069400,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["distributed-tracing","logging","logs","logsql","sql","traces","tracing","victorialogs","victoriametrics","victoriatraces"],"created_at":"2025-10-07T05:56:02.929Z","updated_at":"2025-10-29T03:42:55.595Z","avatar_url":"https://github.com/VictoriaMetrics.png","language":"Go","readme":"[![Latest Release](https://img.shields.io/github/v/release/VictoriaMetrics/sql-to-logsql?sort=semver\u0026label=\u0026filter=!*-victorialogs\u0026logo=github\u0026labelColor=gray\u0026color=gray\u0026link=https%3A%2F%2Fgithub.com%2FVictoriaMetrics%2Fsql-to-logsql%2Freleases%2Flatest)](https://github.com/VictoriaMetrics/sql-to-logsql/releases)\n![License](https://img.shields.io/github/license/VictoriaMetrics/sql-to-logsql?link=https%3A%2F%2Fgithub.com%2FVictoriaMetrics%2Fsql-to-logsql%2Fblob%2Fmain%2FLICENSE)\n![Slack](https://img.shields.io/badge/Join-4A154B?logo=slack\u0026link=https%3A%2F%2Fslack.victoriametrics.com)\n![X](https://img.shields.io/twitter/follow/VictoriaMetrics?style=flat\u0026label=Follow\u0026color=black\u0026logo=x\u0026labelColor=black\u0026link=https%3A%2F%2Fx.com%2FVictoriaMetrics)\n![Reddit](https://img.shields.io/reddit/subreddit-subscribers/VictoriaMetrics?style=flat\u0026label=Join\u0026labelColor=red\u0026logoColor=white\u0026logo=reddit\u0026link=https%3A%2F%2Fwww.reddit.com%2Fr%2FVictoriaMetrics)\n\n# sql-to-logsql\n\nWeb application that provides a simple proof-of-concept UI for querying [VictoriaLogs](https://docs.victoriametrics.com/victorialogs/) or [VictoriaTraces](https://docs.victoriametrics.com/victoriatraces/) data with SQL.\n\nIt lets you write familiar SQL against your log data and instantly translates it to [VictoriaLogs LogsQL](https://docs.victoriametrics.com/victorialogs/logsql/) queries. \nIt can optionally execute the resulting LogsQL against a VictoriaLogs instance, manage reusable views that are stored on disk, and ships with a lightweight web UI for interactive use.\n\n[![Web UI screenshot](screenshot.png)](https://play-sql.victoriametrics.com)\n\n## Highlights\n\n- It supports [integrations](./logsql-jdbc/README.md#integrations) via [JDBC driver](./logsql-jdbc/README.md).\n- Go app + library with zero dependencies\n- Translate `SELECT`, `DESCRIBE`, `SHOW`, `CREATE`, and `DROP` statements from ANSI-like SQL into [LogsQL](https://docs.victoriametrics.com/victorialogs/logsql/) pipelines and query data from [VictoriaLogs](https://docs.victoriametrics.com/victorialogs/) or [VictoriaTraces](https://docs.victoriametrics.com/victoriatraces/).\n- Simple [Web UI](#web-ui) featuring SQL editing, example gallery, and query results rendering.\n- Simple [REST API](#rest-api) (`/api/v1/sql-to-logsql`) that you can call from scripts, CI, or other services.\n- Persist and manage `.logsql` view definitions on the filesystem (with locking, `OR REPLACE`, and `IF NOT EXISTS` support).\n\n## Quick start\n\n### Try without installation\n\nYou can try the live demo on **[play-sql.victoriametrics.com](https://play-sql.victoriametrics.com)**\n\n### Use binaries\n\nJust download the latest release from [Releases](https://github.com/VictoriaMetrics/sql-to-logsql/releases) page and run it.\n\n### Run Docker image\n\nYou can run **sql-to-logsql** using Docker.\nThis is the easiest way to get started without needing to install Go or build from source:\n\n```bash\ndocker run -d --name sql-to-logsql -p 8080:8080 -v /data/views \\\n  ghcr.io/victoriametrics/sql-to-logsql:latest\n```\n\nHere is the example with specified [config file](#configuration):\n\n```bash\ncat \u003e config.json \u003c\u003c EOL\n{\n  \"listenAddr\": \":8080\",\n  \"endpoint\": \"https://play-vmlogs.victoriametrics.com\",\n  \"bearerToken\": \"\",\n  \"tables\": {\n    \"logs\": \"*\",\n    \"errors\": \"* | log.level:ERROR\",\n    \"traces\": \"* | span_id:*\"\n  },\n  \"viewsDir\": \"/home/sql-to-logsql/data/views\"\n}\nEOL\n\ndocker run -d --name sql-to-logsql -p 8080:8080 \\\n  -v /home/sql-to-logsql/data/views \\\n  -v ./config.json:/home/sql-to-logsql/config.json:ro \\\n  ghcr.io/victoriametrics/sql-to-logsql:latest \\\n  --config=config.json\n```\n\n### Run locally with Go\n\n1. Install Go 1.25+, Node.js 18+ (Node 24 recommended, matching the Docker builder), and npm.\n2. Run the comand (defaults to `:8080`):\n   ```bash\n   make run\n   ```\n   `make run` compiles the frontend (`npm install \u0026\u0026 npm run build`) and then executes `go run ./cmd/sql-to-logsql`.\n3. Verify the service:\n   ```bash\n   curl http://localhost:8080/healthz\n   # {\"status\":\"ok\"}\n   ```\n4. Open \u003chttp://localhost:8080\u003e to use the web UI.\n\nYou can skip the UI rebuild if the embedded bundle already exists:\n```bash\ngo run ./cmd/sql-to-logsql\n```\n\n### Use Docker (build from sources)\n\nBuild and run the containerised service (no Node.js required on the host):\n\n```bash\ndocker build -t sql-to-logsql .\ndocker run -d -p 8080:8080 -v /data/views sql-to-logsql\n```\n\n## Configuration\n\nThe binary accepts an optional JSON configuration file with the `-config` flag:\n```bash\nsql-to-logsql -config ./config.json\n```\n\nExample (`config.json`):\n```json\n{\n  \"listenAddr\": \":8080\",\n  \"endpoint\": \"https://play-vmlogs.victoriametrics.com\",\n  \"bearerToken\": \"\u003cVM_BEARER_TOKEN\u003e\",\n  \"tables\": {\n    \"logs\": \"*\",\n    \"errors\": \"* | level:ERROR\",\n    \"traces\": \"* | span_id:*\"\n  },\n  \"viewsDir\": \"./data/views\",\n  \"limit\": 1000\n}\n```\n\n| Field         | Type              | Description                                                                                                             | Default           |\n|---------------|-------------------|-------------------------------------------------------------------------------------------------------------------------|-------------------|\n| `listenAddr`  | string            | Address the HTTP server binds to.                                                                                       | `:8080`           |\n| `endpoint`    | string            | VictoriaLogs base URL. Can be left empty (in this case you can specify it in UI or translate without executing queries) | empty             |\n| `bearerToken` | string            | Optional bearer token injected into VictoriaLogs requests when `endpoint` is set.                                       | empty             |\n| `tables`      | map[string]string | Mapping from SQL table name to LogsQL filter or pipeline fragment. Keys are case-insensitive.                           | `{ \"logs\": \"*\" }` |\n| `viewsDir`    | string            | Directory that stores `.logsql` files for views. Required for `CREATE VIEW`, `DROP VIEW`, and `SHOW VIEWS`.             | `./data/views`    |\n| `limit`       | int               | Maximum number of rows returned by any query.                                                                           | 1000              |\n\nPlease note that VictoriaLogs is called via the backend, so if you are using sql-to-logsql in Docker, localhost refers to the localhost of the container, not your computer.\n\n## SQL features and limits\n\nSupported highlights:\n\n- `SELECT` with :\n  - aliases, \n  - arithmetic expressions, \n  - string helpers (`SUBSTR`, `CONCAT`, `TRIM`, `REPLACE`, `LOWER`, `UPPER`), \n  - math (`ABS`, `CEIL`, `FLOOR`, `ROUND`, `LEAST`, `GREATEST`), \n  - JSON (`JSON_VALUE`),\n  - and date helpers (`CURRENT_DATE`, `CURRENT_TIMESTAMP`).\n- `WHERE` with comparison operators, `BETWEEN`, `IN`, `LIKE`, `IS (NOT) NULL`\n- `ORDER BY`, `LIMIT`, `OFFSET`, `DISTINCT`\n- Common Table Expressions (CTE) using `WITH` keyword and subqueries\n- `GROUP BY`, `HAVING`, `COUNT/SUM/AVG/MIN/MAX`\n- Window functions (`OVER (PARTITION BY ... ORDER BY ...)`) for `SUM` and `COUNT`\n- `JOIN` (inner/left) on equality predicates, including subqueries.\n- Set operations: `UNION ALL`\n- Meta statements: \n  - `DESCRIBE TABLE`, `DESCRIBE VIEW`, \n  - `SHOW TABLES`, `SHOW VIEWS`, \n  - `CREATE [OR REPLACE] VIEW`, `CREATE VIEW IF NOT EXISTS`, `DROP VIEW [IF EXISTS]`.\n\nKnown limitations:\n\n- `CASE/WHEN` is not supported\n- Recursive CTEs, `UNION DISTINCT`, and `INTERSECT`/`EXCEPT` are not supported.\n- Only a curated subset of SQL scalar and window functions is implemented; unsupported functions raise explicit translation errors\n- `RIGHT/OUTER JOIN` is not supported, supported only JOINS with the same field name in both sides \n\n## Working with views\n\n- Views live as `.logsql` files under `viewsDir` (default `./data/views`). The name `My.View` becomes `my_view.logsql`.\n- `CREATE VIEW` writes the translated LogsQL statement to disk (always ending with a newline) and returns the query text.\n- `CREATE VIEW IF NOT EXISTS` leaves existing files untouched; `CREATE OR REPLACE VIEW` atomically swaps the existing file.\n- Lock files (`*.lock`) guarantee safe concurrent writes and are cleaned up automatically.\n- `SELECT` from a view loads the stored LogsQL and combines it with additional filters in the SQL query.\n- `SHOW VIEWS` returns one JSON document per line with `view_name` and `query` fields. `DESCRIBE VIEW` resolves to the underlying LogsQL and reuses the VictoriaLogs describe endpoint when executing.\n\n## REST API\n\nAll JSON responses include either a translated `logsql` statement, optional `data` payload (raw VictoriaLogs response or newline-delimited JSON), or an `error` message. \nSecurity headers (`X-Content-Type-Options`, `X-Frame-Options`, `X-XSS-Protection`) are set on every response.\n\n### `POST /api/v1/sql-to-logsql`\n\nTranslate (and optionally execute) a SQL statement.\n\nRequest body:\n```json\n{\n  \"sql\": \"SELECT * FROM logs LIMIT 10\",\n  \"endpoint\": \"https://victoria-logs.example.com\",\n  \"bearerToken\": \"token\"\n}\n```\n\nSuccessful response:\n\n```json\n{\n  \"logsql\": \"* | limit 10\",\n  \"data\": \"{\\\"table\\\":\\\"logs\\\",\\\"count\\\":10}\\n\"\n}\n```\n\nErrors emit `HTTP 4xx/5xx` with `{ \"error\": \"...\" }`. \nParser, translator, VictoriaLogs client, and view-store errors map to informative messages (`400`, `409`, `423`, `502`, etc.).\n\n### `GET /api/v1/config`\n\nReturns the endpoint and max rows limit configured on the server (used by the UI to decide whether the endpoint fields should be read-only):\n\n```json\n{ \n  \"endpoint\": \"https://victoria-logs.example.com\", \n  \"limit\": 1000 \n}\n```\n\n### `GET /healthz`\n\nSimple health endpoint returning `{ \"status\": \"ok\" }`.\n\n### Static UI\n\n`GET /` and any unrecognised path serves the embedded web bundle (`cmd/sql-to-logsql/web/dist`). Assets are cached in memory on first access.\n\n## Web UI\n\nKey features:\n\n- **SQL editor** with syntax highlighting, keyword completions, example gallery (`examples.ts`), and keyboard shortcuts (`Shift/Ctrl/Cmd + Enter`).\n- **Endpoint panel** to toggle VictoriaLogs execution, edit URL/token, or switch to translation-only mode. If the server was booted with a fixed endpoint, fields are prefilled and locked.\n- **Result viewer** rendering newline-delimited JSON into a table when VictoriaLogs is queried, or showing the translated LogsQL when running offline.\n- **Docs sidebar** explaining supported SQL syntax.\n\n## Contributing\n\nContributions are welcome. Please:\n- Read and follow the [Code of Conduct](CODE_OF_CONDUCT.md).\n- Run `make all` before submitting a PR.\n- Ensure new SQL features include translation tests under `lib/logsql` and, when relevant, API tests under `cmd/sql-to-logsql/api`.\n\n## License\n\nLicensed under the [Apache License, Version 2.0](LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictoriametrics%2Fsql-to-logsql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvictoriametrics%2Fsql-to-logsql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvictoriametrics%2Fsql-to-logsql/lists"}