# 데이터 커스텀 쿼리 API
액세스 토큰이 생성된 후, 커스텀 쿼리 API를 호출하여 프로젝트 데이터를 조회할 수 있습니다. 호출 메서드에 대한 설명은 오픈 API 문서를 참조하십시오.
# 1. SQL쿼리
인터페이스 URL
/querySql?token=xxx&format=json&timeoutSecond=10&sql=select "#country","#province","#city" from v_event_102 where "$part_date"='2018-10-01' limit 200
요청 방법
POST
콘텐츠 유형
application/x-www-form-urlencoded
요청 쿼리 파라미터
Parameter name  |  Sample value  |  Parameter type  |  Is required  |  Parameter description  | 
|---|---|---|---|---|
token  |  xxx  |  String  |  Yes  |  Query key  | 
sql  |  select "#country","#province","#city" from v_event_102 where "$part_date"='2018-10-01' limit 200  |  String  |  Yes  |  SQL statements for queries  | 
format  |  json  |  String  |  No  |  Row data format the default is 'json' (json,csv,csv_header,tsv,tsv_header)  | 
timeoutSeconds  |  10  |  Integer  |  No  |  Request timed out parameter, timeout cancels query task  | 
성공적인 응답 예시
결과는 각 행별로 구분되며, 쿼리 문이 실행될 때 지정된 형식으로 제공됩니다.
- JSON 형식의 결과
 
JSON 형식으로 포맷된 경우, 첫 번째 행에는 다음 형식으로 상태 값과 데이터 메타데이터가 포함됩니다:
{
  "data": { 
      "headers": [
          "#country", 
          "#province", 
          "#city"
      ] 
  },
  "return_code": 0,
  "return_message": "success"
}
| $$Parameter name | Sample value | Parameter type | Parameter description | ||
|---|---|---|---|---|---|
| return_code | 0 | Integer | Return code | ||
| return_message | success | String | Return information | ||
| data | - | Object | Return result | ||
| data.headers | ["#country", "#province", "#city"] | List | First row | ||
쿼리 결과가 비어 있지 않은 경우, 첫 번째 행 다음에 데이터 행이 이어집니다.
["China", "Gansu", "Lanzhou"]
["China", "Beijing", "Beijing"]
["China", "Guangdong", "Guangzhou"]
["China", "Gansu", "Lanzhou"]
- 다른 형식의 반환 결과
 
CSV 헤더 또는 TSV 헤더로 포맷된 경우, 첫 번째 행은 열 정보입니다 (csv_header 또는 tsv_header).
"#country","#province","#city"
그 다음에는 반환된 검색 결과(csv)를 포함하는 개체의 리스트가 있습니다.
"China", "Gansu", "Lanzhou"
"China", "Beijing", "Beijing"
"China", "Guangdong", "Guangzhou"
"China", "Gansu", "Lanzhou"
- 형식이 csv 또는 tsv인 경우
 
