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

fix: Update Copy parser to handle ',' separated option list #49

Merged
merged 8 commits into from
Mar 2, 2022

Conversation

Vizerai
Copy link
Collaborator

@Vizerai Vizerai commented Mar 1, 2022

Update Copy parser to handle ',' separated option list. Also expand single char regex to wider set of characters [! - ~].

single char regex to wider set of characters.
@Vizerai Vizerai changed the title Update Copy parser to handle ',' separated option list refactor: Update Copy parser to handle ',' separated option list Mar 1, 2022
@Vizerai Vizerai requested a review from olavloite March 1, 2022 09:13
@Vizerai Vizerai changed the title refactor: Update Copy parser to handle ',' separated option list fix: Update Copy parser to handle ',' separated option list Mar 1, 2022
@@ -242,6 +241,8 @@ private void parseCopyStatement() throws Exception {
parse(sql, this.options);
} catch (Exception e) {
throw new SQLException("Invalid COPY statement syntax: " + e.toString());
} catch (TokenMgrError e) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: you can combine the two catch clauses into one like this:

    } catch (Exception | TokenMgrError e) {
      throw new SQLException("Invalid COPY statement syntax: " + e.toString());
    }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

assertThat(options.getDelimiter(), is(equalTo(value)));
assertThat(options.getQuote(), is(equalTo(value1)));
assertThat(options.getEscape(), is(equalTo(value2)));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add the following assertion (here and also for the other tests):

Suggested change
}
assertEquals(StatementParser.parseCommand(StatementParser.removeCommentsAndTrim(sql)), "COPY");
}

This assertion currently fails for ESCAPE '\', as our parser (correctly?) sees '' as an unclosed string literal.

Copy link
Collaborator Author

@Vizerai Vizerai Mar 1, 2022

Choose a reason for hiding this comment

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

Yes, removeCommentsAndTrim() does not allow a single '\' in the statement. Copy expects the delimiter, escape, and quote options to be single characters.

Le'ts drop ', ", and \ for now. The logic in removeCommentsAndTrim() would break if we allowed those. We could add them back in at a later point after we rework removeCommentsAndTrim().

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah, that sounds reasonable.

@Vizerai Vizerai requested a review from olavloite March 2, 2022 06:36
@Vizerai Vizerai merged commit 7c6530f into postgresql-dialect Mar 2, 2022
@olavloite olavloite deleted the copy_option branch March 6, 2022 16:05
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.

2 participants