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 COPY .. TO .. syntax support #6355

Merged
merged 6 commits into from
May 19, 2023
Merged

Add COPY .. TO .. syntax support #6355

merged 6 commits into from
May 19, 2023

Conversation

alamb
Copy link
Contributor

@alamb alamb commented May 15, 2023

Which issue does this PR close?

Closes #5988

Rationale for this change

I am working on #5654 (mostly so I can better benchmark datafusion) and part of the code needed for this is parser support.

What changes are included in this PR?

Are these changes tested?

Yes

Are there any user-facing changes?

New syntax is parsed, but throws a "COPY .. TO .. statement is yet supported" when used

@github-actions github-actions bot added core Core DataFusion crate sql SQL Planner sqllogictest SQL Logic Tests (.slt) labels May 15, 2023
struct RelationVisitor<'a>(&'a mut hashbrown::HashSet<ObjectName>);
struct RelationVisitor<'a>(&'a mut hashbrown::HashSet<ObjectName>);

impl<'a> RelationVisitor<'a> {
Copy link
Contributor Author

@alamb alamb May 15, 2023

Choose a reason for hiding this comment

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

this simply pulls the RelationVisitor up a level so it can be used for both DFStatement::DescribeTableStmt and DFStatement::CopyTo

@alamb alamb marked this pull request as ready for review May 15, 2023 19:15

# Copy from table
statement error DataFusion error: This feature is not implemented: `COPY \.\. TO \.\.` statement is yet supported
COPY source_table to '/tmp/table.parquet';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is what I really want -- it is so close

@alamb alamb requested review from crepererum and tustvold and removed request for crepererum May 17, 2023 19:04
@alamb
Copy link
Contributor Author

alamb commented May 17, 2023

cc @aprimadi given your recent work on the parser in #6352 perhaps you are interested / willing in reviewing this PR

@aprimadi
Copy link
Contributor

Sure @alamb I'll review today

Copy link
Contributor

@aprimadi aprimadi left a comment

Choose a reason for hiding this comment

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

This PR looks really good to me -- great work @alamb 👍


impl<'a> RelationVisitor<'a> {
/// Record that `relation` was used in this statement
fn insert(&mut self, relation: &ObjectName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice refactor

datafusion/sql/src/parser.rs Outdated Show resolved Hide resolved
datafusion/sql/src/parser.rs Outdated Show resolved Hide resolved
Comment on lines 398 to 401
Token::Number(ref n, l) => match n.parse() {
Ok(n) => Ok(Value::Number(n, l)),
Err(e) => parser_err!(format!("Could not parse '{n}' as number: {e}")),
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a question: what is these lines of code trying to do?

I might be wrong about this but it seems that n in Token::number(ref n, l) is already guaranteed by the tokenizer to be a number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will admit to simply copy/pasting this from sqlparser code. I will change this to "internal error" to signal that it is not expected

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried to make it an internal error, but the type needs to be a ParserError -- I added some clarifying comments i 17c6960

@aprimadi
Copy link
Contributor

Btw, this PR is fine and working as is. Most of my suggested change is typo fix.

@alamb
Copy link
Contributor Author

alamb commented May 19, 2023

Thanks for the suggestions @aprimadi -- I just ran out of time yesterday to apply them. I will do so today!

Copy link
Contributor

@aprimadi aprimadi left a comment

Choose a reason for hiding this comment

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

Looking great -- thanks @alamb

@alamb
Copy link
Contributor Author

alamb commented May 19, 2023

Thanks again for the reviews and suggestions @aprimadi

@alamb alamb merged commit 412867a into apache:main May 19, 2023
@alamb alamb deleted the alamb/copy_syntax branch May 19, 2023 13:41
@Denys-Bushulyak
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate sql SQL Planner sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LogicalPlan COPY TO statement support
3 participants