注: 以下の翻訳の正確性は検証されていません。AIPを利用して英語版の原文から機械的に翻訳されたものです。
TypeScript 関数をレジストリに公開するには、すべての入力パラメーターに明示的な型注釈を付け、戻り値の型を明示的に指定する必要があります。現在サポートされている関数レジストリのデータ型と、それぞれに対応する言語のデータ型の一覧を以下に示します。
Pipeline Builder で Python 関数をユーザー定義関数(UDF)として使用していますか?以下のスカラー型(str や int など)は、UDF が返す値のデータ型です。これは、関数が行ごとに1回実行され、その戻り値が新しい列になるためです。DataFrame を返すわけではありません。詳しくは、Pipeline Builder で Python 関数がデータを処理する仕組みを参照してください。
| 関数レジストリのデータ型 | TypeScript v1 のデータ型 | TypeScript v2 のデータ型 | Python のデータ型 | |
|---|---|---|---|---|
| 添付ファイル | Attachment | Attachment | Attachment | 例 |
| ブール値 | boolean | boolean | bool | 例 |
| バイナリ | 非対応 | 非対応 | bytes | 例 |
| Byte | 非対応 | 非対応 | int* | 例 |
| 機密情報区分マーキング | ClassificationMarking | ClassificationMarking | ClassificationMarking | 例 |
| 日付 | LocalDate | DateISOString | datetime.date | 例 |
| Decimal | 非対応 | 非対応 | decimal.Decimal | 例 |
| Double | Double | Double | float* | 例 |
| Float | Float | Float | float | 例 |
| Geopoint | GeoPoint | Point | GeoPoint | 例 |
| Geoshape | GeoShape | Geometry | GeoShape | 例 |
| グループ | Group | GroupId | GroupId | 例 |
| Integer | Integer | Integer | int | 例 |
| インターフェース | 非対応 | Osdk.Instance<MyInterface> | 非対応 | 例 |
| インターフェースオブジェクトセット | 非対応 | ObjectSet<MyInterface> | 非対応 | 例 |
| リスト | T[] または Array<T> | T[] または Array<T> | list[T] | 例 |
| Long | Long | Long | int* | 例 |
| 必須マーキング | MandatoryMarking | MandatoryMarking | MandatoryMarking | 例 |
| マップ | FunctionsMap<K, V> | Record<K, V> | dict[K, V] | 例 |
| Media Reference | MediaItem | Media | Media | 例 |
| 通知 | Notification | Notification | Notification | 例 |
| オブジェクト | MyObjectType | Osdk.Instance<MyObjectType> | MyObjectType | 例 |
| オブジェクトセット | ObjectSet<MyObjectType> | ObjectSet<MyObjectType> | MyObjectTypeObjectSet | 例 |
| オントロジーの編集 | void | Edits | OntologyEdit | 例 |
| 任意 | T | undefined | T | undefined | typing.Optional または T | None | 例 |
| プリンシパル | Principal | Principal | Principal | 例 |
| 範囲 | IRange<T> | Range<T> | Range[T] | 例 |
| 集合 | Set<T> | 非対応 | set[T] | 例 |
| Short | 非対応 | 非対応 | int* | 例 |
| 文字列 | string | string | str | 例 |
| 構造体/カスタム型 | interface | interface | dataclasses.dataclass | 例 |
| タイムスタンプ | Timestamp | TimestampISOString | datetime.datetime | 例 |
| 2次元集計 | TwoDimensionalAggregation<K, V> | TwoDimensionalAggregation<K, V> | TwoDimensionalAggregation[K, V] | 例 |
| 3次元集計 | ThreeDimensionalAggregation<K, S, V> | ThreeDimensionalAggregation<K, S, V> | ThreeDimensionalAggregation[K, S, V] | 例 |
| ユーザー | User | UserId | UserId | 例 |
Integer と Long はどちらも Python の int 型に対応しますが、関数シグネチャで直接 int として指定されたフィールドは、Integer 型として登録されます。そのため、数値データ型を登録するには、代わりに API の Integer 型または Long 型を使用することを推奨します。Float と Double にも同様の指針が適用されます。関数シグネチャに Python の float 型が直接記述されている場合、デフォルトで Float として登録されます。
スカラー型は単一の値を表し、一般にテキスト、数値、または日時のデータを保持するために使用されます。
JavaScript と TypeScript には、整数値と浮動小数点値の両方を表すために一般的に使用される number 型があります。型の検証と構造をさらに強化するため、TypeScript v1 関数では @foundry/functions-api パッケージから、TypeScript v2 関数では @osdk/functions パッケージからエクスポートされる数値型のエイリアスのみをサポートしています。同様に、Python 関数で数値型を扱う場合は、functions.api モジュールからエクスポートされる型エイリアスの使用を推奨します。
Copied!1 2 3 4 5 6 7 8import { Function, Integer } from "@foundry/functions-api"; export class MyFunctions { @Function() public isEven(num: Integer): boolean { return num % 2 === 0; } }
Copied!1 2 3 4 5 6 7import { Integer } from "@osdk/functions"; function isEven(num: Integer): boolean { return num % 2 === 0; } export default isEven;
Copied!1 2 3 4 5from functions.api import function, Integer @function def is_even(num: Integer) -> bool: return n % 2 == 0
Copied!1 2 3 4 5 6 7 8import { Function } from "@foundry/functions-api"; export class MyFunctions { @Function() public greet(name: string): string { return `Hello, ${name}!`; } }
Copied!1 2 3 4 5function greet(name: string): string { return `Hello, ${name}!`; } export default greet;
Copied!1 2 3 4 5from functions.api import function @function def greet(name: str) -> str: return f"Hello, {name}!"
-32,768から32,767までの整数値を表します。
Python 関数では、Short 型は組み込みの int 型のエイリアスです。
Copied!1 2 3 4 5from functions.api import function, Short @function def increment(num: Short) -> Short: return num + 1
(-231) から (231 - 1) までの整数値を表します。
Integer 型は組み込みの number 型のエイリアスです。Integer 型は組み込みの int 型のエイリアスです。Copied!1 2 3 4 5 6 7 8import { Function, Integer } from "@foundry/functions-api"; export class MyFunctions { @Function() public sum(a: Integer, b: Integer): Integer { return a + b; } }
Copied!1 2 3 4 5 6 7import { Integer } from "@osdk/functions"; function sum(a: Integer, b: Integer): Integer { return a + b; } export default sum;
Copied!1 2 3 4 5from functions.api import function, Integer @function def sum(a: Integer, b: Integer) -> Integer: return a + b
-(253 - 1) から (253 - 1) までの整数値を表します。これらの境界値は、ブラウザーのコンテキストから関数を呼び出す際に精度が失われるのを防ぐため、JavaScript の Number.MIN_SAFE_INTEGER および Number.MAX_SAFE_INTEGER と同じ値になっています。
Long 型は組み込みの number 型のエイリアスです。TypeScript v2 関数では、Long 型は組み込みの string 型のエイリアスです。Long 型は組み込みの int 型のエイリアスです。Copied!1 2 3 4 5 6 7 8import { Function, Long } from "@foundry/functions-api"; export class MyFunctions { @Function() public subtract(a: Long, b: Long): string { return (BigInt(a) - BigInt(b)).toString(); } }
Copied!1 2 3 4 5 6 7import { Long } from "@osdk/functions"; function subtract(a: Long, b: Long): string { return (BigInt(a) - BigInt(b)).toString(); } export default subtract;
Copied!1 2 3 4 5from functions.api import function, Long @function def subtract(a: Long, b: Long) -> str: return str(a - b)
32ビットの浮動小数点数を表します。
Float 型は組み込みの number 型のエイリアスです。Float 型は組み込みの float 型のエイリアスです。Copied!1 2 3 4 5 6 7 8import { Float, Function } from "@foundry/functions-api"; export class MyFunctions { @Function() public multiply(a: Float, b: Float): Float { return a * b; } }
Copied!1 2 3 4 5 6 7import { Float } from "@osdk/functions"; function multiply(a: Float, b: Float): Float { return a * b; } export default multiply;
Copied!1 2 3 4 5from functions.api import function, Float @function def multiply(a: Float, b: Float) -> Float: return a * b
64ビットの浮動小数点数を表します。
Double 型は組み込みの number 型のエイリアスです。Double 型は組み込みの float 型のエイリアスです。Copied!1 2 3 4 5 6 7 8import { Double, Function } from "@foundry/functions-api"; export class MyFunctions { @Function() public divide(a: Double, b: Double): Double { return a / b; } }
Copied!1 2 3 4 5 6 7import { Double } from "@osdk/functions"; function divide(a: Double, b: Double): Double { return a / b; } export default divide;
Copied!1 2 3 4 5from functions.api import function, Double @function def divide(a: Double, b: Double) -> Double: return a / b
Copied!1 2 3 4 5 6from decimal import Decimal from functions.api import function @function def return_pi() -> Decimal: return Decimal('3.1415926535')
暦日を表します。
Copied!1 2 3 4 5 6 7 8import { Function, LocalDate } from "@foundry/functions-api"; export class MyFunctions { @Function() public returnDate(): LocalDate { return LocalDate.fromISOString("1999-10-17"); } }
Copied!1 2 3 4 5 6 7import { DateISOString } from "@osdk/functions"; function returnDate(): DateISOString { return "1999-10-17"; } export default returnDate;
Copied!1 2 3 4 5 6from datetime import date from functions.api import function, Date @function def return_date() -> Date: return date.fromisoformat('1999-10-17')
時間上のある瞬間を表します。
Copied!1 2 3 4 5 6 7 8import { Function, Timestamp } from "@foundry/functions-api"; export class MyFunctions { @Function() public getCurrentTimestamp(): Timestamp { return Timestamp.now(); } }
Copied!1 2 3 4 5 6 7 8import { TimestampISOString } from "@osdk/functions"; function getCurrentTimestamp(): TimestampISOString { const now = new Date(); return now.toISOString(); } export default getCurrentTimestamp;
Copied!1 2 3 4 5 6from datetime import datetime from functions.api import function, Timestamp @function def get_current_timestamp() -> Timestamp: return datetime.now()
Python 関数では、Binary 型は組み込みの bytes 型のエイリアスです。
Copied!1 2 3 4 5from functions.api import function @function def encode_utf8(param: str) -> bytes: return param.encode('utf-8')
Python 関数では、Byte 型は組み込みの int 型のエイリアスです。
Copied!1 2 3 4 5 6 7from functions.api import function, Byte @function def get_first_byte(param: str) -> Byte: if len(param) == 0: raise Exception("String length cannot be zero.") return param.encode('utf-8')[0]
マーキングは、データにアクセスするユーザーに特定のマーキングを要求することでアクセスを制限する、強制アクセス制御です。
Copied!1 2 3 4 5 6 7 8 9 10 11import { OntologyEditFunction, MandatoryMarking } from "@foundry/functions-api"; import { Employee, Objects } from "@foundry/ontology-api"; export class MyFunctions { @Edits(Employee) @OntologyEditFunction() public async editMandatoryMarkings(markings: MandatoryMarking[]): Promise<void> { const employeeOne = Objects.search().employee().filter(e => e.id.exactMatch(1)).all()[0]; employeeOne.markingsProperty = markings; } }
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16import { Client } from "@osdk/client"; import { Employee } from "@ontology/sdk"; import { Edits, createEditBatch, MandatoryMarking } from "@osdk/functions"; type OntologyEdit = Edits.Object<Employee>; function editMandatoryMarkings(markings: MandatoryMarking[]): OntologyEdit[] { const batch = createEditBatch<OntologyEdit>(client); const employeeOne = await client(Employee).fetchOne(1); batch.update(employeeOne, { markingsProperty: markings }); return batch.getEdits(); } export default editMandatoryMarkings;
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18from foundry_sdk_runtime import Marking from functions.api import function, MandatoryMarking, OntologyEdit from ontology_sdk import FoundryClient from ontology_sdk.ontology.objects import Employee @function def edit_mandatory_markings(markings: list[MandatoryMarking]) -> list[OntologyEdit]: ontology_edits = FoundryClient().ontology.edits() employee: Optional[Employee] = client.ontology.objects.Employee.get("primary_key") if employee is None: return [] editable_employee = ontology_edits.objects.Employee.edit(employee) editable_employee.markings_property = [Marking(m) for m in markings] # "list[MandatoryMarking]" 型の値を代入することもできますが、LSP の警告が表示されます。 # editable_employee.markings_property = markings return ontology_edits.get_edits()
機密情報区分に基づくアクセス制御(CBAC)は、政府の機密情報を保護するために使用される強制アクセス制御です。情報にアクセスするユーザーに特定の機密情報区分マーキングを要求することで、アクセスを制限します。
Copied!1 2 3 4 5 6 7 8 9 10 11import { OntologyEditFunction, ClassificationMarking } from "@foundry/functions-api"; import { Employee, Objects } from "@foundry/ontology-api"; export class MyFunctions { @Edits(Employee) @OntologyEditFunction() public async editClassificationMarkings(markings: ClassificationMarking[]): Promise<void> { const employeeOne = Objects.search().employee().filter(e => e.id.exactMatch(1)).all()[0]; employeeOne.markingsProperty = markings; } }
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16import { Client } from "@osdk/client"; import { Employee } from "@ontology/sdk"; import { Edits, createEditBatch, ClassificationMarking } from "@osdk/functions"; type OntologyEdit = Edits.Object<Employee>; function editClassificationMarkings(markings: ClassificationMarking[]): OntologyEdit[] { const batch = createEditBatch<OntologyEdit>(client); const employeeOne = await client(Employee).fetchOne(1); batch.update(employeeOne, { markingsProperty: markings }); return batch.getEdits(); } export default editClassificationMarkings;
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18from foundry_sdk_runtime import Marking from functions.api import ClassificationMarking, function, OntologyEdit from ontology_sdk import FoundryClient from ontology_sdk.ontology.objects import Employee @function def edit_classification_markings(markings: list[ClassificationMarking]) -> list[OntologyEdit]: ontology_edits = FoundryClient().ontology.edits() employee: Optional[Employee] = client.ontology.objects.Employee.get("primary_key") if employee is None: return [] editable_employee = ontology_edits.objects.Employee.edit(employee) editable_employee.markings_property = [Marking(m) for m in markings] # "list[ClassificationMarking]" 型の値を代入することもできますが、LSP の警告が表示されます。 # editable_employee.markings_property = markings return ontology_edits.get_edits()
コレクション型は、ほかのデータ型をパラメーターとして取ります。たとえば、Array[String] は文字列のリストで、Map[String, Integer] は文字列のキーと整数値を持つ辞書です。パラメーターとなるデータ型は必ず指定する必要があり、サポートされているほかのデータ型でなければなりません。マップのキーに使用できるのは、スカラー型またはオントロジーのオブジェクトタイプのみです。
Copied!1 2 3 4 5 6 7 8import { Function, Integer } from "@foundry/functions-api"; export class MyFunctions { @Function() public filterForEvenIntegers(nums: Integer[]): Integer[] { return nums.filter(num => num % 2 === 0); } }
Copied!1 2 3 4 5 6 7import { Integer } from "@osdk/functions"; function filterForEvenIntegers(nums: Integer[]): Integer[] { return nums.filter(num => num % 2 === 0); } export default filterForEvenIntegers;
Copied!1 2 3 4 5from functions.api import function, Integer @function def filter_for_even_integers(nums: list[Integer]) -> list[Integer]: return [n for n in nums if n % 2 == 0]
マップは、スカラー型をキーとして、関数レジストリのほかの任意のデータ型を持つ関連値にアクセスするために一般的に使用されます。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13import { Function, FunctionsMap } from "@foundry/functions-api"; export class MyFunctions { @Function() public getMap(): FunctionsMap<string, string> { const myMap = new FunctionsMap<string, string>(); myMap.set("Name", "Phil"); myMap.set("Favorite Color", "Blue"); return myMap; } }
Copied!1 2 3 4 5 6 7 8 9 10function getMap(): Record<string, string> { const myMap: Record<string, string> = {}; myMap["Name"] = "Phil"; myMap["Favorite Color"] = "Blue"; return myMap; } export default getMap;
Copied!1 2 3 4 5 6 7 8 9 10from functions.api import function @function def get_map() -> dict[str, str]: my_map = {} my_map["Name"] = "Phil" my_map["Favorite Color"] = "Blue" return my_map
また、マップはキーとしてオントロジーのオブジェクトをサポートしています。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15import { Function, FunctionsMap } from "@foundry/functions-api"; import { Airplane } from "@foundry/ontology-api"; export class MyFunctions { @Function() public getObjectMap(aircraft: Airplane[]): FunctionsMap<Airplane, Integer | undefined> { const myMap = new FunctionsMap<Airplane, Integer | undefined>(); aircraft.forEach(obj => { myMap.set(obj, obj.capacity); }); return myMap; } }
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15import { ObjectSpecifier, Osdk } from "@osdk/client"; import { Integer } from "@osdk/functions"; import { Airplane } from "@ontology/sdk"; function getObjectMap(aircraft: Osdk.Instance<Airplane>[]): Record<ObjectSpecifier<Airplane>, Integer | undefined> { const myMap: Record<ObjectSpecifier<Airplane>, Integer | undefined> = {}; aircraft.forEach(obj => { myMap[obj.$objectSpecifier] = obj.capacity; }); return myMap; } export default getObjectMap;
Copied!1 2 3 4 5 6 7 8 9 10 11from functions.api import function, Integer from ontology_sdk.ontology.objects import Airplane @function def get_object_map(aircraft: list[Airplane]) -> dict[Airplane, Integer | None]: my_map = {} for a in aircraft: my_map[a] = a.capacity return my_map
Copied!1 2 3 4 5 6 7 8import { Function, Integer } from "@foundry/functions-api"; export class MyFunctions { @Function() public getSizeOfSet(mySet: Set<Integer>): Integer { return mySet.size; } }
Copied!1 2 3 4 5from functions.api import function, Integer @function def get_size_of_set(my_set: set[Integer]) -> Integer: return len(my_set)
varName?: T または varName: T | undefined として宣言します。たとえば、value という名前の任意の Integer パラメーターを持つ関数は、value?: Integer または value: Integer | undefined のいずれかで宣言できます。TypeScript 関数では、T | undefined という型を指定することで、戻り値の型も任意として宣言できます。たとえば、Integer を返す場合も値を返さない場合もある関数の戻り値の型は、Integer | undefined になります。typing.Optional[T] または T | None を使用して宣言できます。T | None 構文には Python 3.10以降が必要です。T を必ず指定する必要があり、サポートされているほかのデータ型でなければなりません。Copied!1 2 3 4 5 6 7 8 9 10 11import { Function } from "@foundry/functions-api"; export class MyFunction { @Function() public greet(name?: string): string | undefined { if (name === undefined) { return undefined; } return `Hello, ${name}!`; } }
Copied!1 2 3 4 5 6 7 8function greet(name?: string): string | undefined { if (name === undefined) { return undefined; } return `Hello, ${name}!`; } export default greet;
Copied!1 2 3 4 5 6 7from functions.api import function @function def greet(name: str | None) -> str | None: if name is None: return None return f"Hello, {name}!"
Copied!1 2 3 4 5 6 7 8 9import { Double, Function } from "@foundry/functions-api"; import { Customer } from "@foundry/ontology-api"; export class MyFunctions { @Function() public computeRiskFactor(customer: Customer, weight: Double = 0.75): Double { // ... } }
Copied!1 2 3 4 5 6 7 8 9import { Double } from "@osdk/functions"; import { Osdk } from "@osdk/client"; import { Customer } from "@ontology/sdk"; function computeRiskFactor(customer: Osdk.Instance<Customer>, weight: Double = 0.75): Double { // ... } export default computeRiskFactor;
Copied!1 2 3 4 5 6from functions.api import function, Double from ontology_sdk.ontology.objects import Customer @function def compute_risk_factor(customer: Customer, weight: Double = 0.75) -> Double: # ...
カスタム型は、サポートされているほかのデータ型(ほかのカスタム型を含む)で構成され、関数シグネチャで使用できます。
関数シグネチャで使用するカスタム型は、オントロジーの構造体プロパティに使用する生成済みクラスとは異なります。Python 関数でオントロジーの構造体プロパティを編集するには、構造体プロパティを編集するで説明されている生成済みの構造体プロパティクラスを使用します。
TypeScript 関数では、カスタム型は interface キーワードを使用したユーザー定義の TypeScript インターフェースです。
? または undefined とのユニオン型によってサポートされます。Python 関数では、カスタム型はユーザー定義の Python クラスです。
__init__ メソッドは、フィールドと同じ名前および型注釈を持つ名前付き引数のみを受け取る必要があります。dataclasses.dataclass ↗ デコレーターを使用すると、これらの要件に準拠する __init__ メソッドを自動生成できます。Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17import { Function, Integer } from "@foundry/functions-api"; import { Passenger } from "@foundry/ontology-api"; interface PassengerInfo { name?: string; age?: Integer; } export class MyFunctions { @Function() public getPassengerInfo(passenger: Passenger): PassengerInfo { return { name: passenger.name, age: passenger.age, }; } }
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17import { Osdk } from "@osdk/client"; import { Integer } from "@osdk/functions"; import { Passenger } from "@ontology/sdk"; interface PassengerInfo { name?: string; age?: Integer; } function getPassengerInfo(passenger: Osdk.Instance<Passenger>): PassengerInfo { return { name: passenger.name, age: passenger.age, }; } export default getPassengerInfo;
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15from dataclasses import dataclass from functions.api import function, Integer from ontology_sdk.ontology.objects import Passenger @dataclass class PassengerInfo: name: str | None age: Integer | None @function def get_passenger_info(passenger) -> PassengerInfo: return PassengerInfo( name=passenger.name, age=passenger.age )
集計型は、Workshop のグラフなど、プラットフォームのほかの部分で使用するために関数から返すことができます。
サポートされている集計型は2種類あります。
集計のキーには、いくつかのデータ型を使用できます。
true または false の値を表します。フィールド名はバージョンによって異なります。TSv1 の IRange<T> と Python の Range[T] は min と max を使用します。TSv2 の Range<T> は startValue と endValue を使用し、片側に境界のない範囲では、いずれかを省略する場合があります。
Copied!1 2 3 4 5 6 7 8 9 10 11import { Function, Integer, IRange } from "@foundry/functions-api"; export class MyFunctions { @Function() public getRange(min: Integer, max: Integer): IRange<Integer> { return { min, max, }; } }
Copied!1 2 3 4 5 6 7 8 9 10import { Integer, Range } from "@osdk/functions"; function getRange(min: Integer, max: Integer): Range<Integer> { return { startValue: min, endValue: max, }; } export default getRange;
Copied!1 2 3 4 5 6 7 8from functions.api import function, Integer, Range @function def get_range(min: Integer, max: Integer) -> Range[Integer]: return Range( min=min, max=max )
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13import { Double, Function, TwoDimensionalAggregation } from "@foundry/functions-api"; export class MyFunctions { @Function() public myTwoDimensionalAggregation(): TwoDimensionalAggregation<string, Double> { return { buckets: [ { key: "bucket1", value: 5.0 }, { key: "bucket2", value: 6.0 }, ], }; } }
Copied!1 2 3 4 5 6 7 8 9 10import { Double, TwoDimensionalAggregation } from "@osdk/functions"; function myTwoDimensionalAggregationFunction(): TwoDimensionalAggregation<string, Double> { return [ { key: "bucket1", value: 5.0 }, { key: "bucket2", value: 6.0 }, ]; } export default myTwoDimensionalAggregationFunction;
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15from functions.api import ( function, Double, TwoDimensionalAggregation, SingleBucket ) @function def my_two_dimensional_aggregation_function() -> TwoDimensionalAggregation[str, Double]: return TwoDimensionalAggregation( buckets=[ SingleBucket(key="bucket1", value=Double(5.0)), SingleBucket(key="bucket2", value=Double(6.0)), ] )
バケット構造はバージョンによって異なります。TSv1 は外側のバケットを buckets キーの下にラップし、内側の階層には value キーを使用します。TSv2 はラップされていない配列を返し、内側の階層を groups の下に配置するため、ThreeDimensionalAggregation<T, U, V> は { key: T; groups: { key: U; value: V }[] }[] に解決されます。Python は TSv1 と同様に外側のバケットをラップし、NestedBucket クラスと SingleBucket クラスから構築します。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25import { Double, Function, ThreeDimensionalAggregation } from "@foundry/functions-api"; export class MyFunctions { @Function() public myThreeDimensionalAggregation(): ThreeDimensionalAggregation<string, string, Double> { return { buckets: [ { key: "group-by-1", value: [ { key: "partition-by-1", value: 5.0 }, { key: "partition-by-2", value: 6.0 }, ], }, { key: "group-by-2", value: [ { key: "partition-by-1", value: 7.0 }, { key: "partition-by-2", value: 8.0 }, ], }, ] }; } }
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22import { Double, ThreeDimensionalAggregation } from "@osdk/functions"; function myThreeDimensionalAggregation(): ThreeDimensionalAggregation<string, string, Double> { return [ { key: "group-by-1", groups: [ { key: "partition-by-1", value: 5.0 }, { key: "partition-by-2", value: 6.0 }, ], }, { key: "group-by-2", groups: [ { key: "partition-by-1", value: 7.0 }, { key: "partition-by-2", value: 8.0 }, ], }, ]; } export default myThreeDimensionalAggregation;
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24from functions.api import ( function, Double, ThreeDimensionalAggregation, SingleBucket, NestedBucket, ) @function def my_three_dimensional_aggregation_function() -> ( ThreeDimensionalAggregation[str, str, Double] ): return ThreeDimensionalAggregation( buckets=[ NestedBucket(key="group-by-1", buckets=[ SingleBucket(key="partition-by-1", value=Double(5.0)), SingleBucket(key="partition-by-2", value=Double(6.0)), ]), NestedBucket(key="group-by-2", buckets=[ SingleBucket(key="partition-by-1", value=Double(7.0)), SingleBucket(key="partition-by-2", value=Double(8.0)), ]) ] )
オブジェクトタイプを関数シグネチャで使用するには、リポジトリにインポートする必要があります。オントロジーのインポートについて詳しくはこちら。
オントロジーのオブジェクトタイプは、関数シグネチャの入力と出力の両方に使用できます。オブジェクトタイプの単一のインスタンスを受け取るか返すには、オントロジー SDK からオブジェクトタイプをインポートし、そのデータ型を使用して関数にアノテーションを付けます。
Copied!1 2 3 4 5 6 7 8 9import { Function, Integer } from "@foundry/functions-api"; import { Airplane } from "@foundry/ontology-api"; export class MyFunctions { @Function() public getCapacity(airplane: Airplane): Integer { return airplane.capacity; } }
Copied!1 2 3 4 5 6 7 8 9import { Osdk } from "@osdk/client"; import { Integer } from "@osdk/functions"; import { Airplane } from "@ontology/sdk"; function getCapacity(airplane: Osdk.Instance<Airplane>): Integer { return airplane.capacity; } export default getCapacity;
Copied!1 2 3 4 5 6from functions.api import function, Integer from ontology_sdk.ontology.objects import Airplane @function def get_capacity(airplane: Airplane) -> Integer: return airplane.capacity
TypeScript v2 では、オブジェクトタイプへの参照を構造体パラメーターのフィールドとして使用できます。オブジェクトタイプのインスタンスを含む構造体または構造体のリストを受け取るには、オントロジー SDK のオブジェクトタイプのフィールドを持つカスタム型の入力を作成します。これをオントロジーの編集と組み合わせることで、ほかのオブジェクトタイプから派生したオブジェクトタイプのインスタンスを複数作成するなどのワークフローに対応できます。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24import { Osdk } from "@osdk/client"; import { Integer } from "@osdk/functions"; import { Airplane, Passenger, Ticket } from "@ontology/sdk"; type TicketEdit = Edits.Object<Ticket> interface TicketInfo { airplane?: Osdk.Instance<Airplane>; passenger?: Osdk.Instance<Passenger>; seat?: String; } function createTickets(ticketInfo: TicketInfo[]): TicketEdit[] { const batch = createEditBatch<TicketEdit>(client); ticketInfo.forEach(i => batch.create(TicketEdit, { flightNumber: i.airplane.flightNumber, passengerName: i.passenger.name, seat: i.seat})) return batch.getEdits(); } export default createTickets;
関数がオブジェクトタイプをパラメーターとして宣言すると、関数の実行前にプラットフォームがオブジェクトを読み込みます。次のバージョンでは、オントロジー定義の派生プロパティを含むすべてのプロパティとともにオブジェクトが読み込まれます。
@foundry/functions-typescript-runtime)0.367.0 以降。foundry-sdk-generator)2.246.0 以降で生成されたオントロジー SDK。これより前のバージョンでは、オントロジー定義の派生プロパティを含めずにオブジェクトが読み込まれるため、そのプロパティを読み取っても値は返されません。オブジェクトパラメーターからオントロジー定義の派生プロパティを読み取るには、上記のバージョンにアップグレードしてください。コードの変更は不要です。
TypeScript v1 関数では、オブジェクトがパラメーターとして渡された場合も、関数内で読み込まれた場合も、オントロジー定義の派生プロパティは読み込まれません。オントロジー定義の派生プロパティを読み取るには、TypeScript v2 または Python の関数を使用します。
オントロジー定義の派生プロパティはクエリ時に計算されるため、読み込むと関数呼び出しごとの遅延と計算コストが増える場合があります。関数で少数のプロパティしか読み取らない場合は、代わりに主キーをパラメーターとして受け取り、プロパティを明示的に選択して関数内でオブジェクトを読み込みます。次の例では、passengerCount(Python では passenger_count)がオントロジー定義の派生プロパティです。
Copied!1 2 3 4 5 6 7 8 9 10 11 12import { Client } from "@osdk/client"; import { Integer } from "@osdk/functions"; import { Airplane } from "@ontology/sdk"; async function getPassengerCount(client: Client, airplaneId: string): Promise<Integer> { const airplane = await client(Airplane).fetchOne(airplaneId, { $select: ["passengerCount"], }); return airplane.passengerCount; } export default getPassengerCount;
Copied!1 2 3 4 5 6 7 8 9 10 11 12from functions.api import function, Integer from ontology_sdk import FoundryClient from ontology_sdk.ontology.objects import Airplane @function def get_passenger_count(airplane_id: str) -> Integer: client = FoundryClient() airplane = client.ontology.objects.Airplane.get( airplane_id, properties=[Airplane.object_type.passenger_count], ) return airplane.passenger_count
関数内で読み込むオブジェクトには、ほかのオントロジー SDK リクエストと同じ選択ルールが適用されます。TypeScript OSDK および Python OSDK の選択ルールを確認してください。
関数にオブジェクトの集合を渡したり、関数から返したりする方法は2つあります。配列などの具体的なオブジェクトの集合を使用する方法と、オブジェクトセットを使用する方法です。
オブジェクトの配列を関数に渡すと、具体的なオブジェクトのリストに対してロジックを実行できますが、あらかじめ関数の実行環境にオブジェクトを読み込む必要があります。一方、オブジェクトセットでは、絞り込み、周辺検索、集計の操作を実行し、リクエストしたときにのみ最終結果を読み込むことができます。
オブジェクトセットは、多くの場合パフォーマンスが向上し、10,000個を超えるオブジェクトを関数に渡すことができるため、配列の代わりに使用することを推奨します。
次の例は、オブジェクトをメモリーに読み込まずにオブジェクトセットを絞り込み、絞り込んだオブジェクトセットをアプリケーションの別の部分に返す方法を示しています。
Copied!1 2 3 4 5 6 7 8 9import { Function } from "@foundry/functions-api"; import { Airplane, ObjectSet } from "@foundry/ontology-api"; export class MyFunctions { @Function() public filterAircraft(aircraft: ObjectSet<Airplane>): ObjectSet<Airplane> { return aircraft.filter(a => a.capacity.range().gt(200)); } }
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13import { ObjectSet } from "@osdk/client"; import { Airplane } from "@ontology/sdk"; function filterAircraft(aircraft: ObjectSet<Airplane>): ObjectSet<Airplane> { return aircraft .where({ capacity: { $gt: 200, } }); } export default filterAircraft;
Copied!1 2 3 4 5 6 7from functions.api import function from ontology_sdk.ontology.objects import Airplane from ontology_sdk.ontology.object_sets import AirplaneObjectSet @function def filter_aircraft(aircraft: AirplaneObjectSet) -> AirplaneObjectSet: return aircraft.where(Airplane.object_type.capacity > 200)
オントロジーのインターフェースタイプは、TypeScript v2 関数シグネチャの入力と出力の両方に使用できます。TypeScript v1 または Python では使用できません。
Copied!1 2 3 4 5 6 7 8 9import { Osdk } from "@osdk/client"; import { Integer } from "@osdk/functions"; import { Person } from "@ontology/sdk"; function getAge(person: Osdk.Instance<Person>): Integer { return person.age; } export default getAge;
インターフェースオブジェクトセットは、TypeScript v2 関数シグネチャの入力と出力の両方に使用できます。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13import { ObjectSet } from "@osdk/client"; import { Person } from "@ontology/sdk"; function filterPeople(people: ObjectSet<Person>): ObjectSet<Person> { return people .where({ age: { $gt: 200, } }); } export default filterPeople;
オントロジーからデータを読み取る関数に加えて、オブジェクトを作成し、オブジェクトのプロパティやオブジェクト間のリンクを編集する関数も記述できます。編集関数の仕組みの詳細については、概要ページを参照してください。
編集関数として登録するには、TypeScript v1 関数ではシグネチャの戻り値の型を void にする必要があります。一方、TypeScript v2 と Python の関数では、オントロジーの編集のリストを明示的に返す必要があります。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15import { Edits, OntologyEditFunction } from "@foundry/functions-api"; import { Employee, LaptopRequest, Objects } from "@foundry/ontology-api"; export class MyFunctions { @Edits(Employee, LaptopRequest) @OntologyEditFunction() public assignEmployee(newEmployee: Employee, leadEmployee: Employee): void { const newLaptopRequest = Objects.create().laptopRequest(Date.now().toString()); newLaptopRequest.employeeName = newEmployee.name; newEmployee.lead.set(leadEmployee); } }
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27import { Client } from "@osdk/client"; import { createEditBatch, Edits } from "@osdk/functions"; import { Employee, LaptopRequest } from "@ontology/sdk"; type EmployeeEdit = | Edits.Object<Employee> | Edits.Object<LaptopRequest> | Edits.Link<Employee, "lead">; function assignEmployee( client: Client, newEmployee: Osdk.Instance<Employee>, leadEmployee: Osdk.Instance<Employee> ): EmployeeEdit[] { const batch = createEditBatch<EmployeeEdit>(client); batch.create(LaptopRequest, { id: Date.now().toString(), employeeName: newEmployee.name, }); batch.link(newEmployee, "lead", leadEmployee); return batch.getEdits(); } export default assignEmployee;
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16from functions.api import function, OntologyEdit from ontology_sdk import FoundryClient from ontology_sdk.ontology.objects import Employee, LaptopRequest from time import time @function def assign_employee(new_employee: Employee, lead_employee: Employee) -> list[OntologyEdit]: ontology_edits = FoundryClient().ontology.edits() new_laptop_request = ontology_edits.objects.LaptopRequest.create(str(int(time() * 1000))) new_laptop_request.employee_name = new_employee.name new_employee.lead.set(lead_employee) return ontology_edits.get_edits()
Copied!1 2 3 4 5 6 7 8import { Attachment, Function } from "@foundry/functions-api"; export class MyFunctions { @Function() public loadAttachmentContents(attachment: Attachment): Promise<string> { return attachment.readAsync().then(blob => blob.text()); } }
Copied!1 2 3 4 5 6 7import { Attachment } from "@osdk/functions"; function loadAttachmentContents(attachment: Attachment): Promise<string> { return attachment.fetchContents().then(response => response.text()); } export default loadAttachmentContents;
Copied!1 2 3 4 5from functions.api import function, Attachment @function def load_attachment_contents(attachment: Attachment) -> str: return attachment.read().getvalue().decode('utf-8')
関数から通知のデータ型を返すことで、プラットフォームで送信する通知を柔軟に設定できます。たとえば、User やオブジェクトタイプなどのパラメーターを受け取り、メッセージを設定した Notification を返す関数を作成できます。
Notification は、ShortNotification と EmailNotificationContent の2個のフィールドで構成されます。ShortNotification は通知の要約版を表し、Foundry プラットフォーム内に表示されます。短い heading、content、および Link の集合が含まれます。EmailNotificationContent は、メールを介して外部に送信できる、リッチな形式の通知を表します。subject、ヘッダーのない HTML で構成される body、および Link の集合が含まれます。Link には、ユーザー向けの label と linkTarget があります。LinkTarget には、URL、OntologyObject、または Foundry 内の任意のリソースの rid を指定できます。Notifications API の使用例については、ガイドを確認してください。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22import { EmailNotificationContent, Function, Notification, ShortNotification, } from "@foundry/functions-api"; export class MyFunctions { @Function() public buildNotification(): Notification { return Notification.builder() .shortNotification(ShortNotification.builder() .heading("Issue reminder") .content("Investigate this issue.") .build()) .emailNotificationContent(EmailNotificationContent.builder() .subject("New issue") .body("hello") .build()) .build(); } }
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18import { Notification } from "@osdk/functions"; export default function buildNotification(): Notification { return { platformNotification: { heading: "Issue reminder", content: "Investigate this issue.", links: [] }, emailNotification: { subject: "New issue", body: "hello", links: [] } }; }
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16from functions.api import function, Notification, PlatformNotification, EmailNotification @function() def buildNotification() -> Notification: return Notification( platform_notification=PlatformNotification( heading="Issue reminder", content="Investigate this issue.", links=[] ), email_notification=EmailNotification( subject="New issue", body="hello", links=[] ), )
関数はメディアアイテムを受け取り、返すことができます。TypeScript v1 では、MediaItem 型を使用します。TypeScript v2 と Python では、入力と出力タイプの両方に Media を使用します。呼び出し元は、たとえばオブジェクトのメディアプロパティなど、既存の MediaReference を関数に渡すことができます。下流の利用側は、返された値を使用して内容やメタデータを取得したり、別のオブジェクトにアタッチしたりできます。詳細については、メディアに関するガイドを確認してください。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19import { Function, MediaItem } from "@foundry/functions-api"; export class MyFunctions { @Function() public async echoMedia(media: MediaItem): Promise<string | undefined> { const mimeType: string = media.mimeType; // 種類に固有のメタデータ(ページ数、寸法、再生時間など)を取得します const metadata = await media.getMetadataAsync(); // バイナリの内容を Blob として読み込みます const contents: Blob = await media.readAsync(); // 種類に固有のメソッドを呼び出すために、専用のサブタイプに絞り込みます if (MediaItem.isDocument(media)) { const text = await media.extractTextAsync({ startPage: 0, endPage: 1 }); } else if (MediaItem.isAudio(media)) { const transcript = await media.transcribeAsync(); } return undefined; } }
Copied!1 2 3 4 5 6 7 8 9 10 11 12import type { Media } from "@osdk/client"; export default async function echoMedia(media: Media): Promise<Media> { // 基になる MediaReference を取得します const mediaReference = media.getMediaReference(); // 軽量なメタデータを取得します:path, sizeBytes, mediaType const metadata = await media.fetchMetadata(); // 内容を Response として取得します。バイト列を取得するには .blob() または .arrayBuffer() を呼び出します const response = await media.fetchContents(); const contents = await response.blob(); return media; }
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14from foundry_sdk.v2.core.models import MediaReference from functions.api import function, Media @function def echo_media(media: Media) -> Media: # 基になる MediaReference を取得します media_reference: MediaReference = media.get_media_reference() # 軽量なメタデータを取得します:path, size_bytes, media_type metadata = media.get_media_metadata() # 種類に固有のメタデータ(ページ数、寸法、再生時間、および種類ごとの追加情報)を取得します full_metadata = media.get_media_full_metadata() # バイナリの内容を BytesIO ストリームとして取得します contents = media.get_media_content() return media
プリンシパルは、Foundry のユーザーアカウントまたはグループを表します。これらのデータ型を関数に渡すことで、グループ名やユーザーの名、姓、メールアドレスなど、ユーザーやグループに関連付けられた情報にアクセスできます。すべてのプリンシパルのデータ型は、@foundry/functions-api パッケージからエクスポートされます。
User には常にユーザー名があり、firstName、lastName、email がある場合もあります。また、Principal に関連付けられたすべてのフィールドも含まれます。Group には名前があります。また、Principal に関連付けられたすべてのフィールドも含まれます。Principal は、User または Group のいずれかです。type フィールドを調べることで、特定の Principal が User か Group かを判別できます。Principal には、User および Group 固有のフィールドに加え、id、realm、および attributes の辞書があります。Copied!1 2 3 4 5 6 7 8import { Function, User } from "@foundry/functions-api"; export class MyFunctions { @Function() public getUserEmail(user: User): string { return user.email; } }
Copied!1 2 3 4 5 6 7 8import { UserId } from "@osdk/functions"; import { Users } from "@osdk/foundry.admin"; import { Client } from "@osdk/client"; export default function getUserEmail(client:Client, userId: UserId): string { const user = Users.get(client, userId) return user.email; }
Copied!1 2 3 4 5 6 7 8 9from functions.api import function, UserId from foundry_sdk import FoundryClient import foundry_sdk @function() def getUserEmail(user_id: UserId) -> string: client = FoundryClient(auth=foundry_sdk.UserTokenAuth(...), hostname="example.palantirfoundry.com") user = client.admin.User.get(user_id) return user.email
Copied!1 2 3 4 5 6 7 8import { Function, Group } from "@foundry/functions-api"; export class MyFunctions { @Function() public getGroupName(group: Group): string { return group.name; } }
Copied!1 2 3 4 5 6 7 8import { GroupId } from "@osdk/functions"; import { Groups } from "@osdk/foundry.admin"; import { Client } from "@osdk/client"; export default function getGroupName(client: Client, groupId: GroupId): string { const group = Groups.get(client, groupId) return group.name; }
Copied!1 2 3 4 5 6 7 8 9from functions.api import function, GroupId from foundry_sdk import FoundryClient import foundry_sdk @function() def getGroupName(group_id: GroupId) -> string: client = FoundryClient(auth=foundry_sdk.UserTokenAuth(...), hostname="example.palantirfoundry.com") group = client.admin.Group.get(group_id) return group.name
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16import { Function, Principal } from "@foundry/functions-api"; export class MyFunctions { @Function() public getPrincipalType(principal: Principal): string { switch (principal.type) { case "user": return "User"; case "group": return "Group"; default: return "Unknown"; } } }
Copied!1 2 3 4 5import { GroupId, Principal, UserId } from "@osdk/functions"; export default async function getPrincipals(client: Client, userId: UserId, groupId: GroupId): Principal[] { return [{type: "user", id: userId}, {type: "group", id: groupId}]; }
Copied!1 2 3 4 5from functions.api import Array, function, GroupId, Principal, UserId @function() def getPrincipals(user_id: UserId, group_id: GroupId) -> Array[Principal]: return [Principal.user(user_id), Principal.group(group_id)]
ジオメトリデータ型は、関数内の空間データと地理的な図形を表します。次の2つのジオメトリデータ型がサポートされています。
これらのデータ型は GeoJSON 仕様 ↗に準拠しており、空間演算、地図作成、地理的分析に使用できます。位置引数は、GeoJSON 仕様に従って経度、緯度の順に指定します。
次の例は、Geopoint を作成して返す方法を示しています。
Copied!1 2 3 4 5 6 7 8 9 10 11import { Function, GeoPoint } from "@foundry/functions-api"; export class MyFunctions { @Function() public createPoint(): GeoPoint { return GeoPoint.fromCoordinates({ latitude: 37.7749, longitude: -22.4194 }); } }
Copied!1 2 3 4 5 6 7 8 9 10import { Point } from "@osdk/functions"; function createPoint(): Point { return { type: "Point", coordinates: [-22.4194, 37.7749] }; } export default createPoint;
Copied!1 2 3 4 5from functions.api import function, GeoPoint @function def create_point() -> GeoPoint: return GeoPoint(type="Point", coordinates=[-22.4194, 37.7749])
次の例は、Polygon を作成して返す方法を示しています。
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15import { Function, Polygon, GeoPoint } from "@foundry/functions-api"; export class MyFunctions { @Function() public createPolygon(): Polygon { const ring: GeoPoint[] = [ GeoPoint.fromCoordinates({ latitude: 37.8, longitude: -22.4 }), GeoPoint.fromCoordinates({ latitude: 37.8, longitude: -22.5 }), GeoPoint.fromCoordinates({ latitude: 37.7, longitude: -22.5 }), GeoPoint.fromCoordinates({ latitude: 37.7, longitude: -22.4 }), GeoPoint.fromCoordinates({ latitude: 37.8, longitude: -22.4 }) ]; return Polygon.fromLinearRings([ring]); } }
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16import { Geometry } from "@osdk/functions"; function createPolygon(): Geometry { return { type: "Polygon", coordinates: [[ [-22.4, 37.8], [-22.5, 37.8], [-22.5, 37.7], [-22.4, 37.7], [-22.4, 37.8] ]] }; } export default createPolygon;
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13from functions.api import function, Polygon @function def create_polygon() -> Polygon: return Polygon( type="Polygon", coordinates=[[ [-22.4, 37.8], [-22.5, 37.8], [-22.5, 37.7], [-22.4, 37.7], [-22.4, 37.8] ]])
オントロジー編集関数では、GeoJSON 文字列から geoshape プロパティを設定できますが、変換のステップは言語によって異なります。
GeoShape.fromGeoJson() はパース済みの GeoJSON ジオメトリまたはジオメトリコレクションを受け取るため、渡す前に文字列をパースします。Geometry は通常の GeoJSON オブジェクトであるため、変換関数は不要です。パースした値を直接代入します。Polygon や LineString などの具象ジオメトリクラスには、JSON 文字列自体を受け取る from_geo_json() メソッドが用意されています。GeoShape 型にはこのメソッドがないため、想定するジオメトリに一致するクラスを使用します。次の例は、JSON 文字列から Region オブジェクトの geoshape プロパティを設定します。
Copied!1 2 3 4 5 6 7 8 9 10import { OntologyEditFunction, Edits, GeoShape } from "@foundry/functions-api"; import { Region } from "@foundry/ontology-api"; export class MyFunctions { @Edits(Region) @OntologyEditFunction() public updateBoundary(region: Region, boundary: string): void { region.boundary = GeoShape.fromGeoJson(JSON.parse(boundary)); } }
Copied!1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19import { Region } from "@ontology/sdk"; import { Client, Osdk } from "@osdk/client"; import { createEditBatch, Edits, Geometry } from "@osdk/functions"; type RegionEdit = Edits.Object<Region>; function updateBoundary( client: Client, region: Osdk.Instance<Region>, boundary: string ): RegionEdit[] { const batch = createEditBatch<RegionEdit>(client); batch.update(region, { boundary: JSON.parse(boundary) as Geometry }); return batch.getEdits(); } export default updateBoundary;
Copied!1 2 3 4 5 6 7 8 9 10 11 12from functions.api import function, OntologyEdit, Polygon from ontology_sdk import FoundryClient from ontology_sdk.ontology.objects import Region @function(edits=[Region]) def update_boundary(region: Region, boundary: str) -> list[OntologyEdit]: ontology_edits = FoundryClient().ontology.edits() editable_region = ontology_edits.objects.Region.edit(region) editable_region.boundary = Polygon.from_geo_json(boundary) return ontology_edits.get_edits()