在Apache Druid中,维度可以用作主键,尤其是在数据集中存在唯一标识符的情况下。对于维度,我们可以设置其为索引并将其优化为主维度。主维度将提高查询的性能,并使数据集更具针对性。
示例代码:
下面是一个示例代码,其中使用“country”列作为主维度进行索引和优化:
var druidQuery = { "queryType": "groupBy", "dataSource": "test-data-source", "granularity": "all", "dimensions": ["country"], "filter": { "type": "selector", "dimension": "date", "value": "2020-01-01" }, "aggregations": [ {"type": "count", "name": "count"} ], "intervals": ["2020-01-01T00:00:00.000Z/2020-01-02T00:00:00.000Z"] };
在这个查询中,我们country”列作为“dimensions”中的主维度,并使用“date”列对数据进行筛选。在这里,“dimensions”是一个数组,可以包含多个维度。如果需要将多个维度设置为主维度,可以将它们全部传递到这个数组中进行索引和优化。