{"id":27120726,"url":"https://github.com/awatercolorpen/olap-sql","last_synced_at":"2026-02-26T12:01:55.885Z","repository":{"id":46247088,"uuid":"362081864","full_name":"AWaterColorPen/olap-sql","owner":"AWaterColorPen","description":"golang library for generating  sql by olap query with metrics, dimension and filter.","archived":false,"fork":false,"pushed_at":"2022-11-07T08:44:07.000Z","size":319,"stargazers_count":5,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T16:13:03.715Z","etag":null,"topics":["clickhouse","olap","sql"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AWaterColorPen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-27T11:06:31.000Z","updated_at":"2024-08-29T12:51:31.000Z","dependencies_parsed_at":"2022-09-19T07:30:24.777Z","dependency_job_id":null,"html_url":"https://github.com/AWaterColorPen/olap-sql","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/AWaterColorPen/olap-sql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AWaterColorPen%2Folap-sql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AWaterColorPen%2Folap-sql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AWaterColorPen%2Folap-sql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AWaterColorPen%2Folap-sql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AWaterColorPen","download_url":"https://codeload.github.com/AWaterColorPen/olap-sql/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AWaterColorPen%2Folap-sql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29858461,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-26T08:51:08.701Z","status":"ssl_error","status_checked_at":"2026-02-26T08:50:19.607Z","response_time":89,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["clickhouse","olap","sql"],"created_at":"2025-04-07T10:07:30.258Z","updated_at":"2026-02-26T12:01:55.868Z","avatar_url":"https://github.com/AWaterColorPen.png","language":"Go","readme":"# olap-sql\n\n[![Go](https://github.com/AWaterColorPen/olap-sql/actions/workflows/go.yml/badge.svg)](https://github.com/AWaterColorPen/olap-sql/actions/workflows/go.yml)\n\n## Introduction\n\nolap-sql is golang library for generating **adapted sql** by **olap query** with metrics, dimension and filter. \nThen get **formatted sql result** by queried metrics and dimension.\n\n### Example\n\nThere is unprocessed olap data with table named `wikistat`.\n\n| date       | time                | hits |\n|------------|---------------------|------|\n| 2021-05-07 | 2021-05-07 09:28:27 | 4783 |\n| 2021-05-07 | 2021-05-07 09:33:59 | 1842 |\n| 2021-05-07 | 2021-05-07 10:34:12 | 0    |\n| 2021-05-06 | 2021-05-06 20:32:41 | 5    |\n| 2021-05-06 | 2021-05-06 21:16:39 | 139  |\n\nIt wants a sql to query the data with `metrics: sum(hits) / count(*)` and `dimension: date`.\n\n```sql\nSELECT wikistat.date AS date, ( ( 1.0 * SUM(wikistat.hits) ) /  NULLIF(( COUNT(*) ), 0) ) AS hits_avg FROM wikistat AS wikistat GROUP BY wikistat.date\n```\n\nIt wants a sql to query the data with `metrics: sum(hits)` and `filter: date \u003c= '2021-05-06'`.\n\n```sql\nSELECT SUM(wikistat.hits) AS hits FROM wikistat AS wikistat WHERE wikistat.date \u003c= '2021-05-06'\n```\n\n## Documentation\n\n1. [Configuration](./docs/configuration.md) to configure olap-sql instance and OLAP dictionary.\n2. [Query](./docs/query.md) to define olap query.\n3. [Result](./docs/result.md) to parse olap result.\n\n## Getting Started\n\n### Define the OLAP dictionary configuration file\n\nCreate a new file for example named `olap-sql.toml` to define \n[sets](./docs/configuration.md#sets), \n[sources](./docs/configuration.md#sources), \n[metrics](./docs/configuration.md#metrics),\n[dimensions](./docs/configuration.md#dimensions).\n\n```toml\nsets = [\n  {name = \"wikistat\", type = \"clickhouse\", data_source = \"wikistat\"},\n]\n\nsources = [\n  {database = \"\", name = \"wikistat\", type = \"fact\"},\n]\n\nmetrics = [\n  {data_source = \"wikistat\", type = \"METRIC_SUM\", name = \"hits\", field_name = \"hits\", value_type = \"VALUE_INTEGER\"},\n  {data_source = \"wikistat\", type = \"METRIC_COUNT\", name = \"count\", field_name = \"*\", value_type = \"VALUE_INTEGER\"},\n  {data_source = \"wikistat\", type = \"METRIC_DIVIDE\", name = \"hits_avg\", value_type = \"VALUE_FLOAT\", dependency = [\"wikistat.hits\", \"wikistat.count\"]},\n]\n\ndimensions = [\n  {data_source = \"wikistat\", type = \"DIMENSION_SINGLE\", name = \"date\", field_name = \"date\", value_type = \"VALUE_STRING\"},\n]\n```\n\n### To make use of olap-sql in golang\n\nCreate a new [manager instance](./docs/configuration.md#manager-configuration).\n\n```golang\nimport \"github.com/awatercolorpen/olap-sql\"\n\n// set clients option\nclientsOption := map[string]*olapsql.DBOption{\n\t\"clickhouse\": \u0026olapsql.DBOption{\n\t\tDSN:  \"clickhouse://localhost:9000/default\", \n\t\tType: \"clickhouse\"\n\t}\n},\n\n// set dictionary option\ndictionaryOption := olapsql.AdapterOption{\n\tDsn: \"olap_sql.toml\",\n}\n\n// build manager configuration\nconfiguration := \u0026olapsql.Configuration{\n\tClientsOption:    clientsOption, \n\tDictionaryOption: dictionaryOption,\n}\n\n// create a new manager instance\nmanager, err := olapsql.NewManager(configuration)\n```\n\nBuild olap-sql [query](./docs/query.md).\n\n```golang\nimport \"github.com/awatercolorpen/olap-sql/api/types\"\n\nqueryJson := `\n{\n  \"data_set_name\": \"wikistat\",\n  \"time_interval\": {\n    \"name\": \"date\",\n    \"start\": \"2021-05-06\",\n    \"end\": \"2021-05-08\"\n  },\n  \"metrics\": [\n    \"hits\",\n    \"hits_avg\"\n  ],\n  \"dimensions\": [\n    \"date\"\n  ]\n}`\n\nquery := \u0026types.Query{}\nerr := json.Unmarshal([]byte(queryJson), query)\n```\n\nRun query to get result from manager.\n\n```golang\n// run query with parallel chan\nresult, err := manager.RunChan(query)\n\n// run query with sync\nresult, err := manager.RunSync(query)\n```\n\n### Generate SQL then format result\n\nFirstly, auto generate sql. [For detail](./docs/query.md#generate-sql-from-query).\n\nThen, get [result](./docs/result.md) json with `dimensions` property and `source` property.\n\n```json\n{\n  \"dimensions\": [\n    \"date\",\n    \"hits\",\n    \"hits_avg\"\n  ],\n  \"source\": [\n    {\n      \"date\": \"2021-05-06T00:00:00Z\",\n      \"hits\": 147,\n      \"hits_avg\": 49\n    },\n    {\n      \"date\": \"2021-05-07T00:00:00Z\",\n      \"hits\": 7178,\n      \"hits_avg\": 897.25\n    }\n  ]\n}\n```\n\n## License\n\nSee the [License File](./LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawatercolorpen%2Folap-sql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fawatercolorpen%2Folap-sql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fawatercolorpen%2Folap-sql/lists"}