Jolt 表达式合并二维数组

问题描述 投票:0回答:1

所以我有地理坐标,我想创建多边形字符串,我可以将其作为几何类型插入到 Postgres 中。我正在使用 apache Nifi。

输入:

[
  [
    13,
    52
  ],
  [
    13,
    55
  ],
  [
    14,
    15
  ]
]

预期输出:

POLYGON((13 52, 13 55, 14 15))

我尝试使用以下 JOLT 但没有运气:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "[&1].[&0]"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&"
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "*": "=join(' ',@(1,&))"
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=concat('POLYGON((',@(1,2),'))')"
    }
  }
]
postgresql gis apache-nifi jolt
1个回答
0
投票

您可以将当前的转换为:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&1"
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=join(' ',@(1,&))"
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "@": "Coord"
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "Coord": "=join(' ,',@(1,&))",
      "*": "=concat('POLYGON((',@(1,&),'))')"
    }
  }
]

网站上的 演示 https://jolt-demo.appspot.com/ 是:

© www.soinside.com 2019 - 2024. All rights reserved.