-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into redshift-string-precision
- Loading branch information
Showing
9 changed files
with
59 additions
and
29 deletions.
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
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
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 |
---|---|---|
@@ -1,32 +1,38 @@ | ||
package typing | ||
|
||
import ( | ||
"fmt" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/artie-labs/transfer/lib/typing/decimal" | ||
) | ||
|
||
// TODO: This function should return an error | ||
func ParseNumeric(parts []string) KindDetails { | ||
func ParseNumeric(parts []string) (KindDetails, error) { | ||
if len(parts) == 0 || len(parts) > 2 { | ||
return Invalid | ||
return Invalid, fmt.Errorf("invalid number of parts: %d", len(parts)) | ||
} | ||
|
||
var parsedNumbers []int32 | ||
for _, part := range parts { | ||
parsedNumber, err := strconv.ParseInt(strings.TrimSpace(part), 10, 32) | ||
if err != nil { | ||
return Invalid | ||
return Invalid, fmt.Errorf("failed to parse number: %w", err) | ||
} | ||
|
||
parsedNumbers = append(parsedNumbers, int32(parsedNumber)) | ||
} | ||
|
||
// If scale is 0 or not specified, then number is an int. | ||
if len(parsedNumbers) == 1 || parsedNumbers[1] == 0 { | ||
return NewDecimalDetailsFromTemplate(EDecimal, decimal.NewDetails(parsedNumbers[0], 0)) | ||
return NewDecimalDetailsFromTemplate( | ||
EDecimal, | ||
decimal.NewDetails(parsedNumbers[0], 0), | ||
), nil | ||
} | ||
|
||
return NewDecimalDetailsFromTemplate(EDecimal, decimal.NewDetails(parsedNumbers[0], parsedNumbers[1])) | ||
return NewDecimalDetailsFromTemplate( | ||
EDecimal, | ||
decimal.NewDetails(parsedNumbers[0], parsedNumbers[1]), | ||
), nil | ||
} |
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