Skip to content

Commit 5ce51c4

Browse files
committed
refactor internal/table/scanner/scanner and upload with off gocognit linter
1 parent 1edb132 commit 5ce51c4

File tree

2 files changed

+228
-127
lines changed

2 files changed

+228
-127
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
* Refactored `log/topic` and extract funcs
1+
* Refactored `internal/table/scanner/scanner.go` and extract funcs
2+
* Refactored `log/topic.go` and extract funcs
23
* Refactored `internal/table/scanner/scanner_test.go` and extract funcs
34
* Refactored `log/sql.go` and extract funcs
45
* Refactored `metrics/driver.go` and extract funcs

internal/table/scanner/scanner.go

Lines changed: 226 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -897,153 +897,47 @@ func (s *scanner) scanOptional(v interface{}, defaultValueForOptional bool) {
897897
}
898898
switch v := v.(type) {
899899
case **bool:
900-
if s.isNull() {
901-
*v = nil
902-
} else {
903-
src := s.bool()
904-
*v = &src
905-
}
900+
handleBoolCase(s, v)
906901
case **int8:
907-
if s.isNull() {
908-
*v = nil
909-
} else {
910-
src := s.int8()
911-
*v = &src
912-
}
902+
handleInt8Case(s, v)
913903
case **int16:
914-
if s.isNull() {
915-
*v = nil
916-
} else {
917-
src := s.int16()
918-
*v = &src
919-
}
904+
handleInt16Case(s, v)
920905
case **int32:
921-
if s.isNull() {
922-
*v = nil
923-
} else {
924-
src := s.int32()
925-
*v = &src
926-
}
906+
handleInt32Case(s, v)
927907
case **int:
928-
if s.isNull() {
929-
*v = nil
930-
} else {
931-
src := int(s.int32())
932-
*v = &src
933-
}
908+
handleIntCase(s, v)
934909
case **int64:
935-
if s.isNull() {
936-
*v = nil
937-
} else {
938-
src := s.int64()
939-
*v = &src
940-
}
910+
handleInt64Case(s, v)
941911
case **uint8:
942-
if s.isNull() {
943-
*v = nil
944-
} else {
945-
src := s.uint8()
946-
*v = &src
947-
}
912+
handleUint8Case(s, v)
948913
case **uint16:
949-
if s.isNull() {
950-
*v = nil
951-
} else {
952-
src := s.uint16()
953-
*v = &src
954-
}
914+
handleUint16Case(s, v)
955915
case **uint32:
956-
if s.isNull() {
957-
*v = nil
958-
} else {
959-
src := s.uint32()
960-
*v = &src
961-
}
916+
handleUint32Case(s, v)
962917
case **uint:
963-
if s.isNull() {
964-
*v = nil
965-
} else {
966-
src := uint(s.uint32())
967-
*v = &src
968-
}
918+
handleUintCase(s, v)
969919
case **uint64:
970-
if s.isNull() {
971-
*v = nil
972-
} else {
973-
src := s.uint64()
974-
*v = &src
975-
}
920+
handleUint64Case(s, v)
976921
case **float32:
977-
if s.isNull() {
978-
*v = nil
979-
} else {
980-
src := s.float()
981-
*v = &src
982-
}
922+
handleFloat32Case(s, v)
983923
case **float64:
984-
if s.isNull() {
985-
*v = nil
986-
} else {
987-
src := s.double()
988-
*v = &src
989-
}
924+
handleFloat64Case(s, v)
990925
case **time.Time:
991-
if s.isNull() {
992-
*v = nil
993-
} else {
994-
s.unwrap()
995-
var src time.Time
996-
s.setTime(&src)
997-
*v = &src
998-
}
926+
handleTimeCase(s, v)
999927
case **time.Duration:
1000-
if s.isNull() {
1001-
*v = nil
1002-
} else {
1003-
src := value.IntervalToDuration(s.int64())
1004-
*v = &src
1005-
}
928+
handleDurationCase(s, v)
1006929
case **string:
1007-
if s.isNull() {
1008-
*v = nil
1009-
} else {
1010-
s.unwrap()
1011-
var src string
1012-
s.setString(&src)
1013-
*v = &src
1014-
}
930+
handleStringCase(s, v)
1015931
case **[]byte:
1016-
if s.isNull() {
1017-
*v = nil
1018-
} else {
1019-
s.unwrap()
1020-
var src []byte
1021-
s.setByte(&src)
1022-
*v = &src
1023-
}
932+
handleSliceByteCase(s, v)
1024933
case **[16]byte:
1025-
if s.isNull() {
1026-
*v = nil
1027-
} else {
1028-
src := s.uint128()
1029-
*v = &src
1030-
}
934+
handleArrByte16Case(s, v)
1031935
case **interface{}:
1032-
if s.isNull() {
1033-
*v = nil
1034-
} else {
1035-
src := s.any()
1036-
*v = &src
1037-
}
936+
handleInterfaceCase(s, v)
1038937
case *types.Value:
1039938
*v = s.value()
1040939
case **types.Decimal:
1041-
if s.isNull() {
1042-
*v = nil
1043-
} else {
1044-
src := s.unwrapDecimal()
1045-
*v = &src
1046-
}
940+
handleDecimalCase(s, v)
1047941
case types.Scanner:
1048942
err := v.UnmarshalYDB(s.converter)
1049943
if err != nil {
@@ -1090,6 +984,212 @@ func (s *scanner) scanOptional(v interface{}, defaultValueForOptional bool) {
1090984
}
1091985
}
1092986

987+
// handleBoolCase handles the special case for handling boolean values in the scanner.
988+
func handleBoolCase(s *scanner, v **bool) {
989+
if s.isNull() {
990+
*v = nil
991+
} else {
992+
src := s.bool()
993+
*v = &src
994+
}
995+
}
996+
997+
// handleInt8Case handles the special case for handling int8 values in the scanner.
998+
func handleInt8Case(s *scanner, v **int8) {
999+
if s.isNull() {
1000+
*v = nil
1001+
} else {
1002+
src := s.int8()
1003+
*v = &src
1004+
}
1005+
}
1006+
1007+
// handleInt16Case handles the special case for handling int16 values in the scanner.
1008+
func handleInt16Case(s *scanner, v **int16) {
1009+
if s.isNull() {
1010+
*v = nil
1011+
} else {
1012+
src := s.int16()
1013+
*v = &src
1014+
}
1015+
}
1016+
1017+
// handleInt32Case handles the special case for handling int32 values in the scanner.
1018+
func handleInt32Case(s *scanner, v **int32) {
1019+
if s.isNull() {
1020+
*v = nil
1021+
} else {
1022+
src := s.int32()
1023+
*v = &src
1024+
}
1025+
}
1026+
1027+
// handleIntCase handles the special case for handling int values in the scanner.
1028+
func handleIntCase(s *scanner, v **int) {
1029+
if s.isNull() {
1030+
*v = nil
1031+
} else {
1032+
src := int(s.int32())
1033+
*v = &src
1034+
}
1035+
}
1036+
1037+
// handleInt64Case handles the special case for handling int64 values in the scanner.
1038+
func handleInt64Case(s *scanner, v **int64) {
1039+
if s.isNull() {
1040+
*v = nil
1041+
} else {
1042+
src := s.int64()
1043+
*v = &src
1044+
}
1045+
}
1046+
1047+
// handleUint8Case handles the special case for handling uint8 values in the scanner.
1048+
func handleUint8Case(s *scanner, v **uint8) {
1049+
if s.isNull() {
1050+
*v = nil
1051+
} else {
1052+
src := s.uint8()
1053+
*v = &src
1054+
}
1055+
}
1056+
1057+
// handleUint16Case handles the special case for handling uint16 values in the scanner.
1058+
func handleUint16Case(s *scanner, v **uint16) {
1059+
if s.isNull() {
1060+
*v = nil
1061+
} else {
1062+
src := s.uint16()
1063+
*v = &src
1064+
}
1065+
}
1066+
1067+
// handleUint32Case handles the special case for handling uint32 values in the scanner.
1068+
func handleUint32Case(s *scanner, v **uint32) {
1069+
if s.isNull() {
1070+
*v = nil
1071+
} else {
1072+
src := s.uint32()
1073+
*v = &src
1074+
}
1075+
}
1076+
1077+
// handleUintCase handles the special case for handling uint values in the scanner.
1078+
func handleUintCase(s *scanner, v **uint) {
1079+
if s.isNull() {
1080+
*v = nil
1081+
} else {
1082+
src := uint(s.uint32())
1083+
*v = &src
1084+
}
1085+
}
1086+
1087+
// handleUint64Case handles the special case for handling uint64 values in the scanner.
1088+
func handleUint64Case(s *scanner, v **uint64) {
1089+
if s.isNull() {
1090+
*v = nil
1091+
} else {
1092+
src := s.uint64()
1093+
*v = &src
1094+
}
1095+
}
1096+
1097+
// handleFloat32Case handles the special case for handling float32 values in the scanner.
1098+
func handleFloat32Case(s *scanner, v **float32) {
1099+
if s.isNull() {
1100+
*v = nil
1101+
} else {
1102+
src := s.float()
1103+
*v = &src
1104+
}
1105+
}
1106+
1107+
// handleFloat64Case handles the special case for handling float64 values in the scanner.
1108+
func handleFloat64Case(s *scanner, v **float64) {
1109+
if s.isNull() {
1110+
*v = nil
1111+
} else {
1112+
src := s.double()
1113+
*v = &src
1114+
}
1115+
}
1116+
1117+
// handleTimeCase handles the special case for handling time.Time values in the scanner.
1118+
func handleTimeCase(s *scanner, v **time.Time) {
1119+
if s.isNull() {
1120+
*v = nil
1121+
} else {
1122+
s.unwrap()
1123+
var src time.Time
1124+
s.setTime(&src)
1125+
*v = &src
1126+
}
1127+
}
1128+
1129+
// handleDurationCase handles the special case for handling time.Duration values in the scanner.
1130+
func handleDurationCase(s *scanner, v **time.Duration) {
1131+
if s.isNull() {
1132+
*v = nil
1133+
} else {
1134+
src := value.IntervalToDuration(s.int64())
1135+
*v = &src
1136+
}
1137+
}
1138+
1139+
// handleStringCase handles the special case for handling string values in the scanner.
1140+
func handleStringCase(s *scanner, v **string) {
1141+
if s.isNull() {
1142+
*v = nil
1143+
} else {
1144+
s.unwrap()
1145+
var src string
1146+
s.setString(&src)
1147+
*v = &src
1148+
}
1149+
}
1150+
1151+
// handleSliceByteCase handles the special case for handling []byte values in the scanner.
1152+
func handleSliceByteCase(s *scanner, v **[]byte) {
1153+
if s.isNull() {
1154+
*v = nil
1155+
} else {
1156+
s.unwrap()
1157+
var src []byte
1158+
s.setByte(&src)
1159+
*v = &src
1160+
}
1161+
}
1162+
1163+
// handleArrByte16Case handles the special case for handling [16]byte values in the scanner.
1164+
func handleArrByte16Case(s *scanner, v **[16]byte) {
1165+
if s.isNull() {
1166+
*v = nil
1167+
} else {
1168+
src := s.uint128()
1169+
*v = &src
1170+
}
1171+
}
1172+
1173+
// handleInterfaceCase handles the special case for handling interface{} values in the scanner.
1174+
func handleInterfaceCase(s *scanner, v **interface{}) {
1175+
if s.isNull() {
1176+
*v = nil
1177+
} else {
1178+
src := s.any()
1179+
*v = &src
1180+
}
1181+
}
1182+
1183+
// handleDecimalCase handles the special case for handling types.Decimal values in the scanner.
1184+
func handleDecimalCase(s *scanner, v **types.Decimal) {
1185+
if s.isNull() {
1186+
*v = nil
1187+
} else {
1188+
src := s.unwrapDecimal()
1189+
*v = &src
1190+
}
1191+
}
1192+
10931193
func (s *scanner) setDefaultValue(dst interface{}) {
10941194
switch v := dst.(type) {
10951195
case *bool:

0 commit comments

Comments
 (0)