如何格式化德鲁伊语中的TSV文件

时间:2016-07-21 17:18:31

标签: json hadoop druid

我正在尝试使用此摄取斑点加载德鲁伊的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格式的实际数据集。

1 个答案:

答案 0 :(得分:3)

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

您将使用frist line作为标题来定义列名称 - 因此您可以使用&#34; name&#34;,&#34; age&#34;或者&#34;电子邮件&#34;在spec文件中的维度

对于gmt和utc,它们基本相同

  

格林威治标准时间与格林威治标准时间没有时间差异   协调世界时

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

不要忘记在你的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文件应如下所示:

{
    "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"
                }
            ]
        }
    }
}
相关问题