apache-spark - How to REPLACE INTO using MERGE INTO for upsert in Delta Lake?
问题描述
The recommended way of doing an upsert in a delta table is the following.
MERGE INTO users
USING updates
ON users.userId = updates.userId
WHEN MATCHED THEN
UPDATE SET address = updates.addresses
WHEN NOT MATCHED THEN
INSERT (userId, address) VALUES (updates.userId, updates.address)
Here updates
is a table. My question is how can we do an upsert directly, that is, without using a source table. I would like to give the values myself directly.
In SQLite, we could simply do the following.
REPLACE INTO table(column_list)
VALUES(value_list);
Is there a simple way to do that for Delta tables?
解决方案
源表可以是子查询,因此以下内容应为您提供所需的内容。
MERGE INTO events
USING (VALUES(...)) // round brackets are required to denote a subquery
ON false // an artificial merge condition
WHEN NOT MATCHED THEN INSERT *
推荐阅读
- javascript - javascript: css 没有解决,为什么?
- python - 如何找到离线最近的点?
- django - Django-Filters Lookup_expr type 'AND'
- java - Java int 无法更改,因为 lambda 表达式必须是 final 或有效 final
- c - 带有 UNIX 域数据报套接字的 sendto 上的“无效参数”
- python - 查找按位运算的一个操作数
- c++ - 如何使用 v4l2loopback 将图像渲染到 /dev/video0?
- android - 显示对话框后更改警告对话框的正按钮文本
- android - 画布 drawText 和表情符号 alpha 颜色
- python - Selenium 不会在远程服务器上无头启动