데이터셋 스키마 추가(Put Dataset Schema) (V2)
기존 데이터셋에 PUT 요청으로 스키마를 추가합니다. 대상 데이터셋에 파일을 올릴 때는 이 스키마와 일치해야 합니다.
경로의 datasetRid는 필수 문자열이며 쿼리 매개변수는 없습니다. 본문은 필수 PutDatasetSchemaRequest 객체입니다.
요청 본문 필드
| 필드 | 자료형 | 필수 여부 | 의미 |
|---|---|---|---|
branchName | string | 선택 | 스키마를 추가할 브랜치 이름 |
dataframeReader | enum | 선택 | AVRO, CSV, PARQUET, DATASOURCE. 기본값은 PARQUET |
endTransactionRid | string | 선택 | 끝 트랜잭션 RID |
schema | object | 필수 | 추가할 데이터셋 스키마 |
schema.fieldSchemaList는 열 정의 목록입니다. 각 항목의 type과 nullable은 필수이며 ARRAY, DECIMAL, MAP, STRUCT에는 유형별 하위 설정을 사용할 수 있습니다. userDefinedTypeClass는 Spark UserDefinedType의 하위 클래스여야 합니다. 전체 필드와 예시는 스키마 자료형에 설명되어 있습니다.
응답
응답은 GetDatasetSchemaResponse입니다. branchName, endTransactionRid, schema, versionId를 모두 반환하며, 요청한 스키마의 데이터셋과 버전 정보를 확인할 수 있습니다.
HTTP 요청
PUT /api/v2/datasets/{datasetRid}/putSchema
작업 식별자는 v2.putDatasetSchema입니다. Authorization: Bearer <접근 토큰> 헤더로 인증합니다. OAuth 클라이언트에는 api:datasets-write 권한 범위가 필요합니다.
JSON 요청 예시
가상 데이터셋을 대상으로 하는 요청 본문 예시입니다.
{
"endTransactionRid": "ri.foundry.main.transaction.0a0207cb-26b7-415b-bc80-66a3aa3933f4",
"schema": {
"fieldSchemaList": [
{
"name": "id",
"type": "LONG",
"nullable": false,
"customMetadata": {
"description": "Primary key"
}
},
{
"name": "event_time",
"type": "TIMESTAMP",
"nullable": false
},
{
"name": "price",
"type": "DECIMAL",
"precision": 10,
"scale": 2,
"nullable": true
},
{
"name": "tags",
"type": "ARRAY",
"nullable": true,
"arraySubtype": {
"type": "STRING",
"nullable": false
}
},
{
"name": "metrics",
"type": "STRUCT",
"nullable": true,
"subSchemas": [
{
"name": "temperature",
"type": "DOUBLE",
"nullable": true
},
{
"name": "humidity",
"type": "DOUBLE",
"nullable": true
}
]
}
]
},
"dataframeReader": "PARQUET",
"branchName": "master"
}
JSON 응답 예시
가상 데이터셋의 응답 예시입니다.
{
"endTransactionRid": "ri.foundry.main.transaction.0a0207cb-26b7-415b-bc80-66a3aa3933f4",
"schema": {
"fieldSchemaList": [
{
"name": "id",
"type": "LONG",
"nullable": false,
"customMetadata": {
"description": "Primary key"
}
},
{
"name": "event_time",
"type": "TIMESTAMP",
"nullable": false
},
{
"name": "price",
"type": "DECIMAL",
"precision": 10,
"scale": 2,
"nullable": true
},
{
"name": "tags",
"type": "ARRAY",
"nullable": true,
"arraySubtype": {
"type": "STRING",
"nullable": false
}
},
{
"name": "metrics",
"type": "STRUCT",
"nullable": true,
"subSchemas": [
{
"name": "temperature",
"type": "DOUBLE",
"nullable": true
},
{
"name": "humidity",
"type": "DOUBLE",
"nullable": true
}
]
}
]
},
"versionId": "0000000d-2acf-537c-a228-3a9fe3cdc523",
"branchName": "master"
}
개별 오류
| 오류 이름 | 오류 코드 | HTTP | 의미와 조건 | 추가 매개변수 |
|---|---|---|---|---|
BranchNotFound | NOT_FOUND | 404 | 브랜치를 찾을 수 없거나 토큰이 접근할 수 없습니다. | datasetRid, branchName |
DatasetNotFound | NOT_FOUND | 404 | 데이터셋을 찾을 수 없거나 토큰이 접근할 수 없습니다. | datasetRid |
InvalidSchema | INVALID_ARGUMENT | 400 | 스키마 검증에 실패했습니다. errorType과 message로 원인을 확인합니다. | errorType, message |
DatasetViewNotFound | NOT_FOUND | 404 | 트랜잭션에서 계산한 해당 브랜치와 시점의 데이터셋 뷰를 찾을 수 없습니다. 트랜잭션이나 파일이 없거나, 브랜치가 유효하지 않거나, 토큰이 접근할 수 없는 경우에 발생할 수 있습니다. | datasetRid, branch |
PutDatasetSchemaPermissionDenied | PERMISSION_DENIED | 403 | 데이터셋 스키마 추가 권한이 거부되었습니다. | datasetRid |
요청 예제
FOUNDRY_HOST에는 https://를 제외한 Foundry 호스트를, FOUNDRY_TOKEN에는 유효한 토큰을 환경 변수로 제공합니다. 아래 RID, 이름과 파일 경로는 예시이며 실제 작업 대상으로 바꾸어야 합니다.
cURL
curl -X PUT \
-H "Content-type: application/json" \
-H "Authorization: Bearer ${FOUNDRY_TOKEN}" \
"https://${FOUNDRY_HOST}/api/v2/datasets/ri.foundry.main.dataset.c26f11c8-cdb3-4f44-9f5d-9816ea1c82da/putSchema" \
-d '{"endTransactionRid":"ri.foundry.main.transaction.0a0207cb-26b7-415b-bc80-66a3aa3933f4","schema":{"fieldSchemaList":[{"name":"id","type":"LONG","nullable":false,"customMetadata":{"description":"Primary key"}},{"name":"event_time","type":"TIMESTAMP","nullable":false},{"name":"price","type":"DECIMAL","precision":10,"scale":2,"nullable":true},{"name":"tags","type":"ARRAY","nullable":true,"arraySubtype":{"type":"STRING","nullable":false}},{"name":"metrics","type":"STRUCT","nullable":true,"subSchemas":[{"name":"temperature","type":"DOUBLE","nullable":true},{"name":"humidity","type":"DOUBLE","nullable":true}]}]},"dataframeReader":"PARQUET","branchName":"master"}'
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 = {
"endTransactionRid": "ri.foundry.main.transaction.0a0207cb-26b7-415b-bc80-66a3aa3933f4",
"schema": {
"fieldSchemaList": [
{
"name": "id",
"type": "LONG",
"nullable": False,
"customMetadata": {
"description": "Primary key"
}
},
{
"name": "event_time",
"type": "TIMESTAMP",
"nullable": False
},
{
"name": "price",
"type": "DECIMAL",
"precision": 10,
"scale": 2,
"nullable": True
},
{
"name": "tags",
"type": "ARRAY",
"nullable": True,
"arraySubtype": {
"type": "STRING",
"nullable": False
}
},
{
"name": "metrics",
"type": "STRUCT",
"nullable": True,
"subSchemas": [
{
"name": "temperature",
"type": "DOUBLE",
"nullable": True
},
{
"name": "humidity",
"type": "DOUBLE",
"nullable": True
}
]
}
]
},
"dataframeReader": "PARQUET",
"branchName": "master"
}
response = requests.put('https://{}/api/v2/datasets/ri.foundry.main.dataset.c26f11c8-cdb3-4f44-9f5d-9816ea1c82da/putSchema'.format(HOSTNAME), headers=headers, json=request_body)
print(response)
Java
Apache HttpClient 4.5 API와 try-with-resources를 사용하는 예제입니다. 클래스 이름에 맞는 PutDatasetSchemaExample.java 파일에서 사용합니다.
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPut;
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 PutDatasetSchemaExample {
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()) {
HttpPut request = new HttpPut("https://" + HOSTNAME + "/api/v2/datasets/ri.foundry.main.dataset.c26f11c8-cdb3-4f44-9f5d-9816ea1c82da/putSchema");
request.addHeader("content-type", "application/json");
request.addHeader("authorization", String.format("Bearer %s", TOKEN));
request.setEntity(new StringEntity("{\"endTransactionRid\":\"ri.foundry.main.transaction.0a0207cb-26b7-415b-bc80-66a3aa3933f4\",\"schema\":{\"fieldSchemaList\":[{\"name\":\"id\",\"type\":\"LONG\",\"nullable\":false,\"customMetadata\":{\"description\":\"Primary key\"}},{\"name\":\"event_time\",\"type\":\"TIMESTAMP\",\"nullable\":false},{\"name\":\"price\",\"type\":\"DECIMAL\",\"precision\":10,\"scale\":2,\"nullable\":true},{\"name\":\"tags\",\"type\":\"ARRAY\",\"nullable\":true,\"arraySubtype\":{\"type\":\"STRING\",\"nullable\":false}},{\"name\":\"metrics\",\"type\":\"STRUCT\",\"nullable\":true,\"subSchemas\":[{\"name\":\"temperature\",\"type\":\"DOUBLE\",\"nullable\":true},{\"name\":\"humidity\",\"type\":\"DOUBLE\",\"nullable\":true}]}]},\"dataframeReader\":\"PARQUET\",\"branchName\":\"master\"}", 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/datasets/ri.foundry.main.dataset.c26f11c8-cdb3-4f44-9f5d-9816ea1c82da/putSchema`, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${TOKEN}`,
},
body: '{"endTransactionRid":"ri.foundry.main.transaction.0a0207cb-26b7-415b-bc80-66a3aa3933f4","schema":{"fieldSchemaList":[{"name":"id","type":"LONG","nullable":false,"customMetadata":{"description":"Primary key"}},{"name":"event_time","type":"TIMESTAMP","nullable":false},{"name":"price","type":"DECIMAL","precision":10,"scale":2,"nullable":true},{"name":"tags","type":"ARRAY","nullable":true,"arraySubtype":{"type":"STRING","nullable":false}},{"name":"metrics","type":"STRUCT","nullable":true,"subSchemas":[{"name":"temperature","type":"DOUBLE","nullable":true},{"name":"humidity","type":"DOUBLE","nullable":true}]}]},"dataframeReader":"PARQUET","branchName":"master"}'
}).then((response) => {
console.log(response)
});
PowerShell
$TOKEN = $env:FOUNDRY_TOKEN
$HOSTNAME = $env:FOUNDRY_HOST
$headers = @{
"authorization" = "Bearer $TOKEN"
}
$response = Invoke-WebRequest -Uri "https://$HOSTNAME/api/v2/datasets/ri.foundry.main.dataset.c26f11c8-cdb3-4f44-9f5d-9816ea1c82da/putSchema" `
-Method Put `
-Headers $headers `
-ContentType application/json `
-Body "{`"endTransactionRid`":`"ri.foundry.main.transaction.0a0207cb-26b7-415b-bc80-66a3aa3933f4`",`"schema`":{`"fieldSchemaList`":[{`"name`":`"id`",`"type`":`"LONG`",`"nullable`":false,`"customMetadata`":{`"description`":`"Primary key`"}},{`"name`":`"event_time`",`"type`":`"TIMESTAMP`",`"nullable`":false},{`"name`":`"price`",`"type`":`"DECIMAL`",`"precision`":10,`"scale`":2,`"nullable`":true},{`"name`":`"tags`",`"type`":`"ARRAY`",`"nullable`":true,`"arraySubtype`":{`"type`":`"STRING`",`"nullable`":false}},{`"name`":`"metrics`",`"type`":`"STRUCT`",`"nullable`":true,`"subSchemas`":[{`"name`":`"temperature`",`"type`":`"DOUBLE`",`"nullable`":true},{`"name`":`"humidity`",`"type`":`"DOUBLE`",`"nullable`":true}]}]},`"dataframeReader`":`"PARQUET`",`"branchName`":`"master`"}"
$response.content