Impala:如何查询具有不同模式的多个镶木地板文件
Impala: How to query against multiple parquet files with different schemata
在 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 读取包含多个镶木地板文件的文件夹? Impala 会像 spark 一样执行模式合并吗?执行此操作需要什么查询?使用 Google 无法找到有关它的任何信息。 (总是一个坏兆头...)
谢谢!
据我了解,您有一些 parquet 文件并且想通过 impala tables 查看它们?下面是我对此的解释。
您可以创建一个外部 table 并将位置设置为镶木地板文件目录,如下所示
CREATE EXTERNAL TABLE ingest_parquet_files(col1 string, col2 string) LOCATION "/path/to/my/files/" STORED AS PARQUET;
创建 table
后,您还有另一个加载 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
在 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 读取包含多个镶木地板文件的文件夹? Impala 会像 spark 一样执行模式合并吗?执行此操作需要什么查询?使用 Google 无法找到有关它的任何信息。 (总是一个坏兆头...)
谢谢!
据我了解,您有一些 parquet 文件并且想通过 impala tables 查看它们?下面是我对此的解释。
您可以创建一个外部 table 并将位置设置为镶木地板文件目录,如下所示
CREATE EXTERNAL TABLE ingest_parquet_files(col1 string, col2 string) LOCATION "/path/to/my/files/" STORED AS PARQUET;
创建 table
后,您还有另一个加载 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