UQL()
Method and class:
UQL(uql string, config *configuration.RequestConfig) (*http.UQLResponse, error)
Sending uql()
request will return class UQLResponse.
UQLResponse has below fileds:
Field | Type | Description |
---|---|---|
AliasList | []string | aliases of each return value |
DataItemMap | Map[string]struct | aliases and values (*DataItem) of each return value |
ExplainPlan | *ExplainPlan | UQL statement explanation tree |
Status | *Status | status of request execution |
Statistic | *Statistic | statistics of request execution, including timecost, metadata affected, etc. |
Reply | *ultipa.UqlReply | server reply |
Resp | ultipa.UltipaRpcs_UqlClient | GRPC stream |
UQLResponse has below methods:
Method | Type | Description |
---|---|---|
Get(index int) | *DataItem | acquire an alias as *DataItem by index |
Alias(alias string) | *DataItem | acquire an alias as *DataItem by name |
GetSingleTable() | *structs.Table | acquire the first alias (must be TABLE type) as *structs.Table |
Alias types such as NODE, EDGE and PATH can be connverted to corresponding classes using methods of class DataItem, see next chapter Alias Structs for detail.
Get()
Example: Send UQL return now() as currentTime, pi() as PI
to server and print the first alias
func TestMisc(t *testing.T) {
// omit code of establishing server connection 'conn'
resp, _ := conn.UQL("return now() as currentTime, pi() as PI", nil)
attr, _ := resp.Get(0).AsAttr()
printers.PrintAttr(attr)
}
Output:
+-------------------------+
| currentTime |
+-------------------------+
| 2022-12-17 07:17:39.886 |
+-------------------------+
Alias()
Example: Send UQL return now() as currentTime, pi() as PI
to server and print the 2nd alias
func TestMisc(t *testing.T) {
// omit code of establishing server connection 'conn'
resp, _ := conn.UQL("return now() as currentTime, pi() as PI", nil)
attr, _ := resp.Alias("PI").AsAttr()
printers.PrintAttr(attr)
}
Output:
+------------------+
| PI |
+------------------+
| 3.14159265358979 |
+------------------+
GetSingleTable()
Example: Send UQL uncollect [1,2,3] as number uncollect ["a", "b", "c"] as letter return table(number, letter)
to server and print the table
func TestMisc(t *testing.T) {
// omit code of establishing server connection 'conn'
resp, _ := conn.UQL("uncollect [1,2,3] as number uncollect [\"a\", \"b\", \"c\"] as letter return table(number, letter)", nil)
table, _ := resp.GetSingleTable()
printers.PrintTable(table)
}
Output:
+--------+--------+
| number | letter |
+--------+--------+
| 1 | a |
| 2 | b |
| 3 | c |
+--------+--------+