我正在使用woocommerce API来检索和存储信息.目前我们的设置旨在使用驼峰案例而不是下划线.我正在使用jq处理我们的信息,但我很好奇如何使用该sub(regex, tostring)函数用camelCase替换我的JSON中的下划线?
这是代码的一个例子
"line_items": [
{
"id": xxxx,
"name": "xxxx",
"sku": "xxxx",
"product_id": xxxx,
}
Run Code Online (Sandbox Code Playgroud)
例如,根据我发现的SO的另一个答案,这可行:curl https://www.testsite.com/wp-json/wc/v1/orders -u user:pass | jq '.[] | with_entries( if .key | contains("_") then .key |= sub("_";"") else . end)'并删除下划线.
结果是:
"lineitems": [
{
"id": xxxx,
"name": "xxxx",
"sku": "xxxx",
"productid": xxxx,
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试时,curl https://www.testsite.com/wp-json/wc/v1/orders -u user:pass | jq '.[] | with_entries( if .key | contains("_") then .key |= sub("(\\_)([a-z])";"$2\u") else . end)'我没有得到我期望的结果.
预期结果将是:
"lineItems": …Run Code Online (Sandbox Code Playgroud) 我是云数据流和 Java 的新手,所以我希望这是正确的问题。
我有一个 csv 文件,其中有 n 个列和行,可以是字符串、整数或时间戳。我需要为每一列创建一个新的 PCollection 吗?
我在示例中找到的大多数文档都类似于:
PCollection<String> data = p.apply(TextIO.Read.from("gs://abc/def.csv"));
Run Code Online (Sandbox Code Playgroud)
但对我来说,将整个 csv 文件作为字符串导入是没有意义的。我在这里缺少什么?我应该如何设置我的 PCollections?