首頁 > 後端開發 > Golang > 主體

將 parquet 檔案轉換為帶有巢狀元素的 Golang 結構

王林
發布: 2024-02-10 19:10:08
轉載
764 人瀏覽過

将 parquet 文件转换为带有嵌套元素的 Golang 结构

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中文網其他相關文章!

來源:stackoverflow.com
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!