Cloudant JSON数据加入dashdb表连接

时间:2016-09-14 02:01:09

标签: ibm-cloud cloudant dashdb

我已成功将一些JSON数据导入cloudant,JSON数据有三个级别。然后从cloudant创建dashdb仓库,将数据放入关系表中。看来dashdb已经为JSON数据中的每个级别创建了三个表,但是没有为我提供一个连接回顶级的Key。是否有一个自定义,它告诉dashdb如何连接表。 下面是一个示例JSON文档:

 {
  "_id": "579b56388aa56fd03a4fd0a9",
  "_rev": "1-698183d4326352785f213b823749b9f8",
  "v": 0,
  "startTime": "2016-07-29T12:48:04.204Z",
  "endTime": "2016-07-29T13:11:48.962Z",
  "userId": "Ranger1",
  "uuid": "497568578283117a",
  "modes": [
    {
      "startTime": "2016-07-29T12:54:22.565Z",
      "endTime": "2016-07-29T12:54:49.894Z",
      "name": "bicycle",
      "_id": "579b56388aa56fd03a4fd0b1",
      "locations": []
    },
    {
      "startTime": "2016-07-29T12:48:02.477Z",
      "endTime": "2016-07-29T12:53:28.503Z",
      "name": "walk",
      "_id": "579b56388aa56fd03a4fd0ad",
      "locations": [
        {
          "at": "2016-07-29T12:49:05.716Z",
          "_id": "579b56388aa56fd03a4fd0b0",
          "location": {
            "coords": {
              "latitude": -34.0418308,
              "longitude": 18.3503616,
              "accuracy": 37.5,
              "speed": 0,
              "heading": 0,
              "altitude": 0
            },
            "battery": {
              "is_charging": true,
              "level": 0.7799999713897705
            }
          }
        },
        {
          "at": "2016-07-29T12:49:48.488Z",
          "_id": "579b56388aa56fd03a4fd0af",
          "location": {
            "coords": {
              "latitude": -34.0418718,
              "longitude": 18.3503895,
              "accuracy": 33,
              "speed": 0,
              "heading": 0,
              "altitude": 0
            },
            "battery": {
              "is_charging": true,
              "level": 0.7799999713897705
            }
          }
        },
        {
          "at": "2016-07-29T12:50:20.760Z",
          "_id": "579b56388aa56fd03a4fd0ae",
          "location": {
            "coords": {
              "latitude": -34.0418788,
              "longitude": 18.3503887,
              "accuracy": 33,
              "speed": 0,
              "heading": 0,
              "altitude": 0
            },
            "battery": {
              "is_charging": true,
              "level": 0.7799999713897705
            }
          }
        }
      ]
    },
    {
      "startTime": "2016-07-29T12:53:37.137Z",
      "endTime": "2016-07-29T12:54:18.505Z",
      "name": "carshare",
      "_id": "579b56388aa56fd03a4fd0ac",
      "locations": []
    },
    {
      "startTime": "2016-07-29T12:54:54.112Z",
      "endTime": "2016-07-29T13:11:47.818Z",
      "name": "bus",
      "_id": "579b56388aa56fd03a4fd0aa",
      "locations": [
        {
          "at": "2016-07-29T13:00:08.039Z",
          "_id": "579b56388aa56fd03a4fd0ab",
          "location": {
            "coords": {
              "latitude": -34.0418319,
              "longitude": 18.3503623,
              "accuracy": 36,
              "speed": 0,
              "heading": 0,
              "altitude": 0
            },
            "battery": {
              "is_charging": false,
              "level": 0.800000011920929
            }
          }
        }
      ]
    }
  ]
}

在dashdb中创建的三个表的SQL显示了每个表中的所有字段。请注意,我看不到FK,“_ ID”字段对每个表都是唯一的。

SELECT ENDTIME,STARTTIME,USERID,UUID,V,"_ID","_REV" 
FROM <schemaname>.RANGER_DATA
where "_ID" = '579b56388aa56fd03a4fd0a9'

SELECT ARRAY_INDEX,ENDTIME,NAME,STARTTIME,TOTALPAUSEDMS,"_ID"
FROM <schemaname>.RANGER_DATA_MODES
where "_ID" = '579b56388aa56fd03a4fd0b1'

SELECT ARRAY_INDEX,AT,LOCATION_BATTERY_IS_CHARGING,LOCATION_BATTERY_LEVEL,LOCATION_COORDS_ACCURACY,LOCATION_COORDS_ALTITUDE,LOCATION_COORDS_HEADING,LOCATION_COORDS_LATITUDE,LOCATION_COORDS_LONGITUDE,LOCATION_COORDS_SPEED,RANGER_DATA_MODES,"_ID" 
FROM <schemaname>.RANGER_DATA_MODES_LOCATIONS
where "_ID" = '579b56388aa56fd03a4fd0b0'

1 个答案:

答案 0 :(得分:0)

Cloudant对每个文档使用_id作为其UID。仓库任务似乎迭代这些文档,并假设每次看到新的_id时都有一个新文档。

因为您在模式和位置​​使用_id,这将在SQL DB中产生不希望的结果。

将模式和位置​​中的_id重命名为其他内容应该可以解决问题。