Skip to content
This repository was archived by the owner on Feb 21, 2024. It is now read-only.

Commit e14cde7

Browse files
paddyjokFletcher Haynes
authored andcommitted
SQL BULK INSERT (fb-1749) (#2291)
SQL BULK INSERT This change is to support a BULK INSERT/REPLACE statement that adds the ability to 1) take its input from a file, url or in-line blob 2) to map from the input source to the target columns 3) to transform data (using sql expressions) before inserting 4) support csv and ndjson formats * improving test coverage * increase test coverage again * refactoring for handling transformation with types other than id and int (cherry picked from commit 8f660a5)
1 parent 53170ce commit e14cde7

16 files changed

+1910
-774
lines changed

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ require (
7777
)
7878

7979
require (
80+
github.com/PaesslerAG/gval v1.0.0
81+
github.com/PaesslerAG/jsonpath v0.1.1
8082
github.com/google/uuid v1.3.0
8183
github.com/jaffee/commandeer v0.5.0
8284
github.com/linkedin/goavro/v2 v2.11.1

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v
7575
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
7676
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
7777
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
78+
github.com/PaesslerAG/gval v1.0.0 h1:GEKnRwkWDdf9dOmKcNrar9EA1bz1z9DqPIO1+iLzhd8=
79+
github.com/PaesslerAG/gval v1.0.0/go.mod h1:y/nm5yEyTeX6av0OfKJNp9rBNj2XrGhAf5+v24IBN1I=
80+
github.com/PaesslerAG/jsonpath v0.1.0/go.mod h1:4BzmtoM/PI8fPO4aQGIusjGxGir2BzcV0grWtFzq1Y8=
81+
github.com/PaesslerAG/jsonpath v0.1.1 h1:c1/AToHQMVsduPAa4Vh6xp2U0evy4t8SWp8imEsylIk=
82+
github.com/PaesslerAG/jsonpath v0.1.1/go.mod h1:lVboNxFGal/VwW6d9JzIy56bUsYAP6tH/x80vjnCseY=
7883
github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
7984
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
8085
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=

sql3/errors.go

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ const (
1313

1414
ErrCacheKeyNotFound errors.Code = "ErrCacheKeyNotFound"
1515

16-
ErrDuplicateColumn errors.Code = "ErrDuplicateColumn"
17-
ErrUnknownType errors.Code = "ErrUnknownType"
16+
ErrDuplicateColumn errors.Code = "ErrDuplicateColumn"
17+
ErrUnknownType errors.Code = "ErrUnknownType"
18+
ErrUnknownIdentifier errors.Code = "ErrUnknownIdentifier"
1819

1920
ErrTypeIncompatibleWithBitwiseOperator errors.Code = "ErrTypeIncompatibleWithBitwiseOperator"
2021
ErrTypeIncompatibleWithLogicalOperator errors.Code = "ErrTypeIncompatibleWithLogicalOperator"
@@ -43,6 +44,7 @@ const (
4344
ErrLiteralExpected errors.Code = "ErrLiteralExpected"
4445
ErrIntegerLiteral errors.Code = "ErrIntegerLiteral"
4546
ErrStringLiteral errors.Code = "ErrStringLiteral"
47+
ErrBoolLiteral errors.Code = "ErrBoolLiteral"
4648
ErrLiteralEmptySetNotAllowed errors.Code = "ErrLiteralEmptySetNotAllowed"
4749
ErrLiteralEmptyTupleNotAllowed errors.Code = "ErrLiteralEmptyTupleNotAllowed"
4850
ErrSetLiteralMustContainIntOrString errors.Code = "ErrSetLiteralMustContainIntOrString"
@@ -85,7 +87,18 @@ const (
8587
ErrParameterTypeMistmatch errors.Code = "ErrParameterTypeMistmatch"
8688
ErrCallParameterValueInvalid errors.Code = "ErrCallParameterValueInvalid"
8789

88-
//optimizer errors
90+
// bulk insert errors
91+
92+
ErrReadingDatasource errors.Code = "ErrReadingDatasource"
93+
ErrMappingFromDatasource errors.Code = "ErrMappingFromDatasource"
94+
ErrFormatSpecifierExpected errors.Code = "ErrFormatSpecifierExpected"
95+
ErrInvalidFormatSpecifier errors.Code = "ErrInvalidFormatSpecifier"
96+
ErrInputSpecifierExpected errors.Code = "ErrInputSpecifierExpected"
97+
ErrInvalidInputSpecifier errors.Code = "ErrInvalidInputSpecifier"
98+
ErrInvalidBatchSize errors.Code = "ErrInvalidBatchSize"
99+
ErrTypeConversionOnMap errors.Code = "ErrTypeConversionOnMap"
100+
101+
// optimizer errors
89102
ErrAggregateNotAllowedInGroupBy errors.Code = "ErrIdPercentileNotAllowedInGroupBy"
90103
)
91104

@@ -103,6 +116,13 @@ func NewErrUnknownType(line int, col int, typ string) error {
103116
)
104117
}
105118

119+
func NewErrUnknownIdentifier(line int, col int, ident string) error {
120+
return errors.New(
121+
ErrUnknownIdentifier,
122+
fmt.Sprintf("[%d:%d] unknown identifier '%s'", line, col, ident),
123+
)
124+
}
125+
106126
func NewErrInternal(msg string) error {
107127
preamble := "internal error"
108128
_, filename, line, ok := runtime.Caller(1)
@@ -186,6 +206,13 @@ func NewErrStringLiteral(line, col int) error {
186206
)
187207
}
188208

209+
func NewErrBoolLiteral(line, col int) error {
210+
return errors.New(
211+
ErrBoolLiteral,
212+
fmt.Sprintf("[%d:%d] bool literal expected", line, col),
213+
)
214+
}
215+
189216
func NewErrLiteralEmptySetNotAllowed(line, col int) error {
190217
return errors.New(
191218
ErrLiteralEmptySetNotAllowed,
@@ -533,6 +560,64 @@ func NewErrCallParameterValueInvalid(line, col int, badParameterValue string, pa
533560
)
534561
}
535562

563+
// bulk insert
564+
565+
func NewErrReadingDatasource(line, col int, dataSource string, errorText string) error {
566+
return errors.New(
567+
ErrReadingDatasource,
568+
fmt.Sprintf("[%d:%d] unable to read datasource '%s': %s", line, col, dataSource, errorText),
569+
)
570+
}
571+
572+
func NewErrMappingFromDatasource(line, col int, dataSource string, errorText string) error {
573+
return errors.New(
574+
ErrMappingFromDatasource,
575+
fmt.Sprintf("[%d:%d] unable to map from datasource '%s': %s", line, col, dataSource, errorText),
576+
)
577+
}
578+
579+
func NewErrFormatSpecifierExpected(line, col int) error {
580+
return errors.New(
581+
ErrFormatSpecifierExpected,
582+
fmt.Sprintf("[%d:%d] format specifier expected", line, col),
583+
)
584+
}
585+
586+
func NewErrInvalidFormatSpecifier(line, col int, specifier string) error {
587+
return errors.New(
588+
ErrInvalidFormatSpecifier,
589+
fmt.Sprintf("[%d:%d] invalid format specifier '%s'", line, col, specifier),
590+
)
591+
}
592+
593+
func NewErrInputSpecifierExpected(line, col int) error {
594+
return errors.New(
595+
ErrInputSpecifierExpected,
596+
fmt.Sprintf("[%d:%d] input specifier expected", line, col),
597+
)
598+
}
599+
600+
func NewErrInvalidInputSpecifier(line, col int, specifier string) error {
601+
return errors.New(
602+
ErrInvalidFormatSpecifier,
603+
fmt.Sprintf("[%d:%d] invalid input specifier '%s'", line, col, specifier),
604+
)
605+
}
606+
607+
func NewErrInvalidBatchSize(line, col int, batchSize int) error {
608+
return errors.New(
609+
ErrInvalidBatchSize,
610+
fmt.Sprintf("[%d:%d] invalid batch size '%d'", line, col, batchSize),
611+
)
612+
}
613+
614+
func NewErrTypeConversionOnMap(line, col int, value interface{}, typeName string) error {
615+
return errors.New(
616+
ErrTypeConversionOnMap,
617+
fmt.Sprintf("[%d:%d] value '%v' cannot be converted to type '%s'", line, col, value, typeName),
618+
)
619+
}
620+
536621
// optimizer
537622

538623
func NewErrAggregateNotAllowedInGroupBy(line, col int, aggName string) error {

0 commit comments

Comments
 (0)