|
| 1 | +package presto |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "net/http" |
| 7 | + "time" |
| 8 | +) |
| 9 | + |
| 10 | +// QueryStateInfo is the Go translation of the QueryStateInfo class in Presto Java: |
| 11 | +// https://github.com/prestodb/presto/blob/master/presto-main/src/main/java/com/facebook/presto/server/QueryStateInfo.java |
| 12 | +// Unused fields are commented out for now. |
| 13 | +type QueryStateInfo struct { |
| 14 | + QueryId string `json:"queryId"` |
| 15 | + QueryState string `json:"queryState"` |
| 16 | + //ResourceGroupId []string `json:"resourceGroupId"` |
| 17 | + Query string `json:"query"` |
| 18 | + QueryTruncated bool `json:"queryTruncated"` |
| 19 | + CreateTime time.Time `json:"createTime"` |
| 20 | + User string `json:"user"` |
| 21 | + Authenticated bool `json:"authenticated"` |
| 22 | + Source string `json:"source"` |
| 23 | + Catalog string `json:"catalog"` |
| 24 | + //Progress struct { |
| 25 | + // ElapsedTimeMillis int `json:"elapsedTimeMillis"` |
| 26 | + // QueuedTimeMillis int `json:"queuedTimeMillis"` |
| 27 | + // ExecutionTimeMillis int `json:"executionTimeMillis"` |
| 28 | + // CpuTimeMillis int `json:"cpuTimeMillis"` |
| 29 | + // ScheduledTimeMillis int `json:"scheduledTimeMillis"` |
| 30 | + // CurrentMemoryBytes int `json:"currentMemoryBytes"` |
| 31 | + // PeakMemoryBytes int `json:"peakMemoryBytes"` |
| 32 | + // PeakTotalMemoryBytes int `json:"peakTotalMemoryBytes"` |
| 33 | + // PeakTaskTotalMemoryBytes int `json:"peakTaskTotalMemoryBytes"` |
| 34 | + // CumulativeUserMemory int `json:"cumulativeUserMemory"` |
| 35 | + // CumulativeTotalMemory int `json:"cumulativeTotalMemory"` |
| 36 | + // InputRows int `json:"inputRows"` |
| 37 | + // InputBytes int `json:"inputBytes"` |
| 38 | + // Blocked bool `json:"blocked"` |
| 39 | + // QueuedDrivers int `json:"queuedDrivers"` |
| 40 | + // RunningDrivers int `json:"runningDrivers"` |
| 41 | + // CompletedDrivers int `json:"completedDrivers"` |
| 42 | + //} `json:"progress"` |
| 43 | + //WarningCodes []interface{} `json:"warningCodes"` |
| 44 | +} |
| 45 | + |
| 46 | +// GetQueryStatsOptions includes parameters in https://github.com/prestodb/presto/blob/a7af002182098ba5a61248edfcaaa66e5d50e489/presto-main/src/main/java/com/facebook/presto/server/QueryStateInfoResource.java#L89-L95 |
| 47 | +type GetQueryStatsOptions struct { |
| 48 | + User *string `query:"user"` |
| 49 | + IncludeLocalQueryOnly *bool `query:"includeLocalQueryOnly"` |
| 50 | + IncludeAllQueries *bool `query:"includeAllQueries"` |
| 51 | + IncludeAllQueryProgressStats *bool `query:"includeAllQueryProgressStats"` |
| 52 | + ExcludeResourceGroupPathInfo *bool `query:"excludeResourceGroupPathInfo"` |
| 53 | + QueryTextSizeLimit *int `query:"queryTextSizeLimit"` |
| 54 | +} |
| 55 | + |
| 56 | +func (c *Client) GetQueryState(ctx context.Context, reqOpt *GetQueryStatsOptions, opts ...RequestOption) ([]QueryStateInfo, *http.Response, error) { |
| 57 | + req, err := c.NewRequest("GET", |
| 58 | + fmt.Sprintf("v1/queryState?%s", GenerateHttpQueryParameter(reqOpt)), nil, opts...) |
| 59 | + if err != nil { |
| 60 | + return nil, nil, err |
| 61 | + } |
| 62 | + |
| 63 | + infoArray := make([]QueryStateInfo, 0, 16) |
| 64 | + resp, err := c.Do(ctx, req, infoArray) |
| 65 | + if err != nil { |
| 66 | + return nil, resp, err |
| 67 | + } |
| 68 | + return infoArray, resp, nil |
| 69 | +} |
0 commit comments