Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add hexLit and binaryList support for LOAD DATA #365

Merged
merged 9 commits into from
Jul 3, 2019

Conversation

imtbkcat
Copy link

What problem does this PR solve?

TiDB cannot support LOAD DATA sql which fields terminated by hex expression.

load data local infile '/home/pingcap/jeff-test/merchant.dmp' into table `merchant` fields terminated by X'01'
2018/06/29 13:29:22.709 conn.go:481: [warning] [8448] dispatch error:

What is changed and how it works?

Add hexLit and binaryLit for FieldTerminator, and convert hex expression to string during parsing.

After:

mysql> load data local infile '~/1.csv' into table t_sp FIELDS TERMINATED BY X'2C2C2C2C' enclosed by '"';
Query OK, 3 rows affected (0.00 sec)
Records: 3  Deleted: 0  Skipped: 0  Warnings: 0

Check List

Tests

  • Unit test

@codecov
Copy link

codecov bot commented Jun 21, 2019

Codecov Report

Merging #365 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #365   +/-   ##
=======================================
  Coverage   50.44%   50.44%           
=======================================
  Files          31       31           
  Lines        6918     6918           
=======================================
  Hits         3490     3490           
  Misses       3069     3069           
  Partials      359      359
Impacted Files Coverage Δ
parser.go 70.58% <ø> (ø) ⬆️
ast/misc.go 18.26% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f9dfedc...21f85f8. Read the comment docs.

Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

parser.y Outdated
}
| hexLit
{
$$ = ast.NewValueExpr($1).GetString()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use NewHexLiteral directly here?

parser/ast/misc.go

Lines 2035 to 2039 in 3b36f86

// NewHexLiteral creates a types.HexLiteral value, it's provided by parser driver.
var NewHexLiteral func(string) (interface{}, error)
// NewBitLiteral creates a types.BitLiteral value, it's provided by parser driver.
var NewBitLiteral func(string) (interface{}, error)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But NewHexLiteral will return a n interface. type assert may be very complex

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 Could we change the return type from interface{} to some real interface?

type BinaryLiteral interface {
    ToString() string
}

var NewHexLiteral func(string) (BinaryLiteral, error) 
var NewBitLiteral func(string) (BinaryLiteral, error) 

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good idea.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but it works will in TiDB😂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe try updating go.mod1 and go.sum1? 😂

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kennytm how to upgrade go.mod in parser😂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@imtbkcat Try to rename go.mod1 and go.sum1 to go.mod and go.sum, then do the regular update, then rename them back to go.mod1 and go.sum1 😂

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kennytm fixed, PTAL

Copy link
Contributor

@kennytm kennytm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kennytm kennytm added the status/LGT2 LGT2 label Jul 3, 2019
@kennytm kennytm merged commit 2900147 into pingcap:master Jul 3, 2019
tiancaiamao pushed a commit to tiancaiamao/parser that referenced this pull request Apr 27, 2021
* support hex and bin for terminator

* add more tests

* add test for binary

* adddress comment

* add ast.BinaryLiteral

* go fmt project

* address comment

* fix parser

* update gomod
lyonzhi pushed a commit to lyonzhi/parser that referenced this pull request Apr 25, 2024
* support hex and bin for terminator

* add more tests

* add test for binary

* adddress comment

* add ast.BinaryLiteral

* go fmt project

* address comment

* fix parser

* update gomod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants