php小编新一将介绍如何将 parquet 文件转换为带有嵌套元素的 Golang 结构。Parquet 是一种高效的列式存储格式,而 Golang 是一种强大的编程语言,将它们结合起来可以帮助我们更好地处理和分析大量的数据。通过使用适当的库和技术,我们可以轻松地将 parquet 文件解析为 Golang 的结构,并且可以处理嵌套的元素,从而更好地组织和操作数据。本文将详细介绍实现的步骤和注意事项,帮助读者轻松上手。
问题内容
我正在尝试使用 xitongsys/parquet-go 库读取 go 中带有嵌套数组/结构的镶木地板文件。列表数据没有被读取,也没有看到值。下面是我在 golang 中的结构
type Play struct { SID string `parquet:"name=si, type=BYTE_ARRAY, convertedtype=UTF8, encoding=PLAIN_DICTIONARY, repetitiontype=OPTIONAL" json:"si,omitempty"` TimeStamp int `parquet:"name=ts, type=INT64, repetitiontype=OPTIONAL" json:"ts,omitempty"` SingleID int `parquet:"name=sg, type=INT64, repetitiontype=OPTIONAL" json:"sg,omitempty"` PID int `parquet:"name=playid, type=INT64, repetitiontype=OPTIONAL" json:"playid,omitempty"` StartTimeStamp string `parquet:"name=startts, type=BYTE_ARRAY,repetitiontype=OPTIONAL"` Price []Price1 `parquet:"name=price, type=LIST, repetitiontype=REQUIRED" json:"price,omitempty"` } type Price1 struct { CurrID int `parquet:"name=currId, type=INT64, repetitiontype=REQUIRED" json:"currId,omitempty"` LPTag string `parquet:"name=lptag, type=BYTE_ARRAY,convertedtype=UTF8, repetitiontype=REQUIRED" json:"lptag,omitempty"` LPrice Money `parquet:"name=lpmoney, type=STRUCT" json:"lpmoney,omitempty"` } type Money struct { AdmCurrCode string `parquet:"name=admCC, type=BYTE_ARRAY, repetitiontype=OPTIONAL" json:"admCC,omitempty"` AdmCurrValue string `parquet:"name=admCV, type=BYTE_ARRAY" json:"admCV,omitempty"` }
即使 parquet 文件具有有效值,currid 和 lptag 仍为空
解决方法
我发现github.com/segmentio/parquet-go
包可以正确读取文件。您需要坚持使用 github.com/xitongsys/parquet-go
包吗?
package main import ( "fmt" "github.com/segmentio/parquet-go" ) type Play struct { SID string `parquet:"si"` TimeStamp int `parquet:"ts"` SingleID int `parquet:"sg"` PID int `parquet:"playid"` StartTimeStamp string `parquet:"startts"` Price []Price `parquet:"price,list"` } type Price struct { CurrID int `parquet:"currId"` LPTag string `parquet:"lptag"` LPrice Money `parquet:"lpmoney"` } type Money struct { AdmCurrCode string `parquet:"admCC"` AdmCurrValue string `parquet:"admCV"` } func main() { rows, err := parquet.ReadFile[Play]("s3.parquet") if err != nil { panic(err) } for _, c := range rows { fmt.Printf("%+v\n", c) } }
以上是将 parquet 文件转换为带有嵌套元素的 Golang 结构的详细内容。更多信息请关注PHP中文网其他相关文章!

goisidealforbuildingscalablesystemsduetoitssimplicity,效率和建筑物内currencysupport.1)go'scleansyntaxandaxandaxandaxandMinimalisticDesignenhanceProductivityAndRedCoductivityAndRedCuceErr.2)ItSgoroutinesAndInesAndInesAndInesAndineSandChannelsEnablenableNablenableNableNablenableFifficConcurrentscorncurrentprogragrammentworking torkermenticmminging

Initfunctionsingorunautomationbeforemain()andareusefulforsettingupenvorments和InitializingVariables.usethemforsimpletasks,避免使用辅助效果,andbecautiouswithTestingTestingTestingAndLoggingTomaintAnainCodeCodeCodeClarityAndTestesto。

goinitializespackagesintheordertheordertheyimported,thenexecutesInitFunctionswithinApcageIntheirdeFinityOrder,andfilenamesdetermineTheOrderAcractacractacrosmultiplefiles.thisprocessCanbeCanbeinepessCanbeInfleccessByendercrededBydeccredByDependenciesbetenciesbetencemendencenciesbetnependendpackages,whermayleLeadtocomplexinitialitialializizesizization

CustomInterfacesingoarecrucialforwritingFlexible,可维护,andTestableCode.TheyEnableDevelostOverostOcusonBehaviorBeiroveration,增强ModularityAndRobustness.byDefiningMethodSigntulSignatulSigntulSignTypaterSignTyperesthattypesmustemmustemmustemmustemplement,InterfaceSallowForCodeRepodEreusaperia

使用接口进行模拟和测试的原因是:接口允许定义合同而不指定实现方式,使得测试更加隔离和易于维护。1)接口的隐式实现使创建模拟对象变得简单,这些对象在测试中可以替代真实实现。2)使用接口可以轻松地在单元测试中替换服务的真实实现,降低测试复杂性和时间。3)接口提供的灵活性使得可以为不同测试用例更改模拟行为。4)接口有助于从一开始就设计可测试的代码,提高代码的模块化和可维护性。

在Go中,init函数用于包初始化。1)init函数在包初始化时自动调用,适用于初始化全局变量、设置连接和加载配置文件。2)可以有多个init函数,按文件顺序执行。3)使用时需考虑执行顺序、测试难度和性能影响。4)建议减少副作用、使用依赖注入和延迟初始化以优化init函数的使用。

go'SselectStatementTreamLinesConcurrentProgrambyMultiplexingOperations.1)itallowSwaitingOnMultipleChannEloperations,执行thefirstreadyone.2)theDefirstreadyone.2)thedefefcasepreventlocksbysbysbysbysbysbythoplocktrograpraproxrograpraprocrecrecectefnoopeready.3)

contextancandwaitgroupsarecrucialingoformanaginggoroutineseflect.1)context contextsallowsAllowsAllowsAllowsAllowsAllingCancellationAndDeadLinesAcrossapibiboundaries,确保GoroutinesCanbestoppedGrace.2)WaitGroupsSynChronizeGoroutines,确保Allimizegoroutines,确保AllizeNizeGoROutines,确保AllimizeGoroutines


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

记事本++7.3.1
好用且免费的代码编辑器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

WebStorm Mac版
好用的JavaScript开发工具