결과에는 열 정보가 없으며, 데이터 내용만 포함됩니다.
Curl example
curl -X POST 'http://ta2:8992/querySql?token=bTOzKiTIozG4e19FgXphcA8dDV3DIY8RwdHTO7aSnBsRqSNaIk19BnBMecJDWibD' --header 'Content-Type: application/x-www-form-urlencoded' -d 'sql=select+%22%23country%22%2c%22%23province%22%2c%22%23city%22+from+v_event_102+where+%22%24part_date%22%3d%272018-10-01%27+limit+200&format=json&timeoutSecond=10'
# 2. SQL 페이지별 쿼리
SQL 페이지별 쿼리 API는 두 가지 관련 메서드를 포함합니다. 첫 번째 메서드는 쿼리 문을 실행하고 실행 후 결과의 메타 정보와 페이징 정보를 반환합니다. 두 번째 메서드는 결과의 페이징 데이터를 다운로드하는 데 사용됩니다.
# 쿼리 문 실행
인터페이스 URL
/open/execute-sql?token=xxx&sql=select * from v_user_0 limit 11000&pageSize=10000&format=json&timeoutSeconds=10
요청 방법
POST
콘텐츠 유형
application/x-www-form-urlencoded
요청 쿼리 파라미터
Parameter name  |  Sample value  |  Parameter type  |  Is required  |  Parameter description  | 
|---|---|---|---|---|
token  |  xxx  |  String  |  Yes  |  token  | 
sql  |  select * from v_user_0 limit 11000  |  String  |  Yes  |  SQL statements for queries  | 
format  |  json  |  String  |  No  |  Row data format (json, csv, tsv), default json  | 
pageSize  |  10000  |  Integer  |  No  |  Number of lines per page, minimum 1000, default 10000  | 
timeoutSeconds  |  10  |  Integer  |  No  |  Request timed out parameter, timeout cancels query task  | 
성공적인 응답 예시
{
  "data": {
    "headers": [
      "#user_id",
      "#account_id",
      "#distinct_id",
      "#active_time",
      "#reg_time",
      "#user_operation",
      "#server_time",
      "#is_delete",
      "#update_time",
      "user_level",
      "coin_num",
      "register_time",
      "diamond_num",
      "first_recharge_time"
    ],
    "pageCount": 2,
    "pageSize": 10000,
    "rowCount": 11000,
    "taskId": "119a3a37411f3000"
  },
  "return_code": 0,
  "return_message": "success"
}
$$Parameter name  |  Sample value  |  Parameter type  |  Parameter description  | 
|---|---|---|---|
return_code  |  0  |  Integer  |  Return code  | 
return_message  |  success  |  String  |  Return information  | 
data  |  -  |  Object  |  Return data  | 
data.pageCount  |  2  |  Integer  |  Total number of pages of result data  | 
data.pageSize  |  10000  |  Integer  |  Number of lines per page  | 
data.rowCount  |  11000  |  Integer  |  Total number of rows of result data  | 
data.header  |  ["#user_id"]  |  List  |  List of first-line fields  | 
data.taskId  |  119a3a37411f3000  |  String  |  Task ID  | 
오류 응답 예시
{
    "return_code": -1008,
    "return_message": "The parameter (token) is empty"
}
Parameter name  |  Sample value  |  Parameter type  |  Parameter description  | 
|---|---|---|---|
return_code  |  -1008  |  Integer  |  Return code  | 
return_message  |  The parameter (token) is empty  |  String  |  Return information  | 
Curl example
curl -X POST 'http://ta2:8992/open/execute-sql?token=bTOzKiTIozG4e19FgXphcA8dDV3DIY8RwdHTO7aSnBsRqSNaIk19BnBMecJDWibD' --header 'Content-Type: application/x-www-form-urlencoded' -d 'sql=select * from v_user_0 limit 11000&pageSize=10000&format=json&timeoutSeconds=10'
# 결과 페이지 데이터 다운로드
인터페이스 URL
/open/sql-result-page?token=xxx&taskId=119a3a37411f3000&pageId=0
요청 방법
GET
콘텐츠 유형
application/json
요청 쿼리 파라미터
Parameter name  |  Sample value  |  Parameter type  |  Is required  |  Parameter description  | 
|---|---|---|---|---|
token  |  xxx  |  String  |  Yes  |  token  | 
taskId  |  119a3a37411f3000  |  String  |  Yes  |  The fallback field taskId from the Execute Query Statement interface to the  | 
pageId  |  0  |  Integer  |  No  |  Value range: [0, pageCount-1], default is 0  | 
The return results are separated by rows, and the format of each row of data is the format specified when executing the query statement.
[9324080,"c21756080","c40404080","2019-12-15 16:09:07.000","2019-12-15 16:09:07.000","user_set","2019-12-15 16:22:13.000",false,"2020-06-03 13:10:02.494",6,40000,"2019-12-15 16:09:07.000",0,null]
[9328294,"q21765894","q40422294","2019-12-15 16:19:49.000","2019-12-15 16:19:49.000","user_set","2019-12-15 16:42:18.000",false,"2020-06-03 13:10:02.494",17,642440,"2019-12-15 16:19:49.000",112,"2019-12-15 16:26:13.000"]
[9335719,"t21783319","t40454719","2019-12-15 16:29:45.000","2019-12-15 16:29:45.000","user_set","2019-12-15 16:42:18.000",false,"2020-06-03 13:10:02.494",6,70000,"2019-12-15 16:29:45.000",0,null]
오류 응답 예시
{
    "return_code": -1,
    "return_message": "The task is running"
}
Parameter name  |  Sample value  |  Parameter type  |  Parameter description  | 
|---|---|---|---|
return_code  |  -1  |  Integer  |  Return code  | 
return_message  |  The task is runningThe task is running  |  String  |  Return information  | 
Curl example
curl -X GET 'http://ta2:8992/open/sql-result-page?token=bTOzKiTIozG4e19FgXphcA8dDV3DIY8RwdHTO7aSnBsRqSNaIk19BnBMecJDWibD&taskId=119a3a37411f3000&pageId=1'
# 3. SQL 비동기 쿼리 API
SQL 비동기 쿼리 API에는 네 가지 관련 메서드가 포함되어 있습니다.
- 쿼리 문을 제출하고 쿼리의 작업 ID를 반환합니다.
 - 작업의 실행 상태를 조회합니다.
 - 쿼리 작업의 결과 데이터를 조회합니다.
 - 완료되지 않은 작업을 취소합니다.
 
