【问题标题】:Create nested table using presto?使用 presto 创建嵌套表?
【发布时间】:2020-12-21 19:10:04
【问题描述】:

如果我有这种结构的火花模式,

root
 |-- id: long (nullable = true)
 |-- firstname: string (nullable = true)
 |-- lastname: string (nullable = true)
 |-- orders: array (nullable = true)
 |    |-- element: struct (containsNull = true)
 |    |    |-- id: long (nullable = true)
 |    |    |-- price: double (nullable = true)
 |    |    |-- userid: long (nullable = true)

如何使用此架构创建表, 我试过这个查询,

CREATE TABLE iceberg.test.order (
id BIGINT,
firstName VARCHAR,
lastName VARCHAR,
orders ROW(
    id BIGINT,
    price double,
    userid BIGINT
        )
                )
WITH (
  format = 'PARQUET'
)

【问题讨论】:

    标签: json apache-spark apache-spark-sql presto amazon-athena


    【解决方案1】:

    如果您尝试创建表。要读取 s3 上现有的 parquet 文件,语法类似于下面的示例。我将它调整为您正在显示的架构:orders 是一个结构数组。

    create external table mytable (
       id bigint,
       firstname varchar, 
       lastname varchar, 
       orders array[struct<id:bigint, price:double, userid:bigint>]
    ) stored as parquet
    location 's3://...'
    

    这里有更多示例:https://aws.amazon.com/blogs/big-data/create-tables-in-amazon-athena-from-nested-json-and-mappings-using-jsonserde/

    【讨论】:

    • 语法是array&lt;struct&lt;…&gt;&gt;(即没有方括号)。
    猜你喜欢
    • 2021-12-15
    • 1970-01-01
    • 1970-01-01
    • 2013-02-16
    • 2021-06-10
    • 2012-11-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多