当前位置: 首页 > 知识库问答 >
问题:

JOLT平坦化未命名嵌套数组和拆分函数

邵锐
2023-03-14

处理转换并为输入创建规范。输出是嵌套数组,但我期待扁平数组。2.需要拆分字符串并获得第一个元素。分裂函数似乎不起作用。

[
  {
    "tables": [
      {
        "columns": [
          {
            "size": 20,
            "nullable": false,
            "databaseSpecificType": "varchar",
            "generated": false,
            "dataType": "VARCHAR",
            "name": "firstname",
            "width": "(20)",
            "decimalDigits": 0,
            "remarks": "",
            "autoIncremented": false
          },
          {
            "size": 20,
            "nullable": false,
            "databaseSpecificType": "varchar",
            "generated": false,
            "dataType": "VARCHAR",
            "name": "lastname",
            "width": "(20)",
            "decimalDigits": 0,
            "remarks": "",
            "autoIncremented": false
          }
        ],
        "name": "authors",
        "fullName": "books.authors",
        "type": "table",
        "triggers": [],
        "tableConstraints": [],
        "remarks": "Contact details for book authors",
        "primaryKey": {
          "columns": {
            "sortSequence": "ascending",
            "name": "id"
          },
          "unique": true,
          "name": "pk_authors",
          "remarks": ""
        }
      },
      {
        "columns": [
          {
            "size": 10,
            "nullable": true,
            "databaseSpecificType": "int4",
            "generated": false,
            "dataType": "INTEGER",
            "name": "id",
            "width": "",
            "decimalDigits": 0,
            "remarks": "",
            "autoIncremented": false
          }
        ],
        "name": "authorslist",
        "fullName": "books.authorslist",
        "type": "view",
        "triggers": [],
        "tableConstraints": [],
        "remarks": "",
        "primaryKey": {}
      }
    ],
    "schemaCrawlerHeaderInfo": {
      "crawlTimestamp": "2018-05-23 10:21:55",
      "title": ""
    }
  }
]
[{
  "operation": "shift",
  "spec": {
    "*": {
      "tables": {
        "*": {
          "columns": {
            "*": {
              "@(2,name)": "[&3].[&1].TABLE.tableName",
              "@(2,fullName)": ["[&3].[&1].TABLE.fullName", "[&3].[&1].DB.fullName"],
              "@(2,remarks)": "[&3].[&1].TABLE.tableDesc",
              "name": "[&3].[&1].COLUMN.name",
              "dataType": "[&3].[&1].COLUMN.dataType",
              "size": "[&3].[&1].COLUMN.size",
              "nullable": "[&3].[&1].COLUMN.nullable",
              "databaseSpecificType": "[&3].[&1].COLUMN.databaseSpecificType",
              "width": "[&3].[&1].COLUMN.width",
              "decimalDigits": "[&3].[&1].COLUMN.decimalDigits",
              "remarks": "[&3].[&1].COLUMN.remarks",
              "autoIncremented": "[&3].[&1].COLUMN.autoIncremented"
            }
          }
        }
      }
    }
  }
}]
[
  [
    {
      "TABLE": {
        "tableName": "authors",
        "fullName": "books.authors",
        "tableDesc": "Contact details for book authors"
      },
      "DB": {
        "fullName": "books.authors"
      },
      "COLUMN": {
        "name": "firstname",
        "dataType": "VARCHAR",
        "size": 20,
        "nullable": false,
        "databaseSpecificType": "varchar",
        "width": "(20)",
        "decimalDigits": 0,
        "remarks": "",
        "autoIncremented": false
      }
    },
    {
      "TABLE": {
        "tableName": "authors",
        "fullName": "books.authors",
        "tableDesc": "Contact details for book authors"
      },
      "DB": {
        "fullName": "books.authors"
      },
      "COLUMN": {
        "name": "lastname",
        "dataType": "VARCHAR",
        "size": 20,
        "nullable": false,
        "databaseSpecificType": "varchar",
        "width": "(20)",
        "decimalDigits": 0,
        "remarks": "",
        "autoIncremented": false
      }
    }
  ],
  [
    {
      "TABLE": {
        "tableName": "authorslist",
        "fullName": "books.authorslist",
        "tableDesc": ""
      },
      "DB": {
        "fullName": "books.authorslist"
      },
      "COLUMN": {
        "name": "id",
        "dataType": "INTEGER",
        "size": 10,
        "nullable": true,
        "databaseSpecificType": "int4",
        "width": "",
        "decimalDigits": 0,
        "remarks": "",
        "autoIncremented": false
      }
    }
  ]
]Iamexpectingtheflattenedoutputlikebelowinsinglearrayrathernestedarray.[
  {
    "TABLE": {
      "tableName": "authors",
      "fullName": "books.authors",
      "tableDesc": "Contact details for book authors"
    },
    "DB": {
      "fullName": "books.authors"
    },
    "COLUMN": {
      "name": "firstname",
      "dataType": "VARCHAR",
      "size": 20,
      "nullable": false,
      "databaseSpecificType": "varchar",
      "width": "(20)",
      "decimalDigits": 0,
      "remarks": "",
      "autoIncremented": false
    }
  },
  {
    "TABLE": {
      "tableName": "authors",
      "fullName": "books.authors",
      "tableDesc": "Contact details for book authors"
    },
    "DB": {
      "fullName": "books.authors"
    },
    "COLUMN": {
      "name": "lastname",
      "dataType": "VARCHAR",
      "size": 20,
      "nullable": false,
      "databaseSpecificType": "varchar",
      "width": "(20)",
      "decimalDigits": 0,
      "remarks": "",
      "autoIncremented": false
    }
  },
  {
    "TABLE": {
      "tableName": "authorslist",
      "fullName": "books.authorslist",
      "tableDesc": ""
    },
    "DB": {
      "fullName": "books.authorslist"
    },
    "COLUMN": {
      "name": "id",
      "dataType": "INTEGER",
      "size": 10,
      "nullable": true,
      "databaseSpecificType": "int4",
      "width": "",
      "decimalDigits": 0,
      "remarks": "",
      "autoIncremented": false
    }
  }
]
[
  {
    "TABLE": {
      "tableName": "authors",
      "fullName": "books.authors",
      "tableDesc": "Contact details for book authors"
    },
    "DB": {
      "fullName": "books.authors"
    },
    "COLUMN": {
      "name": "firstname",
      "dataType": "VARCHAR",
      "size": 20,
      "nullable": false,
      "databaseSpecificType": "varchar",
      "width": "(20)",
      "decimalDigits": 0,
      "remarks": "",
      "autoIncremented": false
    }
  },
  {
    "TABLE": {
      "tableName": "authors",
      "fullName": "books.authors",
      "tableDesc": "Contact details for book authors"
    },
    "DB": {
      "fullName": "books.authors"
    },
    "COLUMN": {
      "name": "lastname",
      "dataType": "VARCHAR",
      "size": 20,
      "nullable": false,
      "databaseSpecificType": "varchar",
      "width": "(20)",
      "decimalDigits": 0,
      "remarks": "",
      "autoIncremented": false
    }
  },
  {
    "TABLE": {
      "tableName": "authorslist",
      "fullName": "books.authorslist",
      "tableDesc": ""
    },
    "DB": {
      "fullName": "books.authorslist"
    },
    "COLUMN": {
      "name": "id",
      "dataType": "INTEGER",
      "size": 10,
      "nullable": true,
      "databaseSpecificType": "int4",
      "width": "",
      "decimalDigits": 0,
      "remarks": "",
      "autoIncremented": false
    }
  }
]
"DB" : {
    "fullName" : "books.authors"
  }

