在 Spark 2.1 中我经常使用类似的东西
df = spark.read.parquet(/path/to/my/files/*.parquet)
即使具有不同的架构,也可以加载 parquet 文件的文件夹。 然后我使用 SparkSQL 对数据框执行一些 SQL 查询。
现在我想尝试 Impala,因为我阅读了 wiki article ,其中包含如下句子:
Apache Impala is an open source massively parallel processing (MPP) SQL query engine for data stored in a computer cluster running Apache Hadoop [...].
Reads Hadoop file formats, including text, LZO, SequenceFile, Avro, RCFile, and Parquet.
所以听起来它也适合我的用例(并且执行速度可能更快)。
但是当我尝试这样的事情时:
CREATE EXTERNAL TABLE ingest_parquet_files LIKE PARQUET
'/path/to/my/files/*.parquet'
STORED AS PARQUET
LOCATION '/tmp';
我得到一个 AnalysisException
AnalysisException: Cannot infer schema, path is not a file
那么现在我的问题是:是否可以使用 Impala 读取包含多个 parquet 文件的文件夹? Impala 会像 spark 一样执行模式合并吗?执行此操作需要什么查询?使用谷歌无法找到有关它的任何信息。 (总是一个不好的迹象...)
谢谢!
最佳答案
据我了解,您有一些 parquet 文件并且想通过 impala 表查看它们?下面是我对此的解释。
您可以创建一个外部表并将位置设置为 parquet 文件目录,如下所示
CREATE EXTERNAL TABLE ingest_parquet_files(col1 string, col2 string) LOCATION "/path/to/my/files/" STORED AS PARQUET;
您还有另一种选择,即在创建表后加载 parquet 文件
LOAD DATA INPATH "Your/HDFS/PATH" INTO TABLE schema.ingest_parquet_files;
您正在尝试的也将起作用,您必须删除通配符,因为它需要在 LIKE PARQUET 之后的路径,并在该位置查找文件。
CREATE EXTERNAL TABLE ingest_parquet_files LIKE PARQUET
'/path/to/my/files/'
STORED AS PARQUET
LOCATION '/tmp';
下面是您可以引用的模板,它是从 Cloudera impala doc 中提取的.
CREATE [EXTERNAL] TABLE [IF NOT EXISTS] [db_name.]table_name
LIKE PARQUET 'hdfs_path_of_parquet_file'
[COMMENT 'table_comment']
[PARTITIONED BY (col_name data_type [COMMENT 'col_comment'], ...)]
[WITH SERDEPROPERTIES ('key1'='value1', 'key2'='value2', ...)]
[
[ROW FORMAT row_format] [STORED AS file_format]
]
[LOCATION 'hdfs_path']
[TBLPROPERTIES ('key1'='value1', 'key2'='value2', ...)]
[CACHED IN 'pool_name' [WITH REPLICATION = integer] | UNCACHED]
data_type:
primitive_type
| array_type
| map_type
| struct_type
请注意,您使用的用户应对您提供给 impala 的任何路径具有读写访问权限。您可以通过执行以下步骤来实现它
#Login as hive superuser to perform the below steps
create role <role_name_x>;
#For granting to database
grant all on database to role <role_name_x>;
#For granting to HDFS path
grant all on URI '/hdfs/path' to role <role_name_x>;
#Granting the role to the user you will use to run the impala job
grant role <role_name_x> to group <your_user_name>;
#After you perform the below steps you can validate with the below commands
#grant role should show the URI or database access when you run the grant role check on the role name as below
show grant role <role_name_x>;
#Now to validate if the user has access to the role
show role grant group <your_user_name>;
有关角色和权限的更多信息 here
关于hadoop - Impala:如何查询具有不同模式的多个 Parquet 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48343036/