json - 如何在 Druid 中格式化 TSV 文件

标签 json hadoop druid

我正在尝试使用此摄取 Blob 在德鲁伊中加载 TSV:

最新的规范如下:

{                                                                                                                                                                                               
"type" : "index",
"spec" : {
    "ioConfig" : {
        "type" : "index",
        "inputSpec" : {
            "type": "local",
            "baseDir": "quickstart",
            "filter": "test_data.json"
        }
    },
    "dataSchema" : {
        "dataSource" : "local",
        "granularitySpec" : {
            "type" : "uniform",
            "segmentGranularity" : "hour",
            "queryGranularity" : "none",
            "intervals" : ["2016-07-18/2016-07-22"]
        },
        "parser" : {
            "type" : "string",
            "parseSpec" : {
                "format" : "json",
                "dimensionsSpec" : {
                    "dimensions" : ["name", "email", "age"]
                },
                "timestampSpec" : {
                    "format" : "yyyy-MM-dd HH:mm:ss",
                     "column" : "date"
                }
            }
        },
        "metricsSpec" : [
            {
                "name" : "count",
                "type" : "count"
            },
            {
              "type" : "doubleSum",
              "name" : "age",
              "fieldName" : "age"
            }
        ]
    }
}

如果我的架构如下所示:

Schema: name    email    age

实际数据集如下所示:

name    email    age    Bob    Jones    23    Billy    Jones    45

在上面的 TSV 数据集中,列的格式应该是这样吗^^?像 name email age 应该是第一个(列),然后是实际数据。我很困惑德鲁伊如何知道如何将列映射到 TSV 格式的实际数据集。

最佳答案

TSV 代表制表符分隔格式,因此它看起来与 csv 相同,但您将使用制表符而不是逗号,例如

Name<TAB>Age<TAB>Address
Paul<TAB>23<TAB>1115 W Franklin
Bessy the Cow<TAB>5<TAB>Big Farm Way
Zeke<TAB>45<TAB>W Main St

您将使用第一行作为标题来定义您的列名称 - 因此您可以在规范文件的维度中使用“姓名”、“年龄”或“电子邮件”

至于gmt和utc,基本一样

There is no time difference between Greenwich Mean Time and Coordinated Universal Time

第一个是时区,另一个是时间标准

顺便说一句,不要忘记在您的 tsv 文件中包含一个带有时间值的列!!

例如如果您将拥有如下所示的 tsv 文件:

"name"  "position"  "office"    "age"   "start_date"    "salary"
"Airi Satou"    "Accountant"    "Tokyo" "33"    "2016-07-16T19:20:30+01:00" "162700"
"Angelica Ramos"    "Chief Executive Officer (CEO)" "London"    "47"    "2016-07-16T19:20:30+01:00" "1200000"

您的规范文件应如下所示:

{
    "spec" : {
        "ioConfig" : {
            "inputSpec" : {
                "type": "local",
                "baseDir": "path_to_folder",
                "filter": "name_of_the_file(s)"
            }
        },
        "dataSchema" : {
            "dataSource" : "local",
            "granularitySpec" : {
                "type" : "uniform",
                "segmentGranularity" : "hour",
                "queryGranularity" : "none",
                "intervals" : ["2016-07-01/2016-07-28"]
            },
            "parser" : {
                "type" : "string",
                "parseSpec" : {
                    "format" : "tsv",
                    "dimensionsSpec" : {
                        "dimensions" : [
                            "position",
                            "age",
                            "office"
                        ]
                    },
                    "timestampSpec" : {
                        "format" : "auto",
                         "column" : "start_date"
                    }
                }
            },
            "metricsSpec" : [
                {
                    "name" : "count",
                    "type" : "count"
                },
                {
                    "name" : "sum_sallary",
                    "type" : "longSum",
                    "fieldName" : "salary"
                }
            ]
        }
    }
}

关于json - 如何在 Druid 中格式化 TSV 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38510530/

相关文章:

python - 很好地将 .txt 文件转换为 .json 文件

json - 当作为 JSON 返回时,如何强制将对象的属性作为字符串输出

java - 报表任务管理器中的processedWithError是什么意思?

druid - 如何在使用 imply 时限制德鲁伊生成的日志文件的大小?

javascript - 将数组值放入不同的 html 文本框中

json - 通过cloudformation创建IAM角色时policyName出错

java - 安装Github Project Cascading/vagrant-cascading-hadoop-cluster 出错

hadoop - 如何正确删除 Hadoop 中的节点?

hadoop - Hive将文件存放在HDFS的什么地方?

java - 如何在 Druid io 中将 Post Aggregation 值字段添加为 Metric