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

Split on first period only. Closes #77. #78

Closed

Conversation

jseabold
Copy link
Collaborator

Don't know if ideal, but fixes my problem described in #77.

@graingert
Copy link
Member

Can you create a reflection test for this?

@jseabold
Copy link
Collaborator Author

Yeah, I'll give it a shot.

@jseabold
Copy link
Collaborator Author

Perhaps it's cleaner to make relname always a delimited identifier?

@jseabold
Copy link
Collaborator Author

I added a test but I can't actually get it to fail without the subsequent two commits. Anything obvious to you? Edit I removed the delimiting the relname so that there aren't quotes on everything in the MetaData registry.

@jseabold
Copy link
Collaborator Author

This is semi-related to #74 about things generally needing to be delimited for safety.

@jseabold
Copy link
Collaborator Author

jseabold commented Jan 5, 2016

Any thoughts?

@@ -102,7 +102,7 @@ def _get_relation_key(name, schema):
def _get_schema_and_relation(key):
if '.' not in key:
return (None, key)
identifiers = SQL_IDENTIFIER_RE.findall(key)
identifiers = re.split("\.", key, 1)
Copy link
Member

Choose a reason for hiding this comment

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

If the table name is "this.table", it will always get split up based on this regex, even if no schema name is prepended. So I think this is broken.

Copy link
Member

Choose a reason for hiding this comment

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

Or if I'm mistaken here, could you provide a test that verifies you can call _get_schema_and_relation with "this.table" and get back (None, '"this.table"')?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sorry I missed this comment. Yeah, you're right. This does not handle delimited identifiers well. Let me have a look.

@graingert
Copy link
Member

@jseabold hey there I'd like to get this merged, can you respond to @jklukas's comments

@graingert
Copy link
Member

@jseabold bump

@jseabold
Copy link
Collaborator Author

Are a lot of these tests being skipped? I was trying to figure out why my tests weren't failing when they were expected to and py.test is skipping them. The travis logs seem to indicate that these same tests are being skipped on travis. Any objections to running the tests verbosely on travis?

@graingert
Copy link
Member

The tests that are skipped require a real redshift server
On 28 Apr 2016 20:18, "Skipper Seabold" notifications@github.com wrote:

Are a lot of these tests being skipped? I was trying to figure out why my
tests weren't failing when they were expected to and py.test is skipping
them. The travis logs seem to indicate that these same tests are being
skipped on travis. Any objections to running the tests verbosely on travis?


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#78 (comment)

@jseabold
Copy link
Collaborator Author

Right. So where do they get run, if ever? Do I need to test them against my own server?

@graingert
Copy link
Member

We run it on commits on branches in this repo. I can pull your changes into
one
On 28 Apr 2016 20:21, "Skipper Seabold" notifications@github.com wrote:

Right. So where do they get run, if ever? Do I need to test them against
my own server?


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#78 (comment)

@jseabold
Copy link
Collaborator Author

Ok, thanks. That wasn't clear to me.

@jseabold
Copy link
Collaborator Author

Let's see how this looks.

@jseabold
Copy link
Collaborator Author

jseabold commented Apr 28, 2016

Hmm, I think I've actually lost sight of the original issue with the code comment above.

Since the tables are coming from pg_catalog.pg_class they're not actually delimited in there, which was the whole reason I started digging in to this. I'm actually not sure what a robust solution for this could even look like.

Edit: let me give it one more go.

@jseabold
Copy link
Collaborator Author

Ok...I'm remembering the issue again...

Why are you doing this? Honest question, I don't know. It seems like the only way you can have a key that's table.name is because you set the schema to None. If you don't do this, you don't have the problem. All of the quotes get stripped when the table information is stored, so we can't reliably use them in the regex and always splitting on the first period should work if you don't remove the schema.

https://github.com/sqlalchemy-redshift/sqlalchemy-redshift/blob/master/sqlalchemy_redshift/dialect.py#L635

@atrigent
Copy link

Why does _get_relation_key need to return a string? Why can't it return a tuple, where the separation between the schema and relation name will be preserved?

# the delimited identifier dox is silent on whether the following is
# possible
(("\"crazy schema\".\"crazy table\""),
("\"crazy schema\"", "\"crazy table\"")),
Copy link
Member

Choose a reason for hiding this comment

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

These strings would be easier to read by delimiting with single quotes so that the double quotes inside the strings don't need to be escaped ('other_schema."table_name"', etc.)

@jklukas
Copy link
Member

jklukas commented Sep 29, 2016

Why does _get_relation_key need to return a string? Why can't it return a tuple, where the separation between the schema and relation name will be preserved?

That's a fair point, and I don't think there's any reason it can't. I'll take a look at what would be needed for that change.

@jklukas jklukas mentioned this pull request Sep 30, 2016
4 tasks
@jklukas
Copy link
Member

jklukas commented Sep 30, 2016

See #97 which pulls in the commits here, but factors out table references to a new RelationKey tuple type.

@jseabold jseabold closed this Sep 30, 2016
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.

None yet

4 participants