如何使用Apache Nifi中的JoltTransformJSON来实现预期输出。

huangapple go评论81阅读模式
英文:

How to implement the expected output using Jolttransfromjson In Apache Nifi

问题

  1. [
  2. {
  3. "export_time": "20230",
  4. "account_id": "0107F6-7",
  5. "cost": "0.0"
  6. },
  7. {
  8. "export_time": "20230101",
  9. "account_id": "01DC85-B",
  10. "cost": "3.48E-4"
  11. }
  12. ]
英文:

Please help me out in achieving the expected output in Jolt.

Input :

  1. {
  2. "kind": "bresponse",
  3. "schema": {
  4. "fields": [
  5. {
  6. "name": "export_time",
  7. "type": "STRING",
  8. "mode": "NULLABLE"
  9. },
  10. {
  11. "name": "account_id",
  12. "type": "STRING",
  13. "mode": "NULLABLE"
  14. },
  15. {
  16. "name": "cost",
  17. "type": "FLOAT",
  18. "mode": "NULLABLE"
  19. }
  20. ]
  21. },
  22. "jobReference": {
  23. "projectId": "avach",
  24. "jobId": "job_G4hQs",
  25. "location": "ui"
  26. },
  27. "totalRows": "49",
  28. "pageToken": "BG123",
  29. "rows": [
  30. {
  31. "f": [
  32. {
  33. "v": "20230"
  34. },
  35. {
  36. "v": "0107F6-7"
  37. },
  38. {
  39. "v": "0.0"
  40. }
  41. ]
  42. },
  43. {
  44. "f": [
  45. {
  46. "v": "20230101"
  47. },
  48. {
  49. "v": "01DC85-B"
  50. },
  51. {
  52. "v": "3.48E-4"
  53. }
  54. ]
  55. }
  56. ],
  57. "totalBytesProcessed": "37472",
  58. "jobComplete": true,
  59. "cacheHit": false
  60. }

Expected output :

  1. [
  2. {
  3. "export_time": "20230",
  4. "account_id": "0107F6-7",
  5. "cost": "0.0"
  6. },
  7. {
  8. "export_time": "20230101",
  9. "account_id": "01DC85-B",
  10. "cost": "3.48E-4"
  11. }
  12. ]

Thanks

答案1

得分: 1

你可以在shift变换规范中使用以下内容:

  • 向上移动5级(遍历一次:,四次{)以达到
    通过使用[&1]从数据数组中选择子数组作为字段数组

  • 通过[&3].节点分散所有返回的键值对

例如

  1. [
  2. {
  3. "operation": "shift",
  4. "spec": {
  5. "rows": {
  6. "*": {
  7. "*": {
  8. "*": {
  9. "@v": "[&3].@(5,schema.fields[&].name)"
  10. }
  11. }
  12. }
  13. }
  14. }
  15. }
  16. ]

在网站http://jolt-demo.appspot.com/上的演示如下:

如何使用Apache Nifi中的JoltTransformJSON来实现预期输出。

英文:

You can use a shift transformation spec in which

  • go 5 levels up (traverse once:, and { four times ) in order to reach
    fields array as picking sub-arrays of data array by using [&1]

  • dissipate all returning key-value pairs through use of [&3]. node

such as

  1. [
  2. {
  3. "operation": "shift",
  4. "spec": {
  5. "rows": {
  6. "*": {
  7. "*": {
  8. "*": {
  9. "@v": "[&3].@(5,schema.fields[&].name)"
  10. }
  11. }
  12. }
  13. }
  14. }
  15. }
  16. ]

the demo on the site http://jolt-demo.appspot.com/ is

如何使用Apache Nifi中的JoltTransformJSON来实现预期输出。

huangapple
  • 本文由 发表于 2023年3月4日 00:27:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/75629595.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定