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
Closed

spanner: provide column types in results #1805

rakyll opened this issue Feb 26, 2020 · 6 comments

Comments

@rakyll
Copy link
Contributor

@rakyll 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
Copy link
Contributor Author

@rakyll rakyll commented Feb 26, 2020

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

Loading

@hengfengli
Copy link
Contributor

@hengfengli hengfengli commented Mar 2, 2020

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
}

Loading

@hengfengli
Copy link
Contributor

@hengfengli hengfengli commented May 25, 2020

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?

Loading

@rakyll
Copy link
Contributor Author

@rakyll rakyll commented May 26, 2020

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

Loading

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

@apstndb 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.

Loading

@olavloite
Copy link
Collaborator

@olavloite olavloite commented Oct 19, 2020

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.

Loading

@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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

6 participants