Skip to content

Commit

Permalink
lightning: support column starts with slash/number/non-ascii for parq…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot authored Aug 17, 2022
1 parent 77f7f9d commit ed5dd79
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
7 changes: 3 additions & 4 deletions br/pkg/lightning/mydump/parquet_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,10 @@ func NewParquetParser(

columns := make([]string, 0, len(reader.Footer.Schema)-1)
columnMetas := make([]*parquet.SchemaElement, 0, len(reader.Footer.Schema)-1)
for _, c := range reader.SchemaHandler.SchemaElements {
for i, c := range reader.SchemaHandler.SchemaElements {
if c.GetNumChildren() == 0 {
// NOTE: the SchemaElement.Name is capitalized, SchemaHandler.Infos.ExName is the raw column name
// though in this context, there is no difference between these two fields
columns = append(columns, strings.ToLower(c.Name))
// we need to use the raw name, SchemaElement.Name might be prefixed with PARGO_PERFIX_
columns = append(columns, strings.ToLower(reader.SchemaHandler.GetExName(i)))
// transfer old ConvertedType to LogicalType
columnMeta := c
if c.ConvertedType != nil && c.LogicalType == nil {
Expand Down
Binary file not shown.
8 changes: 8 additions & 0 deletions br/tests/lightning_parquet/db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,11 @@ CREATE TABLE `warehouse` (
PRIMARY KEY (`w_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

DROP TABLE IF EXISTS `special_col_name`;
CREATE TABLE `special_col_name` (
`c1` varchar(128) DEFAULT NULL,
`_c2` timestamp NULL DEFAULT NULL,
`123_c3` timestamp NULL DEFAULT NULL,
`中_c4` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;
1 change: 1 addition & 0 deletions br/tests/lightning_parquet/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ for BACKEND in local importer tidb; do
check_row_count orders 100
check_row_count stock 50
check_row_count warehouse 1
check_row_count special_col_name 1

run_sql 'select sum(c_id) from test.customer;'
check_contains "sum(c_id): 210"
Expand Down

0 comments on commit ed5dd79

Please sign in to comment.