跳到主要内容

DataQL 专为结构转换而生

用脚本查询、转换和聚合数据,可在 Java 应用或 Dataway 接口中运行。

查询脚本DataQL
var price = 20;
var quantity = 3;
return {"quantity": quantity, "total": price * quantity};
示例结果JSON
{"quantity": 3, "total": 60}

接入多种数据源与服务

  • MySQL
  • PostgreSQL
  • Hive
  • ClickHouse
  • MongoDB
  • Redis
  • Elasticsearch
  • Milvus
  • HTTP
  • Dubbo
  • Java

让数据,成为你需要的样子。

结构转换

选择字段、计算新值,一次转换得到所需的数据结构。

了解更多
DataQL查询脚本
var people = [
{"name": "Alice", "age": 25},
{"name": "Bob", "age": 30}
];

return people => [{
"name",
"nextAge": age + 1
}];
JSON示例结果
[
{"name": "Alice", "nextAge": 26},
{"name": "Bob", "nextAge": 31}
]

SQL 查询

通过 SQL 执行器访问数据库。此例使用示例工程中已配置的 ds1 数据源。

了解更多
DataQL查询脚本
hint FRAGMENT_SQL_DATA_SOURCE = "ds1"
hint FRAGMENT_SQL_OPEN_PACKAGE = "off"

var people = @@selectSql()<%
SELECT id AS "id", name AS "name", balance AS "balance"
FROM example_people
ORDER BY id
%>;
return people();
JSON示例结果
[
{"id": 1, "name": "Alice", "balance": 100},
{"id": 2, "name": "Bob", "balance": 200}
]

分组聚合

导入内置函数,按字段分组,组合为新的结果。

了解更多
DataQL查询脚本
import 'net.hasor.dataql.host.function.basic.CollectionUdfSource'
as collect;

var rows = [
{"name": "Alice", "team": "dev"},
{"name": "Bob", "team": "sales"},
{"name": "Carol", "team": "dev"}
];
return collect.groupBy(rows, 'team');
JSON示例结果
{
"dev": [
{"name": "Alice", "team": "dev"},
{"name": "Carol", "team": "dev"}
],
"sales": [
{"name": "Bob", "team": "sales"}
]
}

交流使用经验、反馈问题,参与 DataQL 的改进。