提问人:LordRofticus 提问时间:11/16/2023 最后编辑:Alex OttLordRofticus 更新时间:11/16/2023 访问量:34
具有分区文件夹的 Datalake 中的 Databricks 增量表
Databricks Delta Table from Datalake with Partitioned Folders
问:
我在名为“暂存”的容器中有有关 Azure 存储帐户的数据。
使用 SourceSystem/Dataset 层次结构,我每月还有基于日期的文件夹。在文件夹内,数据以增量格式存储。
在数据块中,我已经装载了容器。 我想创建一个增量表,这样我就可以看到基础文件夹printtransaction文件夹中的所有数据。
DROP TABLE IF EXISTS staging.default.ysoft_printtransaction;
CREATE TABLE staging.default.ysoft_printtransaction
USING delta
OPTIONS ('delta.checkpoint.writeStatsAsJson' 'false', 'delta.checkpoint.writeStatsAsStruct' 'true')
LOCATION 'abfss://[email protected]/ysoft/printtransaction/*/';
SELECT * FROM staging.default.ysoft_printtransaction;
显然,我不想为每个分区文件夹创建一个表。
我有哪些选择?
答:
0赞
Pratik Lad
11/22/2023
#1
根据您提供的信息,这两个文件夹是单独的增量表。我同意 @Alex Ott 所说,因为这两个文件夹是单独的增量表,您需要单独读取它们,然后您可以合并它们并使用不同表中的合并查询进行组合。
它将无法从单个表中的多个增量表中读取数据。
分别读取每个文件夹的示例代码:
CREATE TABLE ysoft_printtransaction1
USING delta
Location 'abfss://[email protected]/sampledb/202113';
CREATE TABLE ysoft_printtransaction2
USING delta
Location 'abfss://[email protected]/sampledb/202110';
要合并表,您可以使用以下命令。
MERGE INTO target USING source
ON target.key = source.key
WHEN NOT MATCHED THEN INSERT *
评论