Skip to content

Commit c192e20

Browse files
committed
Add APIs to get enumerations from an array schema.
1 parent 0e53eed commit c192e20

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed

sources/TileDB.CSharp/ArraySchema.cs

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,73 @@ public Domain Domain()
374374
return new Domain(_ctx, handle);
375375
}
376376

377+
/// <summary>
378+
/// Gets the <see cref="Enumeration"/> of the <see cref="ArraySchema"/> with the given name.
379+
/// </summary>
380+
/// <param name="name">The name of the enumeration.</param>
381+
public Enumeration GetEnumeration(string name)
382+
{
383+
var handle = new EnumerationHandle();
384+
var successful = false;
385+
tiledb_enumeration_t* enumeration_p = null;
386+
try
387+
{
388+
using (var ctxHandle = _ctx.Handle.Acquire())
389+
using (var schemaHandle = _handle.Acquire())
390+
using (var ms_name = new MarshaledString(name))
391+
{
392+
_ctx.handle_error(Methods.tiledb_array_schema_get_enumeration_from_name(ctxHandle, schemaHandle, ms_name, &enumeration_p));
393+
}
394+
successful = true;
395+
}
396+
finally
397+
{
398+
if (successful)
399+
{
400+
handle.InitHandle(enumeration_p);
401+
}
402+
else
403+
{
404+
handle.SetHandleAsInvalid();
405+
}
406+
}
407+
return new Enumeration(_ctx, handle);
408+
}
409+
410+
/// <summary>
411+
/// Gets the <see cref="Enumeration"/> attached to the <see cref="CSharp.Attribute"/>
412+
/// of the <see cref="ArraySchema"/> with the given name.
413+
/// </summary>
414+
/// <param name="name">The name of the attribute.</param>
415+
public Enumeration GetEnumerationOfAttribute(string name)
416+
{
417+
var handle = new EnumerationHandle();
418+
var successful = false;
419+
tiledb_enumeration_t* enumeration_p = null;
420+
try
421+
{
422+
using (var ctxHandle = _ctx.Handle.Acquire())
423+
using (var schemaHandle = _handle.Acquire())
424+
using (var ms_name = new MarshaledString(name))
425+
{
426+
_ctx.handle_error(Methods.tiledb_array_schema_get_enumeration_from_attribute_name(ctxHandle, schemaHandle, ms_name, &enumeration_p));
427+
}
428+
successful = true;
429+
}
430+
finally
431+
{
432+
if (successful)
433+
{
434+
handle.InitHandle(enumeration_p);
435+
}
436+
else
437+
{
438+
handle.SetHandleAsInvalid();
439+
}
440+
}
441+
return new Enumeration(_ctx, handle);
442+
}
443+
377444
/// <summary>
378445
/// Gets the <see cref="ArraySchema"/>'s tile order.
379446
/// </summary>

tests/TileDB.CSharp.Test/EnumerationTest.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,25 @@ public void TestExtend()
9797
CollectionAssert.AreEqual("HelloWorld👋👋👋👋"u8.ToArray(), rawData);
9898
CollectionAssert.AreEqual(new ulong[] { 0, 5, 10, 14 }, rawOffsets);
9999
}
100+
101+
[TestMethod]
102+
public void TestEnumerationFromArraySchema()
103+
{
104+
using var context = new Context();
105+
106+
using var schema = new ArraySchema(context, ArrayType.Dense);
107+
108+
using var enumeration = Enumeration.Create(context, "e", true, ["aaa", "bbb", "ccc"]);
109+
schema.AddEnumeration(enumeration);
110+
111+
using var attr = new Attribute(context, "a1", DataType.Int32);
112+
attr.SetEnumerationName(enumeration.GetName());
113+
schema.AddAttribute(attr);
114+
115+
using var enumerationFromSchema = schema.GetEnumeration(enumeration.GetName());
116+
Assert.AreEqual(enumeration.GetName(), enumerationFromSchema.GetName());
117+
118+
using var enumerationFromSchemaAttribute = schema.GetEnumerationOfAttribute(attr.Name());
119+
Assert.AreEqual(enumeration.GetName(), enumerationFromSchemaAttribute.GetName());
120+
}
100121
}

0 commit comments

Comments
 (0)