使用H2OApi Java绑定来检索H2O帧

时间:2017-05-22 10:10:23

标签: java h2o

我使用H2O Java绑定提供的H2O(3.10.4.7)REST Api处理Java项目,我遇到以下问题:

我们需要从现有的H2O框架中检索元数据,如:

  • 列名和
  • 这些列的数据类型

最好使用H2oApi.class。

我们的方法是从H2O框架中获取一行,然后使用它来获取我们需要的元数据。

到目前为止,我尝试了以下内容:

 FramesV3 targetFrame = new FramesV3();
 targetFrame.frameId = frameKey; // key provided by import process - works
 targetFrame.rowCount = 1; // get one row to figure out specs of all cols
 H2OApi h2oApi = new H2OApi("http://localhost:54321/");
 FramesV3 result = h2oApi.frames(targetFrame);

我得到了这个例外:

 java.lang.IllegalArgumentException: @Field parameters can only be used with form encoding. (parameter #1)
 for method Frames.list
 at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:695)
 at retrofit2.ServiceMethod$Builder.methodError(ServiceMethod.java:686)
 at retrofit2.ServiceMethod$Builder.parameterError(ServiceMethod.java:704)
 at retrofit2.ServiceMethod$Builder.parseParameterAnnotation(ServiceMethod.java:476)
 at retrofit2.ServiceMethod$Builder.parseParameter(ServiceMethod.java:328)
 at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:201)
 at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:166)
 at retrofit2.Retrofit$1.invoke(Retrofit.java:145)
 at com.sun.proxy.$Proxy14.list(Unknown Source)
 at water.bindings.H2oApi.frames(H2oApi.java:882)
 at H2ORestCloudTests.getSpecFromFrameTest(H2ORestCloudTests.java:388)

如果我通过浏览器使用REST API框架端点,它可以工作。 例如:

"http://localhost:54321/3/Frames/89a05762-4bcd-41d8-a800-f9cfc3ac73dd?row_count=1"

浏览器中的结果:

 {

 "__meta": {
     "schema_version": 3,
     "schema_name": "FramesV3",
     "schema_type": "Frames"
 },
 "_exclude_fields": "",
 "row_offset": 0,
 "row_count": 1,
 "column_offset": 0,
 "column_count": 0,
 "job": null,
 "frames": [
     {
         "__meta": {
             "schema_version": 3,
             "schema_name": "FrameV3",
             "schema_type": "Frame"
         },
         "_exclude_fields": "",
         "frame_id": {
             "__meta": {
                 "schema_version": 3,
                 "schema_name": "FrameKeyV3",
                 "schema_type": "Key<Frame>"
             },
             "name": "89a05762-4bcd-41d8-a800-f9cfc3ac73dd",
             "type": "Key<Frame>",
             "URL": "/3/Frames/89a05762-4bcd-41d8-a800-f9cfc3ac73dd"
         },
         "byte_size": 1928,
         "is_text": false,
         "row_offset": 0,
         "row_count": 1,
         "column_offset": 0,
         "column_count": 5,
         "total_column_count": 5,
         "checksum": -7731554748204616990,
         "rows": 150,
         "num_columns": 5,
         "default_percentiles": [
             0.001,
             0.01,
             0.1,
             0.2,
             0.25,
             0.3,
             0.3333333333333333,
             0.4,
             0.5,
             0.6,
             0.6666666666666666,
             0.7,
             0.75,
             0.8,
             0.9,
             0.99,
             0.999
         ],
         "columns": [
             {
                 "__meta": {
                     "schema_version": 3,
                     "schema_name": "ColV3",
                     "schema_type": "Vec"
                 },
                 "label": "sepal_length",
                 "missing_count": 0,
                 "zero_count": 0,
                 "positive_infinity_count": 0,
                 "negative_infinity_count": 0,
                 "mins": [
                     4.3,
                     4.4,
                     4.4,
                     4.4,
                     4.5
                 ],
                 "maxs": [
                     7.9,
                     7.7,
                     7.7,
                     7.7,
                     7.7
                 ],
                 "mean": 5.843333333333334,
                 "sigma": 0.8280661279778637,
                 "type": "real",
                 "domain": null,
                 "domain_cardinality": 0,
                 "data": [
                     5.1000000000000005
                 ],
                 "string_data": null,
                 "precision": 1,
                 "histogram_bins": null,
                 "histogram_base": 0.0,
                 "histogram_stride": 0.0,
                 "percentiles": null
             },
             ...
 }

我是否遗漏了某些内容,或者是否有更好的方法可以通过H2O Java Rest API获取这些Frame信息?

提前谢谢你,祝你有愉快的一天!

尼科

1 个答案:

答案 0 :(得分:0)

回答原始问题(例外)这确实是H2O中的一个错误,目前除了从http://www.oracle.com/technetwork/articles/java/javaserial-1536170.html构建之外没有其他解决方法。

正如所指出的,此方法不返回元数据,将在this branch中回答此部分。