Skip to content

Commit fd441b5

Browse files
committed
Update cli
1 parent 210ee09 commit fd441b5

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

text_2_sql/data_dictionary/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ You can pass the following command line arguements:
122122

123123
- `-- output_directory` or `-o`: Optional directory that the script will write the output files to.
124124
- `-- single_file` or `-s`: Optional flag that writes all schemas to a single file.
125+
- `-- generate_definitions` or `-gen`: Optional flag that uses OpenAI to generate descriptions.
126+
127+
If you need control over the following, run the file directly:
128+
129+
- `entities`: A list of entities to extract. Defaults to None.
130+
- `excluded_entities`: A list of entities to exclude.
131+
- `excluded_schemas`: A list of schemas to exclude.
125132

126133
> [!IMPORTANT]
127134
>

text_2_sql/text_2_sql_core/src/text_2_sql_core/data_dictionary/cli.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ def create(
3737
help="Optional flag that writes all schemas to a single file.",
3838
),
3939
] = False,
40+
generate_definitions: Annotated[
41+
bool,
42+
typer.Option(
43+
"--generate_definitions",
44+
"-gen",
45+
help="Optional flag that will use OpenAI to generate descriptions.",
46+
),
47+
] = False,
4048
) -> None:
4149
"""Execute a Text2SQL Data Dictionary Creator YAML file.
4250
@@ -50,30 +58,36 @@ def create(
5058
5159
"""
5260

61+
kwargs = {
62+
"output_directory": output_directory,
63+
"single_file": single_file,
64+
"generate_definitions": generate_definitions,
65+
}
66+
5367
try:
5468
if engine == DatabaseEngine.DATABRICKS:
5569
from text_2_sql_core.data_dictionary.databricks_data_dictionary_creator import (
5670
DatabricksDataDictionaryCreator,
5771
)
5872

5973
data_dictionary_creator = DatabricksDataDictionaryCreator(
60-
single_file=single_file, output_directory=output_directory
74+
**kwargs,
6175
)
6276
elif engine == DatabaseEngine.SNOWFLAKE:
6377
from text_2_sql_core.data_dictionary.snowflake_data_dictionary_creator import (
6478
SnowflakeDataDictionaryCreator,
6579
)
6680

6781
data_dictionary_creator = SnowflakeDataDictionaryCreator(
68-
single_file=single_file, output_directory=output_directory
82+
**kwargs,
6983
)
7084
elif engine == DatabaseEngine.TSQL:
7185
from text_2_sql_core.data_dictionary.tsql_data_dictionary_creator import (
7286
TSQLDataDictionaryCreator,
7387
)
7488

7589
data_dictionary_creator = TSQLDataDictionaryCreator(
76-
single_file=single_file, output_directory=output_directory
90+
**kwargs,
7791
)
7892
except ImportError:
7993
detailed_error = f"""Failed to import {
@@ -82,10 +96,10 @@ def create(
8296
rich_print(detailed_error)
8397

8498
raise typer.Exit(code=1)
99+
85100
try:
86101
asyncio.run(data_dictionary_creator.create_data_dictionary())
87102
except Exception as e:
88-
raise e
89103
logging.error(e)
90104
rich_print("Text2SQL Data Dictionary Creator Failed ❌")
91105

text_2_sql/text_2_sql_core/src/text_2_sql_core/data_dictionary/data_dictionary_creator.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def __init__(
237237
excluded_entities: list[str] = None,
238238
excluded_schemas: list[str] = None,
239239
single_file: bool = False,
240-
generate_definitions: bool = True,
240+
generate_definitions: bool = False,
241241
output_directory: str = None,
242242
):
243243
"""A method to initialize the DataDictionaryCreator class.
@@ -250,6 +250,11 @@ def __init__(
250250
generate_definitions (bool, optional): A flag to indicate if definitions should be generated. Defaults to True.
251251
"""
252252

253+
if entities is not None and excluded_entities is not None:
254+
raise ValueError(
255+
"Cannot pass both entities and excluded_entities. Please pass only one."
256+
)
257+
253258
if excluded_entities is None:
254259
excluded_entities = []
255260

0 commit comments

Comments
 (0)