Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spanner: provide column types in results #1805

Closed
rakyll opened this issue Feb 26, 2020 · 6 comments · Fixed by #3050
Closed

spanner: provide column types in results #1805

rakyll opened this issue Feb 26, 2020 · 6 comments · Fixed by #3050
Assignees
Labels
api: spanner Issues related to the Spanner API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@rakyll
Copy link
Contributor

rakyll commented Feb 26, 2020

The underlying proto contains ResultSetMetadata.RowType for results returned from the API but spanner.Row or spanner.RowIterator are not surfacing them to the user. I'm trying to put together a "database/sql" driver for Spanner and without the column type it is not possible.

/cc @tbpg

@rakyll rakyll added the triage me I really want to be triaged. label Feb 26, 2020
@tbpg tbpg added api: spanner Issues related to the Spanner API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed triage me I really want to be triaged. labels Feb 26, 2020
@rakyll
Copy link
Contributor Author

rakyll commented Feb 26, 2020

spanner.GenericColumnValue seems to be doing what I want to do.

@hengfengli
Copy link
Contributor

Hi @rakyll, I think currently, using spanner.GenericColumnValue is right choice when you don't know in advance what column type to expect.

In client library, we have the type info in Row.fields[i].Type, which returns *sppb.Type (sppb "google.golang.org/genproto/googleapis/spanner/v1"). However, the type info is not exposed. If we want to expose this info, we might need to add the following code in line 167 of row.go after ColumnNames() method:

// ColumnRawTypes returns all column raw types of the row.
func (r *Row) ColumnRawTypes() []*sppb.Type {
	var n []string
	for _, c := range r.fields {
		n = append(n, c.Type)
	}
	return n
}

@hengfengli hengfengli added the priority: p2 Moderately-important priority. Fix may not be included in next release. label May 12, 2020
@hengfengli
Copy link
Contributor

Hi @rakyll , do you think whether or not the proposed method is a solution for your problem? or have you already solved your problem?

Is this still a feature that you would like us to add?

@rakyll
Copy link
Contributor Author

rakyll commented May 26, 2020

spanner.GenericColumnValue worked for my case. I can close this issue, thanks.

@rakyll rakyll closed this as completed May 26, 2020
@apstndb
Copy link
Contributor

apstndb commented Oct 19, 2020

I want to see ResultSetMetadata.RowType even when there are empty results.
It is available using raw API and gcloud but unavailable using spanner.GenericColumnValue because there is no Row.

$ gcloud spanner databases execute-sql ${DATABASE_ID} --sql='SELECT * FROM (SELECT 1) LIMIT 0' --format=yaml
metadata:
  rowType:
    fields:
    - type:
        code: INT64
  transaction: {}

I believe it is useful to write a generic client application.

@olavloite
Copy link
Contributor

It does seem that the Go client does not return the metadata of a result set, which makes it impossible to determine the column names and types of an empty result set.

@olavloite olavloite reopened this Oct 19, 2020
olavloite added a commit that referenced this issue Oct 19, 2020
Adds ResultSetMetaData to the RowIterator struct. The metadata
are available after the first call to RowIterator.Next() as long
as that call did not return any other error than iterator.Done.

Fixes #1805
olavloite added a commit that referenced this issue Oct 20, 2020
Adds ResultSetMetaData to the RowIterator struct. The metadata
are available after the first call to RowIterator.Next() as long
as that call did not return any other error than iterator.Done.

Fixes #1805
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the Spanner API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants