go-gorm / bigquery

BigQuery golang sql driver/GORM dialect
MIT License
41 stars 23 forks source link

Empty structs #5

Open stbenjam opened 2 years ago

stbenjam commented 2 years ago

Your Question

I'm having an odd issue using GORM with BigQuery. I've pared things down to a very, very simple .Find, and unmarshalling into a struct:

    q.Table("Tags").
        Select("ROW_NUMBER() OVER() id, *").
        Find(&tags)

My Tags struct looks like:

type Tag struct {
    ID int `json:"id" gorm:"column:id"`

    Phase string `json:"phase" gorm:"column:phase"`
}

Logs show it got results from the DB:

[4734.504ms] [rows:10] SELECT ROW_NUMBER() OVER() id, * FROM `Tags` LIMIT 10

And my tags array has 10 entries, but all fields in the structs have zero values. I have no problem using the native BigQuery client, but I need to use GORM on this project since we have some filtering layer for an API built on top of it.

Any idea what's wrong?

The document you expected this should be explained

gorm bigquery driver docs

Expected answer

What I'm doing wrong

stbenjam commented 2 years ago

Some additional info: if I use .Rows() instead of .Find(), and look at rows.Columns(), it's empty - [].

freehere107 commented 2 years ago

@stbenjam Is the current library available? Currently, I execute the create statement without any return, not even a log

plindbe2 commented 2 years ago

I second this issue. I will stay on older versions for now. I've traced it down to when the go sql module is calling bigQueryRows.Columns() it is returning an empty list. Looking at the google code, the RowIterator.Schema has a comment saying "The schema of the table. Available after the first call to Next." which is getting used but the Next hasn't been called yet so it's empty. I believe that previously somehow the query was happening before it gets to this point when it calls Columns. I may try to debug further if I can find the time.

plindbe2 commented 2 years ago

Hello Again. I've submitted a pull request here to fix this issue. Please take a look and let me know if there are any issues:

https://github.com/go-gorm/bigquery/pull/8

MAJA-Lin commented 1 year ago

Hi, I saw the pull request #8 had been merged for a long time. Does the PR fix this issue / can this issue be closed?