@@ -3,10 +3,10 @@ package main
3
3
import (
4
4
"context"
5
5
"database/sql"
6
- "encoding/json"
7
6
"fmt"
8
7
"reflect"
9
8
"slices"
9
+ "strconv"
10
10
"strings"
11
11
12
12
"github.com/estuary/connectors/sqlcapture"
@@ -109,37 +109,36 @@ func translateRecordField(column *sqlcapture.ColumnInfo, val interface{}) (inter
109
109
case nil :
110
110
return nil , nil
111
111
case string :
112
- if dataType .jsonType != "string" {
113
- var out = reflect .New (dataType .t ).Interface ()
114
- if err := json .Unmarshal ([]byte (v ), out ); err != nil {
115
- return nil , err
116
- }
117
- return out , nil
112
+ if dataType .JsonType == "integer" {
113
+ return strconv .Atoi (v )
114
+ } else if dataType .JsonType == "number" {
115
+ return strconv .ParseFloat (v , 64 )
118
116
} else {
119
117
return val , nil
120
118
}
121
119
default :
122
120
}
123
121
124
122
var rv = reflect .ValueOf (val )
125
- if rv .CanConvert (dataType .t ) {
126
- return rv .Convert (dataType .t ).Interface (), nil
123
+ if rv .CanConvert (dataType .T ) {
124
+ return rv .Convert (dataType .T ).Interface (), nil
127
125
}
126
+
128
127
return val , nil
129
128
}
130
129
131
130
func (ct * oracleColumnType ) toJSONSchemaType () * jsonschema.Schema {
132
131
var out = & jsonschema.Schema {
133
- Format : ct .format ,
132
+ Format : ct .Format ,
134
133
Extras : make (map [string ]interface {}),
135
134
}
136
135
137
- if ct .jsonType == "" {
136
+ if ct .JsonType == "" {
138
137
// No type constraint.
139
- } else if ct .nullable {
140
- out .Extras ["type" ] = []string {ct .jsonType , "null" } // Use variadic form.
138
+ } else if ct .Nullable {
139
+ out .Extras ["type" ] = []string {ct .JsonType , "null" } // Use variadic form.
141
140
} else {
142
- out .Type = ct .jsonType
141
+ out .Type = ct .JsonType
143
142
}
144
143
return out
145
144
}
@@ -268,18 +267,18 @@ SELECT t.owner, t.table_name, t.column_id, t.column_name, t.nullable, t.data_typ
268
267
ON (t.owner = c.owner AND t.table_name = c.table_name AND t.column_name = c.column_name)`
269
268
270
269
type oracleColumnType struct {
271
- original string
272
- length int
273
- scale int16
274
- precision int16
275
- t reflect.Type
276
- format string
277
- jsonType string
278
- nullable bool
270
+ Original string
271
+ Length int
272
+ Scale int16
273
+ Precision int16
274
+ T reflect.Type
275
+ Format string
276
+ JsonType string
277
+ Nullable bool
279
278
}
280
279
281
280
func (ct oracleColumnType ) String () string {
282
- return ct .original
281
+ return ct .Original
283
282
}
284
283
285
284
// SMALLINT, INT and INTEGER have a default precision 38 which is not included in the column information
@@ -383,14 +382,14 @@ func getColumns(ctx context.Context, conn *sql.DB, tables []*sqlcapture.Discover
383
382
}
384
383
385
384
sc .DataType = oracleColumnType {
386
- original : dataType ,
387
- scale : dataScale .Int16 ,
388
- precision : precision ,
389
- length : dataLength ,
390
- t : t ,
391
- format : format ,
392
- jsonType : jsonType ,
393
- nullable : sc .IsNullable ,
385
+ Original : dataType ,
386
+ Scale : dataScale .Int16 ,
387
+ Precision : precision ,
388
+ Length : dataLength ,
389
+ T : t ,
390
+ Format : format ,
391
+ JsonType : jsonType ,
392
+ Nullable : sc .IsNullable ,
394
393
}
395
394
396
395
if isPrimaryKey {
0 commit comments