Cloudant JSON 数据到 dashdb table 连接

Cloudant JSON data into dashdb table joins

我已经成功导入一些JSON数据到cloudant中,JSON数据有三个层次。然后从 cloudant 创建了 dashdb 仓库,将数据放入关系 tables 中。看起来 dashdb 已经为 JSON 数据中的每个级别创建了三个 table,但没有为我提供返回顶层的密钥。是否有在某处完成的定制告诉 dashdb 如何加入 tables。 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
            }
          }
        }
      ]
    }
  ]
}

SQL 在 dashdb 中创建的三个 table 显示每个 table 中的所有字段在这里。请注意,我看不到 FK,“_ID”字段对于每个 table.

都是唯一的
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'

Cloudant 使用 _id 作为其每个文档的 UID。好像是入库任务在迭代这些文档,每次看到新的_id就假设有一个新的文档。

因为您在您的模式和位置​​中使用了 _id,所以这将在 SQL 数据库中产生不希望的结果。

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