在 Apache Drill 中查询 tables 而不添加对 table 名称的扩展

Query tables in Apache Drill without adding in extensions to the table name

我有一个带有以下存储插件的 Apache Drill 设置

{
  "type": "file",
  "connection": "file:///",
  "config": null,
  "workspaces": {
    "tmp": {
      "location": "/tmp",
      "writable": true,
      "defaultInputFormat": null,
      "allowAccessOutsideWorkspace": false
    },
    "csv": {
      "location": "/home/user/data/csv",
      "writable": false,
      "defaultInputFormat": "csv",
      "allowAccessOutsideWorkspace": false
    },
    "parquet": {
      "location": "/home/user/data/parquet",
      "writable": false,
      "defaultInputFormat": "parquet",
      "allowAccessOutsideWorkspace": false
    }
  },
  "formats": {
    "csv": {
      "type": "text",
      "extensions": [
        "csv"
      ],
      "skipFirstLine": true,
      "extractHeader": true,
      "delimiter": ","
    },
    "parquet": {
      "type": "parquet",
      "autoCorrectCorruptDates": false
    }
  },
  "enabled": true
}

名称已配置为foo

问题是我想编写一个 table 名称没有扩展名的查询。

我尝试了以下方法,

select * from foo.csv.`agency` limit 100

我收到以下回复

org.apache.drill.common.exceptions.UserRemoteException: VALIDATION ERROR: From line 1, column 15 to line 1, column 21: Object 'agency' not found within 'foo.csv' [Error Id: 80be4497-b71c-47dd-bc2c-6abfa425d55a on nn-hadoop-1:30112]

但这行得通

select * from foo.csv.`agency.csv` limit 100

有什么方法可以让我在创建查询时不在 table 名称(文件名)后加上文件扩展名?我已将 defaultInputFormat 包含在工作区

我找到了解决这个问题的方法。我没有直接查询文件,而是将我要查询的文件放到一个目录中,然后查询该目录。

https://drill.apache.org/docs/querying-directories/

所以,现在我已经创建了一个名为 agency 的文件夹,并将文件 agency.csv 移到了该文件夹中。现在我可以做

select * from foo.csv.`/agency` limit 100

我得到了我想要的结果。

您可以查询table或文件。 对于 table,请创建它:

select * from foo.csv.`agency.csv`

并查询:

select * from agency;

对于第二种情况,Drill 应该有文件或目录的完整路径(包括工作空间,如果你使用的话)

另一种选择是使用视图;首先使用 writable workspace(如上面的 /tmp)

use foo.tmp;

然后创建视图

create view agency as select * from foo.csv.`agency.csv`;

与创建 table 不同,视图不会占用大量磁盘 space,并且会反映文件中的最新数据(以防文件更新。) 用法一样,like

select * from agency limit 100;