Skip to content

Commit 05a2dde

Browse files
authored
Merge pull request #1487 from ydb-platform/allow-skip-sql-fields
Allowed skip struct field in ScanStruct by tag -
2 parents eb7d205 + a760212 commit 05a2dde

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Allowed skip column for `ScanStruct` by tag `-`
2+
13
## v3.81.4
24
* Returned `topicwriter.ErrQueueLimitExceed`, accidental removed at `v3.81.0`
35

internal/query/scanner/struct.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ func (s StructScanner) ScanStruct(dst interface{}, opts ...ScanStructOption) (er
5656
existingFields := make(map[string]struct{}, tt.NumField())
5757
for i := 0; i < tt.NumField(); i++ {
5858
name := fieldName(tt.Field(i), settings.TagName)
59+
if name == "-" {
60+
continue
61+
}
62+
5963
v, err := s.data.seekByName(name)
6064
if err != nil {
6165
missingColumns = append(missingColumns, name)

internal/query/scanner/struct_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,37 @@ func TestStructNotFoundColumns(t *testing.T) {
618618
require.ErrorIs(t, err, ErrColumnsNotFoundInRow)
619619
}
620620

621+
func TestStructSkippedColumns(t *testing.T) {
622+
scanner := Struct(Data(
623+
[]*Ydb.Column{
624+
{
625+
Name: "A",
626+
Type: &Ydb.Type{
627+
Type: &Ydb.Type_TypeId{
628+
TypeId: Ydb.Type_UTF8,
629+
},
630+
},
631+
},
632+
},
633+
[]*Ydb.Value{
634+
{
635+
Value: &Ydb.Value_TextValue{
636+
TextValue: "test-a",
637+
},
638+
},
639+
},
640+
))
641+
642+
var row struct {
643+
A string
644+
C string `sql:"-"`
645+
}
646+
err := scanner.ScanStruct(&row)
647+
require.NoError(t, err)
648+
require.Equal(t, "test-a", row.A)
649+
require.Empty(t, row.C)
650+
}
651+
621652
func TestStructWithAllowMissingColumnsFromSelect(t *testing.T) {
622653
scanner := Struct(Data(
623654
[]*Ydb.Column{

0 commit comments

Comments
 (0)