"DB" : {
    "fullName" : "books"
  }

这方面的任何帮助都是很好的。

共有1个答案

太叔逸春
2023-03-14

得两班倒。

规范与说明

[
  {
    // Your input data is two nested arrays.
    // Tables array, and its nested columns array.
    // The number of elements in your output array is 
    //  the total number of column elements in your input doc.
    // 
    // Can't do it in a single shift.  
    // The sample input tables arrays is length 2
    // The sample input columsn arrays are length 2 and 1.
    // You want an output array of length 3, there is no "3" 
    //  that can be referenced by the first shift operation.
    //
    // So first, "build" the final TABLE, COLUMN, DB format, by
    //  pushing table information down into the columns data, BUT
    //  keeping the same nested table and columns array structure.
    "operation": "shift",
    "spec": {
      "0": {
        "tables": {
          "*": { // tables index
            "columns": {
              "*": { // columns index
                // grabbing info off the "parent" table entry
                "@(2,name)": "tables[&3].cols[&1].TABLE.tableName",
                "@(2,fullName)": ["tables[&3].cols[&1].TABLE.fullName", "tables[&3].cols[&1].DB.fullName"],
                "@(2,remarks)": "tables[&3].cols[&1].TABLE.tableDesc",
                // 
                // handling all the column level data
                "*": "tables[&3].cols[&1].COLUMN.&"
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "tables": {
        "*": {
          "cols": {
            // now walk the nested tables and cols array
            // and accumulate each "fully formatted" 
            // col entry, into the output top-level array
            "*": "[]"
          }
        }
      }
    }
  }
]
 类似资料:
  • 我正在尝试编写一个规范来使用jolt转换进行以下转换。我只对更改json中键的名称感兴趣,值应该保持不变。帮帮我。 输入Json: 预期输出:

  • 我有json,其中包括多个产品,每个产品有多个不同的细节。使用jolt,我只需要输入json中的几个字段,遵循与输入json几乎相同的结构。我成功地迭代了产品,但是当我试图迭代每个产品变体时,我没有得到想要的输出。 输入. json 这里是Spec.json 我想要的预期输出。 我现在得到的实际输出。

  • 我正在努力实现以下转变。然而,我的解决方案在最终数组中添加了不需要的空值。 转换需要为所有元素在array中移位名称。我创建了3个案例来说明这个问题。 编辑:< code >根数组将始终至少有1个元素。 当前的JOLT规范工作正常,除了是空数组的情况。它生成值,我试图指定一个空字符串(或任何硬编码的字符串值,如)

  • 我正在尝试使用 JOLT 根据属性将数组拆分为多个数组。我已经尝试过 JOLT“移位”规范,但无法实现。 我已经查看了几个完成数组转换的链接,但是我找不到任何将数组拆分成多个数组的方法。 示例:根据属性“type”的值将以下数组转换为3个数组。 输入: 输出:

  • 如何使用jolt转换将平面JSON转换为嵌套JSON?我对JSON和jolt是新手。 输入: 预期输出: 编辑:我想在< code>SubFunds中添加一个新字段,但是新字段不在JSON文件中,它是计算字段,我可以按原样添加示例吗 并重命名字段:

  • 嗨,我是ReactJS平台的学生开发者。我以前在render方法中使用过类组件,但现在我学习了钩子和函数组件对它的重要性,就像每个Reactjs开发人员所知道的那样。我在使用嵌套组件时遇到问题,我面临如下错误: index.js:1警告:函数作为React子函数无效。如果返回组件而不是从渲染返回组件,可能会发生这种情况。或者你想调用这个函数而不是返回它 你能帮我解决这个问题吗?如何在返回部分有效地