python - 如何使用阿里巴巴ODPS python SDK中的Schema.from_lists方法创建模式?
问题描述
我通常通过表列和可选分区进行初始化来创建模式。我知道在阿里巴巴 ODPS python SDK 中通过方法创建模式Schema.from_lists
在 LOC 和性能方面要好得多。
我经常用来创建模式的代码是:
from odps.models import Schema, Column, Partition
columns = [Column(name='num', type='bigint', comment='the column')]
partitions = [Partition(name='pt', type='string', comment='the partition')]
schema = Schema(columns=columns, partitions=partitions)
print(schema.columns)
输出:
[<column num, type bigint>, <partition pt, type string>]
如何使用Schema.from_lists
方法创建模式?
解决方案
您可以通过传递四个列表来创建。
In [33]: Schema.from_lists(['num'], ['bigint'], ['pt'], ['string'])
Out[33]:
odps.Schema {
num bigint
}
Partitions {
pt string
}
缺点是通过这种方式,您不能再指定列的注释。
推荐阅读
- javascript - Chrome DevTools - 错误的覆盖率 json?
- python - 使用 Python 在单个 Excel 中将大型 CSV 文件拆分为多个工作表
- html - 如何在 .NET Standard 2.0 中将颜色转换为 HTML 颜色?
- symfony - 在 symfony 事件订阅者中获取调用的上下文
- amazon-ec2 - EC2 实例允许我登录后连接关闭
- java - Java 8 流中的 IfPresentOrElse 场景
- c# - 如何在课堂上使用 Blazor 范围内的服务
- javascript - Javascript 允许文本区域中的特殊字符(电子应用程序)
- android - RecyclerView 在插入新项目时滚动到底部
- c# - 泛型 - 获取属性 LINQ