Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/databricks/labs/lsql/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ def create_dashboard(


@lsql.command(is_unauthenticated=True)
def fmt(folder: Path = Path.cwd(), normalize_case: bool = True):
def fmt(folder: Path = Path.cwd(), *, normalize_case: str = "true"):
"""Format SQL files in a folder"""
logger.debug("Formatting SQL files ...")
folder = Path(folder)
should_normalize_case = normalize_case in STRING_AFFIRMATIVES
for sql_file in folder.glob("**/*.sql"):
sql = sql_file.read_text()
formatted_sql = QueryTile.format(sql, normalize_case)
formatted_sql = QueryTile.format(sql, normalize_case=should_normalize_case)
sql_file.write_text(formatted_sql)
logger.debug(f"Formatted {sql_file}")

Expand Down
8 changes: 4 additions & 4 deletions src/databricks/labs/lsql/dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,16 +418,16 @@ def validate(self) -> None:
raise ValueError(f"Invalid query content: {self.content}") from e

@staticmethod
def format(content: str, normalize_case: bool = True, *, max_text_width: int = 120) -> str:
def format(content: str, *, max_text_width: int = 120, normalize_case: bool = True) -> str:
"""Format the content

Args:
content : str
The content to format
max_text_width : int
max_text_width : int, optional (default: 120)
The maximum text width to wrap at
normalize_case : bool
If the query should be normalized to lower case
normalize_case : bool, optional (default: True)
If the query identifiers should be normalized to lower case
"""
try:
parsed_query = sqlglot.parse(content, dialect=_SQL_DIALECT)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ def test_query_formats_no_normalize():
FROM system.access.audit AS a
LEFT OUTER JOIN inventory.clusters AS c
ON a.request_params.clusterId = c.cluster_id AND a.action_name = 'runCommand'"""
assert QueryTile.format(query, False) == query_formatted
assert QueryTile.format(query, normalize_case=False) == query_formatted


@pytest.mark.parametrize(
Expand Down