如何处理外部 table 位置路径中的空格

How to handle spaces in external table location path

我正在尝试根据存储在 Azure Data Lake 存储中的文件创建外部 table。

除包含空格的路径外,所有路径都按预期工作。

create or replace external table CG 
with location = '@stg/bc4ps/dbo/test$G_L Entry/'
file_format = ( FORMAT_NAME = csv);

以上代码 returns 错误消息“无效 URL: '@stg/bc4ps/dbo/test$G_L 条目/'”。

单引号似乎没有转义外部 table 位置路径中的空格。

文档页面也没有提及任何关于路径中空格的内容。

如何获得带空格的路径?

所以是的,去掉单引号并将 space 替换为 %20

create stage stg  URL ='s3://buck_name/path_mc_pathy_path_path/';

create file format csv;

create external table CG
  with location = @stg/bc4ps/dbo/test$G_L%20Entry/
  file_format = ( FORMAT_NAME = csv);

因此,无论出于何种原因,CREATE EXTERNAL TABLE 位置在使用 Azure Data Lake Gen 2 时不接受空格。我实现此功能的唯一方法是借助正则表达式模式。

我将位置指向根文件夹,然后使用模式来过滤正确的文件。

create external table CG
  with location = @stg/bc4ps/dbo/
  file_format = ( FORMAT_NAME = csv)
  pattern = '.*G_L Entry.*.csv$';

上面的正则表达式是这样做的:

.* - multiple characters
G_L Entry - my search string
.* - multiple characters
.csv - only takes csv extension
$ - indicates end of string

此时我只有一个有限的开发环境,只有很少的数据可以测试,我无法检查正则表达式模式以何种方式影响性能(如果它确实影响的话)。