• Home
  • Raw
  • Download

Lines Matching full:sql

36   """Perfetto SQL dialect implementation."""
39 """Generator for Perfetto SQL dialect."""
74 sql: str,
81 return sql
85 return sql
86 sep = ('\n' if sql and sql[0].isspace() else '') + comments_sql
87 return f"{sep}{self.sep()}{sql.strip()}"
111 sql for sql in (self.sql(e) for e in expressions) if sql)
117 sql = self.sql(e, comment=False)
118 if not sql:
126 result_sqls.append(f"{sep if i > 0 else ''}{prefix}{comments}{sql}")
129 … f"{prefix}{comments}{sql}{(sep.rstrip() if comments else sep) if i + 1 < num_sqls else ''}"
133 f"{prefix}{comments}{sql}{sep if i + 1 < num_sqls else ''}")
150 return f"{self.sql(expression.this.left)} IS NOT NULL"
174 this = self.sql(expression, "this")
178 statements.append(self.maybe_comment(f"WHEN {self.sql(e, 'this')}", e))
179 statements.append(f"THEN {self.sql(e, 'true')}")
181 default = self.sql(expression, "default")
195 sql = self.expressions(expression)
198 return f"WITH\n{recursive}{sql}"
201 return f"RETURNS {self.sql(expression, 'this')}"
379 exp.Interval) and default.this.sql().upper() == "END":
430 def preprocess_macros(sql: str) -> Tuple[str, List[Tuple[str, str]]]:
434 sql: Input SQL string
437 Tuple of (processed SQL, list of (placeholder, original macro text) pairs)
439 result = sql
442 for match in re.finditer(r'(\w+)\s*!\s*\(', sql):
446 while i < len(sql) and paren > 0:
447 if sql[i] == '(':
449 elif sql[i] == ')':
454 macro = sql[start:i]
462 def postprocess_macros(sql: str, macros: List[Tuple[str, str]]) -> str:
466 sql: Formatted SQL with placeholders
470 SQL with macros restored
472 result = sql
478 def extract_comment_blocks(sql: str) -> Tuple[str, Dict[str, str]]:
479 """Extract comment blocks from SQL and replace with placeholders.
485 sql: Input SQL string
489 - Processed SQL with comment blocks replaced by placeholders
495 for line in sql.splitlines():
523 def restore_comment_blocks(sql: str, blocks: Dict[str, str]) -> str:
527 sql: SQL string with placeholders
531 SQL string with comment blocks restored in their original positions
533 result = sql
540 sql: str,
543 """Format SQL content with consistent style.
546 file: Path to the SQL file (for error reporting)
547 sql: SQL content to format
552 Formatted SQL string
555 Exception: If SQL parsing or formatting fails
557 if sql.find('-- sqlformat file off') != -1:
560 return sql
563 sql_with_placeholders, comment_blocks = extract_comment_blocks(sql)
569 for ast in sqlglot.parse(sql=processed, dialect=Perfetto):
570 formatted += ast.sql(
583 print(f"Failed to format SQL: file {file}, {e}", file=sys.stderr)
590 """Format multiple SQL files in place.
600 # Process all .sql files in directory recursively
601 sql_files = path.rglob('*.sql')
608 sql = f.read()
609 formatted = format_sql(sql_file, sql, indent_width, verbose)
619 """Check SQL files for formatting violations without making changes.
633 sql_files = path.rglob('*.sql')
639 sql = f.read()
640 formatted = format_sql(sql_file, sql, indent_width, verbose)
641 if formatted != sql:
655 description='Format SQL queries with consistent style')
659 help='Paths to SQL files or directories containing SQL files')