-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: FIR-44128 report column types in go sdk #131
Open
stepansergeevitch
wants to merge
5
commits into
main
Choose a base branch
from
FIR-44128-report-column-types-in-go-sdk
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
39415d3
refactor out columns reader
stepansergeevitch ac61457
implement column reader interfaces
stepansergeevitch 8b3ca6a
add integration test
stepansergeevitch 6534f2f
stress that client should use a service account in the readme
stepansergeevitch 36e51e0
fix unit tests
stepansergeevitch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package rows | ||
|
||
import ( | ||
"reflect" | ||
|
||
"github.com/firebolt-db/firebolt-go-sdk/types" | ||
) | ||
|
||
type columnRecord struct { | ||
name string | ||
fbType fireboltType | ||
} | ||
|
||
type ColumnReader struct { | ||
columns []columnRecord | ||
} | ||
|
||
func (r *ColumnReader) setColumns(columns []types.Column) error { | ||
r.columns = make([]columnRecord, len(columns)) | ||
for i, column := range columns { | ||
fbType, err := parseType(column.Type) | ||
if err != nil { | ||
return err | ||
} | ||
r.columns[i] = columnRecord{ | ||
name: column.Name, | ||
fbType: fbType, | ||
} | ||
} | ||
return nil | ||
|
||
} | ||
|
||
// Columns returns a list of column names in the current row set | ||
func (r *ColumnReader) Columns() []string { | ||
numColumns := len(r.columns) | ||
result := make([]string, 0, numColumns) | ||
|
||
for _, column := range r.columns { | ||
result = append(result, column.name) | ||
} | ||
|
||
return result | ||
} | ||
|
||
func (r *ColumnReader) ColumnTypeScanType(index int) reflect.Type { | ||
return r.columns[index].fbType.goType | ||
} | ||
|
||
func (r *ColumnReader) ColumnTypeDatabaseTypeName(index int) string { | ||
return r.columns[index].fbType.dbName | ||
} | ||
|
||
func (r *ColumnReader) ColumnTypeNullable(index int) (nullable, ok bool) { | ||
return r.columns[index].fbType.isNullable, true | ||
} | ||
|
||
func (r *ColumnReader) ColumnTypeLength(index int) (length int64, ok bool) { | ||
if r.columns[index].fbType.length > 0 { | ||
return r.columns[index].fbType.length, true | ||
} | ||
return 0, false | ||
} | ||
|
||
func (r *ColumnReader) ColumnTypePrecisionScale(index int) (precision, scale int64, ok bool) { | ||
if r.columns[index].fbType.precision > 0 && r.columns[index].fbType.scale > 0 { | ||
return r.columns[index].fbType.precision, r.columns[index].fbType.scale, true | ||
} | ||
return 0, 0, false | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a valid case when scale is 0, but precision is > 0. Redundant obviously, as it would be better represented by a different type, but nevertheless could occur.