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

[FEAT] static layers extra tables unique names #1445

Merged
merged 3 commits into from
Aug 17, 2022

Conversation

metemaddar
Copy link
Contributor

pick unique name by trailing sequences if table name already exists

  • table name like: file_name -> file_name_1 -> file_name_2

Related issue

#1427

pick unique name by trailing sequences if table name already exists
- table name like: file_name -> file_name_1 -> file_name_2
@metemaddar metemaddar requested a review from EPajares August 16, 2022 20:01
pass
async def list_static_layer_table_names(self, db: AsyncSession, name_like=""):
metadata_obj = MetaData(schema="information_schema")
tables = Table(
Copy link
Collaborator

Choose a reason for hiding this comment

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

A very elegant solution to avoid SQL-string. I did not know this works.

Copy link
Contributor Author

@metemaddar metemaddar Aug 17, 2022

Choose a reason for hiding this comment

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

Thanks a lot @EPajares . Also while searching about functions I found that we can use SqlAlechemy func method to call the functions (ref). So we can use it to have user defined functions also as SqlAlchemy Query object and use it's other methods cleaner.

From doc:

Note that any name not known to func generates the function name as is - there is no restriction on what SQL functions can be called, known or unknown to SQLAlchemy, built-in or user defined. The section here only describes those functions where SQLAlchemy already knows what argument and return types are in use.

db=db, name_like=name
)
counter = 1
while name in static_layer_table_names:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I was thinking again about this logic and I think it could break in the following scenario.

Imagine you have:

table1
table2
table3

And now you delete table2. You will have two tables and the counter will be two. Accordingly it will assign 3 for table3. But table3 is already taken and we will run into duplicated table name. Maybe we could get the max counter and then assign max + 1?

Copy link
Contributor Author

@metemaddar metemaddar Aug 17, 2022

Choose a reason for hiding this comment

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

I think it won't. Because it will be checked again at while part.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You are right. So we should be fine with this.

@EPajares EPajares merged commit f647b5d into goat-community:dev Aug 17, 2022
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