객체 유형 집계(Aggregate Objects) (V2)
온톨로지의 한 객체 유형에서 필터에 맞는 객체를 집계합니다. aggregation으로 계산할 지표를, groupBy로 그룹 구분을 지정합니다.
집계 함수와 정확도에서 8개 함수, 4개 그룹 방식과 응답의 accuracy 및 excludedItems를 확인합니다. 예시의 날짜 범위는 시작을 포함하고 끝을 제외합니다.
HTTP 요청
POST /api/v2/ontologies/{ontology}/objects/{objectType}/aggregate
작업 식별자는 v2.aggregateObjectsV2입니다. OAuth2로 호출하는 타사 애플리케이션에는 api:ontologies-read 권한 범위가 필요합니다. 각 요청에 Authorization: Bearer <접근 토큰>을 전달합니다.
경로 매개변수
| 이름 | 자료형 | 필수 여부 | 의미와 조건 | 예시 값 |
|---|---|---|---|---|
ontology | string | 필수 | 온톨로지의 API 이름 또는 RID입니다. List Ontologies 또는 Ontology Manager에서 확인합니다. | palantir |
objectType | string | 필수 | 집계할 객체 유형입니다. | employee |
쿼리 매개변수
| 이름 | 자료형 | 필수 여부 | 의미와 조건 | 예시 값 |
|---|---|---|---|---|
sdkPackageRid | string | 선택 | 생성된 SDK 패키지의 RID입니다. | |
sdkVersion | string | 선택 | 생성된 SDK의 버전입니다. | |
branch | string | 선택 | 집계할 Foundry 브랜치입니다. 생략하면 기본 브랜치를 사용합니다. 브랜치는 실험적 기능이며 일부 작업 경로는 지원하지 않습니다. | ri.branch..branch.d827184f-ee0e-4351-8b70-efbe51e07252 |
요청 본문
본문 형식은 AggregateObjectsRequestV2이며 필수입니다.
| 이름 | 자료형 | 필수 여부 | 의미와 조건 | 예시 값 |
|---|---|---|---|---|
aggregation | list<AggregationV2> | 선택 | ||
where | SearchJsonQueryV2 | 선택 | ||
groupBy | list<AggregationGroupByV2> | 선택 | ||
accuracy | enum | 선택 | REQUIRE_ACCURATE는 정확성을 보장할 수 있을 때만 결과를 반환하며, 보장할 수 없으면 AggregationAccuracyNotSupported 오류가 발생합니다. ALLOW_APPROXIMATE는 정확한 계산이 어려울 때 근사 결과를 허용하며 기본 동작입니다. 허용값: REQUIRE_ACCURATE, ALLOW_APPROXIMATE. |
aggregation의 구조
배열 항목은 AggregationV2이며 자료형은 AggregationV2입니다.
집계 함수입니다.
8개 함수의 필드는 집계 함수를 따릅니다.
where의 구조
검색 조건의 28개 분기를 사용합니다.
groupBy의 구조
배열 항목은 AggregationGroupByV2이며 자료형은 AggregationGroupByV2입니다.
집계 결과의 그룹 구분 방식입니다.
4개 그룹 방식은 그룹 구분을 따릅니다.
필터와 그룹을 지정하고 tenure의 최솟값과 평균을 계산하는 요청 본문입니다.
{
"aggregation": [
{
"type": "min",
"field": "tenure",
"name": "min_tenure"
},
{
"type": "avg",
"field": "tenure",
"name": "avg_tenure"
}
],
"where": {
"type": "eq",
"field": "name",
"value": "john"
},
"groupBy": [
{
"field": "startDate",
"type": "ranges",
"ranges": [
{
"startValue": "2020-01-01",
"endValue": "2020-06-01"
}
]
},
{
"field": "city",
"type": "exact"
}
]
}
응답
응답 형식은 AggregateObjectsResponseV2입니다.
전체 응답 구조는 집계 응답을 따릅니다.
그룹별 집계 결과의 응답 예시입니다.
{
"data": [
{
"metrics": [
{
"name": "min_tenure",
"value": 1
},
{
"name": "avg_tenure",
"value": 3
}
],
"group": {
"startDate": {
"startValue": "2020-01-01",
"endValue": "2020-06-01"
},
"city": "New York City"
}
},
{
"metrics": [
{
"name": "min_tenure",
"value": 2
},
{
"name": "avg_tenure",
"value": 3
}
],
"group": {
"startDate": {
"startValue": "2020-01-01",
"endValue": "2020-06-01"
},
"city": "San Francisco"
}
}
],
"accuracy": "ACCURATE"
}
개별 오류
오류 응답 처리는 공통 API 오류 계약을 따릅니다.
요청 예제
FOUNDRY_HOST에는 https://를 제외한 Foundry 호스트를, FOUNDRY_TOKEN에는 유효한 토큰을 환경 변수로 제공합니다. 예시 식별자와 매개변수 값은 실제 작업 대상에 맞게 바꿉니다.
온톨로지와 객체 유형의 API 이름, 집계 및 필터 조건, 브랜치는 실제 대상에 맞게 바꿉니다. 기본 브랜치를 사용할 때는 branch를 생략합니다.
cURL
curl -X POST \
-H "Content-type: application/json" \
-H "Authorization: Bearer ${FOUNDRY_TOKEN}" \
"https://${FOUNDRY_HOST}/api/v2/ontologies/palantir/objects/employee/aggregate?branch=ri.branch..branch.d827184f-ee0e-4351-8b70-efbe51e07252" \
-d '{"aggregation":[{"type":"min","field":"tenure","name":"min_tenure"},{"type":"avg","field":"tenure","name":"avg_tenure"}],"where":{"type":"eq","field":"name","value":"john"},"groupBy":[{"field":"startDate","type":"ranges","ranges":[{"startValue":"2020-01-01","endValue":"2020-06-01"}]},{"field":"city","type":"exact"}]}'
Python
Requests 라이브러리가 설치된 Python 환경에서 사용합니다.
import os
import requests
HOSTNAME = os.environ["FOUNDRY_HOST"]
TOKEN = os.environ["FOUNDRY_TOKEN"]
headers = {
"content-type": "application/json",
"authorization": "Bearer {}".format(TOKEN)
}
request_body = {'aggregation': [{'type': 'min', 'field': 'tenure', 'name': 'min_tenure'}, {'type': 'avg', 'field': 'tenure', 'name': 'avg_tenure'}], 'where': {'type': 'eq', 'field': 'name', 'value': 'john'}, 'groupBy': [{'field': 'startDate', 'type': 'ranges', 'ranges': [{'startValue': '2020-01-01', 'endValue': '2020-06-01'}]}, {'field': 'city', 'type': 'exact'}]}
response = requests.post('https://{}/api/v2/ontologies/palantir/objects/employee/aggregate?branch=ri.branch..branch.d827184f-ee0e-4351-8b70-efbe51e07252'.format(HOSTNAME), headers=headers, json=request_body)
print(response)
Java
Apache HttpClient 4.5 API와 try-with-resources를 사용합니다. 클래스 이름에 맞는 AggregateObjectsV2Example.java 파일에서 사용합니다.
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
public class AggregateObjectsV2Example {
public static void main(String[] args) throws Exception {
String HOSTNAME = System.getenv("FOUNDRY_HOST");
String TOKEN = System.getenv("FOUNDRY_TOKEN");
try (CloseableHttpClient httpClient = HttpClientBuilder.create().build()) {
HttpPost request = new HttpPost("https://" + HOSTNAME + "/api/v2/ontologies/palantir/objects/employee/aggregate?branch=ri.branch..branch.d827184f-ee0e-4351-8b70-efbe51e07252");
request.addHeader("content-type", "application/json");
request.addHeader("authorization", String.format("Bearer %s", TOKEN));
request.setEntity(new StringEntity("{\"aggregation\":[{\"type\":\"min\",\"field\":\"tenure\",\"name\":\"min_tenure\"},{\"type\":\"avg\",\"field\":\"tenure\",\"name\":\"avg_tenure\"}],\"where\":{\"type\":\"eq\",\"field\":\"name\",\"value\":\"john\"},\"groupBy\":[{\"field\":\"startDate\",\"type\":\"ranges\",\"ranges\":[{\"startValue\":\"2020-01-01\",\"endValue\":\"2020-06-01\"}]},{\"field\":\"city\",\"type\":\"exact\"}]}", ContentType.APPLICATION_JSON));
try (CloseableHttpResponse response = httpClient.execute(request)) {
System.out.println(response);
}
}
}
}
JavaScript
fetch를 제공하는 Node.js 환경에서 사용합니다. 서비스 사용자 토큰을 브라우저로 전달하지 않습니다.
const HOSTNAME = process.env.FOUNDRY_HOST;
const TOKEN = process.env.FOUNDRY_TOKEN;
fetch(`https://${HOSTNAME}/api/v2/ontologies/palantir/objects/employee/aggregate?branch=ri.branch..branch.d827184f-ee0e-4351-8b70-efbe51e07252`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${TOKEN}`,
},
body: '{"aggregation":[{"type":"min","field":"tenure","name":"min_tenure"},{"type":"avg","field":"tenure","name":"avg_tenure"}],"where":{"type":"eq","field":"name","value":"john"},"groupBy":[{"field":"startDate","type":"ranges","ranges":[{"startValue":"2020-01-01","endValue":"2020-06-01"}]},{"field":"city","type":"exact"}]}'
}).then((response) => {
console.log(response)
});
PowerShell
$ErrorActionPreference = 'Stop'
$TOKEN = $env:FOUNDRY_TOKEN
$HOSTNAME = $env:FOUNDRY_HOST
$headers = @{
"authorization" = "Bearer $TOKEN"
}
$response = Invoke-WebRequest -Uri "https://$HOSTNAME/api/v2/ontologies/palantir/objects/employee/aggregate?branch=ri.branch..branch.d827184f-ee0e-4351-8b70-efbe51e07252" `
-Method Post `
-Headers $headers `
-ContentType application/json `
-Body "{`"aggregation`":[{`"type`":`"min`",`"field`":`"tenure`",`"name`":`"min_tenure`"},{`"type`":`"avg`",`"field`":`"tenure`",`"name`":`"avg_tenure`"}],`"where`":{`"type`":`"eq`",`"field`":`"name`",`"value`":`"john`"},`"groupBy`":[{`"field`":`"startDate`",`"type`":`"ranges`",`"ranges`":[{`"startValue`":`"2020-01-01`",`"endValue`":`"2020-06-01`"}]},{`"field`":`"city`",`"type`":`"exact`"}]}"
$response.content