如何将值插入数组并映射到 sql 数据块?

How to insert values into array and map in sql databricks?

我可以在数据块中创建模式,但如何将数据插入数组和映射? 我就是找不到关于 SQL 的任何信息。这都是关于 python、scala,但我只在寻找 sql。

CREATE TABLE IF NOT EXISTS mydb.arraytest (
  capacity array<INT>,
  mapper MAP<INT, STRING>,
  device_type STRING,
  location_id INT
)

给我预期的架构:

+-------------+-----------------+ 
| col_name    | data_type       | 
+-------------+-----------------+
| capacity    | array<int>      | 
| mapper      | map<int,string> | 
| device_type | string          |
| location_id | int             |

# Partitioning
Not partitioned

但我不知道如何将值插入到数组和映射中?

None 我试过的有效:

INSERT INTO
  mydb.arraytest
VALUES
  (array<1,2,3>, (1, 'mapstring1'), 'string1', 1)
  (<1,2,3>, ....

Array and Map 函数以括号开头,所以像这样的东西应该适合你:

%sql
INSERT INTO arraytest
VALUES (Array(1,2,3), Map(1, 'mapstring1'), 'string1', 1)