Skip to content

Commit 0fdfb87

Browse files
authored
Merge pull request #305 from ydb-platform/WriteTypeStringTo
fixed types.WriteTypeStringTo + added TestWriteTypeStringTo test
2 parents 217fc67 + 8aa292b commit 0fdfb87

File tree

5 files changed

+261
-3
lines changed

5 files changed

+261
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Fixed regression of `table/types.WriteTypeStringTo`
2+
13
## v3.29.4
24
* Added touching of last updated timestamp in existing conns on stage of applying new endpoint list
35

internal/mock/conn.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,4 @@ func (e *Endpoint) Copy() endpoint.Endpoint {
116116
}
117117

118118
func (e *Endpoint) Touch(opts ...endpoint.Option) {
119-
panic("not implemented in mock")
120119
}

internal/value/type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type Type interface {
1818
}
1919

2020
func WriteTypeStringTo(buf *bytes.Buffer, t Type) {
21-
buf.WriteString(fmt.Sprintf("%T", t))
21+
buf.WriteString(t.String())
2222
}
2323

2424
func TypeToYDB(t Type, a *allocator.Allocator) *Ydb.Type {

table/types/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ func Struct(opts ...StructOption) Type {
5353
return value.Struct(s.fields...)
5454
}
5555

56+
func Dict(k, v Type) Type {
57+
return value.Dict(k, v)
58+
}
59+
5660
func Variant(x Type) Type {
5761
return value.Variant(x)
5862
}

table/types/types_test.go

Lines changed: 254 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package types
22

3-
import "testing"
3+
import (
4+
"bytes"
5+
"testing"
6+
)
47

58
func TestEqual(t *testing.T) {
69
tests := []struct {
@@ -47,3 +50,253 @@ func TestEqual(t *testing.T) {
4750
})
4851
}
4952
}
53+
54+
func TestWriteTypeStringTo(t *testing.T) {
55+
for _, tt := range []struct {
56+
t Type
57+
s string
58+
}{
59+
{
60+
t: TypeBool,
61+
s: "Bool",
62+
},
63+
{
64+
t: Optional(TypeBool),
65+
s: "Optional<Bool>",
66+
},
67+
{
68+
t: TypeInt8,
69+
s: "Int8",
70+
},
71+
{
72+
t: Optional(TypeInt8),
73+
s: "Optional<Int8>",
74+
},
75+
{
76+
t: TypeUint8,
77+
s: "Uint8",
78+
},
79+
{
80+
t: Optional(TypeUint8),
81+
s: "Optional<Uint8>",
82+
},
83+
{
84+
t: TypeInt16,
85+
s: "Int16",
86+
},
87+
{
88+
t: Optional(TypeInt16),
89+
s: "Optional<Int16>",
90+
},
91+
{
92+
t: TypeUint16,
93+
s: "Uint16",
94+
},
95+
{
96+
t: Optional(TypeUint16),
97+
s: "Optional<Uint16>",
98+
},
99+
{
100+
t: TypeInt32,
101+
s: "Int32",
102+
},
103+
{
104+
t: Optional(TypeInt32),
105+
s: "Optional<Int32>",
106+
},
107+
{
108+
t: TypeUint32,
109+
s: "Uint32",
110+
},
111+
{
112+
t: Optional(TypeUint32),
113+
s: "Optional<Uint32>",
114+
},
115+
{
116+
t: TypeInt64,
117+
s: "Int64",
118+
},
119+
{
120+
t: Optional(TypeInt64),
121+
s: "Optional<Int64>",
122+
},
123+
{
124+
t: TypeUint64,
125+
s: "Uint64",
126+
},
127+
{
128+
t: Optional(TypeUint64),
129+
s: "Optional<Uint64>",
130+
},
131+
{
132+
t: TypeFloat,
133+
s: "Float",
134+
},
135+
{
136+
t: Optional(TypeFloat),
137+
s: "Optional<Float>",
138+
},
139+
{
140+
t: TypeDouble,
141+
s: "Double",
142+
},
143+
{
144+
t: Optional(TypeDouble),
145+
s: "Optional<Double>",
146+
},
147+
{
148+
t: TypeDate,
149+
s: "Date",
150+
},
151+
{
152+
t: Optional(TypeDate),
153+
s: "Optional<Date>",
154+
},
155+
{
156+
t: TypeDatetime,
157+
s: "Datetime",
158+
},
159+
{
160+
t: Optional(TypeDatetime),
161+
s: "Optional<Datetime>",
162+
},
163+
{
164+
t: TypeTimestamp,
165+
s: "Timestamp",
166+
},
167+
{
168+
t: Optional(TypeTimestamp),
169+
s: "Optional<Timestamp>",
170+
},
171+
{
172+
t: TypeInterval,
173+
s: "Interval",
174+
},
175+
{
176+
t: Optional(TypeInterval),
177+
s: "Optional<Interval>",
178+
},
179+
{
180+
t: TypeTzDate,
181+
s: "TzDate",
182+
},
183+
{
184+
t: Optional(TypeTzDate),
185+
s: "Optional<TzDate>",
186+
},
187+
{
188+
t: TypeTzDatetime,
189+
s: "TzDatetime",
190+
},
191+
{
192+
t: Optional(TypeTzDatetime),
193+
s: "Optional<TzDatetime>",
194+
},
195+
{
196+
t: TypeTzTimestamp,
197+
s: "TzTimestamp",
198+
},
199+
{
200+
t: Optional(TypeTzTimestamp),
201+
s: "Optional<TzTimestamp>",
202+
},
203+
{
204+
t: TypeString,
205+
s: "String",
206+
},
207+
{
208+
t: Optional(TypeString),
209+
s: "Optional<String>",
210+
},
211+
{
212+
t: TypeUTF8,
213+
s: "Utf8",
214+
},
215+
{
216+
t: Optional(TypeUTF8),
217+
s: "Optional<Utf8>",
218+
},
219+
{
220+
t: TypeYSON,
221+
s: "Yson",
222+
},
223+
{
224+
t: Optional(TypeYSON),
225+
s: "Optional<Yson>",
226+
},
227+
{
228+
t: TypeJSON,
229+
s: "Json",
230+
},
231+
{
232+
t: Optional(TypeJSON),
233+
s: "Optional<Json>",
234+
},
235+
{
236+
t: TypeUUID,
237+
s: "Uuid",
238+
},
239+
{
240+
t: Optional(TypeUUID),
241+
s: "Optional<Uuid>",
242+
},
243+
{
244+
t: TypeJSONDocument,
245+
s: "JsonDocument",
246+
},
247+
{
248+
t: Optional(TypeJSONDocument),
249+
s: "Optional<JsonDocument>",
250+
},
251+
{
252+
t: TypeDyNumber,
253+
s: "DyNumber",
254+
},
255+
{
256+
t: Optional(TypeDyNumber),
257+
s: "Optional<DyNumber>",
258+
},
259+
{
260+
t: List(TypeInt64),
261+
s: "List<Int64>",
262+
},
263+
{
264+
t: Struct(
265+
StructField("series_id", TypeUint64),
266+
StructField("title", TypeUTF8),
267+
StructField("air_date", TypeDate),
268+
StructField("remove_date", Optional(TypeTzDatetime)),
269+
),
270+
s: "Struct<series_id:Uint64,title:Utf8,air_date:Date,remove_date:Optional<TzDatetime>>",
271+
},
272+
{
273+
t: Dict(TypeUTF8, Optional(TypeTzDatetime)),
274+
s: "Dict<Utf8,Optional<TzDatetime>>",
275+
},
276+
{
277+
t: Tuple(TypeUTF8, List(TypeInt64), Optional(TypeTzDatetime)),
278+
s: "Tuple<Utf8,List<Int64>,Optional<TzDatetime>>",
279+
},
280+
{
281+
t: Variant(Tuple(TypeUTF8, List(TypeInt64), Optional(TypeTzDatetime))),
282+
s: "Variant<Tuple<Utf8,List<Int64>,Optional<TzDatetime>>>",
283+
},
284+
{
285+
t: Variant(Struct(
286+
StructField("series_id", TypeUint64),
287+
StructField("title", TypeUTF8),
288+
StructField("air_date", TypeDate),
289+
StructField("remove_date", Optional(TypeTzDatetime)),
290+
)),
291+
s: "Variant<Struct<series_id:Uint64,title:Utf8,air_date:Date,remove_date:Optional<TzDatetime>>>",
292+
},
293+
} {
294+
t.Run("", func(t *testing.T) {
295+
var buf bytes.Buffer
296+
WriteTypeStringTo(&buf, tt.t)
297+
if buf.String() != tt.s {
298+
t.Fatalf("unexpected string representation of %+v: %s, exp: %s", tt.t, buf.String(), tt.s)
299+
}
300+
})
301+
}
302+
}

0 commit comments

Comments
 (0)