如何从 teiid REST 服务获得 JSON 响应

How to get JSON response from a teiid REST service

我正在对来自 teiid 的 MySQL 数据源发出 SQL SELECT 查询,并尝试以 JSON 格式获取 SQL 响应.我能够以 XML 格式获得响应,但在尝试以 JSON 格式获得响应时遇到问题。似乎 XMLELEMENT、XMLAGG、XMLFOREST XML 函数没有等效的 JSON 函数。我已经在下面发布了我的查询的 XML 版本。此查询的等效 JSON 版本是什么。

CREATE VIRTUAL PROCEDURE GetFlightRecordsByAirDelay1(IN p1 integer, IN p2 integer) RETURNS (xml_out xml) OPTIONS (UPDATECOUNT 0, "REST:METHOD" 'GET', "REST:URI" 'GetFlightRecordsByAirDelay1') AS /*+ cache(pref_mem ttl:14400000) */ BEGIN SELECT XMLELEMENT("FlightDelayRecords",
XMLAGG(XMLELEMENT("FlightDelayRecord", XMLFOREST(UniqueCarrier,FlightNum, CRSDepTime, DepTime, CRSArrTime, ArrDelay) )) ) as xml_out FROM (SELECT UniqueCarrier,FlightNum, CRSDepTime, DepTime, CRSArrTime,
ArrDelay FROM flight_records_mod1 WHERE flight_records_mod1.ArrDelay < p1 AND flight_records_mod1.YEAR = p2 LIMIT 10) A;
END

return json 可以更简单。产生如下结果:

{"FlightDelayRecords":[{"UniqueCarrier":...},...]}

使用

CREATE VIRTUAL PROCEDURE GetFlightRecordsByAirDelay1(IN p1 integer, IN p2 integer) 
RETURNS (clob json) OPTIONS (UPDATECOUNT 0, "REST:METHOD" 'GET', "REST:URI" 'GetFlightRecordsByAirDelay1') AS /*+ cache(pref_mem ttl:14400000) */ 
BEGIN 
SELECT JSONOBJECT(JSONARRAY_AGG(JSONOBJECT(UniqueCarrier,FlightNum, CRSDepTime, DepTime, CRSArrTime, ArrDelay)) as "FlightDelayRecords") as json FROM (SELECT UniqueCarrier,FlightNum, CRSDepTime, DepTime, CRSArrTime,
ArrDelay FROM flight_records_mod1 WHERE flight_records_mod1.ArrDelay < p1 AND flight_records_mod1.YEAR = p2 LIMIT 10) A;
END