首页 > 后端开发 > Golang > 正文

使用golang apache arrow实现的datatype.go中指定的数据类型来构建模式

WBOY
发布: 2024-02-06 08:36:07
转载
799人浏览过

使用golang apache arrow实现的datatype.go中指定的数据类型来构建模式

问题内容

我正在学习 apache arrow,想要了解有关如何创建模式和箭头记录的更多信息。为此,我引用了一些材料,但到目前为止,所有这些材料都只是使用原始类型来构建如下所示的模式:`

schema := arrow.NewSchema(
    []arrow.Field{
        {Name: "f1-i32", Type: arrow.PrimitiveTypes.Int32},
        {Name: "f2-f64", Type: arrow.PrimitiveTypes.Float64},
    },
    nil,
)
登录后复制

我想要使用的 primitivetypes 中不存在一些数据类型。例如,我想使用bool或decimal128。我正在查看 golang 箭头库,发现文件 datatype.go ,其中包含我想要使用的所有可能的数据类型。 但这里的类型不是构建模式时所需的 datatype 类型。

所以,我有以下三个问题:

  1. 如果可能的话,如何使用 datatype.go 中的这些数据类型来构建我的架构?
  2. 如果我想使用小数类型,如何指定精度和小数位数?
  3. 使用扩展类型的示例。

正确答案


datatype.go 中定义的这些数据类型命名常量已用于创建您想要的新类型的一部分。其中一些是 type decimal128type structtype booleantype struct 如果您检查这些结构的 id 方法的源代码,它们返回在 datatype.go 中定义的常量,其名称与结构的名称相似。这些结构已经实现了 datatype 接口,这意味着您可以将它们分配给 arrow.field.type 因为该字段的类型是 datatype
我对他们的意思是:
bool 中定义的常量 datatype.godatatype_fixedwidth.go 中用作 type booleantype structid 方法的返回值。
func (t *booleantype) id() 类型 { return bool }
同样的事情也适用于 type decimal128type struct
func (*decimal128type) id() 类型 { return decimal128 }.

这些结构之一的方法显示它们正在实现 datatype 接口:

func (*decimal128type) bitwidth() int
func (t *decimal128type) fingerprint() string
func (*decimal128type) id() type
func (*decimal128type) name() string
func (t *decimal128type) string() string
登录后复制

这些方法适用于 type decimal128type struct
以及datatype接口的定义:

type datatype interface {
    id() type
    // name is name of the data type.
    name() string
    fingerprint() string
}
登录后复制

type booleantype struct 也实现了它。

立即学习go语言免费学习笔记(深入)”;

无阶未来模型擂台/AI 应用平台
无阶未来模型擂台/AI 应用平台

无阶未来模型擂台/AI 应用平台,一站式模型+应用平台

无阶未来模型擂台/AI 应用平台 35
查看详情 无阶未来模型擂台/AI 应用平台

因此,您可以将它们用于 type 字段:

type field struct {
    name     string   // field name
    type     datatype // the field's data type
    nullable bool     // fields can be nullable
    metadata metadata // the field's metadata, if any
}
登录后复制

示范性示例:

package main

import (
    "fmt"

    "github.com/apache/arrow/go/arrow"
)

func main() {
    booltype :=  &arrow.booleantype{}
    decimal128type := &arrow.decimal128type{precision: 1, scale: 1}

    schema := arrow.newschema(
        []arrow.field{
            {name: "f1-bool", type: booltype},
            {name: "f2-decimal128", type: decimal128type},
        },
        nil,
    )

    fmt.println(schema)
}
登录后复制

输出:

schema:
  fields: 2
    - f1-bool: type=bool
    - f2-decimal128: type=decimal(1, 1)
登录后复制

您可以在 文档
还有一些与扩展类型相关的东西。
但我不熟悉扩展类型,因此我无法展示它的示例。但如果你熟悉它,你就可以轻松解决它。

以上就是使用golang apache arrow实现的datatype.go中指定的数据类型来构建模式的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:stackoverflow网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
热门推荐
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号