InterSystems IRIS 目前将类限制为 999 个属性。
但是,如果您需要为每个对象存储更多数据该怎么办?
本文将回答这个问题(附加了社区 Python 网关的客串以及如何将广泛的数据集传输到 Python 中)。
答案其实很简单 - InterSystems IRIS 目前将类限制为 999 个属性,但不限制 999 个基元(primitives)。 InterSystems IRIS 中的属性可以是具有 999 个属性的对象等等 - 该限制很容易被忽略。
方法1 .
每个序列属性存储 100 个属性。首先创建一个存储一百个属性的存储类。
Class Test.Serial Extends %SerialObject { Property col0; ... Property col99; }
并在您的主类中添加您需要的尽可能多的属性:
{
Property col00 As Test.Serial;
Property col01 As Test.Serial;
...
Property col63 As Test.Serial;
}
这会立即将您的限制提高到 99900 个属性。
这种方法通过 SQL 和对象层提供对所有属性的统一访问(我们总是通过其编号来了解属性引用)。
方法2 。
一个 $lb 属性:
{
Property col As %List;
}
这种方法更简单,但不提供显式的列名称。
方法3 。
使用集合(列表/数组)属性。
{
Property col As List Of %Integer;
}
此方法也不为各个值提供显式的列名称(但您真的需要它吗?)使用属性参数将属性投影为 SQL 列/表。
方法4 。
根本不要创建属性并通过 SQL 存储过程/ %DispatchGetProperty公开它们。
{
Parameter GLVN = {..GLVN("Test.Record")};
/// SELECT Test_Record.col(ID, 123)
/// FROM Test.Record
///
/// w ##class(Test.Record).col(1, )
ClassMethod col(id, num) As %Decimal [ SqlProc ]
{
#define GLVN(%class) ##Expression(##class(Test.Record).GLVN(%class))
quit $lg($$$GLVN("Test.Record")(id), num + 1)
}
/// Refer to properties as: obj.col123
Method %DispatchGetProperty(Property As %String) [ CodeMode = expression ]
{
..col(..%Id(), $e(Property, 4, *))
}
/// Get data global
/// w ##class(Test.Record).GLVN("Test.Record")
ClassMethod GLVN(class As %Dictionary.CacheClassname = {$classname()}) As %String
{
return:'$$$comClassDefined(class) ""
set strategy = $$$comClassKeyGet(class, $$$cCLASSstoragestrategy)
return $$$defMemberKeyGet(class, $$$cCLASSstorage, strategy, $$$cSDEFdatalocation)
}
这里的技巧是将所有内容存储在主 $lb 中,并使用未分配的Schema存储空间来存储数据。 这是一篇关于Global存储的文章。
通过这种方法,您还可以通过ExecuteGlobal方法轻松地将数据传输到社区 Python 网关的 Python 环境中。
由于结构相似,这也是导入 CSV 文件的最快方法。
结论
999 个属性限制可以在 InterSystems IRIS 中轻松扩展。
您知道存储广泛数据集的其他方法吗?如果有,请分享!