在Azure Blob存储的多个CSV Blob上创建配置单元表
我有一个Azure Blob存储。在一个名为DATA的容器中,我有以下方式的CSV blob- 现在,我已经使用HDInsight创建了一个Hadoop集群 作为下一部分,我想创建用于查询的配置单元表。这里我有一些具体的问题 1)如何在单个查询中将所有blob加载到配置单元表? 对于单个BLOB,我可以使用如下查询。但是如何在一个查询中为多个blob做到这一点呢在Azure Blob存储的多个CSV Blob上创建配置单元表,csv,azure,hadoop,Csv,Azure,Hadoop,我有一个Azure Blob存储。在一个名为DATA的容器中,我有以下方式的CSV blob- 现在,我已经使用HDInsight创建了一个Hadoop集群 作为下一部分,我想创建用于查询的配置单元表。这里我有一些具体的问题 1)如何在单个查询中将所有blob加载到配置单元表? 对于单个BLOB,我可以使用如下查询。但是如何在一个查询中为多个blob做到这一点呢 # Use the external table option. $queryString = "DROP TABLE log4j
# Use the external table option.
$queryString = "DROP TABLE log4jLogs;" +
"CREATE EXTERNAL TABLE log4jLogs(t1 string, t2 string, t3 string, t4 string, t5 string, t6 string, t7 string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ' ' STORED AS TEXTFILE LOCATION 'wasb://$containerName@$storageAccountName.blob.core.windows.net/example/data/';" +
"SELECT t4 AS sev, COUNT(*) AS cnt FROM log4jLogs WHERE t4 = '[ERROR]' GROUP BY t4;"
2) 创建配置单元表时,加载数据和外部表之间的主要区别是什么
任何投入都会有帮助
现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场现场#######
我遵循以下建议,但无法使其适用于一个BLOB
我的斑点是CSV。我通过powershell从本地上传到blob存储。此blob存储和容器获得了HDInsight的默认示例。Blob数据如下所示
- 1,拉米,维穆拉,29岁
- 杰克,阿斯顿,33岁
# Provide Windows Azure subscription name, and the Azure Storage account and container that is used for the default HDInsight file system.
$subscriptionName = "Rami"
$storageAccountName = "storagename"
$containerName = "containername"
# Provide HDInsight cluster name Where you want to run the Hive job
$clusterName = "clustername"
# Use the external table option.
$queryString = "DROP TABLE mylogss;" +
"CREATE EXTERNAL TABLE mylogss(t1 string, t2 string, t3 string, t4 string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS TEXTFILE LOCATION 'wasb://$containerName@$storageAccountName.blob.core.windows.net/blobrami/';" +
"SELECT COUNT(*) AS cnt FROM mylogss;"
# Create a Hive job definition
$hiveJobDefinition = New-AzureHDInsightHiveJobDefinition -Query $queryString
# Submit the job to the cluster
Select-AzureSubscription $subscriptionName
$hiveJob = Start-AzureHDInsightJob -Cluster $clusterName -JobDefinition $hiveJobDefinition
# Wait for the Hive job to complete
Wait-AzureHDInsightJob -Job $hiveJob -WaitTimeoutInSeconds 3600
结果-
因此,最后我无法获得任何输出。它以代码1退出。我不确定我做错了什么。外部表是配置单元仅管理元数据的表(模式,…)。 加载数据的常规配置单元表的元数据及其数据由配置单元管理 如果删除外部表,则不会丢失数据 对于HDInsight,我通常使用外部表,因为我可以在集群关闭时(这样我就不用付钱)继续在blob存储(wasb)中添加数据。当我针对这些数据重新启动集群时,我只需要运行创建外部表的配置单元脚本就可以通过配置单元访问它们。没有数据加载 下面是一个示例脚本:
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
create external table IF NOT EXISTS raw_tweets ( json_response string ) partitioned by (dt string) stored as textfile;
alter table raw_tweets add if not exists partition(dt='2013-03-06') location 'wasb://mycontainer@mystorageaccount.blob.core.windows.net/data/socialvilles/2013-3-6';
alter table raw_tweets add if not exists partition(dt='2013-03-07') location 'wasb://mycontainer@mystorageaccount.blob.core.windows.net/data/socialvilles/2013-3-7';
alter table raw_tweets add if not exists partition(dt='2013-03-08') location 'wasb://mycontainer@mystorageaccount.blob.core.windows.net/data/socialvilles/2013-3-8';
alter table raw_tweets add if not exists partition(dt='2013-03-09') location 'wasb://mycontainer@mystorageaccount.blob.core.windows.net/data/socialvilles/2013-3-9';
alter table raw_tweets add if not exists partition(dt='2013-03-10') location 'wasb://mycontainer@mystorageaccount.blob.core.windows.net/data/socialvilles/2013-3-10';
alter table raw_tweets add if not exists partition(dt='2013-03-11') location 'wasb://mycontainer@mystorageaccount.blob.core.windows.net/data/socialvilles/2013-3-11';
alter table raw_tweets add if not exists partition(dt='2013-03-12') location 'wasb://mycontainer@mystorageaccount.blob.core.windows.net/data/socialvilles/2013-3-12';
create external table IF NOT EXISTS tweets2 (
id string,
lang string,
json_response string)
partitioned by (dt string)
row format delimited fields terminated by '\t' lines terminated by '\n' stored as textfile
location '/wasbwork/tweets2';
insert overwrite table tweets2
partition (dt)
select
get_json_object(json_response, '$.id_str') as id,
get_json_object(json_response, '$.user.lang') as lang,
json_response,
dt
FROM raw_tweets
where (length(json_response) > 500);
然后,您可以删除HDInsight群集,并在您的默认BlobStorage.blob.core.windows.net/yourclustercontainer/wasbwork/tweets2的blob存储中查找结果
如果您想使用常规配置单元表,我建议您使用它在Azure SQL数据库中创建HDInsight群集配置单元和Oozie metastore(创建群集时有一个选项),这样Hive就可以记住数据存储的位置。可以通过以下简单步骤将多个CSV Blob加载到Hive表中 首先,我们需要稍微改变数据在容器中的组织方式。我使用“data/csv/filename”进行了以下格式设置 然后我们可以使用下面的配置单元查询一次加载所有CSV blob。不需要任何迭代
# Provide Windows Azure subscription name, and the Azure Storage account and container that is used for the default HDInsight file system.
$subscriptionName = "***"
$storageAccountName = "***"
$containerName = "***"
$clusterName = "***"
# Use the external table option.
$queryString = "DROP TABLE logs;" +
"CREATE EXTERNAL TABLE logs(t1 string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' STORED AS TEXTFILE LOCATION " +
"'wasb://$containerName@$storageAccountName.blob.core.windows.net/data/csv';"
# Create a Hive job definition
$hiveJobDefinition = New-AzureHDInsightHiveJobDefinition -Query $queryString
# Submit the job to the cluster
Select-AzureSubscription $subscriptionName
$hiveJob = Start-AzureHDInsightJob -Cluster $clusterName -JobDefinition $hiveJobDefinition
# Wait for the Hive job to complete
Wait-AzureHDInsightJob -Job $hiveJob -WaitTimeoutInSeconds 36000
# Get Output
Get-AzureHDInsightJobOutput -Cluster $clusterName -JobId $hiveJob.JobId -StandardOutput -StandardError
你好benjguin,你能看看问题更新吗。我用上传到存储器的blob尝试了一些代码。很遗憾,我无法获得任何结果。您可以使用以下命令在HDInsight中获得作业的输出:get-AzureHDInsightJobOutput-JobId$hiveJob.JobId-StandardError-StandardOutput`-TaskSummary-Cluster$ClusterName您还可以通过调用AzureHDInsightHiveJob使用PowerShell调用Hive,后者将向您发送结果自动地您还可以RDP到head节点,例如将HQL文件存储到C:\1.HQL,然后打开桌面上的命令提示符,cd..\hive\bin,hive-v-f C:\1.HQL还可以查看您的存储文件夹。例如,我已经为(…)/somefolder/*.xxx创建了一个外部表,它创建了一个名为*.xxx的blob。显然,这并不是我所期望的,这会在事后产生错误。谢谢@benjguin,我会尝试一下你的所有建议,并会回复你。