# 쿼리 문 실행
인터페이스 URL
/open/submit-sql?token=xxx&format=json&sql=select * from v_user_0 limit 11000
요청 방법
POST
콘텐츠 유형
application/json
요청 쿼리 파라미터
Parameter name  |  Sample value  |  Parameter type  |  Is required  |  Parameter description  | 
|---|---|---|---|---|
token  |  xxx  |  String  |  Yes  |  token  | 
sql  |  select * from v_user_0 limit 11000  |  String  |  Yes  |  SQL statements for queries  | 
format  |  json  |  String  |  No  |  Row data format (json, csv, tsv), default json  | 
pageSize  |  1000  |  Integer  |  No  |  Number of lines per page, minimum 1000, no paging by default  | 
성공적인 응답 예시
{
  "data": {
    "taskId": "119a3a37411f3000"
  },
  "return_code": 0,
  "return_message": "success"
}
$$Parameter name  |  Sample value  |  Parameter type  |  Parameter description  | 
|---|---|---|---|
data  |  -  |  Object  |  Return result  | 
data.taskId  |  119a3a37411f3000  |  String  |  Task ID  | 
return_code  |  0  |  Integer  |  Return code  | 
return_message  |  success  |  String  |  Return information  | 
오류 응답 예시
{
    "return_code": -1008,
    "return_message": "The parameter (token) is empty"
}
Parameter name  |  Sample value  |  Parameter type  |  Parameter description  | 
|---|---|---|---|
return_code  |  -1008  |  Integer  |  Return code  | 
return_message  |  The parameter (token) is empty  |  String  |  Return information  | 
Curl example
curl -X POST 'http://ta2:8992/open/submit-sql?token=bTOzKiTIozG4e19FgXphcA8dDV3DIY8RwdHTO7aSnBsRqSNaIk19BnBMecJDWibD' --header 'Content-Type: application/x-www-form-urlencoded' -d 'sql=select * from v_user_0 limit 11000&format=json'
# 작업 실행 상태 조회
인터페이스 URL
/open/sql-task-info?token=xxx&taskId=119a3a37411f3000
요청 방법
GET
콘텐츠 유형
application/json
요청 쿼리 파라미터
Parameter name  |  Sample value  |  Parameter type  |  Is required  |  Parameter description  | 
|---|---|---|---|---|
token  |  xxx  |  String  |  Yes  |  token  | 
taskId  |  119a3a37411f3000  |  String  |  Yes  |  The interface executes the query statement and returns the taskId in the result  | 
성공적인 응답 예시
{
  "data": {
    "taskId": "119a3a37411f3000",
    "status": "FINISHED",
    "resultStat": {
        "rowCount": 11000,
        "pageCount": 1,
        "headers": [
          "#user_id",
          "#account_id",
          "#distinct_id",
          "#active_time",
          "#reg_time",
          "#user_operation",
          "#server_time",
          "#is_delete",
          "#update_time",
          "user_level",
          "coin_num",
          "register_time",
          "diamond_num",
          "first_recharge_time"
        ]
     }
  },
  "return_code": 0,
  "return_message": "success"
}
$$Parameter name  |  Sample value  |  Parameter type  |  Parameter description  | 
|---|---|---|---|
return_code  |  0  |  Integer  |  Return code  | 
return_message  |  success  |  String  |  Return information  | 
data  |  -  |  Object  |  Return result  | 
data.taskId  |  119a3a37411f3000  |  String  |  The ID of the query task, which is used for paging data of subsequent download results  | 
data.status  |  FINISHED  |  String  |  Task Status (RUNNING, FINISHED, FAILED)  | 
data.resultStat  |  -  |  Object  |  Result information, returned when the status is FINISHED  | 
data.resultStat.headers  |  ["#user_id"]  |  List  |  List of names  | 
data.resultStat.rowCount  |  11000  |  Integer  |  Total number of rows  | 
data.resultStat.pageCount  |  1  |  Integer  |  Total Pages  | 
오류 응답 예시
{
    "return_code": -1008,
    "return_message": "The parameter (token) is empty"
}
Parameter name  |  Sample value  |  Parameter type  |  Parameter description  | 
|---|---|---|---|
return_code  |  -1008  |  Integer  |  Return code  | 
return_message  |  The parameter (token) is empty  |  String  |  Return information  | 
Curl example
curl -X GET 'http://ta2:8992/open/sql-task-info?token=bTOzKiTIozG4e19FgXphcA8dDV3DIY8RwdHTO7aSnBsRqSNaIk19BnBMecJDWibD&taskId=119a3a37411f3000'
# 결과 페이지 데이터 다운로드
인터페이스 URL
/open/sql-result-page?token=xxx&taskId=119a3a37411f3000
요청 방법
GET
콘텐츠 유형
application/json
요청 쿼리 파라미터
Parameter name  |  Sample value  |  Parameter type  |  Is required  |  Parameter description  | 
|---|---|---|---|---|
token  |  xxx  |  String  |  Yes  |  token  | 
taskId  |  119a3a37411f3000  |  String  |  Yes  |  The interface executes the query statement and returns the taskId in the result  | 
pageId  |  0  |  Integer  |  No  |  Value range: [0, pageCount-1], default is 0  | 
반환 결과는 행 단위로 구분되며, 각 행의 데이터 형식은 쿼리 문을 실행할 때 지정된 형식입니다.
[9324080,"c21756080","c40404080","2019-12-15 16:09:07.000","2019-12-15 16:09:07.000","user_set","2019-12-15 16:22:13.000",false,"2020-06-03 13:10:02.494",6,40000,"2019-12-15 16:09:07.000",0,null]
[9328294,"q21765894","q40422294","2019-12-15 16:19:49.000","2019-12-15 16:19:49.000","user_set","2019-12-15 16:42:18.000",false,"2020-06-03 13:10:02.494",17,642440,"2019-12-15 16:19:49.000",112,"2019-12-15 16:26:13.000"]
[9335719,"t21783319","t40454719","2019-12-15 16:29:45.000","2019-12-15 16:29:45.000","user_set","2019-12-15 16:42:18.000",false,"2020-06-03 13:10:02.494",6,70000,"2019-12-15 16:29:45.000",0,null]
오류 응답 예시
{
    "return_code": -1008,
    "return_message": "The parameter (token) is empty"
}
Parameter name  |  Sample value  |  Parameter type  |  Parameter description  | 
|---|---|---|---|
return_code  |  -1008  |  Integer  |  Return code  | 
return_message  |  The parameter (token) is empty  |  String  |  Return information  | 
Curl example
curl -X GET 'http://ta2:8992/open/sql-result-page?token=bTOzKiTIozG4e19FgXphcA8dDV3DIY8RwdHTO7aSnBsRqSNaIk19BnBMecJDWibD&taskId=119a3a37411f3000'
# 완료되지 않은 작업 취소
인터페이스 URL
/open/cancel-sql-task?token=xxx&taskId=119a3a37411f3000
요청 방법
POST
콘텐츠 유형
application/json
요청 쿼리 파라미터
Parameter name  |  Sample value  |  Parameter type  |  Is required  |  Parameter description  | 
|---|---|---|---|---|
token  |  xxx  |  String  |  Yes  |  token  | 
taskId  |  119a3a37411f3000  |  String  |  Yes  |  The interface executes the query statement and returns the taskId in the result  | 
성공적인 응답 예시
{
  "return_code": 0,
  "return_message": "success"
}
오류 응답 예시
{
    "return_code": -1008,
    "return_message": "The parameter (token) is empty"
}
Parameter name  |  Sample value  |  Parameter type  |  Parameter description  | 
|---|---|---|---|
return_code  |  -1008  |  Integer  |  Return code  | 
return_message  |  The parameter (token) is empty  |  String  |  Return information  | 
Curl Example
curl -X POST 'http://ta2:8992/open/cancel-sql-task?token=bTOzKiTIozG4e19FgXphcA8dDV3DIY8RwdHTO7aSnBsRqSNaIk19BnBMecJDWibD&taskId=119a3a37411f3000'
