Repository navigation
Add Taxonomy to postgres Schema extraction #73
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
Closed
Closed
Changes from 7 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
0a8f65f
add-tax
galshubeli 3438c44
move-const-config
galshubeli b61598b
fix-bug
galshubeli 05b70b0
fix-comments
galshubeli f6b2898
fix-bug
galshubeli e99998e
fix-tests
galshubeli 4f6e6d5
single-func
galshubeli 3d99fea
Update api/config.py
galshubeli 94ede81
Merge branch 'main' into add-taxonomy
gkorland acaade4
gen-queries
galshubeli 7cf175f
fix docker with fastapi
gkorland 26b616a
Merge pull request #102 from FalkorDB/fix-docker
gkorland 9fd9875
clean flask
gkorland 5e9ba19
Merge branch 'main' into staging
gkorland 101b012
Merge branch 'staging' into remove-flask
gkorland 701db7f
Merge pull request #103 from FalkorDB/remove-flask
gkorland 56b9c36
update deps
gkorland 708de13
Merge branch 'staging' into deps
gkorland 1b01b6a
Merge pull request #105 from FalkorDB/deps
gkorland e655e75
clean lint
gkorland 9c2029c
fix lints
gkorland 9d42263
clean lints
gkorland c279334
fix
gkorland 890876a
fix tests
gkorland 61897fe
fix tests
gkorland 80d9315
fix tests
gkorland 349f937
Merge pull request #106 from FalkorDB/lint-fixes
gkorland c0639c7
add design
gkorland 5ce6dda
add header
gkorland d7141a1
Merge pull request #107 from FalkorDB/design
gkorland fe90292
add toolbar to mobile
gkorland d512568
set select size
gkorland f2fba00
Merge pull request #108 from FalkorDB/burgger
gkorland 4d36bfa
Merge branch 'staging' into add-taxonomy
galshubeli 9f7f3ae
rm-rw-condition
galshubeli fc0389d
rm-max-rw
galshubeli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,8 @@ | ||
| """Base loader module providing abstract base class for data loaders.""" | ||
|
|
||
| from abc import ABC | ||
| from typing import Tuple | ||
| from typing import Tuple, List | ||
| from api.config import Config | ||
|
|
||
|
|
||
| class BaseLoader(ABC): | ||
|
|
@@ -14,3 +15,62 @@ def load(_graph_id: str, _data) -> Tuple[bool, str]: | |
| This method must be implemented by any subclass. | ||
| """ | ||
| return False, "Not implemented" | ||
|
|
||
| @staticmethod | ||
| def extract_distinct_values_for_column(cursor, table_name: str, col_name: str) -> List[str]: | ||
| """ | ||
| Extract distinct values for a column if it meets the criteria for inclusion. | ||
|
|
||
| Args: | ||
| cursor: Database cursor | ||
| table_name: Name of the table | ||
| col_name: Name of the column | ||
|
|
||
| Returns: | ||
| List of formatted distinct values to add to description, or empty list | ||
| """ | ||
| # Count rows and distinct values for the column | ||
| cursor.execute( | ||
| f""" | ||
| SELECT COUNT(*) AS total_count, | ||
| COUNT(DISTINCT {col_name}) AS distinct_count | ||
| FROM {table_name}; | ||
| """ | ||
| ) | ||
|
galshubeli marked this conversation as resolved.
Outdated
|
||
| output = cursor.fetchall() | ||
|
|
||
| # Auto-detect result format by checking the first result | ||
| first_result = output[0] | ||
| if isinstance(first_result, dict): | ||
| # MySQL/dictionary-style results | ||
| rows_count, distinct_count = first_result['total_count'], first_result['distinct_count'] | ||
| else: | ||
| # PostgreSQL/tuple-style results | ||
| rows_count, distinct_count = first_result | ||
|
|
||
| max_rows = Config.DB_MAX_ROWS | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @galshubeli you shouldn't limit the MAX_ROWS |
||
| max_distinct = Config.DB_MAX_DISTINCT | ||
| uniqueness_threshold = Config.DB_UNIQUENESS_THRESHOLD | ||
|
|
||
| if 0 < rows_count < max_rows and distinct_count < max_distinct: | ||
| uniqueness_value = distinct_count / rows_count | ||
| if uniqueness_value < uniqueness_threshold: | ||
| cursor.execute( | ||
| f"SELECT DISTINCT {col_name} FROM {table_name};" | ||
| ) | ||
|
|
||
| distinct_results = cursor.fetchall() | ||
| if distinct_results and isinstance(distinct_results[0], dict): | ||
| # MySQL/dictionary-style results | ||
| distinct_values = [row[col_name] for row in distinct_results if row[col_name] is not None] | ||
| else: | ||
| # PostgreSQL/tuple-style results | ||
| distinct_values = [row[0] for row in distinct_results if row[0] is not None] | ||
|
|
||
| if distinct_values: | ||
| # Check first value type to avoid objects like dict/bytes | ||
| first_val = distinct_values[0] | ||
| if isinstance(first_val, (str, int, float)): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @galshubeli should remove the float |
||
| return [f"(Optional values: {', '.join(f'({str(v)})' for v in distinct_values)})"] | ||
|
|
||
| return [] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.