Skip to content

Sourcery refactored main branch - #1

Open
sourcery-ai[bot] wants to merge 1 commit into
mainfrom
sourcery/main
Open

sourcery-ai[bot] wants to merge 1 commit into
mainfrom
sourcery/main

Conversation

@sourcery-ai

@sourcery-ai sourcery-ai Bot commented Dec 28, 2023

Copy link
Copy Markdown

Branch main refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai
sourcery-ai Bot requested a review from edson-github December 28, 2023 20:56

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Due to GitHub API limits, only the first 60 comments can be shown.

Comment thread setup.py
def sqlglotrs_version():
with open("sqlglotrs/Cargo.toml") as fd:
for line in fd.readlines():
for line in fd:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function sqlglotrs_version refactored with the following changes:

Comment thread benchmarks/bench.py

crazy = "SELECT 1+"
crazy += "+".join(str(i) for i in range(500))
crazy = "SELECT 1+" + "+".join(str(i) for i in range(500))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Lines 60-61 refactored with the following changes:

Comment thread benchmarks/bench.py
Comment on lines -203 to +202
return f" ({str(column / row['sqlglot'])[0:5]})"
return f" ({str(column / row['sqlglot'])[:5]})"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function diff refactored with the following changes:

Comment thread benchmarks/bench.py
Comment on lines -222 to +223
row[lib] = np.mean(timeit.repeat(lambda: globals()[lib + "_parse"](sql), number=3))
row[lib] = np.mean(
timeit.repeat(lambda: globals()[f"{lib}_parse"](sql), number=3)
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Lines 222-238 refactored with the following changes:

Comment thread sqlglot/diff.py
self._bigram_histo_cache: t.Dict[int, t.DefaultDict[str, int]] = {}

matching_set = self._compute_matching_set() | {(s, t) for s, t in pre_matched_nodes.items()}
matching_set = self._compute_matching_set() | set(pre_matched_nodes.items())

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function ChangeDistiller.diff refactored with the following changes:

Comment thread sqlglot/expressions.py
Comment on lines -496 to +490
for node, _, _ in self.dfs(prune=lambda n, p, *_: p and not type(n) is self.__class__):
if not type(node) is self.__class__:
for node, _, _ in self.dfs(prune=lambda n, p, *_: p and type(n) is not self.__class__):
if type(node) is not self.__class__:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Expression.flatten refactored with the following changes:

  • Simplify logical expression using De Morgan identities [×2] (de-morgan)

Comment thread sqlglot/expressions.py
Comment on lines -622 to +619
errors: t.List[str] = []

for k in self.args:
if k not in self.arg_types:
errors.append(f"Unexpected keyword: '{k}' for {self.__class__}")
errors: t.List[str] = [
f"Unexpected keyword: '{k}' for {self.__class__}"
for k in self.args
if k not in self.arg_types
]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Expression.error_messages refactored with the following changes:

Comment thread sqlglot/expressions.py
Comment on lines -1013 to +1006
if not with_:
return []
return with_.expressions
return [] if not with_ else with_.expressions

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function DDL.ctes refactored with the following changes:

Comment thread sqlglot/expressions.py
Comment on lines -2338 to +2329
property_cls = cls.NAME_TO_PROPERTY.get(key.upper())
if property_cls:
if property_cls := cls.NAME_TO_PROPERTY.get(key.upper()):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Properties.from_dict refactored with the following changes:

Comment thread sqlglot/expressions.py
Comment on lines -2420 to +2410
if not with_:
return []
return with_.expressions
return [] if not with_ else with_.expressions

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Subqueryable.ctes refactored with the following changes:

Comment thread sqlglot/expressions.py
Comment on lines -2538 to +2526
if isinstance(self.this, Func):
return ""
return self.this.name
return "" if isinstance(self.this, Func) else self.this.name

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Table.name refactored with the following changes:

Comment thread sqlglot/expressions.py
Comment on lines -2575 to +2562
col = column(*reversed(parts[0:4]), *parts[4:], copy=copy) # type: ignore
alias = self.args.get("alias")
if alias:
col = column(*reversed(parts[:4]), *parts[4:], copy=copy)
if alias := self.args.get("alias"):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Table.to_column refactored with the following changes:

This removes the following comments ( why? ):

# type: ignore

Comment thread sqlglot/expressions.py
Comment on lines -3928 to +3916
def build(self, expressions: t.Sequence[Expression]) -> Dot:
def build(cls, expressions: t.Sequence[Expression]) -> Dot:
"""Build a Dot object with a sequence of expressions."""
if len(expressions) < 2:
raise ValueError(f"Dot requires >= 2 expressions.")
raise ValueError("Dot requires >= 2 expressions.")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Dot.build refactored with the following changes:

Comment thread sqlglot/expressions.py
Comment on lines -5393 to +5380
if copy:
return sql_or_expression.copy()
return sql_or_expression

return sql_or_expression.copy() if copy else sql_or_expression
if sql_or_expression is None:
raise ParseError(f"SQL cannot be None")
raise ParseError("SQL cannot be None")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function maybe_parse refactored with the following changes:

Comment thread sqlglot/expressions.py
Comment on lines -6112 to -6120
interval_parts = INTERVAL_STRING_RE.match(interval) # type: ignore

if not interval_parts:
if interval_parts := INTERVAL_STRING_RE.match(interval):
return Interval(
this=Literal.string(interval_parts.group(1)),
unit=Var(this=interval_parts.group(2).upper()),
)
else:
raise ValueError("Invalid interval string.")

return Interval(
this=Literal.string(interval_parts.group(1)),
unit=Var(this=interval_parts.group(2).upper()),
)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function to_interval refactored with the following changes:

This removes the following comments ( why? ):

# type: ignore

Comment thread sqlglot/generator.py
Comment on lines -1134 to +1123
expressions = self.expressions(properties, sep=sep, indent=False)
if expressions:
if expressions := self.expressions(properties, sep=sep, indent=False):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Generator.properties refactored with the following changes:

Comment thread sqlglot/generator.py
Comment on lines -1455 to +1443
when = self.sql(expression, "when")
if when:
if when := self.sql(expression, "when"):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Generator.table_sql refactored with the following changes:

Comment thread sqlglot/generator.py
Comment on lines -1616 to +1610
else:
cube_sql = self.expressions(expression, key="cube", indent=False)
cube_sql = f"{self.seg('CUBE')} {self.wrap(cube_sql)}" if cube_sql else ""
cube_sql = self.expressions(expression, key="cube", indent=False)
cube_sql = f"{self.seg('CUBE')} {self.wrap(cube_sql)}" if cube_sql else ""

rollup = expression.args.get("rollup", [])
if seq_get(rollup, 0) is True:
return f"{group_by}{self.seg('WITH ROLLUP')}"
else:
rollup_sql = self.expressions(expression, key="rollup", indent=False)
rollup_sql = f"{self.seg('ROLLUP')} {self.wrap(rollup_sql)}" if rollup_sql else ""
rollup_sql = self.expressions(expression, key="rollup", indent=False)
rollup_sql = f"{self.seg('ROLLUP')} {self.wrap(rollup_sql)}" if rollup_sql else ""

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Generator.group_sql refactored with the following changes:

Comment thread sqlglot/generator.py
Comment on lines -1682 to +1667
if using:
on_sql = f"{space}USING ({on_sql})"
else:
on_sql = f"{space}ON {on_sql}"
on_sql = f"{space}USING ({on_sql})" if using else f"{space}ON {on_sql}"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Generator.join_sql refactored with the following changes:

Comment thread sqlglot/generator.py
Comment on lines -2072 to +2055
if self.UNNEST_WITH_ORDINALITY:
if alias and isinstance(offset, exp.Expression):
if alias and isinstance(offset, exp.Expression):
if self.UNNEST_WITH_ORDINALITY:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Generator.unnest_sql refactored with the following changes:

Comment thread sqlglot/generator.py
Comment on lines -2175 to +2156
default = self.sql(expression, "default")

if default:
if default := self.sql(expression, "default"):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Generator.case_sql refactored with the following changes:

Comment thread sqlglot/generator.py
Comment on lines -2318 to +2297
nested_schema = self.sql(expression, "nested_schema")

if nested_schema:
if nested_schema := self.sql(expression, "nested_schema"):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Generator.jsoncolumndef_sql refactored with the following changes:

Comment thread sqlglot/generator.py
Comment on lines -2556 to +2540
dtype = self.sql(expression, "dtype")
if dtype:
if dtype := self.sql(expression, "dtype"):
collate = self.sql(expression, "collate")
collate = f" COLLATE {collate}" if collate else ""
using = self.sql(expression, "using")
using = f" USING {using}" if using else ""
return f"ALTER COLUMN {this} SET DATA TYPE {dtype}{collate}{using}"

default = self.sql(expression, "default")
if default:
if default := self.sql(expression, "default"):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Generator.altercolumn_sql refactored with the following changes:

Comment thread sqlglot/generator.py
Comment on lines -2782 to +2757
for value in arg_value:
args.append(value)
args.extend(iter(arg_value))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Generator.function_fallback_sql refactored with the following changes:

Comment thread sqlglot/generator.py
Comment on lines -2979 to +2953
having = self.sql(expression, "having")

if having:
if having := self.sql(expression, "having"):

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Generator.anyvalue_sql refactored with the following changes:

Comment thread sqlglot/parser.py
Comment on lines -1519 to +1518
if before:
prop = self._parse_property_before()
else:
prop = self._parse_property()

prop = self._parse_property_before() if before else self._parse_property()
if not prop:
break
for p in ensure_list(prop):
properties.append(p)

properties.extend(iter(ensure_list(prop)))

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Parser._parse_properties refactored with the following changes:

Comment thread sqlglot/parser.py
Comment on lines -1580 to +1570
if not self._next:
return None

return self._parse_withisolatedloading()
return None if not self._next else self._parse_withisolatedloading()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Parser._parse_with_property refactored with the following changes:

Comment thread sqlglot/parser.py
Comment on lines -1593 to +1580
if not user or not host:
return None

return exp.DefinerProperty(this=f"{user}@{host}")
return exp.DefinerProperty(this=f"{user}@{host}") if user and host else None

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Parser._parse_definer refactored with the following changes:

Comment thread sqlglot/parser.py
Comment on lines -1702 to +1686
autotemp = None
if self._match_text_seq("AUTOTEMP"):
autotemp = self._parse_schema()

autotemp = self._parse_schema() if self._match_text_seq("AUTOTEMP") else None

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Parser._parse_blockcompression refactored with the following changes:

Comment thread sqlglot/parser.py
Comment on lines 1877 to 1884

id_var = self._parse_id_var()
if not id_var:
return None
if id_var := self._parse_id_var():
options.append(
self.expression(exp.Property, this=this, value=exp.var(id_var.this.upper()))
)

options.append(
self.expression(exp.Property, this=this, value=exp.var(id_var.this.upper()))
)
else:
return None

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Function Parser._parse_create_like refactored with the following changes:

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.

0 participants