Skip to content

Support parsing create external table. #46

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

Merged
merged 4 commits into from
Apr 13, 2019
Merged

Support parsing create external table. #46

merged 4 commits into from
Apr 13, 2019

Conversation

zhzy0077
Copy link
Contributor

Add the possibility to parse the following SQL:

CREATE EXTERNAL TABLE uk_cities (
         name VARCHAR(100) NOT NULL,
         lat DOUBLE NULL,
         lng DOUBLE NULL
)
STORED AS TEXTFILE
LOCATION '/tmp/example.csv'

@coveralls
Copy link

coveralls commented Apr 10, 2019

Pull Request Test Coverage Report for Build 142

  • 121 of 143 (84.62%) changed or added relevant lines in 4 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.1%) to 85.225%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tests/sqlparser_generic.rs 34 35 97.14%
src/sqlparser.rs 53 60 88.33%
src/sqlast/mod.rs 25 39 64.1%
Files with Coverage Reduction New Missed Lines %
src/sqlparser.rs 1 80.59%
Totals Coverage Status
Change from base Build 139: 0.1%
Covered Lines: 2613
Relevant Lines: 3066

💛 - Coveralls

Copy link
Member

@andygrove andygrove left a comment

Choose a reason for hiding this comment

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

LGTM!

@andygrove
Copy link
Member

@nickolay Any opinion on this PR?

@nickolay
Copy link
Contributor

Thanks!

LGTM as well, though I'd remove the second (parse_create_external_table_newline) test, since it appears to differ only in whitespace (newline), which is stripped by the tokenizer anyway.

I don't think creating a separate SQLStatement variant for EXTERNAL tables specifically is right, since most of the syntax is shared by CREATE TABLE and CREATE EXTERNAL TABLE (I believe the only difference is that the LOCATION parameter is required for EXTERNAL tables and can't be specified for managed ones). I don't know how the dialect-specific DDL would be best represented though, so a separate variant, as in this PR, looks as good a starting point as any.

Syntax:

@zhzy0077
Copy link
Contributor Author

@nickolay I think it's more intuitive if we have inheritance here. CreateExternalTable will be a subclass of CreateTable and share most fields. However I am a newbie to Rust and don't know how to represent it in rustlang.

@nickolay
Copy link
Contributor

Rust is “composition over inheritance”, so what you’re thinking about is not an option. The only alternative way to add EXTERNAL table parsing without way more work is to add Options for the location and the file format in the existing SQLCreateTable variant. Either way is fine with me.

@andygrove
Copy link
Member

Thanks @nickolay for the review.

For dialect, I am keen on using Hive syntax. I would like to see official support for HiveQL in this crate eventually.

@andygrove
Copy link
Member

andygrove commented Apr 13, 2019

@zhzy0077 I agree that it makes sense to combine SQLCreateTable and SQLCreateExternalTable and use Option for attributes that are only in the external variant, and add an attribute to indicate whether this is EXTERNAL or not. Just a bool would be fine for now.

@zhzy0077
Copy link
Contributor Author

@andygrove I have updated this pr according to your and Nickolay's advice. Thanks for the comprehensive explanation! @nickolay

@andygrove andygrove merged commit d9591cd into apache:master Apr 13, 2019
@zhzy0077 zhzy0077 deleted the feature/external_table branch April 13, 2019 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants