将JSON结构转换为键值元组

时间:2019-05-29 06:21:55

标签: scala apache-spark

我想将JSON结构转换为键值元组并将其存储在RawKeyValueData RDD中,以便我们可以在不同的上下文中对此键值元组执行更多的转换。 下面是原始的JSON结构:

Data {
 "resultId": 238074021,
 resultDate: '2019-05-18 16:34:12',
 odId: '1558197200725_SCHEDULED_2C7E81FD6DCA',
 odReqServerDate: '5/18/2019, 4:33:20 PM',
 odTestType: '2',
 odPreChecks: 1,
 odCmtsIp: '68.86.19.160',
 odProvDnBps: 500000000,
 odProvUpBps: 12500000,
 odCmtsMacIndex: 'acr01.cosprings.co.denver.comcast.net_536870915',
 odTestReason: 'nganDay_55',
 odMake: 'ARRIS Group, Inc.',
 odModel: 'TG3482G',
 odFirmware: 'TG3482PC2_3.3p20s1_PROD_sey',
 odStatus: 'finished',
 odClientId: 'x1:ondemand-mw-dev:19f104',
 odWebResultId: null,
 odClientType: 2,
 odRejectText: null,
 ipv4Address: '75.70.246.234',
 ipv6Address: '2001:558:6040:81:d456:b2ac:ed87:d09f',
 market: 'Denver',
 iperfVersion: 'iperf 3.5',
 serverId: 9,
 serverPort: 5067,
 ipv6: true,
 threads: 4,
 downloadOmit: 3,
 uploadOmit: 0,
 duration: 8,
 ipv4DownloadDuration: null,
 ipv4UploadDuration: null,
 ipv4Latency: null,
 ipv4DownloadBytes: null,
 ipv4DownloadTotalBytes: null,
 ipv4UploadBytes: null,
 ipv4DownloadKbps: null,
 ipv4UploadKbps: null,
 ipv4DownloadClientCpuUtil: null,
 ipv4UploadClientCpuUtil: null,
 ipv6DownloadDuration: 7.999658107757568,
 ipv6UploadDuration: 8.033694982528687,
 ipv6Latency: 13,
 ipv6DownloadBytes: 693860204,
 ipv6DownloadTotalBytes: 629058712,
 ipv6UploadBytes: 13022611,
 ipv6DownloadKbps: 467950.7705922882,
 ipv6UploadKbps: 11708.83587248069,
 ipv6DownloadClientCpuUtil: 46.560214784866965,
 ipv6UploadClientCpuUtil: 4.050145276520021,
 cmmac: '2C:7E:81:FD:6D:CA',
 provSpeedDn: 500000,
 provSpeedUp: 12500,
 firmwareVersion: 'TG3482PC2_3.3p20s1_PROD_sey',
 make: 'ARRIS Group, Inc.',
 model: 'TG3482G',
 statsCpuUsage: 0.04237288236618042,
 statsDownloadKbps: 56.52790451049805,
 statsUploadKbps: 8.278397560119629,
 mwAppVersion: '20190430144203.3d00408',
 speedtestElapsedTime: 46460,
 userAgent: 'RDK_B_ARRIS_SpeedTest/20181022.6b493f',
 error: false,
 errorCode: null,
 additionalErrorText: null }

应转换为元组:

((resultId, 238074021),(resultDate, '2019-05-18 16:34:12'),............,(additionalErrorText, none))

0 个答案:

没有答案