简体   繁体   English

将时间戳列清空为“NULL”

[英]Empty timestamp columns to 'NULL'

Below is my sample JSON data in which I had given few date columns having timestamp data type as empty.下面是我的样本 JSON 数据,其中我给出了几个时间戳数据类型为空的日期列。 Now while ingesting JSON to DB I want the columns having data type as timestamp which are empty ('') to be converted to 'NULL'.现在,在将 JSON 摄取到 DB 时,我希望将数据类型为时间戳的列('')转换为'NULL'。

I have used a Replacetext processor to search for '' after split and Replacement value as 'Null' but if there are any other columns which are empty are also converting to 'Null' (like age).我使用 Replacetext 处理器在拆分后搜索“”,并将替换值设为“Null”,但如果有任何其他为空的列也将转换为“Null”(如年龄)。 I only want to replace the timestamp columns to 'Null'.我只想将时间戳列替换为“Null”。

Any suggestions on this issue?关于这个问题有什么建议吗?

[
  {
    "name": "Tony",
    "age": 22,
    "regdate": "2022-07-01 02:15:15",
    "due_date": "",
    "start_date": ""
  },
  {
    "name": "Steve",
    "age": 21,
    "regdate": "",
    "due_date": "2022-03-01 05:22:15",
    "start_date": ""
  },
  {
    "name": "Peter",
    "age": 23,
    "regdate": "",
    "due_date": "",
    "start_date": "2021-08-06 02:20:15"
  }
]

I have used a Replacetext processor to search for '' after split and Replacement value as 'Null' but if there are any other columns which are empty are also converting to 'Null' (like age).我使用 Replacetext 处理器在拆分后搜索“”,并将替换值设为“Null”,但如果有任何其他为空的列也将转换为“Null”(如年龄)。 I only want to replace the timestamp columns to 'Null'.我只想将时间戳列替换为“Null”。

Adding a JoltTransformJSON processor which converts a JSON value to another formatted JSON value with specification below which contains a conditional logic would suit well for your case:添加一个JoltTransformJSON处理器,将 JSON 值转换为另一个格式化的 JSON 值,其规格如下,其中包含条件逻辑,非常适合您的情况:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {// values without ""(btw, name and age values are presumed to be non-null for every cases)
            "$": "[&3].&2"
          },
          "": "[&2].&1"// values with ""
        }
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "age": "=toInteger"
      }
    }
  }
]

which converts all "" values to null for all attributes.它将所有属性的所有""值转换为null

If conversion of only timestamp attributes, those have substring piece date , matters, then use the following spec如果转换时间戳属性,那些有 substring piece date ,很重要,然后使用以下规范

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "[&1].&",
        "*date": {// to pick only timestamp attributes
          "*": {
            "$": "[&3].&2"
          },
          "": {
            "@": "[&3].&2"
          }
        }
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "age": "=toInteger"
      }
    }
  }
]

the demo on the site http://jolt-demo.appspot.com/ is网站http://jolt-demo.appspot.com/上的演示

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM