Pulsar SQL REST APIs

This section lists resources that make up the Trino REST API v1.

Request for Trino services

All requests for Trino services should use Trino REST API v1 version.

To request services, use the explicit URL http://trino.service:8081/v1``. You need to update trino.service:8081` with your real Trino address before sending requests.

POST requests require the X-Trino-User header. If you use authentication, you must use the same username that is specified in the authentication configuration. If you do not use authentication, you can specify anything for username.

  1. X-Trino-User: username

For more information about headers, refer to client request headers.

Schema

You can use statement in the HTTP body. All data is received as JSON document that might contain a nextUri link. If the received JSON document contains a nextUri link, the request continues with the nextUri link until the received data does not contain a nextUri link. If no error is returned, the query completes successfully. If an error field is displayed in stats, it means the query fails.

The following is an example of show catalogs. The query continues until the received JSON document does not contain a nextUri link. Since no error is displayed in stats, it means that the query completes successfully.

  1. curl --header "X-Trino-User: test-user" --request POST --data 'show catalogs' http://localhost:8081/v1/statement

Output:

  1. {
  2. "infoUri" : "http://localhost:8081/ui/query.html?20191113_033653_00006_dg6hb",
  3. "stats" : {
  4. "queued" : true,
  5. "nodes" : 0,
  6. "userTimeMillis" : 0,
  7. "cpuTimeMillis" : 0,
  8. "wallTimeMillis" : 0,
  9. "processedBytes" : 0,
  10. "processedRows" : 0,
  11. "runningSplits" : 0,
  12. "queuedTimeMillis" : 0,
  13. "queuedSplits" : 0,
  14. "completedSplits" : 0,
  15. "totalSplits" : 0,
  16. "scheduled" : false,
  17. "peakMemoryBytes" : 0,
  18. "state" : "QUEUED",
  19. "elapsedTimeMillis" : 0
  20. },
  21. "id" : "20191113_033653_00006_dg6hb",
  22. "nextUri" : "http://localhost:8081/v1/statement/20191113_033653_00006_dg6hb/1"
  23. }
  1. curl http://localhost:8081/v1/statement/20191113_033653_00006_dg6hb/1

Output:

  1. {
  2. "infoUri" : "http://localhost:8081/ui/query.html?20191113_033653_00006_dg6hb",
  3. "nextUri" : "http://localhost:8081/v1/statement/20191113_033653_00006_dg6hb/2",
  4. "id" : "20191113_033653_00006_dg6hb",
  5. "stats" : {
  6. "state" : "PLANNING",
  7. "totalSplits" : 0,
  8. "queued" : false,
  9. "userTimeMillis" : 0,
  10. "completedSplits" : 0,
  11. "scheduled" : false,
  12. "wallTimeMillis" : 0,
  13. "runningSplits" : 0,
  14. "queuedSplits" : 0,
  15. "cpuTimeMillis" : 0,
  16. "processedRows" : 0,
  17. "processedBytes" : 0,
  18. "nodes" : 0,
  19. "queuedTimeMillis" : 1,
  20. "elapsedTimeMillis" : 2,
  21. "peakMemoryBytes" : 0
  22. }
  23. }
  1. curl http://localhost:8081/v1/statement/20191113_033653_00006_dg6hb/2

Output:

  1. {
  2. "id" : "20191113_033653_00006_dg6hb",
  3. "data" : [
  4. [
  5. "pulsar"
  6. ],
  7. [
  8. "system"
  9. ]
  10. ],
  11. "infoUri" : "http://localhost:8081/ui/query.html?20191113_033653_00006_dg6hb",
  12. "columns" : [
  13. {
  14. "typeSignature" : {
  15. "rawType" : "varchar",
  16. "arguments" : [
  17. {
  18. "kind" : "LONG_LITERAL",
  19. "value" : 6
  20. }
  21. ],
  22. "literalArguments" : [],
  23. "typeArguments" : []
  24. },
  25. "name" : "Catalog",
  26. "type" : "varchar(6)"
  27. }
  28. ],
  29. "stats" : {
  30. "wallTimeMillis" : 104,
  31. "scheduled" : true,
  32. "userTimeMillis" : 14,
  33. "progressPercentage" : 100,
  34. "totalSplits" : 19,
  35. "nodes" : 1,
  36. "cpuTimeMillis" : 16,
  37. "queued" : false,
  38. "queuedTimeMillis" : 1,
  39. "state" : "FINISHED",
  40. "peakMemoryBytes" : 0,
  41. "elapsedTimeMillis" : 111,
  42. "processedBytes" : 0,
  43. "processedRows" : 0,
  44. "queuedSplits" : 0,
  45. "rootStage" : {
  46. "cpuTimeMillis" : 1,
  47. "runningSplits" : 0,
  48. "state" : "FINISHED",
  49. "completedSplits" : 1,
  50. "subStages" : [
  51. {
  52. "cpuTimeMillis" : 14,
  53. "runningSplits" : 0,
  54. "state" : "FINISHED",
  55. "completedSplits" : 17,
  56. "subStages" : [
  57. {
  58. "wallTimeMillis" : 7,
  59. "subStages" : [],
  60. "stageId" : "2",
  61. "done" : true,
  62. "nodes" : 1,
  63. "totalSplits" : 1,
  64. "processedBytes" : 22,
  65. "processedRows" : 2,
  66. "queuedSplits" : 0,
  67. "userTimeMillis" : 1,
  68. "cpuTimeMillis" : 1,
  69. "runningSplits" : 0,
  70. "state" : "FINISHED",
  71. "completedSplits" : 1
  72. }
  73. ],
  74. "wallTimeMillis" : 92,
  75. "nodes" : 1,
  76. "done" : true,
  77. "stageId" : "1",
  78. "userTimeMillis" : 12,
  79. "processedRows" : 2,
  80. "processedBytes" : 51,
  81. "queuedSplits" : 0,
  82. "totalSplits" : 17
  83. }
  84. ],
  85. "wallTimeMillis" : 5,
  86. "done" : true,
  87. "nodes" : 1,
  88. "stageId" : "0",
  89. "userTimeMillis" : 1,
  90. "processedRows" : 2,
  91. "processedBytes" : 22,
  92. "totalSplits" : 1,
  93. "queuedSplits" : 0
  94. },
  95. "runningSplits" : 0,
  96. "completedSplits" : 19
  97. }
  98. }

REST APIs - 图1note

Since the response data is not in sync with the query state from the perspective of clients, you cannot rely on the response data to determine whether the query completes.

For more information about Trino REST API, refer to Trino client REST API.