Search code examples
jsonapache-nifijolt

Mistake with @timestamp in NiFi Jolt Specification


I'm receving mistake with @timestamp parameter in my jolt transformation:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "@(1,timestamp)": "values.[#2].timestamp",
        "$": [
          "values.[#2].id",
          "values.[#2].doc_id"
        ],
        "@": "values.[#2].value"
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "values": {
        "*": {
          "doc_id": "=concat(@(1,doc_id),@(1,timestamp))",
          "@timestamp": "=concat(@(1,timestamp),'000')",
          "value": "=concat(@(1,value),'')"
        }
      }
    }
  }
]

Input ex:

{
  "timestamp": 1559350080,
  "param": 12
}

Is it possible to use the character @ in Jolt Transformation?


Solution

  • @ is a special character. Need to prefix with escape characters(\\) in order to make it a literal by replacing "@timestamp" key with "\\@timestamp".

    This way, you'll have "@timestamp" : "1559350080000" as key-value pair in the output.