Configuration for creating a new manager instance.
Configuration for defining olap database client.
It is a map of key = name and value = one client structure.
Each client have dsn and type two properties.
| type | dsn relate package version |
|---|---|
clickhouse |
gorm.io/driver/clickhouse v0.5.0 |
sqlite |
gorm.io/driver/sqlite v1.3.6 |
mysql |
gorm.io/driver/mysql v1.3.6 |
postgres |
gorm.io/driver/postgres v1.3.6 |
{
"clients_option": {
"clickhouse": {
"dsn": "clickhouse://localhost:9000/default",
"type": "clickhouse"
}
}
}Option for loading OLAP dictionary configuration.
dsn is the path to load OLAP dictionary configuration.
type is dictionary adaptor type.
| adaptor type | description |
|---|---|
|
default type is FILE |
FILE |
load OLAP dictionary configuration from file |
{
"dictionary_option": {
"dsn": "olap_sql.toml",
"type": "FILE"
}
}Create a manager instance by clients option and dictionary option.
import "github.com/awatercolorpen/olap-sql"
// set clients option
clientsOption := map[string]*olapsql.DBOption{},
// set dictionary option
dictionaryOption := olapsql.AdapterOption{}
// build manager configuration
configuration := &olapsql.Configuration{
ClientsOption: clientsOption,
DictionaryOption: dictionaryOption,
}
// create a new manager instance
manager, err := olapsql.NewManager(configuration)
if err != nil {
log.Fatal(err)
}Each set is one set of business query.
nameis the name of business. It is used by query's data_set_name property.typeis the OLAP database client type.data_sourceis the name of sources.
sets = [
{name = "wikistat", type = "clickhouse", data_source = "wikistat"},
]Same with database client type
Each source defines one table or the relationship between tables.
databaseis the database name of source. The dimension type source must setdatabaseproperty.nameis the name of source. It is used by setsdata_sourceproperty.typeis the source / table type.
sources = [
{database = "", name = "wikistat", type = "fact"},
]| type | description |
|---|---|
dimension |
dimension table, used by JOIN ON |
fact |
fact table with really olap raw data |
fact_dimension_join |
combination table from fact table and dimension table |
merge_join |
JOIN ON two different fact tables |
Each metrics defines how one metric be calculated. It is used for SELECT WHERE ORDER BY.
data_sourceis the name of sources. This metrics belong to only one source.typeis the metrics type.nameis the name of metrics. It is used by query'smetricsproperty.field_nameis column name in database table.value_typeis the value type.dependencyis used for the composition type metrics.
metrics = [
{data_source = "wikistat", type = "METRIC_SUM", name = "hits", field_name = "hits", value_type = "VALUE_INTEGER"},
{data_source = "wikistat", type = "METRIC_COUNT", name = "count", field_name = "*", value_type = "VALUE_INTEGER"},
{data_source = "wikistat", type = "METRIC_DIVIDE", name = "hits_avg", value_type = "VALUE_FLOAT", dependency = ["wikistat.hits", "wikistat.count"]},
]| type | description | classify | required with example | sql example |
|---|---|---|---|---|
METRIC_VALUE |
original value as one metrics. | single | field_name = "value" |
SELECT value AS name |
METRIC_COUNT |
count one column as one metrics. | single | field_name = "*" |
SELECT COUNT(*) AS name |
METRIC_DISTINCT_COUNT |
distinct count one metrics to a new metrics. | single | field_name = "value" |
SELECT COUNT(DISTINCT value) AS name |
METRIC_SUM |
sum the metrics to a new metrics. | single | field_name = "value" |
SELECT SUM(value) AS name |
METRIC_ADD |
add multi metrics to a new metrics. | composition | dependency = ["value1", "value2"] |
SELECT value1 + value2 AS name |
METRIC_SUBTRACT |
subtract multi metrics to a new metrics. | composition | dependency = ["value1", "value2"] |
SELECT value1 - value2 AS name |
METRIC_MULTIPLY |
multiply multi metrics to a new metrics. | composition | dependency = ["value1", "value2"] |
SELECT value1 * value2 AS name |
METRIC_DIVIDE |
divide multi metrics to a new metrics. | composition | dependency = ["value1", "value2"] |
SELECT value1 / value2 AS name |
METRIC_AS |
relation with other table metrics to a new metrics. | composition | dependency = ["table.value1", "table.value2"] |
SELECT table.value1 AS name |
METRIC_EXPRESSION |
expression as one metrics | single | field_name = "100" |
SELECT 100 AS name |
Same with supported value type type
Each dimension defines OLAP data dimension to analyze. It is used for SELECT JOIN ON WHERE GROUP BY ORDER BY.
data_sourceis the name of sources. This dimension belong to only one source.typeis the dimension type.nameis the name of dimension. It is used by query'sdimensionproperty.field_nameis column name in database table.value_typeis the value type.dependencyis used for the composition type metrics.
dimensions = [
{data_source = "wikistat", type = "DIMENSION_SINGLE", name = "date", field_name = "date", value_type = "VALUE_STRING"},
]| type | description | classify | required with example | sql example |
|---|---|---|---|---|
METRIC_VALUE |
original value as one dimension. | single | SELECT name ... GROUP BY name |
|
DIMENSION_SINGLE |
one single column as one dimension. | single | field_name = "value" |
SELECT value AS name ... GROUP BY value |
DIMENSION_MULTI |
relation with other tables dimension to a new dimension | composition | dependency = ["table1.value"] |
SELECT table1.value AS name ... GROUP BY table1.value |
DIMENSION_CASE |
CASE pattern for multi dimension to a new dimension |
composition | dependency = ["table1.value1", "table2.value2"] |
SELECT CASE WHEN table1.value1 != '' THEN table2.value2 END AS name |
DIMENSION_EXPRESSION |
expression as one dimension. | single | field_name = "formatDateTime(time, '%Y-%m-%d')" |
SELECT formatDateTime(time, '%Y-%m-%d') AS name ... GROUP BY name |
Same with supported value type type