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

Search tables for TEXT values that are too long for MariaDB #10

Merged
merged 2 commits into from
Sep 13, 2018

Conversation

jsuchome
Copy link
Contributor

@jsuchome jsuchome commented Sep 12, 2018

2nd commit is not exactly related, and I do not know if you like it this way...

aojea
aojea previously requested changes Sep 12, 2018
psql2mysql.py Outdated
print(output_table)
raise Exception("Too long text values found in the source database.")
except Exception as e:
print "Error during precheck: ", e
Copy link
Contributor

Choose a reason for hiding this comment

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

please make it python3 compatible print("Error during precheck: ", e)

psql2mysql.py Outdated
@@ -199,7 +230,8 @@ def do_prechecks(config):
db = DbWrapper(cfg.CONF.source)
db.connect()
tables = db.getSortedTables()
for table in tables:
try:
Copy link

Choose a reason for hiding this comment

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

I do not think that is a good idea, as you are hiding the underlining error, like the one from line 255, with a generic 'something is wrong' message, that will require to edit the code to see the real problem when the exception is not an str.

What I mean is that this works only for the exception raised in 255, but there are potentially other Exception that are not string based, so printing e will not provide information.

I suggest simply to fail here, and capture in the caller with more specific cases.

For the line 255, to break the loop I would suggest to simply use break and a print() to show the error, instead of the raise

Copy link
Contributor Author

Choose a reason for hiding this comment

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

"For the line 255, to break the loop I would suggest to simply use break and a print() to show the error, instead of the raise"

OK, that makes sense I guess

psql2mysql.py Outdated
@@ -61,6 +61,37 @@ def _exclude_deleted(self, table, query):
return query.where(table.c.deleted == 'False')
return query.where(table.c.deleted == False)

def getTextColumns(self, table):
columns = table.columns
return [ c.name for c in columns if str(c.type) == 'TEXT' ]
Copy link

Choose a reason for hiding this comment

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

nit: remove the spaces between the brackets?

psql2mysql.py Outdated
def scanTableForLongTexts(self, table):
textColumns = self.getTextColumns(table)
if not textColumns:
return []
Copy link

Choose a reason for hiding this comment

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

no need of this as later you iterate over text_columns? eventually your logic will return [], or fails for line 77?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well I can skip the query, right?

Copy link

Choose a reason for hiding this comment

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

sure

psql2mysql.py Outdated

long_values = []
primary_keys = []
if not table.primary_key == None:
Copy link

Choose a reason for hiding this comment

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

if table.primary_key is not None or if table.primary_key. Both are equivalent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, how could I missed this

psql2mysql.py Outdated
long_values = []
primary_keys = []
if not table.primary_key == None:
primary_keys = list(table.primary_key)
Copy link

Choose a reason for hiding this comment

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

I guess that table.primary_key is a single element? if so is more clear this: [table.primary_key]

If can be a single element, or an iterator, I think that our code is OK as in any case will return a list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, there could be more

psql2mysql.py Outdated
for row in rows:
for col in textColumns:
if not isinstance(row[col], six.string_types):
continue
Copy link

Choose a reason for hiding this comment

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

oh can this happens? be a text column but do not contain text?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can actually be None, in which case the next call fails. Comes from rhafer@07fcb15

@jsuchome
Copy link
Contributor Author

@aojea @aplanas adapted

aplanas
aplanas previously approved these changes Sep 12, 2018
Copy link

@aplanas aplanas left a comment

Choose a reason for hiding this comment

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

LGMT

@jsuchome
Copy link
Contributor Author

Rebased after merging #11

psql2mysql.py Outdated
=======
MAX_TEXT_LEN = 65536

>>>>>>> de99a7b... Search tables for TEXT values that are too long for MariaDB
Copy link

Choose a reason for hiding this comment

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

XD

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, seen that, fixed already

aplanas
aplanas previously approved these changes Sep 13, 2018
@rhafer rhafer merged commit a114019 into SUSE:master Sep 13, 2018
@jsuchome jsuchome deleted the long-chars branch September 13, 2018 08:46
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