From c51a9844b869fd7cd69e5cc7658d34f61a865185 Mon Sep 17 00:00:00 2001
From: Daniel Baumann select
.
2150class PartitionBoundSpec(Expression): +2151 # this -> IN / MODULUS, expression -> REMAINDER, from_expressions -> FROM (...), to_expressions -> TO (...) +2152 arg_types = { +2153 "this": False, +2154 "expression": False, +2155 "from_expressions": False, +2156 "to_expressions": False, +2157 } +
2160class PartitionedOfProperty(Property): +2161 # this -> parent_table (schema), expression -> FOR VALUES ... / DEFAULT +2162 arg_types = {"this": True, "expression": True} +
2149class RemoteWithConnectionModelProperty(Property): -2150 arg_types = {"this": True} + @@ -32978,8 +33349,8 @@ Otherwise, this resets the expression.
2153class ReturnsProperty(Property): -2154 arg_types = {"this": True, "is_table": False, "table": False} + @@ -33089,8 +33460,8 @@ Otherwise, this resets the expression.
2157class RowFormatProperty(Property): -2158 arg_types = {"this": True} + @@ -33200,17 +33571,17 @@ Otherwise, this resets the expression.
2161class RowFormatDelimitedProperty(Property): -2162 # https://cwiki.apache.org/confluence/display/hive/languagemanual+dml -2163 arg_types = { -2164 "fields": False, -2165 "escaped": False, -2166 "collection_items": False, -2167 "map_keys": False, -2168 "lines": False, -2169 "null": False, -2170 "serde": False, -2171 } +@@ -33321,8 +33692,8 @@ Otherwise, this resets the expression.2177class RowFormatDelimitedProperty(Property): +2178 # https://cwiki.apache.org/confluence/display/hive/languagemanual+dml +2179 arg_types = { +2180 "fields": False, +2181 "escaped": False, +2182 "collection_items": False, +2183 "map_keys": False, +2184 "lines": False, +2185 "null": False, +2186 "serde": False, +2187 }
2174class RowFormatSerdeProperty(Property): -2175 arg_types = {"this": True, "serde_properties": False} + @@ -33432,16 +33803,16 @@ Otherwise, this resets the expression.
2179class QueryTransform(Expression): -2180 arg_types = { -2181 "expressions": True, -2182 "command_script": True, -2183 "schema": False, -2184 "row_format_before": False, -2185 "record_writer": False, -2186 "row_format_after": False, -2187 "record_reader": False, -2188 } + @@ -33552,8 +33923,8 @@ Otherwise, this resets the expression.
2191class SampleProperty(Property): -2192 arg_types = {"this": True} + @@ -33663,8 +34034,8 @@ Otherwise, this resets the expression.
2195class SchemaCommentProperty(Property): -2196 arg_types = {"this": True} + @@ -33774,8 +34145,8 @@ Otherwise, this resets the expression.
2199class SerdeProperties(Property): -2200 arg_types = {"expressions": True} + @@ -33885,8 +34256,8 @@ Otherwise, this resets the expression.
2203class SetProperty(Property): -2204 arg_types = {"multi": True} + @@ -33996,8 +34367,8 @@ Otherwise, this resets the expression.
2207class SettingsProperty(Property): -2208 arg_types = {"expressions": True} + @@ -34107,8 +34478,8 @@ Otherwise, this resets the expression.
2211class SortKeyProperty(Property): -2212 arg_types = {"this": True, "compound": False} + @@ -34218,8 +34589,8 @@ Otherwise, this resets the expression.
2215class SqlSecurityProperty(Property): -2216 arg_types = {"definer": True} + @@ -34329,8 +34700,8 @@ Otherwise, this resets the expression.
2219class StabilityProperty(Property): -2220 arg_types = {"this": True} + @@ -34440,8 +34811,8 @@ Otherwise, this resets the expression.
2223class TemporaryProperty(Property): -2224 arg_types = {} + @@ -34551,8 +34922,8 @@ Otherwise, this resets the expression.
2227class TransformModelProperty(Property): -2228 arg_types = {"expressions": True} + @@ -34662,8 +35033,8 @@ Otherwise, this resets the expression.
2231class TransientProperty(Property): -2232 arg_types = {"this": False} + @@ -34773,8 +35144,8 @@ Otherwise, this resets the expression.
2235class VolatileProperty(Property): -2236 arg_types = {"this": False} + @@ -34884,8 +35255,8 @@ Otherwise, this resets the expression.
2239class WithDataProperty(Property): -2240 arg_types = {"no": True, "statistics": False} + @@ -34995,8 +35366,8 @@ Otherwise, this resets the expression.
2243class WithJournalTableProperty(Property): -2244 arg_types = {"this": True} + @@ -35106,66 +35477,66 @@ Otherwise, this resets the expression.
2247class Properties(Expression): -2248 arg_types = {"expressions": True} -2249 -2250 NAME_TO_PROPERTY = { -2251 "ALGORITHM": AlgorithmProperty, -2252 "AUTO_INCREMENT": AutoIncrementProperty, -2253 "CHARACTER SET": CharacterSetProperty, -2254 "CLUSTERED_BY": ClusteredByProperty, -2255 "COLLATE": CollateProperty, -2256 "COMMENT": SchemaCommentProperty, -2257 "DEFINER": DefinerProperty, -2258 "DISTKEY": DistKeyProperty, -2259 "DISTSTYLE": DistStyleProperty, -2260 "ENGINE": EngineProperty, -2261 "EXECUTE AS": ExecuteAsProperty, -2262 "FORMAT": FileFormatProperty, -2263 "LANGUAGE": LanguageProperty, -2264 "LOCATION": LocationProperty, -2265 "PARTITIONED_BY": PartitionedByProperty, -2266 "RETURNS": ReturnsProperty, -2267 "ROW_FORMAT": RowFormatProperty, -2268 "SORTKEY": SortKeyProperty, -2269 } -2270 -2271 PROPERTY_TO_NAME = {v: k for k, v in NAME_TO_PROPERTY.items()} -2272 -2273 # CREATE property locations -2274 # Form: schema specified -2275 # create [POST_CREATE] -2276 # table a [POST_NAME] -2277 # (b int) [POST_SCHEMA] -2278 # with ([POST_WITH]) -2279 # index (b) [POST_INDEX] -2280 # -2281 # Form: alias selection -2282 # create [POST_CREATE] -2283 # table a [POST_NAME] -2284 # as [POST_ALIAS] (select * from b) [POST_EXPRESSION] -2285 # index (c) [POST_INDEX] -2286 class Location(AutoName): -2287 POST_CREATE = auto() -2288 POST_NAME = auto() -2289 POST_SCHEMA = auto() -2290 POST_WITH = auto() -2291 POST_ALIAS = auto() -2292 POST_EXPRESSION = auto() -2293 POST_INDEX = auto() -2294 UNSUPPORTED = auto() -2295 -2296 @classmethod -2297 def from_dict(cls, properties_dict: t.Dict) -> Properties: -2298 expressions = [] -2299 for key, value in properties_dict.items(): -2300 property_cls = cls.NAME_TO_PROPERTY.get(key.upper()) -2301 if property_cls: -2302 expressions.append(property_cls(this=convert(value))) -2303 else: -2304 expressions.append(Property(this=Literal.string(key), value=convert(value))) -2305 -2306 return cls(expressions=expressions) +@@ -35221,17 +35592,17 @@ Otherwise, this resets the expression.2263class Properties(Expression): +2264 arg_types = {"expressions": True} +2265 +2266 NAME_TO_PROPERTY = { +2267 "ALGORITHM": AlgorithmProperty, +2268 "AUTO_INCREMENT": AutoIncrementProperty, +2269 "CHARACTER SET": CharacterSetProperty, +2270 "CLUSTERED_BY": ClusteredByProperty, +2271 "COLLATE": CollateProperty, +2272 "COMMENT": SchemaCommentProperty, +2273 "DEFINER": DefinerProperty, +2274 "DISTKEY": DistKeyProperty, +2275 "DISTSTYLE": DistStyleProperty, +2276 "ENGINE": EngineProperty, +2277 "EXECUTE AS": ExecuteAsProperty, +2278 "FORMAT": FileFormatProperty, +2279 "LANGUAGE": LanguageProperty, +2280 "LOCATION": LocationProperty, +2281 "PARTITIONED_BY": PartitionedByProperty, +2282 "RETURNS": ReturnsProperty, +2283 "ROW_FORMAT": RowFormatProperty, +2284 "SORTKEY": SortKeyProperty, +2285 } +2286 +2287 PROPERTY_TO_NAME = {v: k for k, v in NAME_TO_PROPERTY.items()} +2288 +2289 # CREATE property locations +2290 # Form: schema specified +2291 # create [POST_CREATE] +2292 # table a [POST_NAME] +2293 # (b int) [POST_SCHEMA] +2294 # with ([POST_WITH]) +2295 # index (b) [POST_INDEX] +2296 # +2297 # Form: alias selection +2298 # create [POST_CREATE] +2299 # table a [POST_NAME] +2300 # as [POST_ALIAS] (select * from b) [POST_EXPRESSION] +2301 # index (c) [POST_INDEX] +2302 class Location(AutoName): +2303 POST_CREATE = auto() +2304 POST_NAME = auto() +2305 POST_SCHEMA = auto() +2306 POST_WITH = auto() +2307 POST_ALIAS = auto() +2308 POST_EXPRESSION = auto() +2309 POST_INDEX = auto() +2310 UNSUPPORTED = auto() +2311 +2312 @classmethod +2313 def from_dict(cls, properties_dict: t.Dict) -> Properties: +2314 expressions = [] +2315 for key, value in properties_dict.items(): +2316 property_cls = cls.NAME_TO_PROPERTY.get(key.upper()) +2317 if property_cls: +2318 expressions.append(property_cls(this=convert(value))) +2319 else: +2320 expressions.append(Property(this=Literal.string(key), value=convert(value))) +2321 +2322 return cls(expressions=expressions)
2296 @classmethod -2297 def from_dict(cls, properties_dict: t.Dict) -> Properties: -2298 expressions = [] -2299 for key, value in properties_dict.items(): -2300 property_cls = cls.NAME_TO_PROPERTY.get(key.upper()) -2301 if property_cls: -2302 expressions.append(property_cls(this=convert(value))) -2303 else: -2304 expressions.append(Property(this=Literal.string(key), value=convert(value))) -2305 -2306 return cls(expressions=expressions) +@@ -35330,15 +35701,15 @@ Otherwise, this resets the expression.2312 @classmethod +2313 def from_dict(cls, properties_dict: t.Dict) -> Properties: +2314 expressions = [] +2315 for key, value in properties_dict.items(): +2316 property_cls = cls.NAME_TO_PROPERTY.get(key.upper()) +2317 if property_cls: +2318 expressions.append(property_cls(this=convert(value))) +2319 else: +2320 expressions.append(Property(this=Literal.string(key), value=convert(value))) +2321 +2322 return cls(expressions=expressions)
2286 class Location(AutoName): -2287 POST_CREATE = auto() -2288 POST_NAME = auto() -2289 POST_SCHEMA = auto() -2290 POST_WITH = auto() -2291 POST_ALIAS = auto() -2292 POST_EXPRESSION = auto() -2293 POST_INDEX = auto() -2294 UNSUPPORTED = auto() + @@ -35464,8 +35835,8 @@ Otherwise, this resets the expression.
2309class Qualify(Expression): -2310 pass + @@ -35564,8 +35935,8 @@ Otherwise, this resets the expression.
2313class InputOutputFormat(Expression): -2314 arg_types = {"input_format": False, "output_format": False} + @@ -35675,8 +36046,8 @@ Otherwise, this resets the expression.
2318class Return(Expression): -2319 pass + @@ -35775,8 +36146,8 @@ Otherwise, this resets the expression.
2322class Reference(Expression): -2323 arg_types = {"this": True, "expressions": False, "options": False} + @@ -35886,29 +36257,29 @@ Otherwise, this resets the expression.
2326class Tuple(Expression): -2327 arg_types = {"expressions": False} -2328 -2329 def isin( -2330 self, -2331 *expressions: t.Any, -2332 query: t.Optional[ExpOrStr] = None, -2333 unnest: t.Optional[ExpOrStr] | t.Collection[ExpOrStr] = None, -2334 copy: bool = True, -2335 **opts, -2336 ) -> In: -2337 return In( -2338 this=maybe_copy(self, copy), -2339 expressions=[convert(e, copy=copy) for e in expressions], -2340 query=maybe_parse(query, copy=copy, **opts) if query else None, -2341 unnest=Unnest( -2342 expressions=[ -2343 maybe_parse(t.cast(ExpOrStr, e), copy=copy, **opts) for e in ensure_list(unnest) -2344 ] -2345 ) -2346 if unnest -2347 else None, -2348 ) +@@ -35937,26 +36308,26 @@ Otherwise, this resets the expression.2342class Tuple(Expression): +2343 arg_types = {"expressions": False} +2344 +2345 def isin( +2346 self, +2347 *expressions: t.Any, +2348 query: t.Optional[ExpOrStr] = None, +2349 unnest: t.Optional[ExpOrStr] | t.Collection[ExpOrStr] = None, +2350 copy: bool = True, +2351 **opts, +2352 ) -> In: +2353 return In( +2354 this=maybe_copy(self, copy), +2355 expressions=[convert(e, copy=copy) for e in expressions], +2356 query=maybe_parse(query, copy=copy, **opts) if query else None, +2357 unnest=Unnest( +2358 expressions=[ +2359 maybe_parse(t.cast(ExpOrStr, e), copy=copy, **opts) for e in ensure_list(unnest) +2360 ] +2361 ) +2362 if unnest +2363 else None, +2364 )
2329 def isin( -2330 self, -2331 *expressions: t.Any, -2332 query: t.Optional[ExpOrStr] = None, -2333 unnest: t.Optional[ExpOrStr] | t.Collection[ExpOrStr] = None, -2334 copy: bool = True, -2335 **opts, -2336 ) -> In: -2337 return In( -2338 this=maybe_copy(self, copy), -2339 expressions=[convert(e, copy=copy) for e in expressions], -2340 query=maybe_parse(query, copy=copy, **opts) if query else None, -2341 unnest=Unnest( -2342 expressions=[ -2343 maybe_parse(t.cast(ExpOrStr, e), copy=copy, **opts) for e in ensure_list(unnest) -2344 ] -2345 ) -2346 if unnest -2347 else None, -2348 ) +@@ -36054,94 +36425,94 @@ Otherwise, this resets the expression.2345 def isin( +2346 self, +2347 *expressions: t.Any, +2348 query: t.Optional[ExpOrStr] = None, +2349 unnest: t.Optional[ExpOrStr] | t.Collection[ExpOrStr] = None, +2350 copy: bool = True, +2351 **opts, +2352 ) -> In: +2353 return In( +2354 this=maybe_copy(self, copy), +2355 expressions=[convert(e, copy=copy) for e in expressions], +2356 query=maybe_parse(query, copy=copy, **opts) if query else None, +2357 unnest=Unnest( +2358 expressions=[ +2359 maybe_parse(t.cast(ExpOrStr, e), copy=copy, **opts) for e in ensure_list(unnest) +2360 ] +2361 ) +2362 if unnest +2363 else None, +2364 )
2351class Subqueryable(Unionable): -2352 def subquery(self, alias: t.Optional[ExpOrStr] = None, copy: bool = True) -> Subquery: -2353 """ -2354 Convert this expression to an aliased expression that can be used as a Subquery. -2355 -2356 Example: -2357 >>> subquery = Select().select("x").from_("tbl").subquery() -2358 >>> Select().select("x").from_(subquery).sql() -2359 'SELECT x FROM (SELECT x FROM tbl)' -2360 -2361 Args: -2362 alias (str | Identifier): an optional alias for the subquery -2363 copy (bool): if `False`, modify this expression instance in-place. -2364 -2365 Returns: -2366 Alias: the subquery -2367 """ -2368 instance = maybe_copy(self, copy) -2369 if not isinstance(alias, Expression): -2370 alias = TableAlias(this=to_identifier(alias)) if alias else None +@@ -36158,27 +36529,27 @@ Otherwise, this resets the expression.2367class Subqueryable(Unionable): +2368 def subquery(self, alias: t.Optional[ExpOrStr] = None, copy: bool = True) -> Subquery: +2369 """ +2370 Convert this expression to an aliased expression that can be used as a Subquery. 2371 -2372 return Subquery(this=instance, alias=alias) -2373 -2374 def limit( -2375 self, expression: ExpOrStr | int, dialect: DialectType = None, copy: bool = True, **opts -2376 ) -> Select: -2377 raise NotImplementedError -2378 -2379 @property -2380 def ctes(self): -2381 with_ = self.args.get("with") -2382 if not with_: -2383 return [] -2384 return with_.expressions -2385 -2386 @property -2387 def selects(self) -> t.List[Expression]: -2388 raise NotImplementedError("Subqueryable objects must implement `selects`") +2372 Example: +2373 >>> subquery = Select().select("x").from_("tbl").subquery() +2374 >>> Select().select("x").from_(subquery).sql() +2375 'SELECT x FROM (SELECT x FROM tbl)' +2376 +2377 Args: +2378 alias (str | Identifier): an optional alias for the subquery +2379 copy (bool): if `False`, modify this expression instance in-place. +2380 +2381 Returns: +2382 Alias: the subquery +2383 """ +2384 instance = maybe_copy(self, copy) +2385 if not isinstance(alias, Expression): +2386 alias = TableAlias(this=to_identifier(alias)) if alias else None +2387 +2388 return Subquery(this=instance, alias=alias) 2389 -2390 @property -2391 def named_selects(self) -> t.List[str]: -2392 raise NotImplementedError("Subqueryable objects must implement `named_selects`") -2393 -2394 def select( -2395 self, -2396 *expressions: t.Optional[ExpOrStr], -2397 append: bool = True, -2398 dialect: DialectType = None, -2399 copy: bool = True, -2400 **opts, -2401 ) -> Subqueryable: -2402 raise NotImplementedError("Subqueryable objects must implement `select`") -2403 -2404 def with_( -2405 self, -2406 alias: ExpOrStr, -2407 as_: ExpOrStr, -2408 recursive: t.Optional[bool] = None, -2409 append: bool = True, -2410 dialect: DialectType = None, -2411 copy: bool = True, -2412 **opts, -2413 ) -> Subqueryable: -2414 """ -2415 Append to or set the common table expressions. -2416 -2417 Example: -2418 >>> Select().with_("tbl2", as_="SELECT * FROM tbl").select("x").from_("tbl2").sql() -2419 'WITH tbl2 AS (SELECT * FROM tbl) SELECT x FROM tbl2' -2420 -2421 Args: -2422 alias: the SQL code string to parse as the table name. -2423 If an `Expression` instance is passed, this is used as-is. -2424 as_: the SQL code string to parse as the table expression. -2425 If an `Expression` instance is passed, it will be used as-is. -2426 recursive: set the RECURSIVE part of the expression. Defaults to `False`. -2427 append: if `True`, add to any existing expressions. -2428 Otherwise, this resets the expressions. -2429 dialect: the dialect used to parse the input expression. -2430 copy: if `False`, modify this expression instance in-place. -2431 opts: other options to use to parse the input expressions. +2390 def limit( +2391 self, expression: ExpOrStr | int, dialect: DialectType = None, copy: bool = True, **opts +2392 ) -> Select: +2393 raise NotImplementedError +2394 +2395 @property +2396 def ctes(self): +2397 with_ = self.args.get("with") +2398 if not with_: +2399 return [] +2400 return with_.expressions +2401 +2402 @property +2403 def selects(self) -> t.List[Expression]: +2404 raise NotImplementedError("Subqueryable objects must implement `selects`") +2405 +2406 @property +2407 def named_selects(self) -> t.List[str]: +2408 raise NotImplementedError("Subqueryable objects must implement `named_selects`") +2409 +2410 def select( +2411 self, +2412 *expressions: t.Optional[ExpOrStr], +2413 append: bool = True, +2414 dialect: DialectType = None, +2415 copy: bool = True, +2416 **opts, +2417 ) -> Subqueryable: +2418 raise NotImplementedError("Subqueryable objects must implement `select`") +2419 +2420 def with_( +2421 self, +2422 alias: ExpOrStr, +2423 as_: ExpOrStr, +2424 recursive: t.Optional[bool] = None, +2425 append: bool = True, +2426 dialect: DialectType = None, +2427 copy: bool = True, +2428 **opts, +2429 ) -> Subqueryable: +2430 """ +2431 Append to or set the common table expressions. 2432 -2433 Returns: -2434 The modified expression. -2435 """ -2436 return _apply_cte_builder( -2437 self, alias, as_, recursive=recursive, append=append, dialect=dialect, copy=copy, **opts -2438 ) +2433 Example: +2434 >>> Select().with_("tbl2", as_="SELECT * FROM tbl").select("x").from_("tbl2").sql() +2435 'WITH tbl2 AS (SELECT * FROM tbl) SELECT x FROM tbl2' +2436 +2437 Args: +2438 alias: the SQL code string to parse as the table name. +2439 If an `Expression` instance is passed, this is used as-is. +2440 as_: the SQL code string to parse as the table expression. +2441 If an `Expression` instance is passed, it will be used as-is. +2442 recursive: set the RECURSIVE part of the expression. Defaults to `False`. +2443 append: if `True`, add to any existing expressions. +2444 Otherwise, this resets the expressions. +2445 dialect: the dialect used to parse the input expression. +2446 copy: if `False`, modify this expression instance in-place. +2447 opts: other options to use to parse the input expressions. +2448 +2449 Returns: +2450 The modified expression. +2451 """ +2452 return _apply_cte_builder( +2453 self, alias, as_, recursive=recursive, append=append, dialect=dialect, copy=copy, **opts +2454 )
2352 def subquery(self, alias: t.Optional[ExpOrStr] = None, copy: bool = True) -> Subquery: -2353 """ -2354 Convert this expression to an aliased expression that can be used as a Subquery. -2355 -2356 Example: -2357 >>> subquery = Select().select("x").from_("tbl").subquery() -2358 >>> Select().select("x").from_(subquery).sql() -2359 'SELECT x FROM (SELECT x FROM tbl)' -2360 -2361 Args: -2362 alias (str | Identifier): an optional alias for the subquery -2363 copy (bool): if `False`, modify this expression instance in-place. -2364 -2365 Returns: -2366 Alias: the subquery -2367 """ -2368 instance = maybe_copy(self, copy) -2369 if not isinstance(alias, Expression): -2370 alias = TableAlias(this=to_identifier(alias)) if alias else None +@@ -36222,10 +36593,10 @@ Otherwise, this resets the expression.2368 def subquery(self, alias: t.Optional[ExpOrStr] = None, copy: bool = True) -> Subquery: +2369 """ +2370 Convert this expression to an aliased expression that can be used as a Subquery. 2371 -2372 return Subquery(this=instance, alias=alias) +2372 Example: +2373 >>> subquery = Select().select("x").from_("tbl").subquery() +2374 >>> Select().select("x").from_(subquery).sql() +2375 'SELECT x FROM (SELECT x FROM tbl)' +2376 +2377 Args: +2378 alias (str | Identifier): an optional alias for the subquery +2379 copy (bool): if `False`, modify this expression instance in-place. +2380 +2381 Returns: +2382 Alias: the subquery +2383 """ +2384 instance = maybe_copy(self, copy) +2385 if not isinstance(alias, Expression): +2386 alias = TableAlias(this=to_identifier(alias)) if alias else None +2387 +2388 return Subquery(this=instance, alias=alias)
2374 def limit( -2375 self, expression: ExpOrStr | int, dialect: DialectType = None, copy: bool = True, **opts -2376 ) -> Select: -2377 raise NotImplementedError + @@ -36276,15 +36647,15 @@ Otherwise, this resets the expression.
2394 def select( -2395 self, -2396 *expressions: t.Optional[ExpOrStr], -2397 append: bool = True, -2398 dialect: DialectType = None, -2399 copy: bool = True, -2400 **opts, -2401 ) -> Subqueryable: -2402 raise NotImplementedError("Subqueryable objects must implement `select`") + @@ -36302,41 +36673,41 @@ Otherwise, this resets the expression.
2404 def with_( -2405 self, -2406 alias: ExpOrStr, -2407 as_: ExpOrStr, -2408 recursive: t.Optional[bool] = None, -2409 append: bool = True, -2410 dialect: DialectType = None, -2411 copy: bool = True, -2412 **opts, -2413 ) -> Subqueryable: -2414 """ -2415 Append to or set the common table expressions. -2416 -2417 Example: -2418 >>> Select().with_("tbl2", as_="SELECT * FROM tbl").select("x").from_("tbl2").sql() -2419 'WITH tbl2 AS (SELECT * FROM tbl) SELECT x FROM tbl2' -2420 -2421 Args: -2422 alias: the SQL code string to parse as the table name. -2423 If an `Expression` instance is passed, this is used as-is. -2424 as_: the SQL code string to parse as the table expression. -2425 If an `Expression` instance is passed, it will be used as-is. -2426 recursive: set the RECURSIVE part of the expression. Defaults to `False`. -2427 append: if `True`, add to any existing expressions. -2428 Otherwise, this resets the expressions. -2429 dialect: the dialect used to parse the input expression. -2430 copy: if `False`, modify this expression instance in-place. -2431 opts: other options to use to parse the input expressions. +@@ -36488,8 +36859,8 @@ Otherwise, this resets the expressions.2420 def with_( +2421 self, +2422 alias: ExpOrStr, +2423 as_: ExpOrStr, +2424 recursive: t.Optional[bool] = None, +2425 append: bool = True, +2426 dialect: DialectType = None, +2427 copy: bool = True, +2428 **opts, +2429 ) -> Subqueryable: +2430 """ +2431 Append to or set the common table expressions. 2432 -2433 Returns: -2434 The modified expression. -2435 """ -2436 return _apply_cte_builder( -2437 self, alias, as_, recursive=recursive, append=append, dialect=dialect, copy=copy, **opts -2438 ) +2433 Example: +2434 >>> Select().with_("tbl2", as_="SELECT * FROM tbl").select("x").from_("tbl2").sql() +2435 'WITH tbl2 AS (SELECT * FROM tbl) SELECT x FROM tbl2' +2436 +2437 Args: +2438 alias: the SQL code string to parse as the table name. +2439 If an `Expression` instance is passed, this is used as-is. +2440 as_: the SQL code string to parse as the table expression. +2441 If an `Expression` instance is passed, it will be used as-is. +2442 recursive: set the RECURSIVE part of the expression. Defaults to `False`. +2443 append: if `True`, add to any existing expressions. +2444 Otherwise, this resets the expressions. +2445 dialect: the dialect used to parse the input expression. +2446 copy: if `False`, modify this expression instance in-place. +2447 opts: other options to use to parse the input expressions. +2448 +2449 Returns: +2450 The modified expression. +2451 """ +2452 return _apply_cte_builder( +2453 self, alias, as_, recursive=recursive, append=append, dialect=dialect, copy=copy, **opts +2454 )
2466class WithTableHint(Expression): -2467 arg_types = {"expressions": True} + @@ -36599,8 +36970,8 @@ Otherwise, this resets the expressions.
2471class IndexTableHint(Expression): -2472 arg_types = {"this": True, "expressions": False, "target": False} + @@ -36710,59 +37081,60 @@ Otherwise, this resets the expressions.
2475class Table(Expression): -2476 arg_types = { -2477 "this": True, -2478 "alias": False, -2479 "db": False, -2480 "catalog": False, -2481 "laterals": False, -2482 "joins": False, -2483 "pivots": False, -2484 "hints": False, -2485 "system_time": False, -2486 "version": False, -2487 "format": False, -2488 "pattern": False, -2489 "index": False, -2490 } -2491 -2492 @property -2493 def name(self) -> str: -2494 if isinstance(self.this, Func): -2495 return "" -2496 return self.this.name -2497 -2498 @property -2499 def db(self) -> str: -2500 return self.text("db") -2501 -2502 @property -2503 def catalog(self) -> str: -2504 return self.text("catalog") -2505 -2506 @property -2507 def selects(self) -> t.List[Expression]: -2508 return [] -2509 -2510 @property -2511 def named_selects(self) -> t.List[str]: -2512 return [] -2513 -2514 @property -2515 def parts(self) -> t.List[Expression]: -2516 """Return the parts of a table in order catalog, db, table.""" -2517 parts: t.List[Expression] = [] +@@ -36772,7 +37144,7 @@ Otherwise, this resets the expressions.2491class Table(Expression): +2492 arg_types = { +2493 "this": True, +2494 "alias": False, +2495 "db": False, +2496 "catalog": False, +2497 "laterals": False, +2498 "joins": False, +2499 "pivots": False, +2500 "hints": False, +2501 "system_time": False, +2502 "version": False, +2503 "format": False, +2504 "pattern": False, +2505 "index": False, +2506 "ordinality": False, +2507 } +2508 +2509 @property +2510 def name(self) -> str: +2511 if isinstance(self.this, Func): +2512 return "" +2513 return self.this.name +2514 +2515 @property +2516 def db(self) -> str: +2517 return self.text("db") 2518 -2519 for arg in ("catalog", "db", "this"): -2520 part = self.args.get(arg) -2521 -2522 if isinstance(part, Dot): -2523 parts.extend(part.flatten()) -2524 elif isinstance(part, Expression): -2525 parts.append(part) +2519 @property +2520 def catalog(self) -> str: +2521 return self.text("catalog") +2522 +2523 @property +2524 def selects(self) -> t.List[Expression]: +2525 return [] 2526 -2527 return parts +2527 @property +2528 def named_selects(self) -> t.List[str]: +2529 return [] +2530 +2531 @property +2532 def parts(self) -> t.List[Expression]: +2533 """Return the parts of a table in order catalog, db, table.""" +2534 parts: t.List[Expression] = [] +2535 +2536 for arg in ("catalog", "db", "this"): +2537 part = self.args.get(arg) +2538 +2539 if isinstance(part, Dot): +2540 parts.extend(part.flatten()) +2541 elif isinstance(part, Expression): +2542 parts.append(part) +2543 +2544 return partsarg_types = - {'this': True, 'alias': False, 'db': False, 'catalog': False, 'laterals': False, 'joins': False, 'pivots': False, 'hints': False, 'system_time': False, 'version': False, 'format': False, 'pattern': False, 'index': False} + {'this': True, 'alias': False, 'db': False, 'catalog': False, 'laterals': False, 'joins': False, 'pivots': False, 'hints': False, 'system_time': False, 'version': False, 'format': False, 'pattern': False, 'index': False, 'ordinality': False}@@ -36940,97 +37312,97 @@ Otherwise, this resets the expressions.
2530class Union(Subqueryable): -2531 arg_types = { -2532 "with": False, -2533 "this": True, -2534 "expression": True, -2535 "distinct": False, -2536 "by_name": False, -2537 **QUERY_MODIFIERS, -2538 } -2539 -2540 def limit( -2541 self, expression: ExpOrStr | int, dialect: DialectType = None, copy: bool = True, **opts -2542 ) -> Select: -2543 """ -2544 Set the LIMIT expression. -2545 -2546 Example: -2547 >>> select("1").union(select("1")).limit(1).sql() -2548 'SELECT * FROM (SELECT 1 UNION SELECT 1) AS _l_0 LIMIT 1' -2549 -2550 Args: -2551 expression: the SQL code string to parse. -2552 This can also be an integer. -2553 If a `Limit` instance is passed, this is used as-is. -2554 If another `Expression` instance is passed, it will be wrapped in a `Limit`. -2555 dialect: the dialect used to parse the input expression. -2556 copy: if `False`, modify this expression instance in-place. -2557 opts: other options to use to parse the input expressions. -2558 -2559 Returns: -2560 The limited subqueryable. -2561 """ -2562 return ( -2563 select("*") -2564 .from_(self.subquery(alias="_l_0", copy=copy)) -2565 .limit(expression, dialect=dialect, copy=False, **opts) -2566 ) -2567 -2568 def select( -2569 self, -2570 *expressions: t.Optional[ExpOrStr], -2571 append: bool = True, -2572 dialect: DialectType = None, -2573 copy: bool = True, -2574 **opts, -2575 ) -> Union: -2576 """Append to or set the SELECT of the union recursively. -2577 -2578 Example: -2579 >>> from sqlglot import parse_one -2580 >>> parse_one("select a from x union select a from y union select a from z").select("b").sql() -2581 'SELECT a, b FROM x UNION SELECT a, b FROM y UNION SELECT a, b FROM z' -2582 -2583 Args: -2584 *expressions: the SQL code strings to parse. -2585 If an `Expression` instance is passed, it will be used as-is. -2586 append: if `True`, add to any existing expressions. -2587 Otherwise, this resets the expressions. -2588 dialect: the dialect used to parse the input expressions. -2589 copy: if `False`, modify this expression instance in-place. -2590 opts: other options to use to parse the input expressions. -2591 -2592 Returns: -2593 Union: the modified expression. -2594 """ -2595 this = self.copy() if copy else self -2596 this.this.unnest().select(*expressions, append=append, dialect=dialect, copy=False, **opts) -2597 this.expression.unnest().select( -2598 *expressions, append=append, dialect=dialect, copy=False, **opts -2599 ) -2600 return this -2601 -2602 @property -2603 def named_selects(self) -> t.List[str]: -2604 return self.this.unnest().named_selects -2605 -2606 @property -2607 def is_star(self) -> bool: -2608 return self.this.is_star or self.expression.is_star -2609 -2610 @property -2611 def selects(self) -> t.List[Expression]: -2612 return self.this.unnest().selects -2613 -2614 @property -2615 def left(self) -> Expression: -2616 return self.this -2617 -2618 @property -2619 def right(self) -> Expression: -2620 return self.expression +@@ -37060,33 +37432,33 @@ Otherwise, this resets the expressions.2547class Union(Subqueryable): +2548 arg_types = { +2549 "with": False, +2550 "this": True, +2551 "expression": True, +2552 "distinct": False, +2553 "by_name": False, +2554 **QUERY_MODIFIERS, +2555 } +2556 +2557 def limit( +2558 self, expression: ExpOrStr | int, dialect: DialectType = None, copy: bool = True, **opts +2559 ) -> Select: +2560 """ +2561 Set the LIMIT expression. +2562 +2563 Example: +2564 >>> select("1").union(select("1")).limit(1).sql() +2565 'SELECT * FROM (SELECT 1 UNION SELECT 1) AS _l_0 LIMIT 1' +2566 +2567 Args: +2568 expression: the SQL code string to parse. +2569 This can also be an integer. +2570 If a `Limit` instance is passed, this is used as-is. +2571 If another `Expression` instance is passed, it will be wrapped in a `Limit`. +2572 dialect: the dialect used to parse the input expression. +2573 copy: if `False`, modify this expression instance in-place. +2574 opts: other options to use to parse the input expressions. +2575 +2576 Returns: +2577 The limited subqueryable. +2578 """ +2579 return ( +2580 select("*") +2581 .from_(self.subquery(alias="_l_0", copy=copy)) +2582 .limit(expression, dialect=dialect, copy=False, **opts) +2583 ) +2584 +2585 def select( +2586 self, +2587 *expressions: t.Optional[ExpOrStr], +2588 append: bool = True, +2589 dialect: DialectType = None, +2590 copy: bool = True, +2591 **opts, +2592 ) -> Union: +2593 """Append to or set the SELECT of the union recursively. +2594 +2595 Example: +2596 >>> from sqlglot import parse_one +2597 >>> parse_one("select a from x union select a from y union select a from z").select("b").sql() +2598 'SELECT a, b FROM x UNION SELECT a, b FROM y UNION SELECT a, b FROM z' +2599 +2600 Args: +2601 *expressions: the SQL code strings to parse. +2602 If an `Expression` instance is passed, it will be used as-is. +2603 append: if `True`, add to any existing expressions. +2604 Otherwise, this resets the expressions. +2605 dialect: the dialect used to parse the input expressions. +2606 copy: if `False`, modify this expression instance in-place. +2607 opts: other options to use to parse the input expressions. +2608 +2609 Returns: +2610 Union: the modified expression. +2611 """ +2612 this = self.copy() if copy else self +2613 this.this.unnest().select(*expressions, append=append, dialect=dialect, copy=False, **opts) +2614 this.expression.unnest().select( +2615 *expressions, append=append, dialect=dialect, copy=False, **opts +2616 ) +2617 return this +2618 +2619 @property +2620 def named_selects(self) -> t.List[str]: +2621 return self.this.unnest().named_selects +2622 +2623 @property +2624 def is_star(self) -> bool: +2625 return self.this.is_star or self.expression.is_star +2626 +2627 @property +2628 def selects(self) -> t.List[Expression]: +2629 return self.this.unnest().selects +2630 +2631 @property +2632 def left(self) -> Expression: +2633 return self.this +2634 +2635 @property +2636 def right(self) -> Expression: +2637 return self.expression
2540 def limit( -2541 self, expression: ExpOrStr | int, dialect: DialectType = None, copy: bool = True, **opts -2542 ) -> Select: -2543 """ -2544 Set the LIMIT expression. -2545 -2546 Example: -2547 >>> select("1").union(select("1")).limit(1).sql() -2548 'SELECT * FROM (SELECT 1 UNION SELECT 1) AS _l_0 LIMIT 1' -2549 -2550 Args: -2551 expression: the SQL code string to parse. -2552 This can also be an integer. -2553 If a `Limit` instance is passed, this is used as-is. -2554 If another `Expression` instance is passed, it will be wrapped in a `Limit`. -2555 dialect: the dialect used to parse the input expression. -2556 copy: if `False`, modify this expression instance in-place. -2557 opts: other options to use to parse the input expressions. -2558 -2559 Returns: -2560 The limited subqueryable. -2561 """ -2562 return ( -2563 select("*") -2564 .from_(self.subquery(alias="_l_0", copy=copy)) -2565 .limit(expression, dialect=dialect, copy=False, **opts) -2566 ) +@@ -37134,39 +37506,39 @@ If another2557 def limit( +2558 self, expression: ExpOrStr | int, dialect: DialectType = None, copy: bool = True, **opts +2559 ) -> Select: +2560 """ +2561 Set the LIMIT expression. +2562 +2563 Example: +2564 >>> select("1").union(select("1")).limit(1).sql() +2565 'SELECT * FROM (SELECT 1 UNION SELECT 1) AS _l_0 LIMIT 1' +2566 +2567 Args: +2568 expression: the SQL code string to parse. +2569 This can also be an integer. +2570 If a `Limit` instance is passed, this is used as-is. +2571 If another `Expression` instance is passed, it will be wrapped in a `Limit`. +2572 dialect: the dialect used to parse the input expression. +2573 copy: if `False`, modify this expression instance in-place. +2574 opts: other options to use to parse the input expressions. +2575 +2576 Returns: +2577 The limited subqueryable. +2578 """ +2579 return ( +2580 select("*") +2581 .from_(self.subquery(alias="_l_0", copy=copy)) +2582 .limit(expression, dialect=dialect, copy=False, **opts) +2583 )Expression
instance is passed,
2568 def select( -2569 self, -2570 *expressions: t.Optional[ExpOrStr], -2571 append: bool = True, -2572 dialect: DialectType = None, -2573 copy: bool = True, -2574 **opts, -2575 ) -> Union: -2576 """Append to or set the SELECT of the union recursively. -2577 -2578 Example: -2579 >>> from sqlglot import parse_one -2580 >>> parse_one("select a from x union select a from y union select a from z").select("b").sql() -2581 'SELECT a, b FROM x UNION SELECT a, b FROM y UNION SELECT a, b FROM z' -2582 -2583 Args: -2584 *expressions: the SQL code strings to parse. -2585 If an `Expression` instance is passed, it will be used as-is. -2586 append: if `True`, add to any existing expressions. -2587 Otherwise, this resets the expressions. -2588 dialect: the dialect used to parse the input expressions. -2589 copy: if `False`, modify this expression instance in-place. -2590 opts: other options to use to parse the input expressions. -2591 -2592 Returns: -2593 Union: the modified expression. -2594 """ -2595 this = self.copy() if copy else self -2596 this.this.unnest().select(*expressions, append=append, dialect=dialect, copy=False, **opts) -2597 this.expression.unnest().select( -2598 *expressions, append=append, dialect=dialect, copy=False, **opts -2599 ) -2600 return this +@@ -37364,8 +37736,8 @@ Otherwise, this resets the expressions.2585 def select( +2586 self, +2587 *expressions: t.Optional[ExpOrStr], +2588 append: bool = True, +2589 dialect: DialectType = None, +2590 copy: bool = True, +2591 **opts, +2592 ) -> Union: +2593 """Append to or set the SELECT of the union recursively. +2594 +2595 Example: +2596 >>> from sqlglot import parse_one +2597 >>> parse_one("select a from x union select a from y union select a from z").select("b").sql() +2598 'SELECT a, b FROM x UNION SELECT a, b FROM y UNION SELECT a, b FROM z' +2599 +2600 Args: +2601 *expressions: the SQL code strings to parse. +2602 If an `Expression` instance is passed, it will be used as-is. +2603 append: if `True`, add to any existing expressions. +2604 Otherwise, this resets the expressions. +2605 dialect: the dialect used to parse the input expressions. +2606 copy: if `False`, modify this expression instance in-place. +2607 opts: other options to use to parse the input expressions. +2608 +2609 Returns: +2610 Union: the modified expression. +2611 """ +2612 this = self.copy() if copy else self +2613 this.this.unnest().select(*expressions, append=append, dialect=dialect, copy=False, **opts) +2614 this.expression.unnest().select( +2615 *expressions, append=append, dialect=dialect, copy=False, **opts +2616 ) +2617 return this
2623class Except(Union): -2624 pass + @@ -37485,8 +37857,8 @@ Otherwise, this resets the expressions.
2627class Intersect(Union): -2628 pass + @@ -37606,12 +37978,12 @@ Otherwise, this resets the expressions.
2631class Unnest(UDTF): -2632 arg_types = { -2633 "expressions": True, -2634 "alias": False, -2635 "offset": False, -2636 } + @@ -37735,17 +38107,17 @@ Otherwise, this resets the expressions.
2639class Update(Expression): -2640 arg_types = { -2641 "with": False, -2642 "this": False, -2643 "expressions": True, -2644 "from": False, -2645 "where": False, -2646 "returning": False, -2647 "order": False, -2648 "limit": False, -2649 } + @@ -37856,12 +38228,8 @@ Otherwise, this resets the expressions.
2652class Values(UDTF): -2653 arg_types = { -2654 "expressions": True, -2655 "ordinality": False, -2656 "alias": False, -2657 } + @@ -37870,7 +38238,7 @@ Otherwise, this resets the expressions.-arg_types = -{'expressions': True, 'ordinality': False, 'alias': False} +{'expressions': True, 'alias': False}@@ -37985,8 +38353,8 @@ Otherwise, this resets the expressions.-2660class Var(Expression): -2661 pass + @@ -38085,18 +38453,18 @@ Otherwise, this resets the expressions.-2664class Version(Expression): -2665 """ -2666 Time travel, iceberg, bigquery etc -2667 https://trino.io/docs/current/connector/iceberg.html?highlight=snapshot#using-snapshots -2668 https://www.databricks.com/blog/2019/02/04/introducing-delta-time-travel-for-large-scale-data-lakes.html -2669 https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#for_system_time_as_of -2670 https://learn.microsoft.com/en-us/sql/relational-databases/tables/querying-data-in-a-system-versioned-temporal-table?view=sql-server-ver16 -2671 this is either TIMESTAMP or VERSION -2672 kind is ("AS OF", "BETWEEN") -2673 """ -2674 -2675 arg_types = {"this": True, "kind": True, "expression": False} +@@ -38214,8 +38582,8 @@ kind is ("AS OF", "BETWEEN")2677class Version(Expression): +2678 """ +2679 Time travel, iceberg, bigquery etc +2680 https://trino.io/docs/current/connector/iceberg.html?highlight=snapshot#using-snapshots +2681 https://www.databricks.com/blog/2019/02/04/introducing-delta-time-travel-for-large-scale-data-lakes.html +2682 https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#for_system_time_as_of +2683 https://learn.microsoft.com/en-us/sql/relational-databases/tables/querying-data-in-a-system-versioned-temporal-table?view=sql-server-ver16 +2684 this is either TIMESTAMP or VERSION +2685 kind is ("AS OF", "BETWEEN") +2686 """ +2687 +2688 arg_types = {"this": True, "kind": True, "expression": False}-2678class Schema(Expression): -2679 arg_types = {"this": False, "expressions": False} + @@ -38325,8 +38693,8 @@ kind is ("AS OF", "BETWEEN")-2684class Lock(Expression): -2685 arg_types = {"update": True, "expressions": False, "wait": False} + @@ -38436,697 +38804,697 @@ kind is ("AS OF", "BETWEEN")-2688class Select(Subqueryable): -2689 arg_types = { -2690 "with": False, -2691 "kind": False, -2692 "expressions": False, -2693 "hint": False, -2694 "distinct": False, -2695 "into": False, -2696 "from": False, -2697 **QUERY_MODIFIERS, -2698 } -2699 -2700 def from_( -2701 self, expression: ExpOrStr, dialect: DialectType = None, copy: bool = True, **opts -2702 ) -> Select: -2703 """ -2704 Set the FROM expression. -2705 -2706 Example: -2707 >>> Select().from_("tbl").select("x").sql() -2708 'SELECT x FROM tbl' -2709 -2710 Args: -2711 expression : the SQL code strings to parse. -2712 If a `From` instance is passed, this is used as-is. -2713 If another `Expression` instance is passed, it will be wrapped in a `From`. -2714 dialect: the dialect used to parse the input expression. -2715 copy: if `False`, modify this expression instance in-place. -2716 opts: other options to use to parse the input expressions. -2717 -2718 Returns: -2719 The modified Select expression. -2720 """ -2721 return _apply_builder( -2722 expression=expression, -2723 instance=self, -2724 arg="from", -2725 into=From, -2726 prefix="FROM", -2727 dialect=dialect, -2728 copy=copy, -2729 **opts, -2730 ) -2731 -2732 def group_by( -2733 self, -2734 *expressions: t.Optional[ExpOrStr], -2735 append: bool = True, -2736 dialect: DialectType = None, -2737 copy: bool = True, -2738 **opts, -2739 ) -> Select: -2740 """ -2741 Set the GROUP BY expression. -2742 -2743 Example: -2744 >>> Select().from_("tbl").select("x", "COUNT(1)").group_by("x").sql() -2745 'SELECT x, COUNT(1) FROM tbl GROUP BY x' -2746 -2747 Args: -2748 *expressions: the SQL code strings to parse. -2749 If a `Group` instance is passed, this is used as-is. -2750 If another `Expression` instance is passed, it will be wrapped in a `Group`. -2751 If nothing is passed in then a group by is not applied to the expression -2752 append: if `True`, add to any existing expressions. -2753 Otherwise, this flattens all the `Group` expression into a single expression. -2754 dialect: the dialect used to parse the input expression. -2755 copy: if `False`, modify this expression instance in-place. -2756 opts: other options to use to parse the input expressions. -2757 -2758 Returns: -2759 The modified Select expression. -2760 """ -2761 if not expressions: -2762 return self if not copy else self.copy() -2763 -2764 return _apply_child_list_builder( -2765 *expressions, -2766 instance=self, -2767 arg="group", -2768 append=append, -2769 copy=copy, -2770 prefix="GROUP BY", -2771 into=Group, -2772 dialect=dialect, -2773 **opts, -2774 ) -2775 -2776 def order_by( -2777 self, -2778 *expressions: t.Optional[ExpOrStr], -2779 append: bool = True, -2780 dialect: DialectType = None, -2781 copy: bool = True, -2782 **opts, -2783 ) -> Select: -2784 """ -2785 Set the ORDER BY expression. -2786 -2787 Example: -2788 >>> Select().from_("tbl").select("x").order_by("x DESC").sql() -2789 'SELECT x FROM tbl ORDER BY x DESC' -2790 -2791 Args: -2792 *expressions: the SQL code strings to parse. -2793 If a `Group` instance is passed, this is used as-is. -2794 If another `Expression` instance is passed, it will be wrapped in a `Order`. -2795 append: if `True`, add to any existing expressions. -2796 Otherwise, this flattens all the `Order` expression into a single expression. -2797 dialect: the dialect used to parse the input expression. -2798 copy: if `False`, modify this expression instance in-place. -2799 opts: other options to use to parse the input expressions. -2800 -2801 Returns: -2802 The modified Select expression. -2803 """ -2804 return _apply_child_list_builder( -2805 *expressions, -2806 instance=self, -2807 arg="order", -2808 append=append, -2809 copy=copy, -2810 prefix="ORDER BY", -2811 into=Order, -2812 dialect=dialect, -2813 **opts, -2814 ) -2815 -2816 def sort_by( -2817 self, -2818 *expressions: t.Optional[ExpOrStr], -2819 append: bool = True, -2820 dialect: DialectType = None, -2821 copy: bool = True, -2822 **opts, -2823 ) -> Select: -2824 """ -2825 Set the SORT BY expression. -2826 -2827 Example: -2828 >>> Select().from_("tbl").select("x").sort_by("x DESC").sql(dialect="hive") -2829 'SELECT x FROM tbl SORT BY x DESC' -2830 -2831 Args: -2832 *expressions: the SQL code strings to parse. -2833 If a `Group` instance is passed, this is used as-is. -2834 If another `Expression` instance is passed, it will be wrapped in a `SORT`. -2835 append: if `True`, add to any existing expressions. -2836 Otherwise, this flattens all the `Order` expression into a single expression. -2837 dialect: the dialect used to parse the input expression. -2838 copy: if `False`, modify this expression instance in-place. -2839 opts: other options to use to parse the input expressions. -2840 -2841 Returns: -2842 The modified Select expression. -2843 """ -2844 return _apply_child_list_builder( -2845 *expressions, -2846 instance=self, -2847 arg="sort", -2848 append=append, -2849 copy=copy, -2850 prefix="SORT BY", -2851 into=Sort, -2852 dialect=dialect, -2853 **opts, -2854 ) -2855 -2856 def cluster_by( -2857 self, -2858 *expressions: t.Optional[ExpOrStr], -2859 append: bool = True, -2860 dialect: DialectType = None, -2861 copy: bool = True, -2862 **opts, -2863 ) -> Select: -2864 """ -2865 Set the CLUSTER BY expression. -2866 -2867 Example: -2868 >>> Select().from_("tbl").select("x").cluster_by("x DESC").sql(dialect="hive") -2869 'SELECT x FROM tbl CLUSTER BY x DESC' -2870 -2871 Args: -2872 *expressions: the SQL code strings to parse. -2873 If a `Group` instance is passed, this is used as-is. -2874 If another `Expression` instance is passed, it will be wrapped in a `Cluster`. -2875 append: if `True`, add to any existing expressions. -2876 Otherwise, this flattens all the `Order` expression into a single expression. -2877 dialect: the dialect used to parse the input expression. -2878 copy: if `False`, modify this expression instance in-place. -2879 opts: other options to use to parse the input expressions. -2880 -2881 Returns: -2882 The modified Select expression. -2883 """ -2884 return _apply_child_list_builder( -2885 *expressions, -2886 instance=self, -2887 arg="cluster", -2888 append=append, -2889 copy=copy, -2890 prefix="CLUSTER BY", -2891 into=Cluster, -2892 dialect=dialect, -2893 **opts, -2894 ) -2895 -2896 def limit( -2897 self, expression: ExpOrStr | int, dialect: DialectType = None, copy: bool = True, **opts -2898 ) -> Select: -2899 """ -2900 Set the LIMIT expression. -2901 -2902 Example: -2903 >>> Select().from_("tbl").select("x").limit(10).sql() -2904 'SELECT x FROM tbl LIMIT 10' -2905 -2906 Args: -2907 expression: the SQL code string to parse. -2908 This can also be an integer. -2909 If a `Limit` instance is passed, this is used as-is. -2910 If another `Expression` instance is passed, it will be wrapped in a `Limit`. -2911 dialect: the dialect used to parse the input expression. -2912 copy: if `False`, modify this expression instance in-place. -2913 opts: other options to use to parse the input expressions. +@@ -39156,37 +39524,37 @@ kind is ("AS OF", "BETWEEN")2701class Select(Subqueryable): +2702 arg_types = { +2703 "with": False, +2704 "kind": False, +2705 "expressions": False, +2706 "hint": False, +2707 "distinct": False, +2708 "into": False, +2709 "from": False, +2710 **QUERY_MODIFIERS, +2711 } +2712 +2713 def from_( +2714 self, expression: ExpOrStr, dialect: DialectType = None, copy: bool = True, **opts +2715 ) -> Select: +2716 """ +2717 Set the FROM expression. +2718 +2719 Example: +2720 >>> Select().from_("tbl").select("x").sql() +2721 'SELECT x FROM tbl' +2722 +2723 Args: +2724 expression : the SQL code strings to parse. +2725 If a `From` instance is passed, this is used as-is. +2726 If another `Expression` instance is passed, it will be wrapped in a `From`. +2727 dialect: the dialect used to parse the input expression. +2728 copy: if `False`, modify this expression instance in-place. +2729 opts: other options to use to parse the input expressions. +2730 +2731 Returns: +2732 The modified Select expression. +2733 """ +2734 return _apply_builder( +2735 expression=expression, +2736 instance=self, +2737 arg="from", +2738 into=From, +2739 prefix="FROM", +2740 dialect=dialect, +2741 copy=copy, +2742 **opts, +2743 ) +2744 +2745 def group_by( +2746 self, +2747 *expressions: t.Optional[ExpOrStr], +2748 append: bool = True, +2749 dialect: DialectType = None, +2750 copy: bool = True, +2751 **opts, +2752 ) -> Select: +2753 """ +2754 Set the GROUP BY expression. +2755 +2756 Example: +2757 >>> Select().from_("tbl").select("x", "COUNT(1)").group_by("x").sql() +2758 'SELECT x, COUNT(1) FROM tbl GROUP BY x' +2759 +2760 Args: +2761 *expressions: the SQL code strings to parse. +2762 If a `Group` instance is passed, this is used as-is. +2763 If another `Expression` instance is passed, it will be wrapped in a `Group`. +2764 If nothing is passed in then a group by is not applied to the expression +2765 append: if `True`, add to any existing expressions. +2766 Otherwise, this flattens all the `Group` expression into a single expression. +2767 dialect: the dialect used to parse the input expression. +2768 copy: if `False`, modify this expression instance in-place. +2769 opts: other options to use to parse the input expressions. +2770 +2771 Returns: +2772 The modified Select expression. +2773 """ +2774 if not expressions: +2775 return self if not copy else self.copy() +2776 +2777 return _apply_child_list_builder( +2778 *expressions, +2779 instance=self, +2780 arg="group", +2781 append=append, +2782 copy=copy, +2783 prefix="GROUP BY", +2784 into=Group, +2785 dialect=dialect, +2786 **opts, +2787 ) +2788 +2789 def order_by( +2790 self, +2791 *expressions: t.Optional[ExpOrStr], +2792 append: bool = True, +2793 dialect: DialectType = None, +2794 copy: bool = True, +2795 **opts, +2796 ) -> Select: +2797 """ +2798 Set the ORDER BY expression. +2799 +2800 Example: +2801 >>> Select().from_("tbl").select("x").order_by("x DESC").sql() +2802 'SELECT x FROM tbl ORDER BY x DESC' +2803 +2804 Args: +2805 *expressions: the SQL code strings to parse. +2806 If a `Group` instance is passed, this is used as-is. +2807 If another `Expression` instance is passed, it will be wrapped in a `Order`. +2808 append: if `True`, add to any existing expressions. +2809 Otherwise, this flattens all the `Order` expression into a single expression. +2810 dialect: the dialect used to parse the input expression. +2811 copy: if `False`, modify this expression instance in-place. +2812 opts: other options to use to parse the input expressions. +2813 +2814 Returns: +2815 The modified Select expression. +2816 """ +2817 return _apply_child_list_builder( +2818 *expressions, +2819 instance=self, +2820 arg="order", +2821 append=append, +2822 copy=copy, +2823 prefix="ORDER BY", +2824 into=Order, +2825 dialect=dialect, +2826 **opts, +2827 ) +2828 +2829 def sort_by( +2830 self, +2831 *expressions: t.Optional[ExpOrStr], +2832 append: bool = True, +2833 dialect: DialectType = None, +2834 copy: bool = True, +2835 **opts, +2836 ) -> Select: +2837 """ +2838 Set the SORT BY expression. +2839 +2840 Example: +2841 >>> Select().from_("tbl").select("x").sort_by("x DESC").sql(dialect="hive") +2842 'SELECT x FROM tbl SORT BY x DESC' +2843 +2844 Args: +2845 *expressions: the SQL code strings to parse. +2846 If a `Group` instance is passed, this is used as-is. +2847 If another `Expression` instance is passed, it will be wrapped in a `SORT`. +2848 append: if `True`, add to any existing expressions. +2849 Otherwise, this flattens all the `Order` expression into a single expression. +2850 dialect: the dialect used to parse the input expression. +2851 copy: if `False`, modify this expression instance in-place. +2852 opts: other options to use to parse the input expressions. +2853 +2854 Returns: +2855 The modified Select expression. +2856 """ +2857 return _apply_child_list_builder( +2858 *expressions, +2859 instance=self, +2860 arg="sort", +2861 append=append, +2862 copy=copy, +2863 prefix="SORT BY", +2864 into=Sort, +2865 dialect=dialect, +2866 **opts, +2867 ) +2868 +2869 def cluster_by( +2870 self, +2871 *expressions: t.Optional[ExpOrStr], +2872 append: bool = True, +2873 dialect: DialectType = None, +2874 copy: bool = True, +2875 **opts, +2876 ) -> Select: +2877 """ +2878 Set the CLUSTER BY expression. +2879 +2880 Example: +2881 >>> Select().from_("tbl").select("x").cluster_by("x DESC").sql(dialect="hive") +2882 'SELECT x FROM tbl CLUSTER BY x DESC' +2883 +2884 Args: +2885 *expressions: the SQL code strings to parse. +2886 If a `Group` instance is passed, this is used as-is. +2887 If another `Expression` instance is passed, it will be wrapped in a `Cluster`. +2888 append: if `True`, add to any existing expressions. +2889 Otherwise, this flattens all the `Order` expression into a single expression. +2890 dialect: the dialect used to parse the input expression. +2891 copy: if `False`, modify this expression instance in-place. +2892 opts: other options to use to parse the input expressions. +2893 +2894 Returns: +2895 The modified Select expression. +2896 """ +2897 return _apply_child_list_builder( +2898 *expressions, +2899 instance=self, +2900 arg="cluster", +2901 append=append, +2902 copy=copy, +2903 prefix="CLUSTER BY", +2904 into=Cluster, +2905 dialect=dialect, +2906 **opts, +2907 ) +2908 +2909 def limit( +2910 self, expression: ExpOrStr | int, dialect: DialectType = None, copy: bool = True, **opts +2911 ) -> Select: +2912 """ +2913 Set the LIMIT expression. 2914 -2915 Returns: -2916 Select: the modified expression. -2917 """ -2918 return _apply_builder( -2919 expression=expression, -2920 instance=self, -2921 arg="limit", -2922 into=Limit, -2923 prefix="LIMIT", -2924 dialect=dialect, -2925 copy=copy, -2926 into_arg="expression", -2927 **opts, -2928 ) -2929 -2930 def offset( -2931 self, expression: ExpOrStr | int, dialect: DialectType = None, copy: bool = True, **opts -2932 ) -> Select: -2933 """ -2934 Set the OFFSET expression. -2935 -2936 Example: -2937 >>> Select().from_("tbl").select("x").offset(10).sql() -2938 'SELECT x FROM tbl OFFSET 10' -2939 -2940 Args: -2941 expression: the SQL code string to parse. -2942 This can also be an integer. -2943 If a `Offset` instance is passed, this is used as-is. -2944 If another `Expression` instance is passed, it will be wrapped in a `Offset`. -2945 dialect: the dialect used to parse the input expression. -2946 copy: if `False`, modify this expression instance in-place. -2947 opts: other options to use to parse the input expressions. +2915 Example: +2916 >>> Select().from_("tbl").select("x").limit(10).sql() +2917 'SELECT x FROM tbl LIMIT 10' +2918 +2919 Args: +2920 expression: the SQL code string to parse. +2921 This can also be an integer. +2922 If a `Limit` instance is passed, this is used as-is. +2923 If another `Expression` instance is passed, it will be wrapped in a `Limit`. +2924 dialect: the dialect used to parse the input expression. +2925 copy: if `False`, modify this expression instance in-place. +2926 opts: other options to use to parse the input expressions. +2927 +2928 Returns: +2929 Select: the modified expression. +2930 """ +2931 return _apply_builder( +2932 expression=expression, +2933 instance=self, +2934 arg="limit", +2935 into=Limit, +2936 prefix="LIMIT", +2937 dialect=dialect, +2938 copy=copy, +2939 into_arg="expression", +2940 **opts, +2941 ) +2942 +2943 def offset( +2944 self, expression: ExpOrStr | int, dialect: DialectType = None, copy: bool = True, **opts +2945 ) -> Select: +2946 """ +2947 Set the OFFSET expression. 2948 -2949 Returns: -2950 The modified Select expression. -2951 """ -2952 return _apply_builder( -2953 expression=expression, -2954 instance=self, -2955 arg="offset", -2956 into=Offset, -2957 prefix="OFFSET", -2958 dialect=dialect, -2959 copy=copy, -2960 into_arg="expression", -2961 **opts, -2962 ) -2963 -2964 def select( -2965 self, -2966 *expressions: t.Optional[ExpOrStr], -2967 append: bool = True, -2968 dialect: DialectType = None, -2969 copy: bool = True, -2970 **opts, -2971 ) -> Select: -2972 """ -2973 Append to or set the SELECT expressions. -2974 -2975 Example: -2976 >>> Select().select("x", "y").sql() -2977 'SELECT x, y' -2978 -2979 Args: -2980 *expressions: the SQL code strings to parse. -2981 If an `Expression` instance is passed, it will be used as-is. -2982 append: if `True`, add to any existing expressions. -2983 Otherwise, this resets the expressions. -2984 dialect: the dialect used to parse the input expressions. -2985 copy: if `False`, modify this expression instance in-place. -2986 opts: other options to use to parse the input expressions. +2949 Example: +2950 >>> Select().from_("tbl").select("x").offset(10).sql() +2951 'SELECT x FROM tbl OFFSET 10' +2952 +2953 Args: +2954 expression: the SQL code string to parse. +2955 This can also be an integer. +2956 If a `Offset` instance is passed, this is used as-is. +2957 If another `Expression` instance is passed, it will be wrapped in a `Offset`. +2958 dialect: the dialect used to parse the input expression. +2959 copy: if `False`, modify this expression instance in-place. +2960 opts: other options to use to parse the input expressions. +2961 +2962 Returns: +2963 The modified Select expression. +2964 """ +2965 return _apply_builder( +2966 expression=expression, +2967 instance=self, +2968 arg="offset", +2969 into=Offset, +2970 prefix="OFFSET", +2971 dialect=dialect, +2972 copy=copy, +2973 into_arg="expression", +2974 **opts, +2975 ) +2976 +2977 def select( +2978 self, +2979 *expressions: t.Optional[ExpOrStr], +2980 append: bool = True, +2981 dialect: DialectType = None, +2982 copy: bool = True, +2983 **opts, +2984 ) -> Select: +2985 """ +2986 Append to or set the SELECT expressions. 2987 -2988 Returns: -2989 The modified Select expression. -2990 """ -2991 return _apply_list_builder( -2992 *expressions, -2993 instance=self, -2994 arg="expressions", -2995 append=append, -2996 dialect=dialect, -2997 copy=copy, -2998 **opts, -2999 ) +2988 Example: +2989 >>> Select().select("x", "y").sql() +2990 'SELECT x, y' +2991 +2992 Args: +2993 *expressions: the SQL code strings to parse. +2994 If an `Expression` instance is passed, it will be used as-is. +2995 append: if `True`, add to any existing expressions. +2996 Otherwise, this resets the expressions. +2997 dialect: the dialect used to parse the input expressions. +2998 copy: if `False`, modify this expression instance in-place. +2999 opts: other options to use to parse the input expressions. 3000 -3001 def lateral( -3002 self, -3003 *expressions: t.Optional[ExpOrStr], -3004 append: bool = True, -3005 dialect: DialectType = None, -3006 copy: bool = True, -3007 **opts, -3008 ) -> Select: -3009 """ -3010 Append to or set the LATERAL expressions. -3011 -3012 Example: -3013 >>> Select().select("x").lateral("OUTER explode(y) tbl2 AS z").from_("tbl").sql() -3014 'SELECT x FROM tbl LATERAL VIEW OUTER EXPLODE(y) tbl2 AS z' -3015 -3016 Args: -3017 *expressions: the SQL code strings to parse. -3018 If an `Expression` instance is passed, it will be used as-is. -3019 append: if `True`, add to any existing expressions. -3020 Otherwise, this resets the expressions. -3021 dialect: the dialect used to parse the input expressions. -3022 copy: if `False`, modify this expression instance in-place. -3023 opts: other options to use to parse the input expressions. +3001 Returns: +3002 The modified Select expression. +3003 """ +3004 return _apply_list_builder( +3005 *expressions, +3006 instance=self, +3007 arg="expressions", +3008 append=append, +3009 dialect=dialect, +3010 copy=copy, +3011 **opts, +3012 ) +3013 +3014 def lateral( +3015 self, +3016 *expressions: t.Optional[ExpOrStr], +3017 append: bool = True, +3018 dialect: DialectType = None, +3019 copy: bool = True, +3020 **opts, +3021 ) -> Select: +3022 """ +3023 Append to or set the LATERAL expressions. 3024 -3025 Returns: -3026 The modified Select expression. -3027 """ -3028 return _apply_list_builder( -3029 *expressions, -3030 instance=self, -3031 arg="laterals", -3032 append=append, -3033 into=Lateral, -3034 prefix="LATERAL VIEW", -3035 dialect=dialect, -3036 copy=copy, -3037 **opts, -3038 ) -3039 -3040 def join( -3041 self, -3042 expression: ExpOrStr, -3043 on: t.Optional[ExpOrStr] = None, -3044 using: t.Optional[ExpOrStr | t.Collection[ExpOrStr]] = None, -3045 append: bool = True, -3046 join_type: t.Optional[str] = None, -3047 join_alias: t.Optional[Identifier | str] = None, -3048 dialect: DialectType = None, -3049 copy: bool = True, -3050 **opts, -3051 ) -> Select: -3052 """ -3053 Append to or set the JOIN expressions. -3054 -3055 Example: -3056 >>> Select().select("*").from_("tbl").join("tbl2", on="tbl1.y = tbl2.y").sql() -3057 'SELECT * FROM tbl JOIN tbl2 ON tbl1.y = tbl2.y' -3058 -3059 >>> Select().select("1").from_("a").join("b", using=["x", "y", "z"]).sql() -3060 'SELECT 1 FROM a JOIN b USING (x, y, z)' -3061 -3062 Use `join_type` to change the type of join: -3063 -3064 >>> Select().select("*").from_("tbl").join("tbl2", on="tbl1.y = tbl2.y", join_type="left outer").sql() -3065 'SELECT * FROM tbl LEFT OUTER JOIN tbl2 ON tbl1.y = tbl2.y' -3066 -3067 Args: -3068 expression: the SQL code string to parse. -3069 If an `Expression` instance is passed, it will be used as-is. -3070 on: optionally specify the join "on" criteria as a SQL string. -3071 If an `Expression` instance is passed, it will be used as-is. -3072 using: optionally specify the join "using" criteria as a SQL string. -3073 If an `Expression` instance is passed, it will be used as-is. -3074 append: if `True`, add to any existing expressions. -3075 Otherwise, this resets the expressions. -3076 join_type: if set, alter the parsed join type. -3077 join_alias: an optional alias for the joined source. -3078 dialect: the dialect used to parse the input expressions. -3079 copy: if `False`, modify this expression instance in-place. -3080 opts: other options to use to parse the input expressions. -3081 -3082 Returns: -3083 Select: the modified expression. -3084 """ -3085 parse_args: t.Dict[str, t.Any] = {"dialect": dialect, **opts} -3086 -3087 try: -3088 expression = maybe_parse(expression, into=Join, prefix="JOIN", **parse_args) -3089 except ParseError: -3090 expression = maybe_parse(expression, into=(Join, Expression), **parse_args) -3091 -3092 join = expression if isinstance(expression, Join) else Join(this=expression) -3093 -3094 if isinstance(join.this, Select): -3095 join.this.replace(join.this.subquery()) -3096 -3097 if join_type: -3098 method: t.Optional[Token] -3099 side: t.Optional[Token] -3100 kind: t.Optional[Token] -3101 -3102 method, side, kind = maybe_parse(join_type, into="JOIN_TYPE", **parse_args) # type: ignore -3103 -3104 if method: -3105 join.set("method", method.text) -3106 if side: -3107 join.set("side", side.text) -3108 if kind: -3109 join.set("kind", kind.text) -3110 -3111 if on: -3112 on = and_(*ensure_list(on), dialect=dialect, copy=copy, **opts) -3113 join.set("on", on) +3025 Example: +3026 >>> Select().select("x").lateral("OUTER explode(y) tbl2 AS z").from_("tbl").sql() +3027 'SELECT x FROM tbl LATERAL VIEW OUTER EXPLODE(y) tbl2 AS z' +3028 +3029 Args: +3030 *expressions: the SQL code strings to parse. +3031 If an `Expression` instance is passed, it will be used as-is. +3032 append: if `True`, add to any existing expressions. +3033 Otherwise, this resets the expressions. +3034 dialect: the dialect used to parse the input expressions. +3035 copy: if `False`, modify this expression instance in-place. +3036 opts: other options to use to parse the input expressions. +3037 +3038 Returns: +3039 The modified Select expression. +3040 """ +3041 return _apply_list_builder( +3042 *expressions, +3043 instance=self, +3044 arg="laterals", +3045 append=append, +3046 into=Lateral, +3047 prefix="LATERAL VIEW", +3048 dialect=dialect, +3049 copy=copy, +3050 **opts, +3051 ) +3052 +3053 def join( +3054 self, +3055 expression: ExpOrStr, +3056 on: t.Optional[ExpOrStr] = None, +3057 using: t.Optional[ExpOrStr | t.Collection[ExpOrStr]] = None, +3058 append: bool = True, +3059 join_type: t.Optional[str] = None, +3060 join_alias: t.Optional[Identifier | str] = None, +3061 dialect: DialectType = None, +3062 copy: bool = True, +3063 **opts, +3064 ) -> Select: +3065 """ +3066 Append to or set the JOIN expressions. +3067 +3068 Example: +3069 >>> Select().select("*").from_("tbl").join("tbl2", on="tbl1.y = tbl2.y").sql() +3070 'SELECT * FROM tbl JOIN tbl2 ON tbl1.y = tbl2.y' +3071 +3072 >>> Select().select("1").from_("a").join("b", using=["x", "y", "z"]).sql() +3073 'SELECT 1 FROM a JOIN b USING (x, y, z)' +3074 +3075 Use `join_type` to change the type of join: +3076 +3077 >>> Select().select("*").from_("tbl").join("tbl2", on="tbl1.y = tbl2.y", join_type="left outer").sql() +3078 'SELECT * FROM tbl LEFT OUTER JOIN tbl2 ON tbl1.y = tbl2.y' +3079 +3080 Args: +3081 expression: the SQL code string to parse. +3082 If an `Expression` instance is passed, it will be used as-is. +3083 on: optionally specify the join "on" criteria as a SQL string. +3084 If an `Expression` instance is passed, it will be used as-is. +3085 using: optionally specify the join "using" criteria as a SQL string. +3086 If an `Expression` instance is passed, it will be used as-is. +3087 append: if `True`, add to any existing expressions. +3088 Otherwise, this resets the expressions. +3089 join_type: if set, alter the parsed join type. +3090 join_alias: an optional alias for the joined source. +3091 dialect: the dialect used to parse the input expressions. +3092 copy: if `False`, modify this expression instance in-place. +3093 opts: other options to use to parse the input expressions. +3094 +3095 Returns: +3096 Select: the modified expression. +3097 """ +3098 parse_args: t.Dict[str, t.Any] = {"dialect": dialect, **opts} +3099 +3100 try: +3101 expression = maybe_parse(expression, into=Join, prefix="JOIN", **parse_args) +3102 except ParseError: +3103 expression = maybe_parse(expression, into=(Join, Expression), **parse_args) +3104 +3105 join = expression if isinstance(expression, Join) else Join(this=expression) +3106 +3107 if isinstance(join.this, Select): +3108 join.this.replace(join.this.subquery()) +3109 +3110 if join_type: +3111 method: t.Optional[Token] +3112 side: t.Optional[Token] +3113 kind: t.Optional[Token] 3114 -3115 if using: -3116 join = _apply_list_builder( -3117 *ensure_list(using), -3118 instance=join, -3119 arg="using", -3120 append=append, -3121 copy=copy, -3122 into=Identifier, -3123 **opts, -3124 ) -3125 -3126 if join_alias: -3127 join.set("this", alias_(join.this, join_alias, table=True)) -3128 -3129 return _apply_list_builder( -3130 join, -3131 instance=self, -3132 arg="joins", -3133 append=append, -3134 copy=copy, -3135 **opts, -3136 ) -3137 -3138 def where( -3139 self, -3140 *expressions: t.Optional[ExpOrStr], -3141 append: bool = True, -3142 dialect: DialectType = None, -3143 copy: bool = True, -3144 **opts, -3145 ) -> Select: -3146 """ -3147 Append to or set the WHERE expressions. -3148 -3149 Example: -3150 >>> Select().select("x").from_("tbl").where("x = 'a' OR x < 'b'").sql() -3151 "SELECT x FROM tbl WHERE x = 'a' OR x < 'b'" -3152 -3153 Args: -3154 *expressions: the SQL code strings to parse. -3155 If an `Expression` instance is passed, it will be used as-is. -3156 Multiple expressions are combined with an AND operator. -3157 append: if `True`, AND the new expressions to any existing expression. -3158 Otherwise, this resets the expression. -3159 dialect: the dialect used to parse the input expressions. -3160 copy: if `False`, modify this expression instance in-place. -3161 opts: other options to use to parse the input expressions. -3162 -3163 Returns: -3164 Select: the modified expression. -3165 """ -3166 return _apply_conjunction_builder( -3167 *expressions, -3168 instance=self, -3169 arg="where", -3170 append=append, -3171 into=Where, -3172 dialect=dialect, -3173 copy=copy, -3174 **opts, -3175 ) -3176 -3177 def having( -3178 self, -3179 *expressions: t.Optional[ExpOrStr], -3180 append: bool = True, -3181 dialect: DialectType = None, -3182 copy: bool = True, -3183 **opts, -3184 ) -> Select: -3185 """ -3186 Append to or set the HAVING expressions. -3187 -3188 Example: -3189 >>> Select().select("x", "COUNT(y)").from_("tbl").group_by("x").having("COUNT(y) > 3").sql() -3190 'SELECT x, COUNT(y) FROM tbl GROUP BY x HAVING COUNT(y) > 3' -3191 -3192 Args: -3193 *expressions: the SQL code strings to parse. -3194 If an `Expression` instance is passed, it will be used as-is. -3195 Multiple expressions are combined with an AND operator. -3196 append: if `True`, AND the new expressions to any existing expression. -3197 Otherwise, this resets the expression. -3198 dialect: the dialect used to parse the input expressions. -3199 copy: if `False`, modify this expression instance in-place. -3200 opts: other options to use to parse the input expressions. -3201 -3202 Returns: -3203 The modified Select expression. -3204 """ -3205 return _apply_conjunction_builder( -3206 *expressions, -3207 instance=self, -3208 arg="having", -3209 append=append, -3210 into=Having, -3211 dialect=dialect, -3212 copy=copy, -3213 **opts, -3214 ) -3215 -3216 def window( -3217 self, -3218 *expressions: t.Optional[ExpOrStr], -3219 append: bool = True, -3220 dialect: DialectType = None, -3221 copy: bool = True, -3222 **opts, -3223 ) -> Select: -3224 return _apply_list_builder( -3225 *expressions, -3226 instance=self, -3227 arg="windows", -3228 append=append, -3229 into=Window, -3230 dialect=dialect, -3231 copy=copy, -3232 **opts, -3233 ) -3234 -3235 def qualify( -3236 self, -3237 *expressions: t.Optional[ExpOrStr], -3238 append: bool = True, -3239 dialect: DialectType = None, -3240 copy: bool = True, -3241 **opts, -3242 ) -> Select: -3243 return _apply_conjunction_builder( -3244 *expressions, -3245 instance=self, -3246 arg="qualify", -3247 append=append, -3248 into=Qualify, -3249 dialect=dialect, -3250 copy=copy, -3251 **opts, -3252 ) -3253 -3254 def distinct( -3255 self, *ons: t.Optional[ExpOrStr], distinct: bool = True, copy: bool = True -3256 ) -> Select: -3257 """ -3258 Set the OFFSET expression. -3259 -3260 Example: -3261 >>> Select().from_("tbl").select("x").distinct().sql() -3262 'SELECT DISTINCT x FROM tbl' -3263 -3264 Args: -3265 ons: the expressions to distinct on -3266 distinct: whether the Select should be distinct -3267 copy: if `False`, modify this expression instance in-place. -3268 -3269 Returns: -3270 Select: the modified expression. -3271 """ -3272 instance = maybe_copy(self, copy) -3273 on = Tuple(expressions=[maybe_parse(on, copy=copy) for on in ons if on]) if ons else None -3274 instance.set("distinct", Distinct(on=on) if distinct else None) -3275 return instance +3115 method, side, kind = maybe_parse(join_type, into="JOIN_TYPE", **parse_args) # type: ignore +3116 +3117 if method: +3118 join.set("method", method.text) +3119 if side: +3120 join.set("side", side.text) +3121 if kind: +3122 join.set("kind", kind.text) +3123 +3124 if on: +3125 on = and_(*ensure_list(on), dialect=dialect, copy=copy, **opts) +3126 join.set("on", on) +3127 +3128 if using: +3129 join = _apply_list_builder( +3130 *ensure_list(using), +3131 instance=join, +3132 arg="using", +3133 append=append, +3134 copy=copy, +3135 into=Identifier, +3136 **opts, +3137 ) +3138 +3139 if join_alias: +3140 join.set("this", alias_(join.this, join_alias, table=True)) +3141 +3142 return _apply_list_builder( +3143 join, +3144 instance=self, +3145 arg="joins", +3146 append=append, +3147 copy=copy, +3148 **opts, +3149 ) +3150 +3151 def where( +3152 self, +3153 *expressions: t.Optional[ExpOrStr], +3154 append: bool = True, +3155 dialect: DialectType = None, +3156 copy: bool = True, +3157 **opts, +3158 ) -> Select: +3159 """ +3160 Append to or set the WHERE expressions. +3161 +3162 Example: +3163 >>> Select().select("x").from_("tbl").where("x = 'a' OR x < 'b'").sql() +3164 "SELECT x FROM tbl WHERE x = 'a' OR x < 'b'" +3165 +3166 Args: +3167 *expressions: the SQL code strings to parse. +3168 If an `Expression` instance is passed, it will be used as-is. +3169 Multiple expressions are combined with an AND operator. +3170 append: if `True`, AND the new expressions to any existing expression. +3171 Otherwise, this resets the expression. +3172 dialect: the dialect used to parse the input expressions. +3173 copy: if `False`, modify this expression instance in-place. +3174 opts: other options to use to parse the input expressions. +3175 +3176 Returns: +3177 Select: the modified expression. +3178 """ +3179 return _apply_conjunction_builder( +3180 *expressions, +3181 instance=self, +3182 arg="where", +3183 append=append, +3184 into=Where, +3185 dialect=dialect, +3186 copy=copy, +3187 **opts, +3188 ) +3189 +3190 def having( +3191 self, +3192 *expressions: t.Optional[ExpOrStr], +3193 append: bool = True, +3194 dialect: DialectType = None, +3195 copy: bool = True, +3196 **opts, +3197 ) -> Select: +3198 """ +3199 Append to or set the HAVING expressions. +3200 +3201 Example: +3202 >>> Select().select("x", "COUNT(y)").from_("tbl").group_by("x").having("COUNT(y) > 3").sql() +3203 'SELECT x, COUNT(y) FROM tbl GROUP BY x HAVING COUNT(y) > 3' +3204 +3205 Args: +3206 *expressions: the SQL code strings to parse. +3207 If an `Expression` instance is passed, it will be used as-is. +3208 Multiple expressions are combined with an AND operator. +3209 append: if `True`, AND the new expressions to any existing expression. +3210 Otherwise, this resets the expression. +3211 dialect: the dialect used to parse the input expressions. +3212 copy: if `False`, modify this expression instance in-place. +3213 opts: other options to use to parse the input expressions. +3214 +3215 Returns: +3216 The modified Select expression. +3217 """ +3218 return _apply_conjunction_builder( +3219 *expressions, +3220 instance=self, +3221 arg="having", +3222 append=append, +3223 into=Having, +3224 dialect=dialect, +3225 copy=copy, +3226 **opts, +3227 ) +3228 +3229 def window( +3230 self, +3231 *expressions: t.Optional[ExpOrStr], +3232 append: bool = True, +3233 dialect: DialectType = None, +3234 copy: bool = True, +3235 **opts, +3236 ) -> Select: +3237 return _apply_list_builder( +3238 *expressions, +3239 instance=self, +3240 arg="windows", +3241 append=append, +3242 into=Window, +3243 dialect=dialect, +3244 copy=copy, +3245 **opts, +3246 ) +3247 +3248 def qualify( +3249 self, +3250 *expressions: t.Optional[ExpOrStr], +3251 append: bool = True, +3252 dialect: DialectType = None, +3253 copy: bool = True, +3254 **opts, +3255 ) -> Select: +3256 return _apply_conjunction_builder( +3257 *expressions, +3258 instance=self, +3259 arg="qualify", +3260 append=append, +3261 into=Qualify, +3262 dialect=dialect, +3263 copy=copy, +3264 **opts, +3265 ) +3266 +3267 def distinct( +3268 self, *ons: t.Optional[ExpOrStr], distinct: bool = True, copy: bool = True +3269 ) -> Select: +3270 """ +3271 Set the OFFSET expression. +3272 +3273 Example: +3274 >>> Select().from_("tbl").select("x").distinct().sql() +3275 'SELECT DISTINCT x FROM tbl' 3276 -3277 def ctas( -3278 self, -3279 table: ExpOrStr, -3280 properties: t.Optional[t.Dict] = None, -3281 dialect: DialectType = None, -3282 copy: bool = True, -3283 **opts, -3284 ) -> Create: -3285 """ -3286 Convert this expression to a CREATE TABLE AS statement. -3287 -3288 Example: -3289 >>> Select().select("*").from_("tbl").ctas("x").sql() -3290 'CREATE TABLE x AS SELECT * FROM tbl' -3291 -3292 Args: -3293 table: the SQL code string to parse as the table name. -3294 If another `Expression` instance is passed, it will be used as-is. -3295 properties: an optional mapping of table properties -3296 dialect: the dialect used to parse the input table. -3297 copy: if `False`, modify this expression instance in-place. -3298 opts: other options to use to parse the input table. -3299 -3300 Returns: -3301 The new Create expression. -3302 """ -3303 instance = maybe_copy(self, copy) -3304 table_expression = maybe_parse( -3305 table, -3306 into=Table, -3307 dialect=dialect, -3308 **opts, -3309 ) -3310 properties_expression = None -3311 if properties: -3312 properties_expression = Properties.from_dict(properties) -3313 -3314 return Create( -3315 this=table_expression, -3316 kind="table", -3317 expression=instance, -3318 properties=properties_expression, -3319 ) -3320 -3321 def lock(self, update: bool = True, copy: bool = True) -> Select: -3322 """ -3323 Set the locking read mode for this expression. -3324 -3325 Examples: -3326 >>> Select().select("x").from_("tbl").where("x = 'a'").lock().sql("mysql") -3327 "SELECT x FROM tbl WHERE x = 'a' FOR UPDATE" -3328 -3329 >>> Select().select("x").from_("tbl").where("x = 'a'").lock(update=False).sql("mysql") -3330 "SELECT x FROM tbl WHERE x = 'a' FOR SHARE" -3331 -3332 Args: -3333 update: if `True`, the locking type will be `FOR UPDATE`, else it will be `FOR SHARE`. -3334 copy: if `False`, modify this expression instance in-place. -3335 -3336 Returns: -3337 The modified expression. -3338 """ -3339 inst = maybe_copy(self, copy) -3340 inst.set("locks", [Lock(update=update)]) +3277 Args: +3278 ons: the expressions to distinct on +3279 distinct: whether the Select should be distinct +3280 copy: if `False`, modify this expression instance in-place. +3281 +3282 Returns: +3283 Select: the modified expression. +3284 """ +3285 instance = maybe_copy(self, copy) +3286 on = Tuple(expressions=[maybe_parse(on, copy=copy) for on in ons if on]) if ons else None +3287 instance.set("distinct", Distinct(on=on) if distinct else None) +3288 return instance +3289 +3290 def ctas( +3291 self, +3292 table: ExpOrStr, +3293 properties: t.Optional[t.Dict] = None, +3294 dialect: DialectType = None, +3295 copy: bool = True, +3296 **opts, +3297 ) -> Create: +3298 """ +3299 Convert this expression to a CREATE TABLE AS statement. +3300 +3301 Example: +3302 >>> Select().select("*").from_("tbl").ctas("x").sql() +3303 'CREATE TABLE x AS SELECT * FROM tbl' +3304 +3305 Args: +3306 table: the SQL code string to parse as the table name. +3307 If another `Expression` instance is passed, it will be used as-is. +3308 properties: an optional mapping of table properties +3309 dialect: the dialect used to parse the input table. +3310 copy: if `False`, modify this expression instance in-place. +3311 opts: other options to use to parse the input table. +3312 +3313 Returns: +3314 The new Create expression. +3315 """ +3316 instance = maybe_copy(self, copy) +3317 table_expression = maybe_parse( +3318 table, +3319 into=Table, +3320 dialect=dialect, +3321 **opts, +3322 ) +3323 properties_expression = None +3324 if properties: +3325 properties_expression = Properties.from_dict(properties) +3326 +3327 return Create( +3328 this=table_expression, +3329 kind="table", +3330 expression=instance, +3331 properties=properties_expression, +3332 ) +3333 +3334 def lock(self, update: bool = True, copy: bool = True) -> Select: +3335 """ +3336 Set the locking read mode for this expression. +3337 +3338 Examples: +3339 >>> Select().select("x").from_("tbl").where("x = 'a'").lock().sql("mysql") +3340 "SELECT x FROM tbl WHERE x = 'a' FOR UPDATE" 3341 -3342 return inst -3343 -3344 def hint(self, *hints: ExpOrStr, dialect: DialectType = None, copy: bool = True) -> Select: -3345 """ -3346 Set hints for this expression. -3347 -3348 Examples: -3349 >>> Select().select("x").from_("tbl").hint("BROADCAST(y)").sql(dialect="spark") -3350 'SELECT /*+ BROADCAST(y) */ x FROM tbl' -3351 -3352 Args: -3353 hints: The SQL code strings to parse as the hints. -3354 If an `Expression` instance is passed, it will be used as-is. -3355 dialect: The dialect used to parse the hints. -3356 copy: If `False`, modify this expression instance in-place. -3357 -3358 Returns: -3359 The modified expression. -3360 """ -3361 inst = maybe_copy(self, copy) -3362 inst.set( -3363 "hint", Hint(expressions=[maybe_parse(h, copy=copy, dialect=dialect) for h in hints]) -3364 ) -3365 -3366 return inst -3367 -3368 @property -3369 def named_selects(self) -> t.List[str]: -3370 return [e.output_name for e in self.expressions if e.alias_or_name] -3371 -3372 @property -3373 def is_star(self) -> bool: -3374 return any(expression.is_star for expression in self.expressions) -3375 -3376 @property -3377 def selects(self) -> t.List[Expression]: -3378 return self.expressions +3342 >>> Select().select("x").from_("tbl").where("x = 'a'").lock(update=False).sql("mysql") +3343 "SELECT x FROM tbl WHERE x = 'a' FOR SHARE" +3344 +3345 Args: +3346 update: if `True`, the locking type will be `FOR UPDATE`, else it will be `FOR SHARE`. +3347 copy: if `False`, modify this expression instance in-place. +3348 +3349 Returns: +3350 The modified expression. +3351 """ +3352 inst = maybe_copy(self, copy) +3353 inst.set("locks", [Lock(update=update)]) +3354 +3355 return inst +3356 +3357 def hint(self, *hints: ExpOrStr, dialect: DialectType = None, copy: bool = True) -> Select: +3358 """ +3359 Set hints for this expression. +3360 +3361 Examples: +3362 >>> Select().select("x").from_("tbl").hint("BROADCAST(y)").sql(dialect="spark") +3363 'SELECT /*+ BROADCAST(y) */ x FROM tbl' +3364 +3365 Args: +3366 hints: The SQL code strings to parse as the hints. +3367 If an `Expression` instance is passed, it will be used as-is. +3368 dialect: The dialect used to parse the hints. +3369 copy: If `False`, modify this expression instance in-place. +3370 +3371 Returns: +3372 The modified expression. +3373 """ +3374 inst = maybe_copy(self, copy) +3375 inst.set( +3376 "hint", Hint(expressions=[maybe_parse(h, copy=copy, dialect=dialect) for h in hints]) +3377 ) +3378 +3379 return inst +3380 +3381 @property +3382 def named_selects(self) -> t.List[str]: +3383 return [e.output_name for e in self.expressions if e.alias_or_name] +3384 +3385 @property +3386 def is_star(self) -> bool: +3387 return any(expression.is_star for expression in self.expressions) +3388 +3389 @property +3390 def selects(self) -> t.List[Expression]: +3391 return self.expressions-2700 def from_( -2701 self, expression: ExpOrStr, dialect: DialectType = None, copy: bool = True, **opts -2702 ) -> Select: -2703 """ -2704 Set the FROM expression. -2705 -2706 Example: -2707 >>> Select().from_("tbl").select("x").sql() -2708 'SELECT x FROM tbl' -2709 -2710 Args: -2711 expression : the SQL code strings to parse. -2712 If a `From` instance is passed, this is used as-is. -2713 If another `Expression` instance is passed, it will be wrapped in a `From`. -2714 dialect: the dialect used to parse the input expression. -2715 copy: if `False`, modify this expression instance in-place. -2716 opts: other options to use to parse the input expressions. -2717 -2718 Returns: -2719 The modified Select expression. -2720 """ -2721 return _apply_builder( -2722 expression=expression, -2723 instance=self, -2724 arg="from", -2725 into=From, -2726 prefix="FROM", -2727 dialect=dialect, -2728 copy=copy, -2729 **opts, -2730 ) +@@ -39233,49 +39601,49 @@ If another2713 def from_( +2714 self, expression: ExpOrStr, dialect: DialectType = None, copy: bool = True, **opts +2715 ) -> Select: +2716 """ +2717 Set the FROM expression. +2718 +2719 Example: +2720 >>> Select().from_("tbl").select("x").sql() +2721 'SELECT x FROM tbl' +2722 +2723 Args: +2724 expression : the SQL code strings to parse. +2725 If a `From` instance is passed, this is used as-is. +2726 If another `Expression` instance is passed, it will be wrapped in a `From`. +2727 dialect: the dialect used to parse the input expression. +2728 copy: if `False`, modify this expression instance in-place. +2729 opts: other options to use to parse the input expressions. +2730 +2731 Returns: +2732 The modified Select expression. +2733 """ +2734 return _apply_builder( +2735 expression=expression, +2736 instance=self, +2737 arg="from", +2738 into=From, +2739 prefix="FROM", +2740 dialect=dialect, +2741 copy=copy, +2742 **opts, +2743 )Expression
instance is passed,-2732 def group_by( -2733 self, -2734 *expressions: t.Optional[ExpOrStr], -2735 append: bool = True, -2736 dialect: DialectType = None, -2737 copy: bool = True, -2738 **opts, -2739 ) -> Select: -2740 """ -2741 Set the GROUP BY expression. -2742 -2743 Example: -2744 >>> Select().from_("tbl").select("x", "COUNT(1)").group_by("x").sql() -2745 'SELECT x, COUNT(1) FROM tbl GROUP BY x' -2746 -2747 Args: -2748 *expressions: the SQL code strings to parse. -2749 If a `Group` instance is passed, this is used as-is. -2750 If another `Expression` instance is passed, it will be wrapped in a `Group`. -2751 If nothing is passed in then a group by is not applied to the expression -2752 append: if `True`, add to any existing expressions. -2753 Otherwise, this flattens all the `Group` expression into a single expression. -2754 dialect: the dialect used to parse the input expression. -2755 copy: if `False`, modify this expression instance in-place. -2756 opts: other options to use to parse the input expressions. -2757 -2758 Returns: -2759 The modified Select expression. -2760 """ -2761 if not expressions: -2762 return self if not copy else self.copy() -2763 -2764 return _apply_child_list_builder( -2765 *expressions, -2766 instance=self, -2767 arg="group", -2768 append=append, -2769 copy=copy, -2770 prefix="GROUP BY", -2771 into=Group, -2772 dialect=dialect, -2773 **opts, -2774 ) +@@ -39325,45 +39693,45 @@ Otherwise, this flattens all the2745 def group_by( +2746 self, +2747 *expressions: t.Optional[ExpOrStr], +2748 append: bool = True, +2749 dialect: DialectType = None, +2750 copy: bool = True, +2751 **opts, +2752 ) -> Select: +2753 """ +2754 Set the GROUP BY expression. +2755 +2756 Example: +2757 >>> Select().from_("tbl").select("x", "COUNT(1)").group_by("x").sql() +2758 'SELECT x, COUNT(1) FROM tbl GROUP BY x' +2759 +2760 Args: +2761 *expressions: the SQL code strings to parse. +2762 If a `Group` instance is passed, this is used as-is. +2763 If another `Expression` instance is passed, it will be wrapped in a `Group`. +2764 If nothing is passed in then a group by is not applied to the expression +2765 append: if `True`, add to any existing expressions. +2766 Otherwise, this flattens all the `Group` expression into a single expression. +2767 dialect: the dialect used to parse the input expression. +2768 copy: if `False`, modify this expression instance in-place. +2769 opts: other options to use to parse the input expressions. +2770 +2771 Returns: +2772 The modified Select expression. +2773 """ +2774 if not expressions: +2775 return self if not copy else self.copy() +2776 +2777 return _apply_child_list_builder( +2778 *expressions, +2779 instance=self, +2780 arg="group", +2781 append=append, +2782 copy=copy, +2783 prefix="GROUP BY", +2784 into=Group, +2785 dialect=dialect, +2786 **opts, +2787 )Group
express-2776 def order_by( -2777 self, -2778 *expressions: t.Optional[ExpOrStr], -2779 append: bool = True, -2780 dialect: DialectType = None, -2781 copy: bool = True, -2782 **opts, -2783 ) -> Select: -2784 """ -2785 Set the ORDER BY expression. -2786 -2787 Example: -2788 >>> Select().from_("tbl").select("x").order_by("x DESC").sql() -2789 'SELECT x FROM tbl ORDER BY x DESC' -2790 -2791 Args: -2792 *expressions: the SQL code strings to parse. -2793 If a `Group` instance is passed, this is used as-is. -2794 If another `Expression` instance is passed, it will be wrapped in a `Order`. -2795 append: if `True`, add to any existing expressions. -2796 Otherwise, this flattens all the `Order` expression into a single expression. -2797 dialect: the dialect used to parse the input expression. -2798 copy: if `False`, modify this expression instance in-place. -2799 opts: other options to use to parse the input expressions. -2800 -2801 Returns: -2802 The modified Select expression. -2803 """ -2804 return _apply_child_list_builder( -2805 *expressions, -2806 instance=self, -2807 arg="order", -2808 append=append, -2809 copy=copy, -2810 prefix="ORDER BY", -2811 into=Order, -2812 dialect=dialect, -2813 **opts, -2814 ) +@@ -39412,45 +39780,45 @@ Otherwise, this flattens all the2789 def order_by( +2790 self, +2791 *expressions: t.Optional[ExpOrStr], +2792 append: bool = True, +2793 dialect: DialectType = None, +2794 copy: bool = True, +2795 **opts, +2796 ) -> Select: +2797 """ +2798 Set the ORDER BY expression. +2799 +2800 Example: +2801 >>> Select().from_("tbl").select("x").order_by("x DESC").sql() +2802 'SELECT x FROM tbl ORDER BY x DESC' +2803 +2804 Args: +2805 *expressions: the SQL code strings to parse. +2806 If a `Group` instance is passed, this is used as-is. +2807 If another `Expression` instance is passed, it will be wrapped in a `Order`. +2808 append: if `True`, add to any existing expressions. +2809 Otherwise, this flattens all the `Order` expression into a single expression. +2810 dialect: the dialect used to parse the input expression. +2811 copy: if `False`, modify this expression instance in-place. +2812 opts: other options to use to parse the input expressions. +2813 +2814 Returns: +2815 The modified Select expression. +2816 """ +2817 return _apply_child_list_builder( +2818 *expressions, +2819 instance=self, +2820 arg="order", +2821 append=append, +2822 copy=copy, +2823 prefix="ORDER BY", +2824 into=Order, +2825 dialect=dialect, +2826 **opts, +2827 )Order
express-2816 def sort_by( -2817 self, -2818 *expressions: t.Optional[ExpOrStr], -2819 append: bool = True, -2820 dialect: DialectType = None, -2821 copy: bool = True, -2822 **opts, -2823 ) -> Select: -2824 """ -2825 Set the SORT BY expression. -2826 -2827 Example: -2828 >>> Select().from_("tbl").select("x").sort_by("x DESC").sql(dialect="hive") -2829 'SELECT x FROM tbl SORT BY x DESC' -2830 -2831 Args: -2832 *expressions: the SQL code strings to parse. -2833 If a `Group` instance is passed, this is used as-is. -2834 If another `Expression` instance is passed, it will be wrapped in a `SORT`. -2835 append: if `True`, add to any existing expressions. -2836 Otherwise, this flattens all the `Order` expression into a single expression. -2837 dialect: the dialect used to parse the input expression. -2838 copy: if `False`, modify this expression instance in-place. -2839 opts: other options to use to parse the input expressions. -2840 -2841 Returns: -2842 The modified Select expression. -2843 """ -2844 return _apply_child_list_builder( -2845 *expressions, -2846 instance=self, -2847 arg="sort", -2848 append=append, -2849 copy=copy, -2850 prefix="SORT BY", -2851 into=Sort, -2852 dialect=dialect, -2853 **opts, -2854 ) +@@ -39499,45 +39867,45 @@ Otherwise, this flattens all the2829 def sort_by( +2830 self, +2831 *expressions: t.Optional[ExpOrStr], +2832 append: bool = True, +2833 dialect: DialectType = None, +2834 copy: bool = True, +2835 **opts, +2836 ) -> Select: +2837 """ +2838 Set the SORT BY expression. +2839 +2840 Example: +2841 >>> Select().from_("tbl").select("x").sort_by("x DESC").sql(dialect="hive") +2842 'SELECT x FROM tbl SORT BY x DESC' +2843 +2844 Args: +2845 *expressions: the SQL code strings to parse. +2846 If a `Group` instance is passed, this is used as-is. +2847 If another `Expression` instance is passed, it will be wrapped in a `SORT`. +2848 append: if `True`, add to any existing expressions. +2849 Otherwise, this flattens all the `Order` expression into a single expression. +2850 dialect: the dialect used to parse the input expression. +2851 copy: if `False`, modify this expression instance in-place. +2852 opts: other options to use to parse the input expressions. +2853 +2854 Returns: +2855 The modified Select expression. +2856 """ +2857 return _apply_child_list_builder( +2858 *expressions, +2859 instance=self, +2860 arg="sort", +2861 append=append, +2862 copy=copy, +2863 prefix="SORT BY", +2864 into=Sort, +2865 dialect=dialect, +2866 **opts, +2867 )Order
express-2856 def cluster_by( -2857 self, -2858 *expressions: t.Optional[ExpOrStr], -2859 append: bool = True, -2860 dialect: DialectType = None, -2861 copy: bool = True, -2862 **opts, -2863 ) -> Select: -2864 """ -2865 Set the CLUSTER BY expression. -2866 -2867 Example: -2868 >>> Select().from_("tbl").select("x").cluster_by("x DESC").sql(dialect="hive") -2869 'SELECT x FROM tbl CLUSTER BY x DESC' -2870 -2871 Args: -2872 *expressions: the SQL code strings to parse. -2873 If a `Group` instance is passed, this is used as-is. -2874 If another `Expression` instance is passed, it will be wrapped in a `Cluster`. -2875 append: if `True`, add to any existing expressions. -2876 Otherwise, this flattens all the `Order` expression into a single expression. -2877 dialect: the dialect used to parse the input expression. -2878 copy: if `False`, modify this expression instance in-place. -2879 opts: other options to use to parse the input expressions. -2880 -2881 Returns: -2882 The modified Select expression. -2883 """ -2884 return _apply_child_list_builder( -2885 *expressions, -2886 instance=self, -2887 arg="cluster", -2888 append=append, -2889 copy=copy, -2890 prefix="CLUSTER BY", -2891 into=Cluster, -2892 dialect=dialect, -2893 **opts, -2894 ) +@@ -39586,39 +39954,39 @@ Otherwise, this flattens all the2869 def cluster_by( +2870 self, +2871 *expressions: t.Optional[ExpOrStr], +2872 append: bool = True, +2873 dialect: DialectType = None, +2874 copy: bool = True, +2875 **opts, +2876 ) -> Select: +2877 """ +2878 Set the CLUSTER BY expression. +2879 +2880 Example: +2881 >>> Select().from_("tbl").select("x").cluster_by("x DESC").sql(dialect="hive") +2882 'SELECT x FROM tbl CLUSTER BY x DESC' +2883 +2884 Args: +2885 *expressions: the SQL code strings to parse. +2886 If a `Group` instance is passed, this is used as-is. +2887 If another `Expression` instance is passed, it will be wrapped in a `Cluster`. +2888 append: if `True`, add to any existing expressions. +2889 Otherwise, this flattens all the `Order` expression into a single expression. +2890 dialect: the dialect used to parse the input expression. +2891 copy: if `False`, modify this expression instance in-place. +2892 opts: other options to use to parse the input expressions. +2893 +2894 Returns: +2895 The modified Select expression. +2896 """ +2897 return _apply_child_list_builder( +2898 *expressions, +2899 instance=self, +2900 arg="cluster", +2901 append=append, +2902 copy=copy, +2903 prefix="CLUSTER BY", +2904 into=Cluster, +2905 dialect=dialect, +2906 **opts, +2907 )Order
express-2896 def limit( -2897 self, expression: ExpOrStr | int, dialect: DialectType = None, copy: bool = True, **opts -2898 ) -> Select: -2899 """ -2900 Set the LIMIT expression. -2901 -2902 Example: -2903 >>> Select().from_("tbl").select("x").limit(10).sql() -2904 'SELECT x FROM tbl LIMIT 10' -2905 -2906 Args: -2907 expression: the SQL code string to parse. -2908 This can also be an integer. -2909 If a `Limit` instance is passed, this is used as-is. -2910 If another `Expression` instance is passed, it will be wrapped in a `Limit`. -2911 dialect: the dialect used to parse the input expression. -2912 copy: if `False`, modify this expression instance in-place. -2913 opts: other options to use to parse the input expressions. +@@ -39666,39 +40034,39 @@ If another2909 def limit( +2910 self, expression: ExpOrStr | int, dialect: DialectType = None, copy: bool = True, **opts +2911 ) -> Select: +2912 """ +2913 Set the LIMIT expression. 2914 -2915 Returns: -2916 Select: the modified expression. -2917 """ -2918 return _apply_builder( -2919 expression=expression, -2920 instance=self, -2921 arg="limit", -2922 into=Limit, -2923 prefix="LIMIT", -2924 dialect=dialect, -2925 copy=copy, -2926 into_arg="expression", -2927 **opts, -2928 ) +2915 Example: +2916 >>> Select().from_("tbl").select("x").limit(10).sql() +2917 'SELECT x FROM tbl LIMIT 10' +2918 +2919 Args: +2920 expression: the SQL code string to parse. +2921 This can also be an integer. +2922 If a `Limit` instance is passed, this is used as-is. +2923 If another `Expression` instance is passed, it will be wrapped in a `Limit`. +2924 dialect: the dialect used to parse the input expression. +2925 copy: if `False`, modify this expression instance in-place. +2926 opts: other options to use to parse the input expressions. +2927 +2928 Returns: +2929 Select: the modified expression. +2930 """ +2931 return _apply_builder( +2932 expression=expression, +2933 instance=self, +2934 arg="limit", +2935 into=Limit, +2936 prefix="LIMIT", +2937 dialect=dialect, +2938 copy=copy, +2939 into_arg="expression", +2940 **opts, +2941 )Expression
instance is passed,-2930 def offset( -2931 self, expression: ExpOrStr | int, dialect: DialectType = None, copy: bool = True, **opts -2932 ) -> Select: -2933 """ -2934 Set the OFFSET expression. -2935 -2936 Example: -2937 >>> Select().from_("tbl").select("x").offset(10).sql() -2938 'SELECT x FROM tbl OFFSET 10' -2939 -2940 Args: -2941 expression: the SQL code string to parse. -2942 This can also be an integer. -2943 If a `Offset` instance is passed, this is used as-is. -2944 If another `Expression` instance is passed, it will be wrapped in a `Offset`. -2945 dialect: the dialect used to parse the input expression. -2946 copy: if `False`, modify this expression instance in-place. -2947 opts: other options to use to parse the input expressions. +@@ -39746,42 +40114,42 @@ If another2943 def offset( +2944 self, expression: ExpOrStr | int, dialect: DialectType = None, copy: bool = True, **opts +2945 ) -> Select: +2946 """ +2947 Set the OFFSET expression. 2948 -2949 Returns: -2950 The modified Select expression. -2951 """ -2952 return _apply_builder( -2953 expression=expression, -2954 instance=self, -2955 arg="offset", -2956 into=Offset, -2957 prefix="OFFSET", -2958 dialect=dialect, -2959 copy=copy, -2960 into_arg="expression", -2961 **opts, -2962 ) +2949 Example: +2950 >>> Select().from_("tbl").select("x").offset(10).sql() +2951 'SELECT x FROM tbl OFFSET 10' +2952 +2953 Args: +2954 expression: the SQL code string to parse. +2955 This can also be an integer. +2956 If a `Offset` instance is passed, this is used as-is. +2957 If another `Expression` instance is passed, it will be wrapped in a `Offset`. +2958 dialect: the dialect used to parse the input expression. +2959 copy: if `False`, modify this expression instance in-place. +2960 opts: other options to use to parse the input expressions. +2961 +2962 Returns: +2963 The modified Select expression. +2964 """ +2965 return _apply_builder( +2966 expression=expression, +2967 instance=self, +2968 arg="offset", +2969 into=Offset, +2970 prefix="OFFSET", +2971 dialect=dialect, +2972 copy=copy, +2973 into_arg="expression", +2974 **opts, +2975 )Expression
instance is passed,-2964 def select( -2965 self, -2966 *expressions: t.Optional[ExpOrStr], -2967 append: bool = True, -2968 dialect: DialectType = None, -2969 copy: bool = True, -2970 **opts, -2971 ) -> Select: -2972 """ -2973 Append to or set the SELECT expressions. -2974 -2975 Example: -2976 >>> Select().select("x", "y").sql() -2977 'SELECT x, y' -2978 -2979 Args: -2980 *expressions: the SQL code strings to parse. -2981 If an `Expression` instance is passed, it will be used as-is. -2982 append: if `True`, add to any existing expressions. -2983 Otherwise, this resets the expressions. -2984 dialect: the dialect used to parse the input expressions. -2985 copy: if `False`, modify this expression instance in-place. -2986 opts: other options to use to parse the input expressions. +@@ -39829,44 +40197,44 @@ Otherwise, this resets the expressions.2977 def select( +2978 self, +2979 *expressions: t.Optional[ExpOrStr], +2980 append: bool = True, +2981 dialect: DialectType = None, +2982 copy: bool = True, +2983 **opts, +2984 ) -> Select: +2985 """ +2986 Append to or set the SELECT expressions. 2987 -2988 Returns: -2989 The modified Select expression. -2990 """ -2991 return _apply_list_builder( -2992 *expressions, -2993 instance=self, -2994 arg="expressions", -2995 append=append, -2996 dialect=dialect, -2997 copy=copy, -2998 **opts, -2999 ) +2988 Example: +2989 >>> Select().select("x", "y").sql() +2990 'SELECT x, y' +2991 +2992 Args: +2993 *expressions: the SQL code strings to parse. +2994 If an `Expression` instance is passed, it will be used as-is. +2995 append: if `True`, add to any existing expressions. +2996 Otherwise, this resets the expressions. +2997 dialect: the dialect used to parse the input expressions. +2998 copy: if `False`, modify this expression instance in-place. +2999 opts: other options to use to parse the input expressions. +3000 +3001 Returns: +3002 The modified Select expression. +3003 """ +3004 return _apply_list_builder( +3005 *expressions, +3006 instance=self, +3007 arg="expressions", +3008 append=append, +3009 dialect=dialect, +3010 copy=copy, +3011 **opts, +3012 )-3001 def lateral( -3002 self, -3003 *expressions: t.Optional[ExpOrStr], -3004 append: bool = True, -3005 dialect: DialectType = None, -3006 copy: bool = True, -3007 **opts, -3008 ) -> Select: -3009 """ -3010 Append to or set the LATERAL expressions. -3011 -3012 Example: -3013 >>> Select().select("x").lateral("OUTER explode(y) tbl2 AS z").from_("tbl").sql() -3014 'SELECT x FROM tbl LATERAL VIEW OUTER EXPLODE(y) tbl2 AS z' -3015 -3016 Args: -3017 *expressions: the SQL code strings to parse. -3018 If an `Expression` instance is passed, it will be used as-is. -3019 append: if `True`, add to any existing expressions. -3020 Otherwise, this resets the expressions. -3021 dialect: the dialect used to parse the input expressions. -3022 copy: if `False`, modify this expression instance in-place. -3023 opts: other options to use to parse the input expressions. +@@ -39914,103 +40282,103 @@ Otherwise, this resets the expressions.3014 def lateral( +3015 self, +3016 *expressions: t.Optional[ExpOrStr], +3017 append: bool = True, +3018 dialect: DialectType = None, +3019 copy: bool = True, +3020 **opts, +3021 ) -> Select: +3022 """ +3023 Append to or set the LATERAL expressions. 3024 -3025 Returns: -3026 The modified Select expression. -3027 """ -3028 return _apply_list_builder( -3029 *expressions, -3030 instance=self, -3031 arg="laterals", -3032 append=append, -3033 into=Lateral, -3034 prefix="LATERAL VIEW", -3035 dialect=dialect, -3036 copy=copy, -3037 **opts, -3038 ) +3025 Example: +3026 >>> Select().select("x").lateral("OUTER explode(y) tbl2 AS z").from_("tbl").sql() +3027 'SELECT x FROM tbl LATERAL VIEW OUTER EXPLODE(y) tbl2 AS z' +3028 +3029 Args: +3030 *expressions: the SQL code strings to parse. +3031 If an `Expression` instance is passed, it will be used as-is. +3032 append: if `True`, add to any existing expressions. +3033 Otherwise, this resets the expressions. +3034 dialect: the dialect used to parse the input expressions. +3035 copy: if `False`, modify this expression instance in-place. +3036 opts: other options to use to parse the input expressions. +3037 +3038 Returns: +3039 The modified Select expression. +3040 """ +3041 return _apply_list_builder( +3042 *expressions, +3043 instance=self, +3044 arg="laterals", +3045 append=append, +3046 into=Lateral, +3047 prefix="LATERAL VIEW", +3048 dialect=dialect, +3049 copy=copy, +3050 **opts, +3051 )-3040 def join( -3041 self, -3042 expression: ExpOrStr, -3043 on: t.Optional[ExpOrStr] = None, -3044 using: t.Optional[ExpOrStr | t.Collection[ExpOrStr]] = None, -3045 append: bool = True, -3046 join_type: t.Optional[str] = None, -3047 join_alias: t.Optional[Identifier | str] = None, -3048 dialect: DialectType = None, -3049 copy: bool = True, -3050 **opts, -3051 ) -> Select: -3052 """ -3053 Append to or set the JOIN expressions. -3054 -3055 Example: -3056 >>> Select().select("*").from_("tbl").join("tbl2", on="tbl1.y = tbl2.y").sql() -3057 'SELECT * FROM tbl JOIN tbl2 ON tbl1.y = tbl2.y' -3058 -3059 >>> Select().select("1").from_("a").join("b", using=["x", "y", "z"]).sql() -3060 'SELECT 1 FROM a JOIN b USING (x, y, z)' -3061 -3062 Use `join_type` to change the type of join: -3063 -3064 >>> Select().select("*").from_("tbl").join("tbl2", on="tbl1.y = tbl2.y", join_type="left outer").sql() -3065 'SELECT * FROM tbl LEFT OUTER JOIN tbl2 ON tbl1.y = tbl2.y' -3066 -3067 Args: -3068 expression: the SQL code string to parse. -3069 If an `Expression` instance is passed, it will be used as-is. -3070 on: optionally specify the join "on" criteria as a SQL string. -3071 If an `Expression` instance is passed, it will be used as-is. -3072 using: optionally specify the join "using" criteria as a SQL string. -3073 If an `Expression` instance is passed, it will be used as-is. -3074 append: if `True`, add to any existing expressions. -3075 Otherwise, this resets the expressions. -3076 join_type: if set, alter the parsed join type. -3077 join_alias: an optional alias for the joined source. -3078 dialect: the dialect used to parse the input expressions. -3079 copy: if `False`, modify this expression instance in-place. -3080 opts: other options to use to parse the input expressions. -3081 -3082 Returns: -3083 Select: the modified expression. -3084 """ -3085 parse_args: t.Dict[str, t.Any] = {"dialect": dialect, **opts} -3086 -3087 try: -3088 expression = maybe_parse(expression, into=Join, prefix="JOIN", **parse_args) -3089 except ParseError: -3090 expression = maybe_parse(expression, into=(Join, Expression), **parse_args) -3091 -3092 join = expression if isinstance(expression, Join) else Join(this=expression) -3093 -3094 if isinstance(join.this, Select): -3095 join.this.replace(join.this.subquery()) -3096 -3097 if join_type: -3098 method: t.Optional[Token] -3099 side: t.Optional[Token] -3100 kind: t.Optional[Token] -3101 -3102 method, side, kind = maybe_parse(join_type, into="JOIN_TYPE", **parse_args) # type: ignore -3103 -3104 if method: -3105 join.set("method", method.text) -3106 if side: -3107 join.set("side", side.text) -3108 if kind: -3109 join.set("kind", kind.text) -3110 -3111 if on: -3112 on = and_(*ensure_list(on), dialect=dialect, copy=copy, **opts) -3113 join.set("on", on) +@@ -40078,44 +40446,44 @@ Otherwise, this resets the expressions.3053 def join( +3054 self, +3055 expression: ExpOrStr, +3056 on: t.Optional[ExpOrStr] = None, +3057 using: t.Optional[ExpOrStr | t.Collection[ExpOrStr]] = None, +3058 append: bool = True, +3059 join_type: t.Optional[str] = None, +3060 join_alias: t.Optional[Identifier | str] = None, +3061 dialect: DialectType = None, +3062 copy: bool = True, +3063 **opts, +3064 ) -> Select: +3065 """ +3066 Append to or set the JOIN expressions. +3067 +3068 Example: +3069 >>> Select().select("*").from_("tbl").join("tbl2", on="tbl1.y = tbl2.y").sql() +3070 'SELECT * FROM tbl JOIN tbl2 ON tbl1.y = tbl2.y' +3071 +3072 >>> Select().select("1").from_("a").join("b", using=["x", "y", "z"]).sql() +3073 'SELECT 1 FROM a JOIN b USING (x, y, z)' +3074 +3075 Use `join_type` to change the type of join: +3076 +3077 >>> Select().select("*").from_("tbl").join("tbl2", on="tbl1.y = tbl2.y", join_type="left outer").sql() +3078 'SELECT * FROM tbl LEFT OUTER JOIN tbl2 ON tbl1.y = tbl2.y' +3079 +3080 Args: +3081 expression: the SQL code string to parse. +3082 If an `Expression` instance is passed, it will be used as-is. +3083 on: optionally specify the join "on" criteria as a SQL string. +3084 If an `Expression` instance is passed, it will be used as-is. +3085 using: optionally specify the join "using" criteria as a SQL string. +3086 If an `Expression` instance is passed, it will be used as-is. +3087 append: if `True`, add to any existing expressions. +3088 Otherwise, this resets the expressions. +3089 join_type: if set, alter the parsed join type. +3090 join_alias: an optional alias for the joined source. +3091 dialect: the dialect used to parse the input expressions. +3092 copy: if `False`, modify this expression instance in-place. +3093 opts: other options to use to parse the input expressions. +3094 +3095 Returns: +3096 Select: the modified expression. +3097 """ +3098 parse_args: t.Dict[str, t.Any] = {"dialect": dialect, **opts} +3099 +3100 try: +3101 expression = maybe_parse(expression, into=Join, prefix="JOIN", **parse_args) +3102 except ParseError: +3103 expression = maybe_parse(expression, into=(Join, Expression), **parse_args) +3104 +3105 join = expression if isinstance(expression, Join) else Join(this=expression) +3106 +3107 if isinstance(join.this, Select): +3108 join.this.replace(join.this.subquery()) +3109 +3110 if join_type: +3111 method: t.Optional[Token] +3112 side: t.Optional[Token] +3113 kind: t.Optional[Token] 3114 -3115 if using: -3116 join = _apply_list_builder( -3117 *ensure_list(using), -3118 instance=join, -3119 arg="using", -3120 append=append, -3121 copy=copy, -3122 into=Identifier, -3123 **opts, -3124 ) -3125 -3126 if join_alias: -3127 join.set("this", alias_(join.this, join_alias, table=True)) -3128 -3129 return _apply_list_builder( -3130 join, -3131 instance=self, -3132 arg="joins", -3133 append=append, -3134 copy=copy, -3135 **opts, -3136 ) +3115 method, side, kind = maybe_parse(join_type, into="JOIN_TYPE", **parse_args) # type: ignore +3116 +3117 if method: +3118 join.set("method", method.text) +3119 if side: +3120 join.set("side", side.text) +3121 if kind: +3122 join.set("kind", kind.text) +3123 +3124 if on: +3125 on = and_(*ensure_list(on), dialect=dialect, copy=copy, **opts) +3126 join.set("on", on) +3127 +3128 if using: +3129 join = _apply_list_builder( +3130 *ensure_list(using), +3131 instance=join, +3132 arg="using", +3133 append=append, +3134 copy=copy, +3135 into=Identifier, +3136 **opts, +3137 ) +3138 +3139 if join_alias: +3140 join.set("this", alias_(join.this, join_alias, table=True)) +3141 +3142 return _apply_list_builder( +3143 join, +3144 instance=self, +3145 arg="joins", +3146 append=append, +3147 copy=copy, +3148 **opts, +3149 )-3138 def where( -3139 self, -3140 *expressions: t.Optional[ExpOrStr], -3141 append: bool = True, -3142 dialect: DialectType = None, -3143 copy: bool = True, -3144 **opts, -3145 ) -> Select: -3146 """ -3147 Append to or set the WHERE expressions. -3148 -3149 Example: -3150 >>> Select().select("x").from_("tbl").where("x = 'a' OR x < 'b'").sql() -3151 "SELECT x FROM tbl WHERE x = 'a' OR x < 'b'" -3152 -3153 Args: -3154 *expressions: the SQL code strings to parse. -3155 If an `Expression` instance is passed, it will be used as-is. -3156 Multiple expressions are combined with an AND operator. -3157 append: if `True`, AND the new expressions to any existing expression. -3158 Otherwise, this resets the expression. -3159 dialect: the dialect used to parse the input expressions. -3160 copy: if `False`, modify this expression instance in-place. -3161 opts: other options to use to parse the input expressions. -3162 -3163 Returns: -3164 Select: the modified expression. -3165 """ -3166 return _apply_conjunction_builder( -3167 *expressions, -3168 instance=self, -3169 arg="where", -3170 append=append, -3171 into=Where, -3172 dialect=dialect, -3173 copy=copy, -3174 **opts, -3175 ) +@@ -40164,44 +40532,44 @@ Otherwise, this resets the expression.3151 def where( +3152 self, +3153 *expressions: t.Optional[ExpOrStr], +3154 append: bool = True, +3155 dialect: DialectType = None, +3156 copy: bool = True, +3157 **opts, +3158 ) -> Select: +3159 """ +3160 Append to or set the WHERE expressions. +3161 +3162 Example: +3163 >>> Select().select("x").from_("tbl").where("x = 'a' OR x < 'b'").sql() +3164 "SELECT x FROM tbl WHERE x = 'a' OR x < 'b'" +3165 +3166 Args: +3167 *expressions: the SQL code strings to parse. +3168 If an `Expression` instance is passed, it will be used as-is. +3169 Multiple expressions are combined with an AND operator. +3170 append: if `True`, AND the new expressions to any existing expression. +3171 Otherwise, this resets the expression. +3172 dialect: the dialect used to parse the input expressions. +3173 copy: if `False`, modify this expression instance in-place. +3174 opts: other options to use to parse the input expressions. +3175 +3176 Returns: +3177 Select: the modified expression. +3178 """ +3179 return _apply_conjunction_builder( +3180 *expressions, +3181 instance=self, +3182 arg="where", +3183 append=append, +3184 into=Where, +3185 dialect=dialect, +3186 copy=copy, +3187 **opts, +3188 )-3177 def having( -3178 self, -3179 *expressions: t.Optional[ExpOrStr], -3180 append: bool = True, -3181 dialect: DialectType = None, -3182 copy: bool = True, -3183 **opts, -3184 ) -> Select: -3185 """ -3186 Append to or set the HAVING expressions. -3187 -3188 Example: -3189 >>> Select().select("x", "COUNT(y)").from_("tbl").group_by("x").having("COUNT(y) > 3").sql() -3190 'SELECT x, COUNT(y) FROM tbl GROUP BY x HAVING COUNT(y) > 3' -3191 -3192 Args: -3193 *expressions: the SQL code strings to parse. -3194 If an `Expression` instance is passed, it will be used as-is. -3195 Multiple expressions are combined with an AND operator. -3196 append: if `True`, AND the new expressions to any existing expression. -3197 Otherwise, this resets the expression. -3198 dialect: the dialect used to parse the input expressions. -3199 copy: if `False`, modify this expression instance in-place. -3200 opts: other options to use to parse the input expressions. -3201 -3202 Returns: -3203 The modified Select expression. -3204 """ -3205 return _apply_conjunction_builder( -3206 *expressions, -3207 instance=self, -3208 arg="having", -3209 append=append, -3210 into=Having, -3211 dialect=dialect, -3212 copy=copy, -3213 **opts, -3214 ) +@@ -40250,24 +40618,24 @@ Otherwise, this resets the expression.3190 def having( +3191 self, +3192 *expressions: t.Optional[ExpOrStr], +3193 append: bool = True, +3194 dialect: DialectType = None, +3195 copy: bool = True, +3196 **opts, +3197 ) -> Select: +3198 """ +3199 Append to or set the HAVING expressions. +3200 +3201 Example: +3202 >>> Select().select("x", "COUNT(y)").from_("tbl").group_by("x").having("COUNT(y) > 3").sql() +3203 'SELECT x, COUNT(y) FROM tbl GROUP BY x HAVING COUNT(y) > 3' +3204 +3205 Args: +3206 *expressions: the SQL code strings to parse. +3207 If an `Expression` instance is passed, it will be used as-is. +3208 Multiple expressions are combined with an AND operator. +3209 append: if `True`, AND the new expressions to any existing expression. +3210 Otherwise, this resets the expression. +3211 dialect: the dialect used to parse the input expressions. +3212 copy: if `False`, modify this expression instance in-place. +3213 opts: other options to use to parse the input expressions. +3214 +3215 Returns: +3216 The modified Select expression. +3217 """ +3218 return _apply_conjunction_builder( +3219 *expressions, +3220 instance=self, +3221 arg="having", +3222 append=append, +3223 into=Having, +3224 dialect=dialect, +3225 copy=copy, +3226 **opts, +3227 )-3216 def window( -3217 self, -3218 *expressions: t.Optional[ExpOrStr], -3219 append: bool = True, -3220 dialect: DialectType = None, -3221 copy: bool = True, -3222 **opts, -3223 ) -> Select: -3224 return _apply_list_builder( -3225 *expressions, -3226 instance=self, -3227 arg="windows", -3228 append=append, -3229 into=Window, -3230 dialect=dialect, -3231 copy=copy, -3232 **opts, -3233 ) +@@ -40285,24 +40653,24 @@ Otherwise, this resets the expression.3229 def window( +3230 self, +3231 *expressions: t.Optional[ExpOrStr], +3232 append: bool = True, +3233 dialect: DialectType = None, +3234 copy: bool = True, +3235 **opts, +3236 ) -> Select: +3237 return _apply_list_builder( +3238 *expressions, +3239 instance=self, +3240 arg="windows", +3241 append=append, +3242 into=Window, +3243 dialect=dialect, +3244 copy=copy, +3245 **opts, +3246 )-3235 def qualify( -3236 self, -3237 *expressions: t.Optional[ExpOrStr], -3238 append: bool = True, -3239 dialect: DialectType = None, -3240 copy: bool = True, -3241 **opts, -3242 ) -> Select: -3243 return _apply_conjunction_builder( -3244 *expressions, -3245 instance=self, -3246 arg="qualify", -3247 append=append, -3248 into=Qualify, -3249 dialect=dialect, -3250 copy=copy, -3251 **opts, -3252 ) +@@ -40320,28 +40688,28 @@ Otherwise, this resets the expression.3248 def qualify( +3249 self, +3250 *expressions: t.Optional[ExpOrStr], +3251 append: bool = True, +3252 dialect: DialectType = None, +3253 copy: bool = True, +3254 **opts, +3255 ) -> Select: +3256 return _apply_conjunction_builder( +3257 *expressions, +3258 instance=self, +3259 arg="qualify", +3260 append=append, +3261 into=Qualify, +3262 dialect=dialect, +3263 copy=copy, +3264 **opts, +3265 )-3254 def distinct( -3255 self, *ons: t.Optional[ExpOrStr], distinct: bool = True, copy: bool = True -3256 ) -> Select: -3257 """ -3258 Set the OFFSET expression. -3259 -3260 Example: -3261 >>> Select().from_("tbl").select("x").distinct().sql() -3262 'SELECT DISTINCT x FROM tbl' -3263 -3264 Args: -3265 ons: the expressions to distinct on -3266 distinct: whether the Select should be distinct -3267 copy: if `False`, modify this expression instance in-place. -3268 -3269 Returns: -3270 Select: the modified expression. -3271 """ -3272 instance = maybe_copy(self, copy) -3273 on = Tuple(expressions=[maybe_parse(on, copy=copy) for on in ons if on]) if ons else None -3274 instance.set("distinct", Distinct(on=on) if distinct else None) -3275 return instance +@@ -40385,49 +40753,49 @@ Otherwise, this resets the expression.3267 def distinct( +3268 self, *ons: t.Optional[ExpOrStr], distinct: bool = True, copy: bool = True +3269 ) -> Select: +3270 """ +3271 Set the OFFSET expression. +3272 +3273 Example: +3274 >>> Select().from_("tbl").select("x").distinct().sql() +3275 'SELECT DISTINCT x FROM tbl' +3276 +3277 Args: +3278 ons: the expressions to distinct on +3279 distinct: whether the Select should be distinct +3280 copy: if `False`, modify this expression instance in-place. +3281 +3282 Returns: +3283 Select: the modified expression. +3284 """ +3285 instance = maybe_copy(self, copy) +3286 on = Tuple(expressions=[maybe_parse(on, copy=copy) for on in ons if on]) if ons else None +3287 instance.set("distinct", Distinct(on=on) if distinct else None) +3288 return instance-3277 def ctas( -3278 self, -3279 table: ExpOrStr, -3280 properties: t.Optional[t.Dict] = None, -3281 dialect: DialectType = None, -3282 copy: bool = True, -3283 **opts, -3284 ) -> Create: -3285 """ -3286 Convert this expression to a CREATE TABLE AS statement. -3287 -3288 Example: -3289 >>> Select().select("*").from_("tbl").ctas("x").sql() -3290 'CREATE TABLE x AS SELECT * FROM tbl' -3291 -3292 Args: -3293 table: the SQL code string to parse as the table name. -3294 If another `Expression` instance is passed, it will be used as-is. -3295 properties: an optional mapping of table properties -3296 dialect: the dialect used to parse the input table. -3297 copy: if `False`, modify this expression instance in-place. -3298 opts: other options to use to parse the input table. -3299 -3300 Returns: -3301 The new Create expression. -3302 """ -3303 instance = maybe_copy(self, copy) -3304 table_expression = maybe_parse( -3305 table, -3306 into=Table, -3307 dialect=dialect, -3308 **opts, -3309 ) -3310 properties_expression = None -3311 if properties: -3312 properties_expression = Properties.from_dict(properties) -3313 -3314 return Create( -3315 this=table_expression, -3316 kind="table", -3317 expression=instance, -3318 properties=properties_expression, -3319 ) +@@ -40474,28 +40842,28 @@ If another3290 def ctas( +3291 self, +3292 table: ExpOrStr, +3293 properties: t.Optional[t.Dict] = None, +3294 dialect: DialectType = None, +3295 copy: bool = True, +3296 **opts, +3297 ) -> Create: +3298 """ +3299 Convert this expression to a CREATE TABLE AS statement. +3300 +3301 Example: +3302 >>> Select().select("*").from_("tbl").ctas("x").sql() +3303 'CREATE TABLE x AS SELECT * FROM tbl' +3304 +3305 Args: +3306 table: the SQL code string to parse as the table name. +3307 If another `Expression` instance is passed, it will be used as-is. +3308 properties: an optional mapping of table properties +3309 dialect: the dialect used to parse the input table. +3310 copy: if `False`, modify this expression instance in-place. +3311 opts: other options to use to parse the input table. +3312 +3313 Returns: +3314 The new Create expression. +3315 """ +3316 instance = maybe_copy(self, copy) +3317 table_expression = maybe_parse( +3318 table, +3319 into=Table, +3320 dialect=dialect, +3321 **opts, +3322 ) +3323 properties_expression = None +3324 if properties: +3325 properties_expression = Properties.from_dict(properties) +3326 +3327 return Create( +3328 this=table_expression, +3329 kind="table", +3330 expression=instance, +3331 properties=properties_expression, +3332 )Expression
instance is passed,-3321 def lock(self, update: bool = True, copy: bool = True) -> Select: -3322 """ -3323 Set the locking read mode for this expression. -3324 -3325 Examples: -3326 >>> Select().select("x").from_("tbl").where("x = 'a'").lock().sql("mysql") -3327 "SELECT x FROM tbl WHERE x = 'a' FOR UPDATE" -3328 -3329 >>> Select().select("x").from_("tbl").where("x = 'a'").lock(update=False).sql("mysql") -3330 "SELECT x FROM tbl WHERE x = 'a' FOR SHARE" -3331 -3332 Args: -3333 update: if `True`, the locking type will be `FOR UPDATE`, else it will be `FOR SHARE`. -3334 copy: if `False`, modify this expression instance in-place. -3335 -3336 Returns: -3337 The modified expression. -3338 """ -3339 inst = maybe_copy(self, copy) -3340 inst.set("locks", [Lock(update=update)]) +@@ -40544,29 +40912,29 @@ If another3334 def lock(self, update: bool = True, copy: bool = True) -> Select: +3335 """ +3336 Set the locking read mode for this expression. +3337 +3338 Examples: +3339 >>> Select().select("x").from_("tbl").where("x = 'a'").lock().sql("mysql") +3340 "SELECT x FROM tbl WHERE x = 'a' FOR UPDATE" 3341 -3342 return inst +3342 >>> Select().select("x").from_("tbl").where("x = 'a'").lock(update=False).sql("mysql") +3343 "SELECT x FROM tbl WHERE x = 'a' FOR SHARE" +3344 +3345 Args: +3346 update: if `True`, the locking type will be `FOR UPDATE`, else it will be `FOR SHARE`. +3347 copy: if `False`, modify this expression instance in-place. +3348 +3349 Returns: +3350 The modified expression. +3351 """ +3352 inst = maybe_copy(self, copy) +3353 inst.set("locks", [Lock(update=update)]) +3354 +3355 return instExpression
instance is passed,-3344 def hint(self, *hints: ExpOrStr, dialect: DialectType = None, copy: bool = True) -> Select: -3345 """ -3346 Set hints for this expression. -3347 -3348 Examples: -3349 >>> Select().select("x").from_("tbl").hint("BROADCAST(y)").sql(dialect="spark") -3350 'SELECT /*+ BROADCAST(y) */ x FROM tbl' -3351 -3352 Args: -3353 hints: The SQL code strings to parse as the hints. -3354 If an `Expression` instance is passed, it will be used as-is. -3355 dialect: The dialect used to parse the hints. -3356 copy: If `False`, modify this expression instance in-place. -3357 -3358 Returns: -3359 The modified expression. -3360 """ -3361 inst = maybe_copy(self, copy) -3362 inst.set( -3363 "hint", Hint(expressions=[maybe_parse(h, copy=copy, dialect=dialect) for h in hints]) -3364 ) -3365 -3366 return inst +@@ -40738,47 +41106,47 @@ If an3357 def hint(self, *hints: ExpOrStr, dialect: DialectType = None, copy: bool = True) -> Select: +3358 """ +3359 Set hints for this expression. +3360 +3361 Examples: +3362 >>> Select().select("x").from_("tbl").hint("BROADCAST(y)").sql(dialect="spark") +3363 'SELECT /*+ BROADCAST(y) */ x FROM tbl' +3364 +3365 Args: +3366 hints: The SQL code strings to parse as the hints. +3367 If an `Expression` instance is passed, it will be used as-is. +3368 dialect: The dialect used to parse the hints. +3369 copy: If `False`, modify this expression instance in-place. +3370 +3371 Returns: +3372 The modified expression. +3373 """ +3374 inst = maybe_copy(self, copy) +3375 inst.set( +3376 "hint", Hint(expressions=[maybe_parse(h, copy=copy, dialect=dialect) for h in hints]) +3377 ) +3378 +3379 return instExpression
instance is passed, it w-3381class Subquery(DerivedTable, Unionable): -3382 arg_types = { -3383 "this": True, -3384 "alias": False, -3385 "with": False, -3386 **QUERY_MODIFIERS, -3387 } -3388 -3389 def unnest(self): -3390 """ -3391 Returns the first non subquery. -3392 """ -3393 expression = self -3394 while isinstance(expression, Subquery): -3395 expression = expression.this -3396 return expression -3397 -3398 def unwrap(self) -> Subquery: -3399 expression = self -3400 while expression.same_parent and expression.is_wrapper: -3401 expression = t.cast(Subquery, expression.parent) -3402 return expression -3403 -3404 @property -3405 def is_wrapper(self) -> bool: -3406 """ -3407 Whether this Subquery acts as a simple wrapper around another expression. -3408 -3409 SELECT * FROM (((SELECT * FROM t))) -3410 ^ -3411 This corresponds to a "wrapper" Subquery node -3412 """ -3413 return all(v is None for k, v in self.args.items() if k != "this") -3414 -3415 @property -3416 def is_star(self) -> bool: -3417 return self.this.is_star -3418 -3419 @property -3420 def output_name(self) -> str: -3421 return self.alias +@@ -40808,14 +41176,14 @@ If an3394class Subquery(DerivedTable, Unionable): +3395 arg_types = { +3396 "this": True, +3397 "alias": False, +3398 "with": False, +3399 **QUERY_MODIFIERS, +3400 } +3401 +3402 def unnest(self): +3403 """ +3404 Returns the first non subquery. +3405 """ +3406 expression = self +3407 while isinstance(expression, Subquery): +3408 expression = expression.this +3409 return expression +3410 +3411 def unwrap(self) -> Subquery: +3412 expression = self +3413 while expression.same_parent and expression.is_wrapper: +3414 expression = t.cast(Subquery, expression.parent) +3415 return expression +3416 +3417 @property +3418 def is_wrapper(self) -> bool: +3419 """ +3420 Whether this Subquery acts as a simple wrapper around another expression. +3421 +3422 SELECT * FROM (((SELECT * FROM t))) +3423 ^ +3424 This corresponds to a "wrapper" Subquery node +3425 """ +3426 return all(v is None for k, v in self.args.items() if k != "this") +3427 +3428 @property +3429 def is_star(self) -> bool: +3430 return self.this.is_star +3431 +3432 @property +3433 def output_name(self) -> str: +3434 return self.aliasExpression
instance is passed, it w-3389 def unnest(self): -3390 """ -3391 Returns the first non subquery. -3392 """ -3393 expression = self -3394 while isinstance(expression, Subquery): -3395 expression = expression.this -3396 return expression +@@ -40835,11 +41203,11 @@ If an3402 def unnest(self): +3403 """ +3404 Returns the first non subquery. +3405 """ +3406 expression = self +3407 while isinstance(expression, Subquery): +3408 expression = expression.this +3409 return expressionExpression
instance is passed, it w-3398 def unwrap(self) -> Subquery: -3399 expression = self -3400 while expression.same_parent and expression.is_wrapper: -3401 expression = t.cast(Subquery, expression.parent) -3402 return expression +@@ -41006,20 +41374,20 @@ If an3411 def unwrap(self) -> Subquery: +3412 expression = self +3413 while expression.same_parent and expression.is_wrapper: +3414 expression = t.cast(Subquery, expression.parent) +3415 return expressionExpression
instance is passed, it w-3424class TableSample(Expression): -3425 arg_types = { -3426 "this": False, -3427 "expressions": False, -3428 "method": False, -3429 "bucket_numerator": False, -3430 "bucket_denominator": False, -3431 "bucket_field": False, -3432 "percent": False, -3433 "rows": False, -3434 "size": False, -3435 "seed": False, -3436 "kind": False, -3437 } +@@ -41130,14 +41498,14 @@ If an3437class TableSample(Expression): +3438 arg_types = { +3439 "this": False, +3440 "expressions": False, +3441 "method": False, +3442 "bucket_numerator": False, +3443 "bucket_denominator": False, +3444 "bucket_field": False, +3445 "percent": False, +3446 "rows": False, +3447 "size": False, +3448 "seed": False, +3449 "kind": False, +3450 }Expression
instance is passed, it w-3440class Tag(Expression): -3441 """Tags are used for generating arbitrary sql like SELECT <span>x</span>.""" -3442 -3443 arg_types = { -3444 "this": False, -3445 "prefix": False, -3446 "postfix": False, -3447 } +@@ -41249,18 +41617,18 @@ If an3453class Tag(Expression): +3454 """Tags are used for generating arbitrary sql like SELECT <span>x</span>.""" +3455 +3456 arg_types = { +3457 "this": False, +3458 "prefix": False, +3459 "postfix": False, +3460 }Expression
instance is passed, it w-3452class Pivot(Expression): -3453 arg_types = { -3454 "this": False, -3455 "alias": False, -3456 "expressions": False, -3457 "field": False, -3458 "unpivot": False, -3459 "using": False, -3460 "group": False, -3461 "columns": False, -3462 "include_nulls": False, -3463 } +@@ -41371,16 +41739,16 @@ If an3465class Pivot(Expression): +3466 arg_types = { +3467 "this": False, +3468 "alias": False, +3469 "expressions": False, +3470 "field": False, +3471 "unpivot": False, +3472 "using": False, +3473 "group": False, +3474 "columns": False, +3475 "include_nulls": False, +3476 }Expression
instance is passed, it w-3466class Window(Condition): -3467 arg_types = { -3468 "this": True, -3469 "partition_by": False, -3470 "order": False, -3471 "spec": False, -3472 "alias": False, -3473 "over": False, -3474 "first": False, -3475 } +@@ -41491,14 +41859,14 @@ If an3479class Window(Condition): +3480 arg_types = { +3481 "this": True, +3482 "partition_by": False, +3483 "order": False, +3484 "spec": False, +3485 "alias": False, +3486 "over": False, +3487 "first": False, +3488 }Expression
instance is passed, it w-3478class WindowSpec(Expression): -3479 arg_types = { -3480 "kind": False, -3481 "start": False, -3482 "start_side": False, -3483 "end": False, -3484 "end_side": False, -3485 } +@@ -41608,8 +41976,8 @@ If an3491class WindowSpec(Expression): +3492 arg_types = { +3493 "kind": False, +3494 "start": False, +3495 "start_side": False, +3496 "end": False, +3497 "end_side": False, +3498 }Expression
instance is passed, it w-3488class Where(Expression): -3489 pass + @@ -41708,16 +42076,16 @@ If anExpression
instance is passed, it w-3492class Star(Expression): -3493 arg_types = {"except": False, "replace": False} -3494 -3495 @property -3496 def name(self) -> str: -3497 return "*" -3498 -3499 @property -3500 def output_name(self) -> str: -3501 return self.name +@@ -41866,8 +42234,8 @@ If an3505class Star(Expression): +3506 arg_types = {"except": False, "replace": False} +3507 +3508 @property +3509 def name(self) -> str: +3510 return "*" +3511 +3512 @property +3513 def output_name(self) -> str: +3514 return self.nameExpression
instance is passed, it w3504class Parameter(Condition): -3505 arg_types = {"this": True, "wrapped": False} + @@ -41876,7 +42244,7 @@ If anExpression
instance is passed, it w-arg_types = -{'this': True, 'wrapped': False} +{'this': True, 'expression': False}@@ -41977,8 +42345,8 @@ If anExpression
instance is passed, it w-3508class SessionParameter(Condition): -3509 arg_types = {"this": True, "kind": False} + @@ -42088,8 +42456,8 @@ If anExpression
instance is passed, it w-3512class Placeholder(Condition): -3513 arg_types = {"this": False, "kind": False} + @@ -42199,12 +42567,12 @@ If anExpression
instance is passed, it w-3516class Null(Condition): -3517 arg_types: t.Dict[str, t.Any] = {} -3518 -3519 @property -3520 def name(self) -> str: -3521 return "NULL" +@@ -42324,8 +42692,8 @@ If an3529class Null(Condition): +3530 arg_types: t.Dict[str, t.Any] = {} +3531 +3532 @property +3533 def name(self) -> str: +3534 return "NULL"Expression
instance is passed, it w-3524class Boolean(Condition): -3525 pass + @@ -42424,8 +42792,8 @@ If anExpression
instance is passed, it w-3528class DataTypeParam(Expression): -3529 arg_types = {"this": True, "expression": False} + @@ -42535,224 +42903,224 @@ If anExpression
instance is passed, it w-3532class DataType(Expression): -3533 arg_types = { -3534 "this": True, -3535 "expressions": False, -3536 "nested": False, -3537 "values": False, -3538 "prefix": False, -3539 "kind": False, -3540 } -3541 -3542 class Type(AutoName): -3543 ARRAY = auto() -3544 BIGDECIMAL = auto() -3545 BIGINT = auto() -3546 BIGSERIAL = auto() -3547 BINARY = auto() -3548 BIT = auto() -3549 BOOLEAN = auto() -3550 CHAR = auto() -3551 DATE = auto() -3552 DATEMULTIRANGE = auto() -3553 DATERANGE = auto() -3554 DATETIME = auto() -3555 DATETIME64 = auto() -3556 DECIMAL = auto() -3557 DOUBLE = auto() -3558 ENUM = auto() -3559 ENUM8 = auto() -3560 ENUM16 = auto() -3561 FIXEDSTRING = auto() -3562 FLOAT = auto() -3563 GEOGRAPHY = auto() -3564 GEOMETRY = auto() -3565 HLLSKETCH = auto() -3566 HSTORE = auto() -3567 IMAGE = auto() -3568 INET = auto() -3569 INT = auto() -3570 INT128 = auto() -3571 INT256 = auto() -3572 INT4MULTIRANGE = auto() -3573 INT4RANGE = auto() -3574 INT8MULTIRANGE = auto() -3575 INT8RANGE = auto() -3576 INTERVAL = auto() -3577 IPADDRESS = auto() -3578 IPPREFIX = auto() -3579 JSON = auto() -3580 JSONB = auto() -3581 LONGBLOB = auto() -3582 LONGTEXT = auto() -3583 LOWCARDINALITY = auto() -3584 MAP = auto() -3585 MEDIUMBLOB = auto() -3586 MEDIUMINT = auto() -3587 MEDIUMTEXT = auto() -3588 MONEY = auto() -3589 NCHAR = auto() -3590 NESTED = auto() -3591 NULL = auto() -3592 NULLABLE = auto() -3593 NUMMULTIRANGE = auto() -3594 NUMRANGE = auto() -3595 NVARCHAR = auto() -3596 OBJECT = auto() -3597 ROWVERSION = auto() -3598 SERIAL = auto() -3599 SET = auto() -3600 SMALLINT = auto() -3601 SMALLMONEY = auto() -3602 SMALLSERIAL = auto() -3603 STRUCT = auto() -3604 SUPER = auto() -3605 TEXT = auto() -3606 TINYBLOB = auto() -3607 TINYTEXT = auto() -3608 TIME = auto() -3609 TIMETZ = auto() -3610 TIMESTAMP = auto() -3611 TIMESTAMPLTZ = auto() -3612 TIMESTAMPTZ = auto() -3613 TIMESTAMP_S = auto() -3614 TIMESTAMP_MS = auto() -3615 TIMESTAMP_NS = auto() -3616 TINYINT = auto() -3617 TSMULTIRANGE = auto() -3618 TSRANGE = auto() -3619 TSTZMULTIRANGE = auto() -3620 TSTZRANGE = auto() -3621 UBIGINT = auto() -3622 UINT = auto() -3623 UINT128 = auto() -3624 UINT256 = auto() -3625 UMEDIUMINT = auto() -3626 UDECIMAL = auto() -3627 UNIQUEIDENTIFIER = auto() -3628 UNKNOWN = auto() # Sentinel value, useful for type annotation -3629 USERDEFINED = "USER-DEFINED" -3630 USMALLINT = auto() -3631 UTINYINT = auto() -3632 UUID = auto() -3633 VARBINARY = auto() -3634 VARCHAR = auto() -3635 VARIANT = auto() -3636 XML = auto() -3637 YEAR = auto() -3638 -3639 TEXT_TYPES = { -3640 Type.CHAR, -3641 Type.NCHAR, -3642 Type.VARCHAR, -3643 Type.NVARCHAR, -3644 Type.TEXT, -3645 } -3646 -3647 INTEGER_TYPES = { -3648 Type.INT, -3649 Type.TINYINT, -3650 Type.SMALLINT, -3651 Type.BIGINT, -3652 Type.INT128, -3653 Type.INT256, -3654 } -3655 -3656 FLOAT_TYPES = { -3657 Type.FLOAT, -3658 Type.DOUBLE, -3659 } -3660 -3661 NUMERIC_TYPES = { -3662 *INTEGER_TYPES, -3663 *FLOAT_TYPES, -3664 } -3665 -3666 TEMPORAL_TYPES = { -3667 Type.TIME, -3668 Type.TIMETZ, -3669 Type.TIMESTAMP, -3670 Type.TIMESTAMPTZ, -3671 Type.TIMESTAMPLTZ, -3672 Type.TIMESTAMP_S, -3673 Type.TIMESTAMP_MS, -3674 Type.TIMESTAMP_NS, -3675 Type.DATE, -3676 Type.DATETIME, -3677 Type.DATETIME64, -3678 } -3679 -3680 @classmethod -3681 def build( -3682 cls, -3683 dtype: str | DataType | DataType.Type, -3684 dialect: DialectType = None, -3685 udt: bool = False, -3686 **kwargs, -3687 ) -> DataType: -3688 """ -3689 Constructs a DataType object. -3690 -3691 Args: -3692 dtype: the data type of interest. -3693 dialect: the dialect to use for parsing `dtype`, in case it's a string. -3694 udt: when set to True, `dtype` will be used as-is if it can't be parsed into a -3695 DataType, thus creating a user-defined type. -3696 kawrgs: additional arguments to pass in the constructor of DataType. -3697 -3698 Returns: -3699 The constructed DataType object. -3700 """ -3701 from sqlglot import parse_one -3702 -3703 if isinstance(dtype, str): -3704 if dtype.upper() == "UNKNOWN": -3705 return DataType(this=DataType.Type.UNKNOWN, **kwargs) -3706 -3707 try: -3708 data_type_exp = parse_one( -3709 dtype, read=dialect, into=DataType, error_level=ErrorLevel.IGNORE -3710 ) -3711 except ParseError: -3712 if udt: -3713 return DataType(this=DataType.Type.USERDEFINED, kind=dtype, **kwargs) -3714 raise -3715 elif isinstance(dtype, DataType.Type): -3716 data_type_exp = DataType(this=dtype) -3717 elif isinstance(dtype, DataType): -3718 return dtype -3719 else: -3720 raise ValueError(f"Invalid data type: {type(dtype)}. Expected str or DataType.Type") -3721 -3722 return DataType(**{**data_type_exp.args, **kwargs}) -3723 -3724 def is_type(self, *dtypes: str | DataType | DataType.Type) -> bool: -3725 """ -3726 Checks whether this DataType matches one of the provided data types. Nested types or precision -3727 will be compared using "structural equivalence" semantics, so e.g. array<int> != array<float>. -3728 -3729 Args: -3730 dtypes: the data types to compare this DataType to. -3731 -3732 Returns: -3733 True, if and only if there is a type in `dtypes` which is equal to this DataType. -3734 """ -3735 for dtype in dtypes: -3736 other = DataType.build(dtype, udt=True) -3737 -3738 if ( -3739 other.expressions -3740 or self.this == DataType.Type.USERDEFINED -3741 or other.this == DataType.Type.USERDEFINED -3742 ): -3743 matches = self == other -3744 else: -3745 matches = self.this == other.this -3746 -3747 if matches: -3748 return True -3749 return False +@@ -42775,7 +43143,7 @@ If an3545class DataType(Expression): +3546 arg_types = { +3547 "this": True, +3548 "expressions": False, +3549 "nested": False, +3550 "values": False, +3551 "prefix": False, +3552 "kind": False, +3553 } +3554 +3555 class Type(AutoName): +3556 ARRAY = auto() +3557 BIGDECIMAL = auto() +3558 BIGINT = auto() +3559 BIGSERIAL = auto() +3560 BINARY = auto() +3561 BIT = auto() +3562 BOOLEAN = auto() +3563 CHAR = auto() +3564 DATE = auto() +3565 DATEMULTIRANGE = auto() +3566 DATERANGE = auto() +3567 DATETIME = auto() +3568 DATETIME64 = auto() +3569 DECIMAL = auto() +3570 DOUBLE = auto() +3571 ENUM = auto() +3572 ENUM8 = auto() +3573 ENUM16 = auto() +3574 FIXEDSTRING = auto() +3575 FLOAT = auto() +3576 GEOGRAPHY = auto() +3577 GEOMETRY = auto() +3578 HLLSKETCH = auto() +3579 HSTORE = auto() +3580 IMAGE = auto() +3581 INET = auto() +3582 INT = auto() +3583 INT128 = auto() +3584 INT256 = auto() +3585 INT4MULTIRANGE = auto() +3586 INT4RANGE = auto() +3587 INT8MULTIRANGE = auto() +3588 INT8RANGE = auto() +3589 INTERVAL = auto() +3590 IPADDRESS = auto() +3591 IPPREFIX = auto() +3592 JSON = auto() +3593 JSONB = auto() +3594 LONGBLOB = auto() +3595 LONGTEXT = auto() +3596 LOWCARDINALITY = auto() +3597 MAP = auto() +3598 MEDIUMBLOB = auto() +3599 MEDIUMINT = auto() +3600 MEDIUMTEXT = auto() +3601 MONEY = auto() +3602 NCHAR = auto() +3603 NESTED = auto() +3604 NULL = auto() +3605 NULLABLE = auto() +3606 NUMMULTIRANGE = auto() +3607 NUMRANGE = auto() +3608 NVARCHAR = auto() +3609 OBJECT = auto() +3610 ROWVERSION = auto() +3611 SERIAL = auto() +3612 SET = auto() +3613 SMALLINT = auto() +3614 SMALLMONEY = auto() +3615 SMALLSERIAL = auto() +3616 STRUCT = auto() +3617 SUPER = auto() +3618 TEXT = auto() +3619 TINYBLOB = auto() +3620 TINYTEXT = auto() +3621 TIME = auto() +3622 TIMETZ = auto() +3623 TIMESTAMP = auto() +3624 TIMESTAMPLTZ = auto() +3625 TIMESTAMPTZ = auto() +3626 TIMESTAMP_S = auto() +3627 TIMESTAMP_MS = auto() +3628 TIMESTAMP_NS = auto() +3629 TINYINT = auto() +3630 TSMULTIRANGE = auto() +3631 TSRANGE = auto() +3632 TSTZMULTIRANGE = auto() +3633 TSTZRANGE = auto() +3634 UBIGINT = auto() +3635 UINT = auto() +3636 UINT128 = auto() +3637 UINT256 = auto() +3638 UMEDIUMINT = auto() +3639 UDECIMAL = auto() +3640 UNIQUEIDENTIFIER = auto() +3641 UNKNOWN = auto() # Sentinel value, useful for type annotation +3642 USERDEFINED = "USER-DEFINED" +3643 USMALLINT = auto() +3644 UTINYINT = auto() +3645 UUID = auto() +3646 VARBINARY = auto() +3647 VARCHAR = auto() +3648 VARIANT = auto() +3649 XML = auto() +3650 YEAR = auto() +3651 +3652 TEXT_TYPES = { +3653 Type.CHAR, +3654 Type.NCHAR, +3655 Type.VARCHAR, +3656 Type.NVARCHAR, +3657 Type.TEXT, +3658 } +3659 +3660 INTEGER_TYPES = { +3661 Type.INT, +3662 Type.TINYINT, +3663 Type.SMALLINT, +3664 Type.BIGINT, +3665 Type.INT128, +3666 Type.INT256, +3667 } +3668 +3669 FLOAT_TYPES = { +3670 Type.FLOAT, +3671 Type.DOUBLE, +3672 } +3673 +3674 NUMERIC_TYPES = { +3675 *INTEGER_TYPES, +3676 *FLOAT_TYPES, +3677 } +3678 +3679 TEMPORAL_TYPES = { +3680 Type.TIME, +3681 Type.TIMETZ, +3682 Type.TIMESTAMP, +3683 Type.TIMESTAMPTZ, +3684 Type.TIMESTAMPLTZ, +3685 Type.TIMESTAMP_S, +3686 Type.TIMESTAMP_MS, +3687 Type.TIMESTAMP_NS, +3688 Type.DATE, +3689 Type.DATETIME, +3690 Type.DATETIME64, +3691 } +3692 +3693 @classmethod +3694 def build( +3695 cls, +3696 dtype: str | DataType | DataType.Type, +3697 dialect: DialectType = None, +3698 udt: bool = False, +3699 **kwargs, +3700 ) -> DataType: +3701 """ +3702 Constructs a DataType object. +3703 +3704 Args: +3705 dtype: the data type of interest. +3706 dialect: the dialect to use for parsing `dtype`, in case it's a string. +3707 udt: when set to True, `dtype` will be used as-is if it can't be parsed into a +3708 DataType, thus creating a user-defined type. +3709 kawrgs: additional arguments to pass in the constructor of DataType. +3710 +3711 Returns: +3712 The constructed DataType object. +3713 """ +3714 from sqlglot import parse_one +3715 +3716 if isinstance(dtype, str): +3717 if dtype.upper() == "UNKNOWN": +3718 return DataType(this=DataType.Type.UNKNOWN, **kwargs) +3719 +3720 try: +3721 data_type_exp = parse_one( +3722 dtype, read=dialect, into=DataType, error_level=ErrorLevel.IGNORE +3723 ) +3724 except ParseError: +3725 if udt: +3726 return DataType(this=DataType.Type.USERDEFINED, kind=dtype, **kwargs) +3727 raise +3728 elif isinstance(dtype, DataType.Type): +3729 data_type_exp = DataType(this=dtype) +3730 elif isinstance(dtype, DataType): +3731 return dtype +3732 else: +3733 raise ValueError(f"Invalid data type: {type(dtype)}. Expected str or DataType.Type") +3734 +3735 return DataType(**{**data_type_exp.args, **kwargs}) +3736 +3737 def is_type(self, *dtypes: str | DataType | DataType.Type) -> bool: +3738 """ +3739 Checks whether this DataType matches one of the provided data types. Nested types or precision +3740 will be compared using "structural equivalence" semantics, so e.g. array<int> != array<float>. +3741 +3742 Args: +3743 dtypes: the data types to compare this DataType to. +3744 +3745 Returns: +3746 True, if and only if there is a type in `dtypes` which is equal to this DataType. +3747 """ +3748 for dtype in dtypes: +3749 other = DataType.build(dtype, udt=True) +3750 +3751 if ( +3752 other.expressions +3753 or self.this == DataType.Type.USERDEFINED +3754 or other.this == DataType.Type.USERDEFINED +3755 ): +3756 matches = self == other +3757 else: +3758 matches = self.this == other.this +3759 +3760 if matches: +3761 return True +3762 return FalseExpression
instance is passed, it wTEXT_TYPES = - {<Type.CHAR: 'CHAR'>, <Type.TEXT: 'TEXT'>, <Type.NVARCHAR: 'NVARCHAR'>, <Type.NCHAR: 'NCHAR'>, <Type.VARCHAR: 'VARCHAR'>} + {<Type.TEXT: 'TEXT'>, <Type.NVARCHAR: 'NVARCHAR'>, <Type.NCHAR: 'NCHAR'>, <Type.VARCHAR: 'VARCHAR'>, <Type.CHAR: 'CHAR'>}@@ -42788,7 +43156,7 @@ If anExpression
instance is passed, it wINTEGER_TYPES = - {<Type.SMALLINT: 'SMALLINT'>, <Type.INT: 'INT'>, <Type.TINYINT: 'TINYINT'>, <Type.INT256: 'INT256'>, <Type.BIGINT: 'BIGINT'>, <Type.INT128: 'INT128'>} + {<Type.INT256: 'INT256'>, <Type.SMALLINT: 'SMALLINT'>, <Type.INT128: 'INT128'>, <Type.BIGINT: 'BIGINT'>, <Type.TINYINT: 'TINYINT'>, <Type.INT: 'INT'>}@@ -42800,7 +43168,7 @@ If anExpression
instance is passed, it w-FLOAT_TYPES = -{<Type.FLOAT: 'FLOAT'>, <Type.DOUBLE: 'DOUBLE'>} +{<Type.DOUBLE: 'DOUBLE'>, <Type.FLOAT: 'FLOAT'>}@@ -42813,7 +43181,7 @@ If anExpression
instance is passed, it wNUMERIC_TYPES = - {<Type.FLOAT: 'FLOAT'>, <Type.SMALLINT: 'SMALLINT'>, <Type.BIGINT: 'BIGINT'>, <Type.DOUBLE: 'DOUBLE'>, <Type.INT: 'INT'>, <Type.INT128: 'INT128'>, <Type.TINYINT: 'TINYINT'>, <Type.INT256: 'INT256'>} + {<Type.INT256: 'INT256'>, <Type.SMALLINT: 'SMALLINT'>, <Type.INT: 'INT'>, <Type.INT128: 'INT128'>, <Type.BIGINT: 'BIGINT'>, <Type.TINYINT: 'TINYINT'>, <Type.DOUBLE: 'DOUBLE'>, <Type.FLOAT: 'FLOAT'>}@@ -42826,7 +43194,7 @@ If anExpression
instance is passed, it wTEMPORAL_TYPES = - {<Type.TIMETZ: 'TIMETZ'>, <Type.TIMESTAMP: 'TIMESTAMP'>, <Type.DATETIME: 'DATETIME'>, <Type.TIME: 'TIME'>, <Type.TIMESTAMPLTZ: 'TIMESTAMPLTZ'>, <Type.TIMESTAMP_S: 'TIMESTAMP_S'>, <Type.DATETIME64: 'DATETIME64'>, <Type.TIMESTAMP_NS: 'TIMESTAMP_NS'>, <Type.TIMESTAMPTZ: 'TIMESTAMPTZ'>, <Type.TIMESTAMP_MS: 'TIMESTAMP_MS'>, <Type.DATE: 'DATE'>} + {<Type.TIMESTAMP_NS: 'TIMESTAMP_NS'>, <Type.DATE: 'DATE'>, <Type.TIME: 'TIME'>, <Type.TIMESTAMP_MS: 'TIMESTAMP_MS'>, <Type.TIMESTAMP: 'TIMESTAMP'>, <Type.TIMESTAMPTZ: 'TIMESTAMPTZ'>, <Type.TIMESTAMPLTZ: 'TIMESTAMPLTZ'>, <Type.TIMETZ: 'TIMETZ'>, <Type.TIMESTAMP_S: 'TIMESTAMP_S'>, <Type.DATETIME: 'DATETIME'>, <Type.DATETIME64: 'DATETIME64'>}@@ -42847,49 +43215,49 @@ If anExpression
instance is passed, it w-3680 @classmethod -3681 def build( -3682 cls, -3683 dtype: str | DataType | DataType.Type, -3684 dialect: DialectType = None, -3685 udt: bool = False, -3686 **kwargs, -3687 ) -> DataType: -3688 """ -3689 Constructs a DataType object. -3690 -3691 Args: -3692 dtype: the data type of interest. -3693 dialect: the dialect to use for parsing `dtype`, in case it's a string. -3694 udt: when set to True, `dtype` will be used as-is if it can't be parsed into a -3695 DataType, thus creating a user-defined type. -3696 kawrgs: additional arguments to pass in the constructor of DataType. -3697 -3698 Returns: -3699 The constructed DataType object. -3700 """ -3701 from sqlglot import parse_one -3702 -3703 if isinstance(dtype, str): -3704 if dtype.upper() == "UNKNOWN": -3705 return DataType(this=DataType.Type.UNKNOWN, **kwargs) -3706 -3707 try: -3708 data_type_exp = parse_one( -3709 dtype, read=dialect, into=DataType, error_level=ErrorLevel.IGNORE -3710 ) -3711 except ParseError: -3712 if udt: -3713 return DataType(this=DataType.Type.USERDEFINED, kind=dtype, **kwargs) -3714 raise -3715 elif isinstance(dtype, DataType.Type): -3716 data_type_exp = DataType(this=dtype) -3717 elif isinstance(dtype, DataType): -3718 return dtype -3719 else: -3720 raise ValueError(f"Invalid data type: {type(dtype)}. Expected str or DataType.Type") -3721 -3722 return DataType(**{**data_type_exp.args, **kwargs}) +@@ -42925,32 +43293,32 @@ DataType, thus creating a user-defined type.3693 @classmethod +3694 def build( +3695 cls, +3696 dtype: str | DataType | DataType.Type, +3697 dialect: DialectType = None, +3698 udt: bool = False, +3699 **kwargs, +3700 ) -> DataType: +3701 """ +3702 Constructs a DataType object. +3703 +3704 Args: +3705 dtype: the data type of interest. +3706 dialect: the dialect to use for parsing `dtype`, in case it's a string. +3707 udt: when set to True, `dtype` will be used as-is if it can't be parsed into a +3708 DataType, thus creating a user-defined type. +3709 kawrgs: additional arguments to pass in the constructor of DataType. +3710 +3711 Returns: +3712 The constructed DataType object. +3713 """ +3714 from sqlglot import parse_one +3715 +3716 if isinstance(dtype, str): +3717 if dtype.upper() == "UNKNOWN": +3718 return DataType(this=DataType.Type.UNKNOWN, **kwargs) +3719 +3720 try: +3721 data_type_exp = parse_one( +3722 dtype, read=dialect, into=DataType, error_level=ErrorLevel.IGNORE +3723 ) +3724 except ParseError: +3725 if udt: +3726 return DataType(this=DataType.Type.USERDEFINED, kind=dtype, **kwargs) +3727 raise +3728 elif isinstance(dtype, DataType.Type): +3729 data_type_exp = DataType(this=dtype) +3730 elif isinstance(dtype, DataType): +3731 return dtype +3732 else: +3733 raise ValueError(f"Invalid data type: {type(dtype)}. Expected str or DataType.Type") +3734 +3735 return DataType(**{**data_type_exp.args, **kwargs})-3724 def is_type(self, *dtypes: str | DataType | DataType.Type) -> bool: -3725 """ -3726 Checks whether this DataType matches one of the provided data types. Nested types or precision -3727 will be compared using "structural equivalence" semantics, so e.g. array<int> != array<float>. -3728 -3729 Args: -3730 dtypes: the data types to compare this DataType to. -3731 -3732 Returns: -3733 True, if and only if there is a type in `dtypes` which is equal to this DataType. -3734 """ -3735 for dtype in dtypes: -3736 other = DataType.build(dtype, udt=True) -3737 -3738 if ( -3739 other.expressions -3740 or self.this == DataType.Type.USERDEFINED -3741 or other.this == DataType.Type.USERDEFINED -3742 ): -3743 matches = self == other -3744 else: -3745 matches = self.this == other.this -3746 -3747 if matches: -3748 return True -3749 return False +@@ -43064,102 +43432,102 @@ will be compared using "structural equivalence" semantics, so e.g. array3737 def is_type(self, *dtypes: str | DataType | DataType.Type) -> bool: +3738 """ +3739 Checks whether this DataType matches one of the provided data types. Nested types or precision +3740 will be compared using "structural equivalence" semantics, so e.g. array<int> != array<float>. +3741 +3742 Args: +3743 dtypes: the data types to compare this DataType to. +3744 +3745 Returns: +3746 True, if and only if there is a type in `dtypes` which is equal to this DataType. +3747 """ +3748 for dtype in dtypes: +3749 other = DataType.build(dtype, udt=True) +3750 +3751 if ( +3752 other.expressions +3753 or self.this == DataType.Type.USERDEFINED +3754 or other.this == DataType.Type.USERDEFINED +3755 ): +3756 matches = self == other +3757 else: +3758 matches = self.this == other.this +3759 +3760 if matches: +3761 return True +3762 return False!= -3542 class Type(AutoName): -3543 ARRAY = auto() -3544 BIGDECIMAL = auto() -3545 BIGINT = auto() -3546 BIGSERIAL = auto() -3547 BINARY = auto() -3548 BIT = auto() -3549 BOOLEAN = auto() -3550 CHAR = auto() -3551 DATE = auto() -3552 DATEMULTIRANGE = auto() -3553 DATERANGE = auto() -3554 DATETIME = auto() -3555 DATETIME64 = auto() -3556 DECIMAL = auto() -3557 DOUBLE = auto() -3558 ENUM = auto() -3559 ENUM8 = auto() -3560 ENUM16 = auto() -3561 FIXEDSTRING = auto() -3562 FLOAT = auto() -3563 GEOGRAPHY = auto() -3564 GEOMETRY = auto() -3565 HLLSKETCH = auto() -3566 HSTORE = auto() -3567 IMAGE = auto() -3568 INET = auto() -3569 INT = auto() -3570 INT128 = auto() -3571 INT256 = auto() -3572 INT4MULTIRANGE = auto() -3573 INT4RANGE = auto() -3574 INT8MULTIRANGE = auto() -3575 INT8RANGE = auto() -3576 INTERVAL = auto() -3577 IPADDRESS = auto() -3578 IPPREFIX = auto() -3579 JSON = auto() -3580 JSONB = auto() -3581 LONGBLOB = auto() -3582 LONGTEXT = auto() -3583 LOWCARDINALITY = auto() -3584 MAP = auto() -3585 MEDIUMBLOB = auto() -3586 MEDIUMINT = auto() -3587 MEDIUMTEXT = auto() -3588 MONEY = auto() -3589 NCHAR = auto() -3590 NESTED = auto() -3591 NULL = auto() -3592 NULLABLE = auto() -3593 NUMMULTIRANGE = auto() -3594 NUMRANGE = auto() -3595 NVARCHAR = auto() -3596 OBJECT = auto() -3597 ROWVERSION = auto() -3598 SERIAL = auto() -3599 SET = auto() -3600 SMALLINT = auto() -3601 SMALLMONEY = auto() -3602 SMALLSERIAL = auto() -3603 STRUCT = auto() -3604 SUPER = auto() -3605 TEXT = auto() -3606 TINYBLOB = auto() -3607 TINYTEXT = auto() -3608 TIME = auto() -3609 TIMETZ = auto() -3610 TIMESTAMP = auto() -3611 TIMESTAMPLTZ = auto() -3612 TIMESTAMPTZ = auto() -3613 TIMESTAMP_S = auto() -3614 TIMESTAMP_MS = auto() -3615 TIMESTAMP_NS = auto() -3616 TINYINT = auto() -3617 TSMULTIRANGE = auto() -3618 TSRANGE = auto() -3619 TSTZMULTIRANGE = auto() -3620 TSTZRANGE = auto() -3621 UBIGINT = auto() -3622 UINT = auto() -3623 UINT128 = auto() -3624 UINT256 = auto() -3625 UMEDIUMINT = auto() -3626 UDECIMAL = auto() -3627 UNIQUEIDENTIFIER = auto() -3628 UNKNOWN = auto() # Sentinel value, useful for type annotation -3629 USERDEFINED = "USER-DEFINED" -3630 USMALLINT = auto() -3631 UTINYINT = auto() -3632 UUID = auto() -3633 VARBINARY = auto() -3634 VARCHAR = auto() -3635 VARIANT = auto() -3636 XML = auto() -3637 YEAR = auto() +@@ -44329,8 +44697,8 @@ will be compared using "structural equivalence" semantics, so e.g. array3555 class Type(AutoName): +3556 ARRAY = auto() +3557 BIGDECIMAL = auto() +3558 BIGINT = auto() +3559 BIGSERIAL = auto() +3560 BINARY = auto() +3561 BIT = auto() +3562 BOOLEAN = auto() +3563 CHAR = auto() +3564 DATE = auto() +3565 DATEMULTIRANGE = auto() +3566 DATERANGE = auto() +3567 DATETIME = auto() +3568 DATETIME64 = auto() +3569 DECIMAL = auto() +3570 DOUBLE = auto() +3571 ENUM = auto() +3572 ENUM8 = auto() +3573 ENUM16 = auto() +3574 FIXEDSTRING = auto() +3575 FLOAT = auto() +3576 GEOGRAPHY = auto() +3577 GEOMETRY = auto() +3578 HLLSKETCH = auto() +3579 HSTORE = auto() +3580 IMAGE = auto() +3581 INET = auto() +3582 INT = auto() +3583 INT128 = auto() +3584 INT256 = auto() +3585 INT4MULTIRANGE = auto() +3586 INT4RANGE = auto() +3587 INT8MULTIRANGE = auto() +3588 INT8RANGE = auto() +3589 INTERVAL = auto() +3590 IPADDRESS = auto() +3591 IPPREFIX = auto() +3592 JSON = auto() +3593 JSONB = auto() +3594 LONGBLOB = auto() +3595 LONGTEXT = auto() +3596 LOWCARDINALITY = auto() +3597 MAP = auto() +3598 MEDIUMBLOB = auto() +3599 MEDIUMINT = auto() +3600 MEDIUMTEXT = auto() +3601 MONEY = auto() +3602 NCHAR = auto() +3603 NESTED = auto() +3604 NULL = auto() +3605 NULLABLE = auto() +3606 NUMMULTIRANGE = auto() +3607 NUMRANGE = auto() +3608 NVARCHAR = auto() +3609 OBJECT = auto() +3610 ROWVERSION = auto() +3611 SERIAL = auto() +3612 SET = auto() +3613 SMALLINT = auto() +3614 SMALLMONEY = auto() +3615 SMALLSERIAL = auto() +3616 STRUCT = auto() +3617 SUPER = auto() +3618 TEXT = auto() +3619 TINYBLOB = auto() +3620 TINYTEXT = auto() +3621 TIME = auto() +3622 TIMETZ = auto() +3623 TIMESTAMP = auto() +3624 TIMESTAMPLTZ = auto() +3625 TIMESTAMPTZ = auto() +3626 TIMESTAMP_S = auto() +3627 TIMESTAMP_MS = auto() +3628 TIMESTAMP_NS = auto() +3629 TINYINT = auto() +3630 TSMULTIRANGE = auto() +3631 TSRANGE = auto() +3632 TSTZMULTIRANGE = auto() +3633 TSTZRANGE = auto() +3634 UBIGINT = auto() +3635 UINT = auto() +3636 UINT128 = auto() +3637 UINT256 = auto() +3638 UMEDIUMINT = auto() +3639 UDECIMAL = auto() +3640 UNIQUEIDENTIFIER = auto() +3641 UNKNOWN = auto() # Sentinel value, useful for type annotation +3642 USERDEFINED = "USER-DEFINED" +3643 USMALLINT = auto() +3644 UTINYINT = auto() +3645 UUID = auto() +3646 VARBINARY = auto() +3647 VARCHAR = auto() +3648 VARIANT = auto() +3649 XML = auto() +3650 YEAR = auto()!= -3753class PseudoType(DataType): -3754 arg_types = {"this": True} + @@ -44451,8 +44819,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3758class ObjectIdentifier(DataType): -3759 arg_types = {"this": True} + @@ -44573,8 +44941,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3763class SubqueryPredicate(Predicate): -3764 pass + @@ -44673,8 +45041,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3767class All(SubqueryPredicate): -3768 pass + @@ -44773,8 +45141,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3771class Any(SubqueryPredicate): -3772 pass + @@ -44873,8 +45241,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3775class Exists(SubqueryPredicate): -3776 pass + @@ -44973,8 +45341,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3781class Command(Expression): -3782 arg_types = {"this": True, "expression": False} + @@ -45084,8 +45452,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3785class Transaction(Expression): -3786 arg_types = {"this": False, "modes": False, "mark": False} + @@ -45195,8 +45563,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3789class Commit(Expression): -3790 arg_types = {"chain": False, "this": False, "durability": False} +@@ -45306,8 +45674,8 @@ will be compared using "structural equivalence" semantics, so e.g. array3802class Commit(Expression): +3803 arg_types = {"chain": False, "this": False, "durability": False}!= -3793class Rollback(Expression): -3794 arg_types = {"savepoint": False, "this": False} + @@ -45417,8 +45785,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3797class AlterTable(Expression): -3798 arg_types = {"this": True, "actions": True, "exists": False, "only": False} +@@ -45528,8 +45896,8 @@ will be compared using "structural equivalence" semantics, so e.g. array3810class AlterTable(Expression): +3811 arg_types = {"this": True, "actions": True, "exists": False, "only": False}!= -3801class AddConstraint(Expression): -3802 arg_types = {"this": False, "expression": False, "enforced": False} +@@ -45639,8 +46007,8 @@ will be compared using "structural equivalence" semantics, so e.g. array3814class AddConstraint(Expression): +3815 arg_types = {"this": False, "expression": False, "enforced": False}!= -3805class DropPartition(Expression): -3806 arg_types = {"expressions": True, "exists": False} + @@ -45750,16 +46118,16 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3810class Binary(Condition): -3811 arg_types = {"this": True, "expression": True} -3812 -3813 @property -3814 def left(self) -> Expression: -3815 return self.this -3816 -3817 @property -3818 def right(self) -> Expression: -3819 return self.expression +@@ -45891,8 +46259,8 @@ will be compared using "structural equivalence" semantics, so e.g. array3823class Binary(Condition): +3824 arg_types = {"this": True, "expression": True} +3825 +3826 @property +3827 def left(self) -> Expression: +3828 return self.this +3829 +3830 @property +3831 def right(self) -> Expression: +3832 return self.expression!= -3822class Add(Binary): -3823 pass + @@ -45996,8 +46364,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3826class Connector(Binary): -3827 pass + @@ -46101,8 +46469,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3830class And(Connector): -3831 pass + @@ -46206,8 +46574,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3834class Or(Connector): -3835 pass + @@ -46311,8 +46679,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3838class BitwiseAnd(Binary): -3839 pass + @@ -46416,8 +46784,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3842class BitwiseLeftShift(Binary): -3843 pass + @@ -46521,8 +46889,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3846class BitwiseOr(Binary): -3847 pass + @@ -46626,8 +46994,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3850class BitwiseRightShift(Binary): -3851 pass + @@ -46731,8 +47099,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3854class BitwiseXor(Binary): -3855 pass + @@ -46836,8 +47204,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3858class Div(Binary): -3859 pass + @@ -46941,8 +47309,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3862class Overlaps(Binary): -3863 pass + @@ -47046,22 +47414,22 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3866class Dot(Binary): -3867 @property -3868 def name(self) -> str: -3869 return self.expression.name -3870 -3871 @property -3872 def output_name(self) -> str: -3873 return self.name -3874 -3875 @classmethod -3876 def build(self, expressions: t.Sequence[Expression]) -> Dot: -3877 """Build a Dot object with a sequence of expressions.""" -3878 if len(expressions) < 2: -3879 raise ValueError(f"Dot requires >= 2 expressions.") -3880 -3881 return t.cast(Dot, reduce(lambda x, y: Dot(this=x, expression=y), expressions)) +@@ -47120,13 +47488,13 @@ will be compared using "structural equivalence" semantics, so e.g. array3879class Dot(Binary): +3880 @property +3881 def name(self) -> str: +3882 return self.expression.name +3883 +3884 @property +3885 def output_name(self) -> str: +3886 return self.name +3887 +3888 @classmethod +3889 def build(self, expressions: t.Sequence[Expression]) -> Dot: +3890 """Build a Dot object with a sequence of expressions.""" +3891 if len(expressions) < 2: +3892 raise ValueError(f"Dot requires >= 2 expressions.") +3893 +3894 return t.cast(Dot, reduce(lambda x, y: Dot(this=x, expression=y), expressions))!= -3875 @classmethod -3876 def build(self, expressions: t.Sequence[Expression]) -> Dot: -3877 """Build a Dot object with a sequence of expressions.""" -3878 if len(expressions) < 2: -3879 raise ValueError(f"Dot requires >= 2 expressions.") -3880 -3881 return t.cast(Dot, reduce(lambda x, y: Dot(this=x, expression=y), expressions)) +@@ -47231,8 +47599,8 @@ will be compared using "structural equivalence" semantics, so e.g. array3888 @classmethod +3889 def build(self, expressions: t.Sequence[Expression]) -> Dot: +3890 """Build a Dot object with a sequence of expressions.""" +3891 if len(expressions) < 2: +3892 raise ValueError(f"Dot requires >= 2 expressions.") +3893 +3894 return t.cast(Dot, reduce(lambda x, y: Dot(this=x, expression=y), expressions))!= -3884class DPipe(Binary): -3885 pass + @@ -47336,8 +47704,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3888class SafeDPipe(DPipe): -3889 pass + @@ -47441,8 +47809,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3892class EQ(Binary, Predicate): -3893 pass + @@ -47546,8 +47914,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3896class NullSafeEQ(Binary, Predicate): -3897 pass + @@ -47651,8 +48019,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3900class NullSafeNEQ(Binary, Predicate): -3901 pass + @@ -47756,8 +48124,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3904class Distance(Binary): -3905 pass + @@ -47861,8 +48229,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3908class Escape(Binary): -3909 pass + @@ -47966,8 +48334,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3912class Glob(Binary, Predicate): -3913 pass + @@ -48071,8 +48439,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3916class GT(Binary, Predicate): -3917 pass + @@ -48176,8 +48544,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3920class GTE(Binary, Predicate): -3921 pass + @@ -48281,8 +48649,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3924class ILike(Binary, Predicate): -3925 pass + @@ -48386,8 +48754,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3928class ILikeAny(Binary, Predicate): -3929 pass + @@ -48491,8 +48859,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3932class IntDiv(Binary): -3933 pass + @@ -48596,8 +48964,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3936class Is(Binary, Predicate): -3937 pass + @@ -48701,8 +49069,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3940class Kwarg(Binary): -3941 """Kwarg in special functions like func(kwarg => y).""" + @@ -48808,8 +49176,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3944class Like(Binary, Predicate): -3945 pass + @@ -48913,8 +49281,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3948class LikeAny(Binary, Predicate): -3949 pass + @@ -49018,8 +49386,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3952class LT(Binary, Predicate): -3953 pass + @@ -49123,8 +49491,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3956class LTE(Binary, Predicate): -3957 pass + @@ -49228,8 +49596,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3960class Mod(Binary): -3961 pass + @@ -49333,8 +49701,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3964class Mul(Binary): -3965 pass + @@ -49438,8 +49806,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3968class NEQ(Binary, Predicate): -3969 pass + @@ -49543,8 +49911,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3972class SimilarTo(Binary, Predicate): -3973 pass + @@ -49648,8 +50016,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3976class Slice(Binary): -3977 arg_types = {"this": False, "expression": False} + @@ -49764,8 +50132,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3980class Sub(Binary): -3981 pass + @@ -49869,8 +50237,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3984class ArrayOverlaps(Binary): -3985 pass + @@ -49974,8 +50342,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3990class Unary(Condition): -3991 pass + @@ -50074,8 +50442,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3994class BitwiseNot(Unary): -3995 pass + @@ -50174,8 +50542,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -3998class Not(Unary): -3999 pass + @@ -50274,12 +50642,12 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -4002class Paren(Unary): -4003 arg_types = {"this": True, "with": False} -4004 -4005 @property -4006 def output_name(self) -> str: -4007 return self.this.name +@@ -50418,8 +50786,8 @@ will be compared using "structural equivalence" semantics, so e.g. array4015class Paren(Unary): +4016 arg_types = {"this": True, "with": False} +4017 +4018 @property +4019 def output_name(self) -> str: +4020 return self.this.name!= -4010class Neg(Unary): -4011 pass + @@ -50518,12 +50886,12 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -4014class Alias(Expression): -4015 arg_types = {"this": True, "alias": False} -4016 -4017 @property -4018 def output_name(self) -> str: -4019 return self.alias +@@ -50662,12 +51030,12 @@ will be compared using "structural equivalence" semantics, so e.g. array4027class Alias(Expression): +4028 arg_types = {"this": True, "alias": False} +4029 +4030 @property +4031 def output_name(self) -> str: +4032 return self.alias!= -4022class Aliases(Expression): -4023 arg_types = {"this": True, "expressions": True} -4024 -4025 @property -4026 def aliases(self): -4027 return self.expressions +@@ -50788,8 +51156,8 @@ will be compared using "structural equivalence" semantics, so e.g. array4035class Aliases(Expression): +4036 arg_types = {"this": True, "expressions": True} +4037 +4038 @property +4039 def aliases(self): +4040 return self.expressions!= -4030class AtTimeZone(Expression): -4031 arg_types = {"this": True, "zone": True} + @@ -50899,8 +51267,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -4034class Between(Predicate): -4035 arg_types = {"this": True, "low": True, "high": True} + @@ -51010,15 +51378,15 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -4038class Bracket(Condition): -4039 arg_types = {"this": True, "expressions": True} -4040 -4041 @property -4042 def output_name(self) -> str: -4043 if len(self.expressions) == 1: -4044 return self.expressions[0].output_name -4045 -4046 return super().output_name +@@ -51157,8 +51525,8 @@ will be compared using "structural equivalence" semantics, so e.g. array4051class Bracket(Condition): +4052 arg_types = {"this": True, "expressions": True} +4053 +4054 @property +4055 def output_name(self) -> str: +4056 if len(self.expressions) == 1: +4057 return self.expressions[0].output_name +4058 +4059 return super().output_name!= -4049class SafeBracket(Bracket): -4050 """Represents array lookup where OOB index yields NULL instead of causing a failure.""" +@@ -51262,8 +51630,8 @@ will be compared using "structural equivalence" semantics, so e.g. array4062class SafeBracket(Bracket): +4063 """Represents array lookup where OOB index yields NULL instead of causing a failure."""!= -4053class Distinct(Expression): -4054 arg_types = {"expressions": False, "on": False} + @@ -51373,15 +51741,15 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -4057class In(Predicate): -4058 arg_types = { -4059 "this": True, -4060 "expressions": False, -4061 "query": False, -4062 "unnest": False, -4063 "field": False, -4064 "is_global": False, -4065 } +@@ -51492,23 +51860,38 @@ will be compared using "structural equivalence" semantics, so e.g. array4070class In(Predicate): +4071 arg_types = { +4072 "this": True, +4073 "expressions": False, +4074 "query": False, +4075 "unnest": False, +4076 "field": False, +4077 "is_global": False, +4078 }!= -4068class TimeUnit(Expression): -4069 """Automatically converts unit arg into a var.""" -4070 -4071 arg_types = {"unit": False} -4072 -4073 def __init__(self, **args): -4074 unit = args.get("unit") -4075 if isinstance(unit, (Column, Literal)): -4076 args["unit"] = Var(this=unit.name) -4077 elif isinstance(unit, Week): -4078 unit.set("this", Var(this=unit.this.name)) -4079 -4080 super().__init__(**args) -4081 -4082 @property -4083 def unit(self) -> t.Optional[Var]: -4084 return self.args.get("unit") +@@ -51526,14 +51909,14 @@ will be compared using "structural equivalence" semantics, so e.g. array4081class TimeUnit(Expression): +4082 """Automatically converts unit arg into a var.""" +4083 +4084 arg_types = {"unit": False} +4085 +4086 UNABBREVIATED_UNIT_NAME = { +4087 "d": "day", +4088 "h": "hour", +4089 "m": "minute", +4090 "ms": "millisecond", +4091 "ns": "nanosecond", +4092 "q": "quarter", +4093 "s": "second", +4094 "us": "microsecond", +4095 "w": "week", +4096 "y": "year", +4097 } +4098 +4099 VAR_LIKE = (Column, Literal, Var) +4100 +4101 def __init__(self, **args): +4102 unit = args.get("unit") +4103 if isinstance(unit, self.VAR_LIKE): +4104 args["unit"] = Var(this=self.UNABBREVIATED_UNIT_NAME.get(unit.name) or unit.name) +4105 elif isinstance(unit, Week): +4106 unit.set("this", Var(this=unit.this.name)) +4107 +4108 super().__init__(**args) +4109 +4110 @property +4111 def unit(self) -> t.Optional[Var]: +4112 return self.args.get("unit")!= +4073 def __init__(self, **args): -4074 unit = args.get("unit") -4075 if isinstance(unit, (Column, Literal)): -4076 args["unit"] = Var(this=unit.name) -4077 elif isinstance(unit, Week): -4078 unit.set("this", Var(this=unit.this.name)) -4079 -4080 super().__init__(**args) +@@ -51551,6 +51934,32 @@ will be compared using "structural equivalence" semantics, so e.g. array4101 def __init__(self, **args): +4102 unit = args.get("unit") +4103 if isinstance(unit, self.VAR_LIKE): +4104 args["unit"] = Var(this=self.UNABBREVIATED_UNIT_NAME.get(unit.name) or unit.name) +4105 elif isinstance(unit, Week): +4106 unit.set("this", Var(this=unit.this.name)) +4107 +4108 super().__init__(**args)!= + +++ UNABBREVIATED_UNIT_NAME = + + {'d': 'day', 'h': 'hour', 'm': 'minute', 'ms': 'millisecond', 'ns': 'nanosecond', 'q': 'quarter', 's': 'second', 'us': 'microsecond', 'w': 'week', 'y': 'year'} + + ++ + + + ++ +@@ -51654,14 +52063,14 @@ will be compared using "structural equivalence" semantics, so e.g. array-!= -4087class IntervalOp(TimeUnit): -4088 arg_types = {"unit": True, "expression": True} -4089 -4090 def interval(self): -4091 return Interval( -4092 this=self.expression.copy(), -4093 unit=self.unit.copy(), -4094 ) +@@ -51690,11 +52099,11 @@ will be compared using "structural equivalence" semantics, so e.g. array4115class IntervalOp(TimeUnit): +4116 arg_types = {"unit": True, "expression": True} +4117 +4118 def interval(self): +4119 return Interval( +4120 this=self.expression.copy(), +4121 unit=self.unit.copy(), +4122 )!= -4090 def interval(self): -4091 return Interval( -4092 this=self.expression.copy(), -4093 unit=self.unit.copy(), -4094 ) +@@ -51718,6 +52127,8 @@ will be compared using "structural equivalence" semantics, so e.g. array4118 def interval(self): +4119 return Interval( +4120 this=self.expression.copy(), +4121 unit=self.unit.copy(), +4122 )!= @@ -51797,8 +52208,8 @@ will be compared using "structural equivalence" semantics, so e.g. array
!= -4100class IntervalSpan(DataType): -4101 arg_types = {"this": True, "expression": True} + @@ -51919,8 +52330,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -4104class Interval(TimeUnit): -4105 arg_types = {"this": False, "unit": False} + @@ -51955,6 +52366,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= @@ -52034,8 +52447,8 @@ will be compared using "structural equivalence" semantics, so e.g. array
!= -4108class IgnoreNulls(Expression): -4109 pass + @@ -52134,8 +52547,8 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -4112class RespectNulls(Expression): -4113 pass + @@ -52234,53 +52647,53 @@ will be compared using "structural equivalence" semantics, so e.g. array!= -4117class Func(Condition): -4118 """ -4119 The base class for all function expressions. -4120 -4121 Attributes: -4122 is_var_len_args (bool): if set to True the last argument defined in arg_types will be -4123 treated as a variable length argument and the argument's value will be stored as a list. -4124 _sql_names (list): determines the SQL name (1st item in the list) and aliases (subsequent items) -4125 for this function expression. These values are used to map this node to a name during parsing -4126 as well as to provide the function's name during SQL string generation. By default the SQL -4127 name is set to the expression's class name transformed to snake case. -4128 """ -4129 -4130 is_var_len_args = False -4131 -4132 @classmethod -4133 def from_arg_list(cls, args): -4134 if cls.is_var_len_args: -4135 all_arg_keys = list(cls.arg_types) -4136 # If this function supports variable length argument treat the last argument as such. -4137 non_var_len_arg_keys = all_arg_keys[:-1] if cls.is_var_len_args else all_arg_keys -4138 num_non_var = len(non_var_len_arg_keys) -4139 -4140 args_dict = {arg_key: arg for arg, arg_key in zip(args, non_var_len_arg_keys)} -4141 args_dict[all_arg_keys[-1]] = args[num_non_var:] -4142 else: -4143 args_dict = {arg_key: arg for arg, arg_key in zip(args, cls.arg_types)} -4144 -4145 return cls(**args_dict) -4146 -4147 @classmethod -4148 def sql_names(cls): -4149 if cls is Func: -4150 raise NotImplementedError( -4151 "SQL name is only supported by concrete function implementations" -4152 ) -4153 if "_sql_names" not in cls.__dict__: -4154 cls._sql_names = [camel_to_snake_case(cls.__name__)] -4155 return cls._sql_names -4156 -4157 @classmethod -4158 def sql_name(cls): -4159 return cls.sql_names()[0] -4160 -4161 @classmethod -4162 def default_parser_mappings(cls): -4163 return {name: cls.from_arg_list for name in cls.sql_names()} +@@ -52323,20 +52736,20 @@ name is set to the expression's class name transformed to snake case.4145class Func(Condition): +4146 """ +4147 The base class for all function expressions. +4148 +4149 Attributes: +4150 is_var_len_args (bool): if set to True the last argument defined in arg_types will be +4151 treated as a variable length argument and the argument's value will be stored as a list. +4152 _sql_names (list): determines the SQL name (1st item in the list) and aliases (subsequent items) +4153 for this function expression. These values are used to map this node to a name during parsing +4154 as well as to provide the function's name during SQL string generation. By default the SQL +4155 name is set to the expression's class name transformed to snake case. +4156 """ +4157 +4158 is_var_len_args = False +4159 +4160 @classmethod +4161 def from_arg_list(cls, args): +4162 if cls.is_var_len_args: +4163 all_arg_keys = list(cls.arg_types) +4164 # If this function supports variable length argument treat the last argument as such. +4165 non_var_len_arg_keys = all_arg_keys[:-1] if cls.is_var_len_args else all_arg_keys +4166 num_non_var = len(non_var_len_arg_keys) +4167 +4168 args_dict = {arg_key: arg for arg, arg_key in zip(args, non_var_len_arg_keys)} +4169 args_dict[all_arg_keys[-1]] = args[num_non_var:] +4170 else: +4171 args_dict = {arg_key: arg for arg, arg_key in zip(args, cls.arg_types)} +4172 +4173 return cls(**args_dict) +4174 +4175 @classmethod +4176 def sql_names(cls): +4177 if cls is Func: +4178 raise NotImplementedError( +4179 "SQL name is only supported by concrete function implementations" +4180 ) +4181 if "_sql_names" not in cls.__dict__: +4182 cls._sql_names = [camel_to_snake_case(cls.__name__)] +4183 return cls._sql_names +4184 +4185 @classmethod +4186 def sql_name(cls): +4187 return cls.sql_names()[0] +4188 +4189 @classmethod +4190 def default_parser_mappings(cls): +4191 return {name: cls.from_arg_list for name in cls.sql_names()}-4132 @classmethod -4133 def from_arg_list(cls, args): -4134 if cls.is_var_len_args: -4135 all_arg_keys = list(cls.arg_types) -4136 # If this function supports variable length argument treat the last argument as such. -4137 non_var_len_arg_keys = all_arg_keys[:-1] if cls.is_var_len_args else all_arg_keys -4138 num_non_var = len(non_var_len_arg_keys) -4139 -4140 args_dict = {arg_key: arg for arg, arg_key in zip(args, non_var_len_arg_keys)} -4141 args_dict[all_arg_keys[-1]] = args[num_non_var:] -4142 else: -4143 args_dict = {arg_key: arg for arg, arg_key in zip(args, cls.arg_types)} -4144 -4145 return cls(**args_dict) +@@ -52355,15 +52768,15 @@ name is set to the expression's class name transformed to snake case.4160 @classmethod +4161 def from_arg_list(cls, args): +4162 if cls.is_var_len_args: +4163 all_arg_keys = list(cls.arg_types) +4164 # If this function supports variable length argument treat the last argument as such. +4165 non_var_len_arg_keys = all_arg_keys[:-1] if cls.is_var_len_args else all_arg_keys +4166 num_non_var = len(non_var_len_arg_keys) +4167 +4168 args_dict = {arg_key: arg for arg, arg_key in zip(args, non_var_len_arg_keys)} +4169 args_dict[all_arg_keys[-1]] = args[num_non_var:] +4170 else: +4171 args_dict = {arg_key: arg for arg, arg_key in zip(args, cls.arg_types)} +4172 +4173 return cls(**args_dict)-4147 @classmethod -4148 def sql_names(cls): -4149 if cls is Func: -4150 raise NotImplementedError( -4151 "SQL name is only supported by concrete function implementations" -4152 ) -4153 if "_sql_names" not in cls.__dict__: -4154 cls._sql_names = [camel_to_snake_case(cls.__name__)] -4155 return cls._sql_names +@@ -52382,9 +52795,9 @@ name is set to the expression's class name transformed to snake case.4175 @classmethod +4176 def sql_names(cls): +4177 if cls is Func: +4178 raise NotImplementedError( +4179 "SQL name is only supported by concrete function implementations" +4180 ) +4181 if "_sql_names" not in cls.__dict__: +4182 cls._sql_names = [camel_to_snake_case(cls.__name__)] +4183 return cls._sql_names-4157 @classmethod -4158 def sql_name(cls): -4159 return cls.sql_names()[0] + @@ -52403,9 +52816,9 @@ name is set to the expression's class name transformed to snake case.-4161 @classmethod -4162 def default_parser_mappings(cls): -4163 return {name: cls.from_arg_list for name in cls.sql_names()} + @@ -52505,8 +52918,8 @@ name is set to the expression's class name transformed to snake case.-4166class AggFunc(Func): -4167 pass + @@ -52613,8 +53026,8 @@ name is set to the expression's class name transformed to snake case.- + +4170class ParameterizedAgg(AggFunc): -4171 arg_types = {"this": True, "expressions": True, "params": True} + @@ -52732,8 +53145,8 @@ name is set to the expression's class name transformed to snake case.+ + + + ++ + + + + + +4206class ArgMax(AggFunc): +4207 arg_types = {"this": True, "expression": True, "count": False} +4208 _sql_names = ["ARG_MAX", "ARGMAX", "MAX_BY"] +++Inherited Members
++
++ +- Expression
+- Expression
+- args
+- parent
+- arg_key
+- comments
+- hashable_args
+- this
+- expression
+- expressions
+- text
+- is_string
+- is_number
+- is_int
+- is_star
+- alias
+- alias_column_names
+- name
+- alias_or_name
+- output_name
+- type
+- meta
+- copy
+- add_comments
+- append
+- set
+- depth
+- iter_expressions
+- find
+- find_all
+- find_ancestor
+- parent_select
+- same_parent
+- root
+- walk
+- dfs
+- bfs
+- unnest
+- unalias
+- unnest_operands
+- flatten
+- sql
+- transform
+- replace
+- pop
+- assert_is
+- error_messages
+- dump
+- load
+- and_
+- or_
+- not_
+- as_
+- isin
+- between
+- is_
+- like
+- ilike
+- eq
+- neq
+- rlike
+ ++ + + + ++ + + + + + +4211class ArgMin(AggFunc): +4212 arg_types = {"this": True, "expression": True, "count": False} +4213 _sql_names = ["ARG_MIN", "ARGMIN", "MIN_BY"] +++Inherited Members
++
++ +- Expression
+- Expression
+- args
+- parent
+- arg_key
+- comments
+- hashable_args
+- this
+- expression
+- expressions
+- text
+- is_string
+- is_number
+- is_int
+- is_star
+- alias
+- alias_column_names
+- name
+- alias_or_name
+- output_name
+- type
+- meta
+- copy
+- add_comments
+- append
+- set
+- depth
+- iter_expressions
+- find
+- find_all
+- find_ancestor
+- parent_select
+- same_parent
+- root
+- walk
+- dfs
+- bfs
+- unnest
+- unalias
+- unnest_operands
+- flatten
+- sql
+- transform
+- replace
+- pop
+- assert_is
+- error_messages
+- dump
+- load
+- and_
+- or_
+- not_
+- as_
+- isin
+- between
+- is_
+- like
+- ilike
+- eq
+- neq
+- rlike
+ ++ + + + + + + + + + +4216class ApproxTopK(AggFunc): +4217 arg_types = {"this": True, "expression": False, "counters": False} ++@@ -52840,8 +53612,8 @@ name is set to the expression's class name transformed to snake case.Inherited Members
++
+- Expression
+- Expression
+- args
+- parent
+- arg_key
+- comments
+- hashable_args
+- this
+- expression
+- expressions
+- text
+- is_string
+- is_number
+- is_int
+- is_star
+- alias
+- alias_column_names
+- name
+- alias_or_name
+- output_name
+- type
+- meta
+- copy
+- add_comments
+- append
+- set
+- depth
+- iter_expressions
+- find
+- find_all
+- find_ancestor
+- parent_select
+- same_parent
+- root
+- walk
+- dfs
+- bfs
+- unnest
+- unalias
+- unnest_operands
+- flatten
+- sql
+- transform
+- replace
+- pop
+- assert_is
+- error_messages
+- dump
+- load
+- and_
+- or_
+- not_
+- as_
+- isin
+- between
+- is_
+- like
+- ilike
+- eq
+- neq
+- rlike
+ +-4178class Flatten(Func): -4179 pass + @@ -52948,8 +53720,8 @@ name is set to the expression's class name transformed to snake case.-4183class Transform(Func): -4184 arg_types = {"this": True, "expression": True} + @@ -53067,9 +53839,9 @@ name is set to the expression's class name transformed to snake case.-4187class Anonymous(Func): -4188 arg_types = {"this": True, "expressions": False} -4189 is_var_len_args = True + @@ -53198,9 +53970,9 @@ name is set to the expression's class name transformed to snake case.-4194class Hll(AggFunc): -4195 arg_types = {"this": True, "expressions": False} -4196 is_var_len_args = True + @@ -53329,9 +54101,9 @@ name is set to the expression's class name transformed to snake case.-4199class ApproxDistinct(AggFunc): -4200 arg_types = {"this": True, "accuracy": False} -4201 _sql_names = ["APPROX_DISTINCT", "APPROX_COUNT_DISTINCT"] + @@ -53449,9 +54221,9 @@ name is set to the expression's class name transformed to snake case.-4204class Array(Func): -4205 arg_types = {"expressions": False} -4206 is_var_len_args = True + @@ -53580,8 +54352,8 @@ name is set to the expression's class name transformed to snake case.-4210class ToChar(Func): -4211 arg_types = {"this": True, "format": False} + @@ -53699,8 +54471,8 @@ name is set to the expression's class name transformed to snake case.-4214class GenerateSeries(Func): -4215 arg_types = {"start": True, "end": True, "step": False} + @@ -53818,8 +54590,8 @@ name is set to the expression's class name transformed to snake case.-4218class ArrayAgg(AggFunc): -4219 pass + @@ -53926,8 +54698,8 @@ name is set to the expression's class name transformed to snake case.-4222class ArrayAll(Func): -4223 arg_types = {"this": True, "expression": True} + @@ -54045,8 +54817,8 @@ name is set to the expression's class name transformed to snake case.-4226class ArrayAny(Func): -4227 arg_types = {"this": True, "expression": True} + @@ -54164,10 +54936,10 @@ name is set to the expression's class name transformed to snake case.-4230class ArrayConcat(Func): -4231 _sql_names = ["ARRAY_CONCAT", "ARRAY_CAT"] -4232 arg_types = {"this": True, "expressions": False} -4233 is_var_len_args = True + @@ -54296,8 +55068,8 @@ name is set to the expression's class name transformed to snake case.-4236class ArrayContains(Binary, Func): -4237 pass + @@ -54409,8 +55181,8 @@ name is set to the expression's class name transformed to snake case.-4240class ArrayContained(Binary): -4241 pass + @@ -54514,9 +55286,9 @@ name is set to the expression's class name transformed to snake case.-4244class ArrayFilter(Func): -4245 arg_types = {"this": True, "expression": True} -4246 _sql_names = ["FILTER", "ARRAY_FILTER"] + @@ -54634,8 +55406,8 @@ name is set to the expression's class name transformed to snake case.-4249class ArrayJoin(Func): -4250 arg_types = {"this": True, "expression": True, "null": False} + @@ -54753,8 +55525,8 @@ name is set to the expression's class name transformed to snake case.-4253class ArraySize(Func): -4254 arg_types = {"this": True, "expression": False} + @@ -54872,8 +55644,8 @@ name is set to the expression's class name transformed to snake case.-4257class ArraySort(Func): -4258 arg_types = {"this": True, "expression": False} + @@ -54991,8 +55763,8 @@ name is set to the expression's class name transformed to snake case.-4261class ArraySum(Func): -4262 pass + @@ -55099,8 +55871,8 @@ name is set to the expression's class name transformed to snake case.-4265class ArrayUnionAgg(AggFunc): -4266 pass + @@ -55207,8 +55979,8 @@ name is set to the expression's class name transformed to snake case.-4269class Avg(AggFunc): -4270 pass + @@ -55315,8 +56087,8 @@ name is set to the expression's class name transformed to snake case.-4273class AnyValue(AggFunc): -4274 arg_types = {"this": True, "having": False, "max": False, "ignore_nulls": False} + @@ -55434,8 +56206,8 @@ name is set to the expression's class name transformed to snake case.-4277class First(Func): -4278 arg_types = {"this": True, "ignore_nulls": False} + @@ -55553,8 +56325,8 @@ name is set to the expression's class name transformed to snake case.-4281class Last(Func): -4282 arg_types = {"this": True, "ignore_nulls": False} + @@ -55672,24 +56444,24 @@ name is set to the expression's class name transformed to snake case.-4285class Case(Func): -4286 arg_types = {"this": False, "ifs": True, "default": False} -4287 -4288 def when(self, condition: ExpOrStr, then: ExpOrStr, copy: bool = True, **opts) -> Case: -4289 instance = maybe_copy(self, copy) -4290 instance.append( -4291 "ifs", -4292 If( -4293 this=maybe_parse(condition, copy=copy, **opts), -4294 true=maybe_parse(then, copy=copy, **opts), -4295 ), -4296 ) -4297 return instance -4298 -4299 def else_(self, condition: ExpOrStr, copy: bool = True, **opts) -> Case: -4300 instance = maybe_copy(self, copy) -4301 instance.set("default", maybe_parse(condition, copy=copy, **opts)) -4302 return instance +@@ -55718,16 +56490,16 @@ name is set to the expression's class name transformed to snake case.4327class Case(Func): +4328 arg_types = {"this": False, "ifs": True, "default": False} +4329 +4330 def when(self, condition: ExpOrStr, then: ExpOrStr, copy: bool = True, **opts) -> Case: +4331 instance = maybe_copy(self, copy) +4332 instance.append( +4333 "ifs", +4334 If( +4335 this=maybe_parse(condition, copy=copy, **opts), +4336 true=maybe_parse(then, copy=copy, **opts), +4337 ), +4338 ) +4339 return instance +4340 +4341 def else_(self, condition: ExpOrStr, copy: bool = True, **opts) -> Case: +4342 instance = maybe_copy(self, copy) +4343 instance.set("default", maybe_parse(condition, copy=copy, **opts)) +4344 return instance-4288 def when(self, condition: ExpOrStr, then: ExpOrStr, copy: bool = True, **opts) -> Case: -4289 instance = maybe_copy(self, copy) -4290 instance.append( -4291 "ifs", -4292 If( -4293 this=maybe_parse(condition, copy=copy, **opts), -4294 true=maybe_parse(then, copy=copy, **opts), -4295 ), -4296 ) -4297 return instance +@@ -55745,10 +56517,10 @@ name is set to the expression's class name transformed to snake case.4330 def when(self, condition: ExpOrStr, then: ExpOrStr, copy: bool = True, **opts) -> Case: +4331 instance = maybe_copy(self, copy) +4332 instance.append( +4333 "ifs", +4334 If( +4335 this=maybe_parse(condition, copy=copy, **opts), +4336 true=maybe_parse(then, copy=copy, **opts), +4337 ), +4338 ) +4339 return instance-4299 def else_(self, condition: ExpOrStr, copy: bool = True, **opts) -> Case: -4300 instance = maybe_copy(self, copy) -4301 instance.set("default", maybe_parse(condition, copy=copy, **opts)) -4302 return instance + @@ -55855,34 +56627,34 @@ name is set to the expression's class name transformed to snake case.-4305class Cast(Func): -4306 arg_types = {"this": True, "to": True, "format": False, "safe": False} -4307 -4308 @property -4309 def name(self) -> str: -4310 return self.this.name -4311 -4312 @property -4313 def to(self) -> DataType: -4314 return self.args["to"] -4315 -4316 @property -4317 def output_name(self) -> str: -4318 return self.name -4319 -4320 def is_type(self, *dtypes: str | DataType | DataType.Type) -> bool: -4321 """ -4322 Checks whether this Cast's DataType matches one of the provided data types. Nested types -4323 like arrays or structs will be compared using "structural equivalence" semantics, so e.g. -4324 array<int> != array<float>. -4325 -4326 Args: -4327 dtypes: the data types to compare this Cast's DataType to. -4328 -4329 Returns: -4330 True, if and only if there is a type in `dtypes` which is equal to this Cast's DataType. -4331 """ -4332 return self.to.is_type(*dtypes) +@@ -55963,19 +56735,19 @@ name is set to the expression's class name transformed to snake case.4347class Cast(Func): +4348 arg_types = {"this": True, "to": True, "format": False, "safe": False} +4349 +4350 @property +4351 def name(self) -> str: +4352 return self.this.name +4353 +4354 @property +4355 def to(self) -> DataType: +4356 return self.args["to"] +4357 +4358 @property +4359 def output_name(self) -> str: +4360 return self.name +4361 +4362 def is_type(self, *dtypes: str | DataType | DataType.Type) -> bool: +4363 """ +4364 Checks whether this Cast's DataType matches one of the provided data types. Nested types +4365 like arrays or structs will be compared using "structural equivalence" semantics, so e.g. +4366 array<int> != array<float>. +4367 +4368 Args: +4369 dtypes: the data types to compare this Cast's DataType to. +4370 +4371 Returns: +4372 True, if and only if there is a type in `dtypes` which is equal to this Cast's DataType. +4373 """ +4374 return self.to.is_type(*dtypes)- -4320 def is_type(self, *dtypes: str | DataType | DataType.Type) -> bool: -4321 """ -4322 Checks whether this Cast's DataType matches one of the provided data types. Nested types -4323 like arrays or structs will be compared using "structural equivalence" semantics, so e.g. -4324 array<int> != array<float>. -4325 -4326 Args: -4327 dtypes: the data types to compare this Cast's DataType to. -4328 -4329 Returns: -4330 True, if and only if there is a type in `dtypes` which is equal to this Cast's DataType. -4331 """ -4332 return self.to.is_type(*dtypes) +@@ -56096,8 +56868,8 @@ array4362 def is_type(self, *dtypes: str | DataType | DataType.Type) -> bool: +4363 """ +4364 Checks whether this Cast's DataType matches one of the provided data types. Nested types +4365 like arrays or structs will be compared using "structural equivalence" semantics, so e.g. +4366 array<int> != array<float>. +4367 +4368 Args: +4369 dtypes: the data types to compare this Cast's DataType to. +4370 +4371 Returns: +4372 True, if and only if there is a type in `dtypes` which is equal to this Cast's DataType. +4373 """ +4374 return self.to.is_type(*dtypes)!= array . - -4339class CastToStrType(Func): -4340 arg_types = {"this": True, "to": True} + @@ -56328,8 +57100,8 @@ array!= array . -4347class Ceil(Func): -4348 arg_types = {"this": True, "decimals": False} -4349 _sql_names = ["CEIL", "CEILING"] +@@ -56561,10 +57333,10 @@ array4389class Ceil(Func): +4390 arg_types = {"this": True, "decimals": False} +4391 _sql_names = ["CEIL", "CEILING"]!= array . -4352class Coalesce(Func): -4353 arg_types = {"this": True, "expressions": False} -4354 is_var_len_args = True -4355 _sql_names = ["COALESCE", "IFNULL", "NVL"] +@@ -56693,10 +57465,10 @@ array4394class Coalesce(Func): +4395 arg_types = {"this": True, "expressions": False} +4396 is_var_len_args = True +4397 _sql_names = ["COALESCE", "IFNULL", "NVL"]!= array . -4358class Chr(Func): -4359 arg_types = {"this": True, "charset": False, "expressions": False} -4360 is_var_len_args = True -4361 _sql_names = ["CHR", "CHAR"] +@@ -56825,9 +57597,9 @@ array4400class Chr(Func): +4401 arg_types = {"this": True, "charset": False, "expressions": False} +4402 is_var_len_args = True +4403 _sql_names = ["CHR", "CHAR"]!= array . - -4364class Concat(Func): -4365 arg_types = {"expressions": True} -4366 is_var_len_args = True + @@ -56956,8 +57728,8 @@ array!= array . -4373class ConcatWs(Concat): -4374 _sql_names = ["CONCAT_WS"] + @@ -57178,9 +57950,9 @@ array!= array . - -4377class Count(AggFunc): -4378 arg_types = {"this": False, "expressions": False} -4379 is_var_len_args = True +@@ -57309,8 +58081,8 @@ array4419class Count(AggFunc): +4420 arg_types = {"this": False, "expressions": False} +4421 is_var_len_args = True!= array . -4386class CurrentDate(Func): -4387 arg_types = {"this": False} + @@ -57536,8 +58308,8 @@ array!= array . -4390class CurrentDatetime(Func): -4391 arg_types = {"this": False} + @@ -57655,8 +58427,8 @@ array!= array . -4394class CurrentTime(Func): -4395 arg_types = {"this": False} + @@ -57774,8 +58546,8 @@ array!= array . -4398class CurrentTimestamp(Func): -4399 arg_types = {"this": False} + @@ -57893,8 +58665,8 @@ array!= array . -4402class CurrentUser(Func): -4403 arg_types = {"this": False} + @@ -58012,8 +58784,8 @@ array!= array . -4406class DateAdd(Func, IntervalOp): -4407 arg_types = {"this": True, "expression": True, "unit": False} +@@ -58048,6 +58820,8 @@ array4448class DateAdd(Func, IntervalOp): +4449 arg_types = {"this": True, "expression": True, "unit": False}!= array . @@ -58139,8 +58913,8 @@ array
!= array . -4410class DateSub(Func, IntervalOp): -4411 arg_types = {"this": True, "expression": True, "unit": False} +@@ -58175,6 +58949,8 @@ array4452class DateSub(Func, IntervalOp): +4453 arg_types = {"this": True, "expression": True, "unit": False}!= array . @@ -58266,9 +59042,9 @@ array
!= array . -4414class DateDiff(Func, TimeUnit): -4415 _sql_names = ["DATEDIFF", "DATE_DIFF"] -4416 arg_types = {"this": True, "expression": True, "unit": False} +@@ -58303,6 +59079,8 @@ array4456class DateDiff(Func, TimeUnit): +4457 _sql_names = ["DATEDIFF", "DATE_DIFF"] +4458 arg_types = {"this": True, "expression": True, "unit": False}!= array . @@ -58390,12 +59168,12 @@ array
!= array . -4419class DateTrunc(Func): -4420 arg_types = {"unit": True, "this": True, "zone": False} -4421 -4422 @property -4423 def unit(self) -> Expression: -4424 return self.args["unit"] +@@ -58524,8 +59302,8 @@ array4461class DateTrunc(Func): +4462 arg_types = {"unit": True, "this": True, "zone": False} +4463 +4464 @property +4465 def unit(self) -> Expression: +4466 return self.args["unit"]!= array . -4427class DatetimeAdd(Func, IntervalOp): -4428 arg_types = {"this": True, "expression": True, "unit": False} +@@ -58560,6 +59338,8 @@ array4469class DatetimeAdd(Func, IntervalOp): +4470 arg_types = {"this": True, "expression": True, "unit": False}!= array . @@ -58651,8 +59431,8 @@ array
!= array . -4431class DatetimeSub(Func, IntervalOp): -4432 arg_types = {"this": True, "expression": True, "unit": False} +@@ -58687,6 +59467,8 @@ array4473class DatetimeSub(Func, IntervalOp): +4474 arg_types = {"this": True, "expression": True, "unit": False}!= array . @@ -58778,8 +59560,8 @@ array
!= array . -4435class DatetimeDiff(Func, TimeUnit): -4436 arg_types = {"this": True, "expression": True, "unit": False} +@@ -58814,6 +59596,8 @@ array4477class DatetimeDiff(Func, TimeUnit): +4478 arg_types = {"this": True, "expression": True, "unit": False}!= array . @@ -58901,8 +59685,8 @@ array
!= array . -4439class DatetimeTrunc(Func, TimeUnit): -4440 arg_types = {"this": True, "unit": True, "zone": False} +@@ -58937,6 +59721,8 @@ array4481class DatetimeTrunc(Func, TimeUnit): +4482 arg_types = {"this": True, "unit": True, "zone": False}!= array . @@ -59024,8 +59810,8 @@ array
!= array . -4443class DayOfWeek(Func): -4444 _sql_names = ["DAY_OF_WEEK", "DAYOFWEEK"] + @@ -59132,8 +59918,8 @@ array!= array . -4447class DayOfMonth(Func): -4448 _sql_names = ["DAY_OF_MONTH", "DAYOFMONTH"] + @@ -59240,8 +60026,8 @@ array!= array . - -4451class DayOfYear(Func): -4452 _sql_names = ["DAY_OF_YEAR", "DAYOFYEAR"] + @@ -59348,8 +60134,8 @@ array!= array . -4459class WeekOfYear(Func): -4460 _sql_names = ["WEEK_OF_YEAR", "WEEKOFYEAR"] + @@ -59564,8 +60350,8 @@ array!= array . - -4463class MonthsBetween(Func): -4464 arg_types = {"this": True, "expression": True, "roundoff": False} +@@ -59683,8 +60469,8 @@ array4505class MonthsBetween(Func): +4506 arg_types = {"this": True, "expression": True, "roundoff": False}!= array . -4471class Extract(Func): -4472 arg_types = {"this": True, "expression": True} + @@ -59910,8 +60696,8 @@ array!= array . -4475class Timestamp(Func): -4476 arg_types = {"this": False, "expression": False} + @@ -60029,8 +60815,8 @@ array!= array . -4479class TimestampAdd(Func, TimeUnit): -4480 arg_types = {"this": True, "expression": True, "unit": False} +@@ -60065,6 +60851,8 @@ array4521class TimestampAdd(Func, TimeUnit): +4522 arg_types = {"this": True, "expression": True, "unit": False}!= array . @@ -60152,8 +60940,8 @@ array
!= array . -4483class TimestampSub(Func, TimeUnit): -4484 arg_types = {"this": True, "expression": True, "unit": False} +@@ -60188,6 +60976,8 @@ array4525class TimestampSub(Func, TimeUnit): +4526 arg_types = {"this": True, "expression": True, "unit": False}!= array . @@ -60275,8 +61065,8 @@ array
!= array . -4487class TimestampDiff(Func, TimeUnit): -4488 arg_types = {"this": True, "expression": True, "unit": False} +@@ -60311,6 +61101,8 @@ array4529class TimestampDiff(Func, TimeUnit): +4530 arg_types = {"this": True, "expression": True, "unit": False}!= array . @@ -60398,8 +61190,8 @@ array
!= array . -4491class TimestampTrunc(Func, TimeUnit): -4492 arg_types = {"this": True, "unit": True, "zone": False} +@@ -60434,6 +61226,8 @@ array4533class TimestampTrunc(Func, TimeUnit): +4534 arg_types = {"this": True, "unit": True, "zone": False}!= array . @@ -60521,8 +61315,8 @@ array
!= array . -4495class TimeAdd(Func, TimeUnit): -4496 arg_types = {"this": True, "expression": True, "unit": False} +@@ -60557,6 +61351,8 @@ array4537class TimeAdd(Func, TimeUnit): +4538 arg_types = {"this": True, "expression": True, "unit": False}!= array . @@ -60644,8 +61440,8 @@ array
!= array . -4499class TimeSub(Func, TimeUnit): -4500 arg_types = {"this": True, "expression": True, "unit": False} +@@ -60680,6 +61476,8 @@ array4541class TimeSub(Func, TimeUnit): +4542 arg_types = {"this": True, "expression": True, "unit": False}!= array . @@ -60767,8 +61565,8 @@ array
!= array . -4503class TimeDiff(Func, TimeUnit): -4504 arg_types = {"this": True, "expression": True, "unit": False} +@@ -60803,6 +61601,8 @@ array4545class TimeDiff(Func, TimeUnit): +4546 arg_types = {"this": True, "expression": True, "unit": False}!= array . @@ -60890,8 +61690,8 @@ array
!= array . -4507class TimeTrunc(Func, TimeUnit): -4508 arg_types = {"this": True, "unit": True, "zone": False} + @@ -60926,6 +61726,8 @@ array!= array . @@ -61013,9 +61815,9 @@ array
!= array . - - - -4511class DateFromParts(Func): -4512 _sql_names = ["DATEFROMPARTS"] -4513 arg_types = {"year": True, "month": True, "day": True} +@@ -61133,8 +61935,8 @@ array4553class DateFromParts(Func): +4554 _sql_names = ["DATEFROMPARTS"] +4555 arg_types = {"year": True, "month": True, "day": True}!= array . - -4529class Date(Func): -4530 arg_types = {"this": False, "zone": False, "expressions": False} -4531 is_var_len_args = True +@@ -61588,8 +62390,8 @@ array4571class Date(Func): +4572 arg_types = {"this": False, "zone": False, "expressions": False} +4573 is_var_len_args = True!= array . - -4538class Decode(Func): -4539 arg_types = {"this": True, "charset": True, "replace": False} + @@ -61815,8 +62617,8 @@ array!= array . - -4546class Encode(Func): -4547 arg_types = {"this": True, "charset": True} + @@ -62042,8 +62844,8 @@ array!= array . - - - -4555class Explode(Func): -4556 arg_types = {"this": True, "expressions": False} -4557 is_var_len_args = True +@@ -62281,8 +63083,8 @@ array4597class Explode(Func): +4598 arg_types = {"this": True, "expressions": False} +4599 is_var_len_args = True!= array . - - -4572class Floor(Func): -4573 arg_types = {"this": True, "decimals": False} + @@ -62733,8 +63535,8 @@ array!= array . -4584class Greatest(Func): -4585 arg_types = {"this": True, "expressions": False} -4586 is_var_len_args = True +@@ -63080,8 +63882,8 @@ array4626class Greatest(Func): +4627 arg_types = {"this": True, "expressions": False} +4628 is_var_len_args = True!= array . - -4589class GroupConcat(AggFunc): -4590 arg_types = {"this": True, "separator": False} + @@ -63199,8 +64001,8 @@ array!= array . -4597class Xor(Connector, Func): -4598 arg_types = {"this": False, "expression": False, "expressions": False} +@@ -63431,8 +64233,8 @@ array4639class Xor(Connector, Func): +4640 arg_types = {"this": False, "expression": False, "expressions": False}!= array . -4601class If(Func): -4602 arg_types = {"this": True, "true": True, "false": False} + @@ -63550,8 +64352,8 @@ array!= array . -4605class Initcap(Func): -4606 arg_types = {"this": True, "expression": False} + @@ -63669,8 +64471,8 @@ array!= array . - -4609class IsNan(Func): -4610 _sql_names = ["IS_NAN", "ISNAN"] + @@ -63777,8 +64579,8 @@ array!= array . -4617class JSONKeyValue(Expression): -4618 arg_types = {"this": True, "expression": True} + @@ -63988,14 +64790,14 @@ array!= array . -4621class JSONObject(Func): -4622 arg_types = { -4623 "expressions": False, -4624 "null_handling": False, -4625 "unique_keys": False, -4626 "return_type": False, -4627 "encoding": False, -4628 } +@@ -64114,13 +64916,13 @@ array4663class JSONObject(Func): +4664 arg_types = { +4665 "expressions": False, +4666 "null_handling": False, +4667 "unique_keys": False, +4668 "return_type": False, +4669 "encoding": False, +4670 }!= array . -4632class JSONArray(Func): -4633 arg_types = { -4634 "expressions": True, -4635 "null_handling": False, -4636 "return_type": False, -4637 "strict": False, -4638 } +@@ -64238,14 +65040,14 @@ array4674class JSONArray(Func): +4675 arg_types = { +4676 "expressions": True, +4677 "null_handling": False, +4678 "return_type": False, +4679 "strict": False, +4680 }!= array . -4642class JSONArrayAgg(Func): -4643 arg_types = { -4644 "this": True, -4645 "order": False, -4646 "null_handling": False, -4647 "return_type": False, -4648 "strict": False, -4649 } +@@ -64363,8 +65165,8 @@ array4684class JSONArrayAgg(Func): +4685 arg_types = { +4686 "this": True, +4687 "order": False, +4688 "null_handling": False, +4689 "return_type": False, +4690 "strict": False, +4691 }!= array . -4654class JSONColumnDef(Expression): -4655 arg_types = {"this": False, "kind": False, "path": False, "nested_schema": False} +@@ -64474,8 +65276,8 @@ array4696class JSONColumnDef(Expression): +4697 arg_types = {"this": False, "kind": False, "path": False, "nested_schema": False}!= array . -4658class JSONSchema(Expression): -4659 arg_types = {"expressions": True} + @@ -64585,14 +65387,14 @@ array!= array . -4663class JSONTable(Func): -4664 arg_types = { -4665 "this": True, -4666 "schema": True, -4667 "path": False, -4668 "error_handling": False, -4669 "empty_handling": False, -4670 } +@@ -64710,8 +65512,8 @@ array4705class JSONTable(Func): +4706 arg_types = { +4707 "this": True, +4708 "schema": True, +4709 "path": False, +4710 "error_handling": False, +4711 "empty_handling": False, +4712 }!= array . -4673class OpenJSONColumnDef(Expression): -4674 arg_types = {"this": True, "kind": True, "path": False, "as_json": False} +@@ -64821,8 +65623,8 @@ array4715class OpenJSONColumnDef(Expression): +4716 arg_types = {"this": True, "kind": True, "path": False, "as_json": False}!= array . -4677class OpenJSON(Func): -4678 arg_types = {"this": True, "path": False, "expressions": False} + @@ -64940,8 +65742,8 @@ array!= array . -4681class JSONBContains(Binary): -4682 _sql_names = ["JSONB_CONTAINS"] + @@ -65045,8 +65847,8 @@ array!= array . -4685class JSONExtract(Binary, Func): -4686 _sql_names = ["JSON_EXTRACT"] + @@ -65158,8 +65960,8 @@ array!= array . -4689class JSONExtractScalar(JSONExtract): -4690 _sql_names = ["JSON_EXTRACT_SCALAR"] + @@ -65271,8 +66073,8 @@ array!= array . -4693class JSONBExtract(JSONExtract): -4694 _sql_names = ["JSONB_EXTRACT"] + @@ -65384,8 +66186,8 @@ array!= array . -4697class JSONBExtractScalar(JSONExtract): -4698 _sql_names = ["JSONB_EXTRACT_SCALAR"] + @@ -65497,9 +66299,9 @@ array!= array . -4701class JSONFormat(Func): -4702 arg_types = {"this": False, "options": False} -4703 _sql_names = ["JSON_FORMAT"] +@@ -65617,8 +66419,8 @@ array4743class JSONFormat(Func): +4744 arg_types = {"this": False, "options": False} +4745 _sql_names = ["JSON_FORMAT"]!= array . -4707class JSONArrayContains(Binary, Predicate, Func): -4708 _sql_names = ["JSON_ARRAY_CONTAINS"] + @@ -65730,11 +66532,11 @@ array!= array . -4711class ParseJSON(Func): -4712 # BigQuery, Snowflake have PARSE_JSON, Presto has JSON_PARSE -4713 _sql_names = ["PARSE_JSON", "JSON_PARSE"] -4714 arg_types = {"this": True, "expressions": False} -4715 is_var_len_args = True +@@ -65863,9 +66665,9 @@ array4753class ParseJSON(Func): +4754 # BigQuery, Snowflake have PARSE_JSON, Presto has JSON_PARSE +4755 _sql_names = ["PARSE_JSON", "JSON_PARSE"] +4756 arg_types = {"this": True, "expressions": False} +4757 is_var_len_args = True!= array . -4718class Least(Func): -4719 arg_types = {"this": True, "expressions": False} -4720 is_var_len_args = True +@@ -65994,8 +66796,8 @@ array4760class Least(Func): +4761 arg_types = {"this": True, "expressions": False} +4762 is_var_len_args = True!= array . -4723class Left(Func): -4724 arg_types = {"this": True, "expression": True} + @@ -66113,8 +66915,8 @@ array!= array . -4727class Right(Func): -4728 arg_types = {"this": True, "expression": True} + @@ -66232,8 +67034,8 @@ array!= array . -4731class Length(Func): -4732 _sql_names = ["LENGTH", "LEN"] + @@ -66340,14 +67142,14 @@ array!= array . - -4735class Levenshtein(Func): -4736 arg_types = { -4737 "this": True, -4738 "expression": False, -4739 "ins_cost": False, -4740 "del_cost": False, -4741 "sub_cost": False, -4742 } +@@ -66465,8 +67267,8 @@ array4777class Levenshtein(Func): +4778 arg_types = { +4779 "this": True, +4780 "expression": False, +4781 "ins_cost": False, +4782 "del_cost": False, +4783 "sub_cost": False, +4784 }!= array . - - -4749class Log(Func): -4750 arg_types = {"this": True, "expression": False} + @@ -66692,8 +67494,8 @@ array!= array . -4761class LogicalOr(AggFunc): -4762 _sql_names = ["LOGICAL_OR", "BOOL_OR", "BOOLOR_AGG"] + @@ -67016,8 +67818,8 @@ array!= array . -4765class LogicalAnd(AggFunc): -4766 _sql_names = ["LOGICAL_AND", "BOOL_AND", "BOOLAND_AGG"] + @@ -67124,8 +67926,8 @@ array!= array . -4769class Lower(Func): -4770 _sql_names = ["LOWER", "LCASE"] + @@ -67232,8 +68034,18 @@ array!= array . +4773class Map(Func): -4774 arg_types = {"keys": False, "values": False} +@@ -67250,6 +68062,28 @@ array4815class Map(Func): +4816 arg_types = {"keys": False, "values": False} +4817 +4818 @property +4819 def keys(self) -> t.List[Expression]: +4820 keys = self.args.get("keys") +4821 return keys.expressions if keys else [] +4822 +4823 @property +4824 def values(self) -> t.List[Expression]: +4825 values = self.args.get("values") +4826 return values.expressions if values else []!= array . + +++ keys: List[Expression] + + ++ + + + +++ values: List[Expression] + + ++ + + +@@ -67351,8 +68185,8 @@ array- - -!= array . -4785class VarMap(Func): -4786 arg_types = {"keys": True, "values": True} -4787 is_var_len_args = True -4788 -4789 @property -4790 def keys(self) -> t.List[Expression]: -4791 return self.args["keys"].expressions -4792 -4793 @property -4794 def values(self) -> t.List[Expression]: -4795 return self.args["values"].expressions +@@ -67728,8 +68562,8 @@ array4837class VarMap(Func): +4838 arg_types = {"keys": True, "values": True} +4839 is_var_len_args = True +4840 +4841 @property +4842 def keys(self) -> t.List[Expression]: +4843 return self.args["keys"].expressions +4844 +4845 @property +4846 def values(self) -> t.List[Expression]: +4847 return self.args["values"].expressions!= array . -4799class MatchAgainst(Func): -4800 arg_types = {"this": True, "expressions": True, "modifier": False} +@@ -67847,9 +68681,9 @@ array4851class MatchAgainst(Func): +4852 arg_types = {"this": True, "expressions": True, "modifier": False}!= array . - -4803class Max(AggFunc): -4804 arg_types = {"this": True, "expressions": False} -4805 is_var_len_args = True +@@ -67978,8 +68812,8 @@ array4855class Max(AggFunc): +4856 arg_types = {"this": True, "expressions": False} +4857 is_var_len_args = True!= array . -4813class MD5Digest(Func): -4814 _sql_names = ["MD5_DIGEST"] + @@ -68194,9 +69028,9 @@ array!= array . - -4817class Min(AggFunc): -4818 arg_types = {"this": True, "expressions": False} -4819 is_var_len_args = True +@@ -68325,8 +69159,8 @@ array4869class Min(AggFunc): +4870 arg_types = {"this": True, "expressions": False} +4871 is_var_len_args = True!= array . -4826class Nvl2(Func): -4827 arg_types = {"this": True, "true": True, "false": False} + @@ -68552,8 +69386,8 @@ array!= array . -4831class Predict(Func): -4832 arg_types = {"this": True, "expression": True, "params_struct": False} +@@ -68671,8 +69505,8 @@ array4883class Predict(Func): +4884 arg_types = {"this": True, "expression": True, "params_struct": False}!= array . -4835class Pow(Binary, Func): -4836 _sql_names = ["POWER", "POW"] + @@ -68784,8 +69618,8 @@ array!= array . -4839class PercentileCont(AggFunc): -4840 arg_types = {"this": True, "expression": False} + @@ -68903,8 +69737,8 @@ array!= array . -4843class PercentileDisc(AggFunc): -4844 arg_types = {"this": True, "expression": False} + @@ -69022,8 +69856,8 @@ array!= array . -4847class Quantile(AggFunc): -4848 arg_types = {"this": True, "quantile": True} + @@ -69141,8 +69975,8 @@ array!= array . -4851class ApproxQuantile(Quantile): -4852 arg_types = {"this": True, "quantile": True, "accuracy": False, "weight": False} +@@ -69260,8 +70094,8 @@ array4903class ApproxQuantile(Quantile): +4904 arg_types = {"this": True, "quantile": True, "accuracy": False, "weight": False}!= array . -4855class RangeN(Func): -4856 arg_types = {"this": True, "expressions": True, "each": False} + @@ -69379,10 +70213,10 @@ array!= array . -4859class ReadCSV(Func): -4860 _sql_names = ["READ_CSV"] -4861 is_var_len_args = True -4862 arg_types = {"this": True, "expressions": False} +@@ -69511,8 +70345,8 @@ array4911class ReadCSV(Func): +4912 _sql_names = ["READ_CSV"] +4913 is_var_len_args = True +4914 arg_types = {"this": True, "expressions": False}!= array . -4865class Reduce(Func): -4866 arg_types = {"this": True, "initial": True, "merge": True, "finish": False} +@@ -69630,15 +70464,15 @@ array4917class Reduce(Func): +4918 arg_types = {"this": True, "initial": True, "merge": True, "finish": False}!= array . -4869class RegexpExtract(Func): -4870 arg_types = { -4871 "this": True, -4872 "expression": True, -4873 "position": False, -4874 "occurrence": False, -4875 "parameters": False, -4876 "group": False, -4877 } +@@ -69757,16 +70591,16 @@ array4921class RegexpExtract(Func): +4922 arg_types = { +4923 "this": True, +4924 "expression": True, +4925 "position": False, +4926 "occurrence": False, +4927 "parameters": False, +4928 "group": False, +4929 }!= array . -4880class RegexpReplace(Func): -4881 arg_types = { -4882 "this": True, -4883 "expression": True, -4884 "replacement": True, -4885 "position": False, -4886 "occurrence": False, -4887 "parameters": False, -4888 "modifiers": False, -4889 } +@@ -69885,8 +70719,8 @@ array4932class RegexpReplace(Func): +4933 arg_types = { +4934 "this": True, +4935 "expression": True, +4936 "replacement": True, +4937 "position": False, +4938 "occurrence": False, +4939 "parameters": False, +4940 "modifiers": False, +4941 }!= array . -4892class RegexpLike(Binary, Func): -4893 arg_types = {"this": True, "expression": True, "flag": False} +@@ -70009,8 +70843,8 @@ array4944class RegexpLike(Binary, Func): +4945 arg_types = {"this": True, "expression": True, "flag": False}!= array . -4896class RegexpILike(Binary, Func): -4897 arg_types = {"this": True, "expression": True, "flag": False} +@@ -70133,8 +70967,8 @@ array4948class RegexpILike(Binary, Func): +4949 arg_types = {"this": True, "expression": True, "flag": False}!= array . -4902class RegexpSplit(Func): -4903 arg_types = {"this": True, "expression": True, "limit": False} + @@ -70252,8 +71086,8 @@ array!= array . -4906class Repeat(Func): -4907 arg_types = {"this": True, "times": True} + @@ -70371,8 +71205,8 @@ array!= array . -4910class Round(Func): -4911 arg_types = {"this": True, "decimals": False} + @@ -70490,8 +71324,8 @@ array!= array . -4914class RowNumber(Func): -4915 arg_types: t.Dict[str, t.Any] = {} + @@ -70609,8 +71443,8 @@ array!= array . - - -4918class SafeDivide(Func): -4919 arg_types = {"this": True, "expression": True} + @@ -70728,8 +71562,8 @@ array!= array . -4930class SHA2(Func): -4931 _sql_names = ["SHA2"] -4932 arg_types = {"this": True, "length": False} + @@ -71064,8 +71898,8 @@ array!= array . -4935class SortArray(Func): -4936 arg_types = {"this": True, "asc": False} + @@ -71183,8 +72017,8 @@ array!= array . -4939class Split(Func): -4940 arg_types = {"this": True, "expression": True, "limit": False} + @@ -71302,8 +72136,8 @@ array!= array . -4945class Substring(Func): -4946 arg_types = {"this": True, "start": False, "length": False} + @@ -71421,8 +72255,8 @@ array!= array . -4949class StandardHash(Func): -4950 arg_types = {"this": True, "expression": False} + @@ -71540,9 +72374,9 @@ array!= array . -4953class StartsWith(Func): -4954 _sql_names = ["STARTS_WITH", "STARTSWITH"] -4955 arg_types = {"this": True, "expression": True} +@@ -71660,13 +72494,13 @@ array5005class StartsWith(Func): +5006 _sql_names = ["STARTS_WITH", "STARTSWITH"] +5007 arg_types = {"this": True, "expression": True}!= array . -4958class StrPosition(Func): -4959 arg_types = { -4960 "this": True, -4961 "substr": True, -4962 "position": False, -4963 "instance": False, -4964 } +@@ -71784,8 +72618,8 @@ array5010class StrPosition(Func): +5011 arg_types = { +5012 "this": True, +5013 "substr": True, +5014 "position": False, +5015 "instance": False, +5016 }!= array . -4967class StrToDate(Func): -4968 arg_types = {"this": True, "format": True} + @@ -71903,8 +72737,8 @@ array!= array . -4971class StrToTime(Func): -4972 arg_types = {"this": True, "format": True, "zone": False} + @@ -72022,8 +72856,8 @@ array!= array . -4977class StrToUnix(Func): -4978 arg_types = {"this": False, "format": False} + @@ -72141,13 +72975,13 @@ array!= array . -4983class StrToMap(Func): -4984 arg_types = { -4985 "this": True, -4986 "pair_delim": False, -4987 "key_value_delim": False, -4988 "duplicate_resolution_callback": False, -4989 } +@@ -72266,8 +73100,8 @@ array5035class StrToMap(Func): +5036 arg_types = { +5037 "this": True, +5038 "pair_delim": False, +5039 "key_value_delim": False, +5040 "duplicate_resolution_callback": False, +5041 }!= array . -4992class NumberToStr(Func): -4993 arg_types = {"this": True, "format": True, "culture": False} + @@ -72385,8 +73219,8 @@ array!= array . -4996class FromBase(Func): -4997 arg_types = {"this": True, "expression": True} + @@ -72504,9 +73338,9 @@ array!= array . 5000class Struct(Func): -5001 arg_types = {"expressions": True} -5002 is_var_len_args = True + @@ -72515,7 +73349,7 @@ array!= array . -arg_types = -{'expressions': True} +{'expressions': False}@@ -72635,8 +73469,8 @@ array!= array . -5005class StructExtract(Func): -5006 arg_types = {"this": True, "expression": True} + @@ -72754,9 +73588,9 @@ array!= array . - - - - - -5011class Stuff(Func): -5012 _sql_names = ["STUFF", "INSERT"] -5013 arg_types = {"this": True, "start": True, "length": True, "expression": True} +@@ -72874,8 +73708,8 @@ array5063class Stuff(Func): +5064 _sql_names = ["STUFF", "INSERT"] +5065 arg_types = {"this": True, "start": True, "length": True, "expression": True}!= array . - - - - - -5036class TimeToStr(Func): -5037 arg_types = {"this": True, "format": True, "culture": False} + @@ -73533,8 +74367,8 @@ array!= array . -5060class Trim(Func): -5061 arg_types = { -5062 "this": True, -5063 "expression": False, -5064 "position": False, -5065 "collation": False, -5066 } +@@ -74197,8 +75031,8 @@ array5112class Trim(Func): +5113 arg_types = { +5114 "this": True, +5115 "expression": False, +5116 "position": False, +5117 "collation": False, +5118 }!= array . - -5069class TsOrDsAdd(Func, TimeUnit): -5070 arg_types = {"this": True, "expression": True, "unit": False} +@@ -74233,6 +75067,8 @@ array5121class TsOrDsAdd(Func, TimeUnit): +5122 arg_types = {"this": True, "expression": True, "unit": False}!= array . @@ -74320,8 +75156,8 @@ array
!= array . - - -5077class TsOrDsToDate(Func): -5078 arg_types = {"this": True, "format": False} + @@ -74547,8 +75383,8 @@ array!= array . -5089class UnixToStr(Func): -5090 arg_types = {"this": True, "format": False} + @@ -74882,12 +75718,12 @@ array!= array . - -5095class UnixToTime(Func): -5096 arg_types = {"this": True, "scale": False, "zone": False, "hours": False, "minutes": False} -5097 -5098 SECONDS = Literal.string("seconds") -5099 MILLIS = Literal.string("millis") -5100 MICROS = Literal.string("micros") +@@ -75041,8 +75877,8 @@ array5147class UnixToTime(Func): +5148 arg_types = {"this": True, "scale": False, "zone": False, "hours": False, "minutes": False} +5149 +5150 SECONDS = Literal.string("seconds") +5151 MILLIS = Literal.string("millis") +5152 MICROS = Literal.string("micros")!= array . -5107class Upper(Func): -5108 _sql_names = ["UPPER", "UCASE"] + @@ -75257,8 +76093,8 @@ array!= array . -5111class Variance(AggFunc): -5112 _sql_names = ["VARIANCE", "VARIANCE_SAMP", "VAR_SAMP"] + @@ -75365,8 +76201,8 @@ array!= array . -5115class VariancePop(AggFunc): -5116 _sql_names = ["VARIANCE_POP", "VAR_POP"] + @@ -75473,8 +76309,8 @@ array!= array . -5119class Week(Func): -5120 arg_types = {"this": True, "mode": False} + @@ -75592,8 +76428,8 @@ array!= array . - -5123class XMLTable(Func): -5124 arg_types = {"this": True, "passing": False, "columns": False, "by_ref": False} +@@ -75711,8 +76547,8 @@ array5175class XMLTable(Func): +5176 arg_types = {"this": True, "passing": False, "columns": False, "by_ref": False}!= array . -5131class Use(Expression): -5132 arg_types = {"this": True, "kind": False} + @@ -75930,8 +76766,8 @@ array!= array . 5135class Merge(Expression): -5136 arg_types = {"this": True, "using": True, "on": True, "expressions": True} +@@ -75940,7 +76776,7 @@ array5187class Merge(Expression): +5188 arg_types = {"this": True, "using": True, "on": True, "expressions": True, "with": False}!= array . -arg_types = -{'this': True, 'using': True, 'on': True, 'expressions': True} +{'this': True, 'using': True, 'on': True, 'expressions': True, 'with': False}@@ -76041,8 +76877,8 @@ array!= array . -5139class When(Func): -5140 arg_types = {"matched": True, "source": False, "condition": False, "then": True} +@@ -76160,8 +76996,8 @@ array5191class When(Func): +5192 arg_types = {"matched": True, "source": False, "condition": False, "then": True}!= array . -5145class NextValueFor(Func): -5146 arg_types = {"this": True, "order": False} + @@ -76272,7 +77108,7 @@ array!= array . ALL_FUNCTIONS = - [<class 'Abs'>, <class 'AnyValue'>, <class 'ApproxDistinct'>, <class 'ApproxQuantile'>, <class 'Array'>, <class 'ArrayAgg'>, <class 'ArrayAll'>, <class 'ArrayAny'>, <class 'ArrayConcat'>, <class 'ArrayContains'>, <class 'ArrayFilter'>, <class 'ArrayJoin'>, <class 'ArraySize'>, <class 'ArraySort'>, <class 'ArraySum'>, <class 'ArrayUnionAgg'>, <class 'Avg'>, <class 'Case'>, <class 'Cast'>, <class 'CastToStrType'>, <class 'Ceil'>, <class 'Chr'>, <class 'Coalesce'>, <class 'Collate'>, <class 'Concat'>, <class 'ConcatWs'>, <class 'Count'>, <class 'CountIf'>, <class 'CurrentDate'>, <class 'CurrentDatetime'>, <class 'CurrentTime'>, <class 'CurrentTimestamp'>, <class 'CurrentUser'>, <class 'Date'>, <class 'DateAdd'>, <class 'DateDiff'>, <class 'DateFromParts'>, <class 'DateStrToDate'>, <class 'DateSub'>, <class 'DateToDateStr'>, <class 'DateToDi'>, <class 'DateTrunc'>, <class 'DatetimeAdd'>, <class 'DatetimeDiff'>, <class 'DatetimeSub'>, <class 'DatetimeTrunc'>, <class 'Day'>, <class 'DayOfMonth'>, <class 'DayOfWeek'>, <class 'DayOfYear'>, <class 'Decode'>, <class 'DiToDate'>, <class 'Encode'>, <class 'Exp'>, <class 'Explode'>, <class 'ExplodeOuter'>, <class 'Extract'>, <class 'First'>, <class 'Flatten'>, <class 'Floor'>, <class 'FromBase'>, <class 'FromBase64'>, <class 'GenerateSeries'>, <class 'Greatest'>, <class 'GroupConcat'>, <class 'Hex'>, <class 'Hll'>, <class 'If'>, <class 'Initcap'>, <class 'IsNan'>, <class 'JSONArray'>, <class 'JSONArrayAgg'>, <class 'JSONArrayContains'>, <class 'JSONBExtract'>, <class 'JSONBExtractScalar'>, <class 'JSONExtract'>, <class 'JSONExtractScalar'>, <class 'JSONFormat'>, <class 'JSONObject'>, <class 'JSONTable'>, <class 'Last'>, <class 'LastDateOfMonth'>, <class 'Least'>, <class 'Left'>, <class 'Length'>, <class 'Levenshtein'>, <class 'Ln'>, <class 'Log'>, <class 'Log10'>, <class 'Log2'>, <class 'LogicalAnd'>, <class 'LogicalOr'>, <class 'Lower'>, <class 'MD5'>, <class 'MD5Digest'>, <class 'Map'>, <class 'MapFromEntries'>, <class 'MatchAgainst'>, <class 'Max'>, <class 'Min'>, <class 'Month'>, <class 'MonthsBetween'>, <class 'NextValueFor'>, <class 'NumberToStr'>, <class 'Nvl2'>, <class 'OpenJSON'>, <class 'ParameterizedAgg'>, <class 'ParseJSON'>, <class 'PercentileCont'>, <class 'PercentileDisc'>, <class 'Posexplode'>, <class 'PosexplodeOuter'>, <class 'Pow'>, <class 'Predict'>, <class 'Quantile'>, <class 'RangeN'>, <class 'ReadCSV'>, <class 'Reduce'>, <class 'RegexpExtract'>, <class 'RegexpILike'>, <class 'RegexpLike'>, <class 'RegexpReplace'>, <class 'RegexpSplit'>, <class 'Repeat'>, <class 'Right'>, <class 'Round'>, <class 'RowNumber'>, <class 'SHA'>, <class 'SHA2'>, <class 'SafeConcat'>, <class 'SafeDivide'>, <class 'SetAgg'>, <class 'SortArray'>, <class 'Split'>, <class 'Sqrt'>, <class 'StandardHash'>, <class 'StarMap'>, <class 'StartsWith'>, <class 'Stddev'>, <class 'StddevPop'>, <class 'StddevSamp'>, <class 'StrPosition'>, <class 'StrToDate'>, <class 'StrToMap'>, <class 'StrToTime'>, <class 'StrToUnix'>, <class 'Struct'>, <class 'StructExtract'>, <class 'Stuff'>, <class 'Substring'>, <class 'Sum'>, <class 'TimeAdd'>, <class 'TimeDiff'>, <class 'TimeStrToDate'>, <class 'TimeStrToTime'>, <class 'TimeStrToUnix'>, <class 'TimeSub'>, <class 'TimeToStr'>, <class 'TimeToTimeStr'>, <class 'TimeToUnix'>, <class 'TimeTrunc'>, <class 'Timestamp'>, <class 'TimestampAdd'>, <class 'TimestampDiff'>, <class 'TimestampSub'>, <class 'TimestampTrunc'>, <class 'ToBase64'>, <class 'ToChar'>, <class 'ToDays'>, <class 'Transform'>, <class 'Trim'>, <class 'TryCast'>, <class 'TsOrDiToDi'>, <class 'TsOrDsAdd'>, <class 'TsOrDsToDate'>, <class 'TsOrDsToDateStr'>, <class 'Unhex'>, <class 'UnixToStr'>, <class 'UnixToTime'>, <class 'UnixToTimeStr'>, <class 'Upper'>, <class 'VarMap'>, <class 'Variance'>, <class 'VariancePop'>, <class 'Week'>, <class 'WeekOfYear'>, <class 'When'>, <class 'XMLTable'>, <class 'Xor'>, <class 'Year'>] + [<class 'Abs'>, <class 'AnyValue'>, <class 'ApproxDistinct'>, <class 'ApproxQuantile'>, <class 'ApproxTopK'>, <class 'ArgMax'>, <class 'ArgMin'>, <class 'Array'>, <class 'ArrayAgg'>, <class 'ArrayAll'>, <class 'ArrayAny'>, <class 'ArrayConcat'>, <class 'ArrayContains'>, <class 'ArrayFilter'>, <class 'ArrayJoin'>, <class 'ArraySize'>, <class 'ArraySort'>, <class 'ArraySum'>, <class 'ArrayUnionAgg'>, <class 'Avg'>, <class 'Case'>, <class 'Cast'>, <class 'CastToStrType'>, <class 'Ceil'>, <class 'Chr'>, <class 'Coalesce'>, <class 'Collate'>, <class 'Concat'>, <class 'ConcatWs'>, <class 'Count'>, <class 'CountIf'>, <class 'CurrentDate'>, <class 'CurrentDatetime'>, <class 'CurrentTime'>, <class 'CurrentTimestamp'>, <class 'CurrentUser'>, <class 'Date'>, <class 'DateAdd'>, <class 'DateDiff'>, <class 'DateFromParts'>, <class 'DateStrToDate'>, <class 'DateSub'>, <class 'DateToDateStr'>, <class 'DateToDi'>, <class 'DateTrunc'>, <class 'DatetimeAdd'>, <class 'DatetimeDiff'>, <class 'DatetimeSub'>, <class 'DatetimeTrunc'>, <class 'Day'>, <class 'DayOfMonth'>, <class 'DayOfWeek'>, <class 'DayOfYear'>, <class 'Decode'>, <class 'DiToDate'>, <class 'Encode'>, <class 'Exp'>, <class 'Explode'>, <class 'ExplodeOuter'>, <class 'Extract'>, <class 'First'>, <class 'Flatten'>, <class 'Floor'>, <class 'FromBase'>, <class 'FromBase64'>, <class 'GenerateSeries'>, <class 'Greatest'>, <class 'GroupConcat'>, <class 'Hex'>, <class 'Hll'>, <class 'If'>, <class 'Initcap'>, <class 'IsNan'>, <class 'JSONArray'>, <class 'JSONArrayAgg'>, <class 'JSONArrayContains'>, <class 'JSONBExtract'>, <class 'JSONBExtractScalar'>, <class 'JSONExtract'>, <class 'JSONExtractScalar'>, <class 'JSONFormat'>, <class 'JSONObject'>, <class 'JSONTable'>, <class 'Last'>, <class 'LastDateOfMonth'>, <class 'Least'>, <class 'Left'>, <class 'Length'>, <class 'Levenshtein'>, <class 'Ln'>, <class 'Log'>, <class 'Log10'>, <class 'Log2'>, <class 'LogicalAnd'>, <class 'LogicalOr'>, <class 'Lower'>, <class 'MD5'>, <class 'MD5Digest'>, <class 'Map'>, <class 'MapFromEntries'>, <class 'MatchAgainst'>, <class 'Max'>, <class 'Min'>, <class 'Month'>, <class 'MonthsBetween'>, <class 'NextValueFor'>, <class 'NumberToStr'>, <class 'Nvl2'>, <class 'OpenJSON'>, <class 'ParameterizedAgg'>, <class 'ParseJSON'>, <class 'PercentileCont'>, <class 'PercentileDisc'>, <class 'Posexplode'>, <class 'PosexplodeOuter'>, <class 'Pow'>, <class 'Predict'>, <class 'Quantile'>, <class 'RangeN'>, <class 'ReadCSV'>, <class 'Reduce'>, <class 'RegexpExtract'>, <class 'RegexpILike'>, <class 'RegexpLike'>, <class 'RegexpReplace'>, <class 'RegexpSplit'>, <class 'Repeat'>, <class 'Right'>, <class 'Round'>, <class 'RowNumber'>, <class 'SHA'>, <class 'SHA2'>, <class 'SafeConcat'>, <class 'SafeDivide'>, <class 'SetAgg'>, <class 'SortArray'>, <class 'Split'>, <class 'Sqrt'>, <class 'StandardHash'>, <class 'StarMap'>, <class 'StartsWith'>, <class 'Stddev'>, <class 'StddevPop'>, <class 'StddevSamp'>, <class 'StrPosition'>, <class 'StrToDate'>, <class 'StrToMap'>, <class 'StrToTime'>, <class 'StrToUnix'>, <class 'Struct'>, <class 'StructExtract'>, <class 'Stuff'>, <class 'Substring'>, <class 'Sum'>, <class 'TimeAdd'>, <class 'TimeDiff'>, <class 'TimeStrToDate'>, <class 'TimeStrToTime'>, <class 'TimeStrToUnix'>, <class 'TimeSub'>, <class 'TimeToStr'>, <class 'TimeToTimeStr'>, <class 'TimeToUnix'>, <class 'TimeTrunc'>, <class 'Timestamp'>, <class 'TimestampAdd'>, <class 'TimestampDiff'>, <class 'TimestampSub'>, <class 'TimestampTrunc'>, <class 'ToBase64'>, <class 'ToChar'>, <class 'ToDays'>, <class 'Transform'>, <class 'Trim'>, <class 'TryCast'>, <class 'TsOrDiToDi'>, <class 'TsOrDsAdd'>, <class 'TsOrDsToDate'>, <class 'TsOrDsToDateStr'>, <class 'Unhex'>, <class 'UnixToStr'>, <class 'UnixToTime'>, <class 'UnixToTimeStr'>, <class 'Upper'>, <class 'VarMap'>, <class 'Variance'>, <class 'VariancePop'>, <class 'Week'>, <class 'WeekOfYear'>, <class 'When'>, <class 'XMLTable'>, <class 'Xor'>, <class 'Year'>]@@ -76292,52 +77128,52 @@ array!= array . -5183def maybe_parse( -5184 sql_or_expression: ExpOrStr, -5185 *, -5186 into: t.Optional[IntoType] = None, -5187 dialect: DialectType = None, -5188 prefix: t.Optional[str] = None, -5189 copy: bool = False, -5190 **opts, -5191) -> Expression: -5192 """Gracefully handle a possible string or expression. -5193 -5194 Example: -5195 >>> maybe_parse("1") -5196 (LITERAL this: 1, is_string: False) -5197 >>> maybe_parse(to_identifier("x")) -5198 (IDENTIFIER this: x, quoted: False) -5199 -5200 Args: -5201 sql_or_expression: the SQL code string or an expression -5202 into: the SQLGlot Expression to parse into -5203 dialect: the dialect used to parse the input expressions (in the case that an -5204 input expression is a SQL string). -5205 prefix: a string to prefix the sql with before it gets parsed -5206 (automatically includes a space) -5207 copy: whether or not to copy the expression. -5208 **opts: other options to use to parse the input expressions (again, in the case -5209 that an input expression is a SQL string). -5210 -5211 Returns: -5212 Expression: the parsed or given expression. -5213 """ -5214 if isinstance(sql_or_expression, Expression): -5215 if copy: -5216 return sql_or_expression.copy() -5217 return sql_or_expression -5218 -5219 if sql_or_expression is None: -5220 raise ParseError(f"SQL cannot be None") -5221 -5222 import sqlglot -5223 -5224 sql = str(sql_or_expression) -5225 if prefix: -5226 sql = f"{prefix} {sql}" -5227 -5228 return sqlglot.parse_one(sql, read=dialect, into=into, **opts) +@@ -76389,8 +77225,8 @@ that an input expression is a SQL string).5235def maybe_parse( +5236 sql_or_expression: ExpOrStr, +5237 *, +5238 into: t.Optional[IntoType] = None, +5239 dialect: DialectType = None, +5240 prefix: t.Optional[str] = None, +5241 copy: bool = False, +5242 **opts, +5243) -> Expression: +5244 """Gracefully handle a possible string or expression. +5245 +5246 Example: +5247 >>> maybe_parse("1") +5248 (LITERAL this: 1, is_string: False) +5249 >>> maybe_parse(to_identifier("x")) +5250 (IDENTIFIER this: x, quoted: False) +5251 +5252 Args: +5253 sql_or_expression: the SQL code string or an expression +5254 into: the SQLGlot Expression to parse into +5255 dialect: the dialect used to parse the input expressions (in the case that an +5256 input expression is a SQL string). +5257 prefix: a string to prefix the sql with before it gets parsed +5258 (automatically includes a space) +5259 copy: whether or not to copy the expression. +5260 **opts: other options to use to parse the input expressions (again, in the case +5261 that an input expression is a SQL string). +5262 +5263 Returns: +5264 Expression: the parsed or given expression. +5265 """ +5266 if isinstance(sql_or_expression, Expression): +5267 if copy: +5268 return sql_or_expression.copy() +5269 return sql_or_expression +5270 +5271 if sql_or_expression is None: +5272 raise ParseError(f"SQL cannot be None") +5273 +5274 import sqlglot +5275 +5276 sql = str(sql_or_expression) +5277 if prefix: +5278 sql = f"{prefix} {sql}" +5279 +5280 return sqlglot.parse_one(sql, read=dialect, into=into, **opts)5241def maybe_copy(instance, copy=True): -5242 return instance.copy() if copy and instance else instance +@@ -76402,38 +77238,44 @@ that an input expression is a SQL string).5293def maybe_copy(instance, copy=True): +5294 return instance.copy() if copy and instance else instancedef - union( left: Union[str, Expression], right: Union[str, Expression], distinct: bool = True, dialect: Union[str, sqlglot.dialects.dialect.Dialect, Type[sqlglot.dialects.dialect.Dialect], NoneType] = None, **opts) -> Union: + union( left: Union[str, Expression], right: Union[str, Expression], distinct: bool = True, dialect: Union[str, sqlglot.dialects.dialect.Dialect, Type[sqlglot.dialects.dialect.Dialect], NoneType] = None, copy: bool = True, **opts) -> Union:-5423def union( -5424 left: ExpOrStr, right: ExpOrStr, distinct: bool = True, dialect: DialectType = None, **opts -5425) -> Union: -5426 """ -5427 Initializes a syntax tree from one UNION expression. -5428 -5429 Example: -5430 >>> union("SELECT * FROM foo", "SELECT * FROM bla").sql() -5431 'SELECT * FROM foo UNION SELECT * FROM bla' -5432 -5433 Args: -5434 left: the SQL code string corresponding to the left-hand side. -5435 If an `Expression` instance is passed, it will be used as-is. -5436 right: the SQL code string corresponding to the right-hand side. -5437 If an `Expression` instance is passed, it will be used as-is. -5438 distinct: set the DISTINCT flag if and only if this is true. -5439 dialect: the dialect used to parse the input expression. -5440 opts: other options to use to parse the input expressions. -5441 -5442 Returns: -5443 The new Union instance. -5444 """ -5445 left = maybe_parse(sql_or_expression=left, dialect=dialect, **opts) -5446 right = maybe_parse(sql_or_expression=right, dialect=dialect, **opts) -5447 -5448 return Union(this=left, expression=right, distinct=distinct) +@@ -76458,6 +77300,7 @@ If an5475def union( +5476 left: ExpOrStr, +5477 right: ExpOrStr, +5478 distinct: bool = True, +5479 dialect: DialectType = None, +5480 copy: bool = True, +5481 **opts, +5482) -> Union: +5483 """ +5484 Initializes a syntax tree from one UNION expression. +5485 +5486 Example: +5487 >>> union("SELECT * FROM foo", "SELECT * FROM bla").sql() +5488 'SELECT * FROM foo UNION SELECT * FROM bla' +5489 +5490 Args: +5491 left: the SQL code string corresponding to the left-hand side. +5492 If an `Expression` instance is passed, it will be used as-is. +5493 right: the SQL code string corresponding to the right-hand side. +5494 If an `Expression` instance is passed, it will be used as-is. +5495 distinct: set the DISTINCT flag if and only if this is true. +5496 dialect: the dialect used to parse the input expression. +5497 copy: whether or not to copy the expression. +5498 opts: other options to use to parse the input expressions. +5499 +5500 Returns: +5501 The new Union instance. +5502 """ +5503 left = maybe_parse(sql_or_expression=left, dialect=dialect, copy=copy, **opts) +5504 right = maybe_parse(sql_or_expression=right, dialect=dialect, copy=copy, **opts) +5505 +5506 return Union(this=left, expression=right, distinct=distinct)Expression
instance is passed, it w If anExpression
instance is passed, it will be used as-is.distinct: set the DISTINCT flag if and only if this is true. dialect: the dialect used to parse the input expression. +copy: whether or not to copy the expression. opts: other options to use to parse the input expressions. @@ -76475,38 +77318,44 @@ If anExpression
instance is passed, it wdef - intersect( left: Union[str, Expression], right: Union[str, Expression], distinct: bool = True, dialect: Union[str, sqlglot.dialects.dialect.Dialect, Type[sqlglot.dialects.dialect.Dialect], NoneType] = None, **opts) -> Intersect: + intersect( left: Union[str, Expression], right: Union[str, Expression], distinct: bool = True, dialect: Union[str, sqlglot.dialects.dialect.Dialect, Type[sqlglot.dialects.dialect.Dialect], NoneType] = None, copy: bool = True, **opts) -> Intersect:-5451def intersect( -5452 left: ExpOrStr, right: ExpOrStr, distinct: bool = True, dialect: DialectType = None, **opts -5453) -> Intersect: -5454 """ -5455 Initializes a syntax tree from one INTERSECT expression. -5456 -5457 Example: -5458 >>> intersect("SELECT * FROM foo", "SELECT * FROM bla").sql() -5459 'SELECT * FROM foo INTERSECT SELECT * FROM bla' -5460 -5461 Args: -5462 left: the SQL code string corresponding to the left-hand side. -5463 If an `Expression` instance is passed, it will be used as-is. -5464 right: the SQL code string corresponding to the right-hand side. -5465 If an `Expression` instance is passed, it will be used as-is. -5466 distinct: set the DISTINCT flag if and only if this is true. -5467 dialect: the dialect used to parse the input expression. -5468 opts: other options to use to parse the input expressions. -5469 -5470 Returns: -5471 The new Intersect instance. -5472 """ -5473 left = maybe_parse(sql_or_expression=left, dialect=dialect, **opts) -5474 right = maybe_parse(sql_or_expression=right, dialect=dialect, **opts) -5475 -5476 return Intersect(this=left, expression=right, distinct=distinct) +@@ -76531,6 +77380,7 @@ If an5509def intersect( +5510 left: ExpOrStr, +5511 right: ExpOrStr, +5512 distinct: bool = True, +5513 dialect: DialectType = None, +5514 copy: bool = True, +5515 **opts, +5516) -> Intersect: +5517 """ +5518 Initializes a syntax tree from one INTERSECT expression. +5519 +5520 Example: +5521 >>> intersect("SELECT * FROM foo", "SELECT * FROM bla").sql() +5522 'SELECT * FROM foo INTERSECT SELECT * FROM bla' +5523 +5524 Args: +5525 left: the SQL code string corresponding to the left-hand side. +5526 If an `Expression` instance is passed, it will be used as-is. +5527 right: the SQL code string corresponding to the right-hand side. +5528 If an `Expression` instance is passed, it will be used as-is. +5529 distinct: set the DISTINCT flag if and only if this is true. +5530 dialect: the dialect used to parse the input expression. +5531 copy: whether or not to copy the expression. +5532 opts: other options to use to parse the input expressions. +5533 +5534 Returns: +5535 The new Intersect instance. +5536 """ +5537 left = maybe_parse(sql_or_expression=left, dialect=dialect, copy=copy, **opts) +5538 right = maybe_parse(sql_or_expression=right, dialect=dialect, copy=copy, **opts) +5539 +5540 return Intersect(this=left, expression=right, distinct=distinct)Expression
instance is passed, it w If anExpression
instance is passed, it will be used as-is.distinct: set the DISTINCT flag if and only if this is true. dialect: the dialect used to parse the input expression. +copy: whether or not to copy the expression. opts: other options to use to parse the input expressions. @@ -76548,38 +77398,44 @@ If anExpression
instance is passed, it wdef - except_( left: Union[str, Expression], right: Union[str, Expression], distinct: bool = True, dialect: Union[str, sqlglot.dialects.dialect.Dialect, Type[sqlglot.dialects.dialect.Dialect], NoneType] = None, **opts) -> Except: + except_( left: Union[str, Expression], right: Union[str, Expression], distinct: bool = True, dialect: Union[str, sqlglot.dialects.dialect.Dialect, Type[sqlglot.dialects.dialect.Dialect], NoneType] = None, copy: bool = True, **opts) -> Except:--5479def except_( -5480 left: ExpOrStr, right: ExpOrStr, distinct: bool = True, dialect: DialectType = None, **opts -5481) -> Except: -5482 """ -5483 Initializes a syntax tree from one EXCEPT expression. -5484 -5485 Example: -5486 >>> except_("SELECT * FROM foo", "SELECT * FROM bla").sql() -5487 'SELECT * FROM foo EXCEPT SELECT * FROM bla' -5488 -5489 Args: -5490 left: the SQL code string corresponding to the left-hand side. -5491 If an `Expression` instance is passed, it will be used as-is. -5492 right: the SQL code string corresponding to the right-hand side. -5493 If an `Expression` instance is passed, it will be used as-is. -5494 distinct: set the DISTINCT flag if and only if this is true. -5495 dialect: the dialect used to parse the input expression. -5496 opts: other options to use to parse the input expressions. -5497 -5498 Returns: -5499 The new Except instance. -5500 """ -5501 left = maybe_parse(sql_or_expression=left, dialect=dialect, **opts) -5502 right = maybe_parse(sql_or_expression=right, dialect=dialect, **opts) -5503 -5504 return Except(this=left, expression=right, distinct=distinct) +@@ -76604,6 +77460,7 @@ If an5543def except_( +5544 left: ExpOrStr, +5545 right: ExpOrStr, +5546 distinct: bool = True, +5547 dialect: DialectType = None, +5548 copy: bool = True, +5549 **opts, +5550) -> Except: +5551 """ +5552 Initializes a syntax tree from one EXCEPT expression. +5553 +5554 Example: +5555 >>> except_("SELECT * FROM foo", "SELECT * FROM bla").sql() +5556 'SELECT * FROM foo EXCEPT SELECT * FROM bla' +5557 +5558 Args: +5559 left: the SQL code string corresponding to the left-hand side. +5560 If an `Expression` instance is passed, it will be used as-is. +5561 right: the SQL code string corresponding to the right-hand side. +5562 If an `Expression` instance is passed, it will be used as-is. +5563 distinct: set the DISTINCT flag if and only if this is true. +5564 dialect: the dialect used to parse the input expression. +5565 copy: whether or not to copy the expression. +5566 opts: other options to use to parse the input expressions. +5567 +5568 Returns: +5569 The new Except instance. +5570 """ +5571 left = maybe_parse(sql_or_expression=left, dialect=dialect, copy=copy, **opts) +5572 right = maybe_parse(sql_or_expression=right, dialect=dialect, copy=copy, **opts) +5573 +5574 return Except(this=left, expression=right, distinct=distinct)Expression
instance is passed, it w If anExpression
instance is passed, it will be used as-is.distinct: set the DISTINCT flag if and only if this is true. dialect: the dialect used to parse the input expression. +copy: whether or not to copy the expression. opts: other options to use to parse the input expressions. @@ -76627,26 +77484,26 @@ If anExpression
instance is passed, it w-5507def select(*expressions: ExpOrStr, dialect: DialectType = None, **opts) -> Select: -5508 """ -5509 Initializes a syntax tree from one or multiple SELECT expressions. -5510 -5511 Example: -5512 >>> select("col1", "col2").from_("tbl").sql() -5513 'SELECT col1, col2 FROM tbl' -5514 -5515 Args: -5516 *expressions: the SQL code string to parse as the expressions of a -5517 SELECT statement. If an Expression instance is passed, this is used as-is. -5518 dialect: the dialect used to parse the input expressions (in the case that an -5519 input expression is a SQL string). -5520 **opts: other options to use to parse the input expressions (again, in the case -5521 that an input expression is a SQL string). -5522 -5523 Returns: -5524 Select: the syntax tree for the SELECT statement. -5525 """ -5526 return Select().select(*expressions, dialect=dialect, **opts) +@@ -76693,26 +77550,26 @@ that an input expression is a SQL string).5577def select(*expressions: ExpOrStr, dialect: DialectType = None, **opts) -> Select: +5578 """ +5579 Initializes a syntax tree from one or multiple SELECT expressions. +5580 +5581 Example: +5582 >>> select("col1", "col2").from_("tbl").sql() +5583 'SELECT col1, col2 FROM tbl' +5584 +5585 Args: +5586 *expressions: the SQL code string to parse as the expressions of a +5587 SELECT statement. If an Expression instance is passed, this is used as-is. +5588 dialect: the dialect used to parse the input expressions (in the case that an +5589 input expression is a SQL string). +5590 **opts: other options to use to parse the input expressions (again, in the case +5591 that an input expression is a SQL string). +5592 +5593 Returns: +5594 Select: the syntax tree for the SELECT statement. +5595 """ +5596 return Select().select(*expressions, dialect=dialect, **opts)-5529def from_(expression: ExpOrStr, dialect: DialectType = None, **opts) -> Select: -5530 """ -5531 Initializes a syntax tree from a FROM expression. -5532 -5533 Example: -5534 >>> from_("tbl").select("col1", "col2").sql() -5535 'SELECT col1, col2 FROM tbl' -5536 -5537 Args: -5538 *expression: the SQL code string to parse as the FROM expressions of a -5539 SELECT statement. If an Expression instance is passed, this is used as-is. -5540 dialect: the dialect used to parse the input expression (in the case that the -5541 input expression is a SQL string). -5542 **opts: other options to use to parse the input expressions (again, in the case -5543 that the input expression is a SQL string). -5544 -5545 Returns: -5546 Select: the syntax tree for the SELECT statement. -5547 """ -5548 return Select().from_(expression, dialect=dialect, **opts) +@@ -76759,53 +77616,53 @@ that the input expression is a SQL string).5599def from_(expression: ExpOrStr, dialect: DialectType = None, **opts) -> Select: +5600 """ +5601 Initializes a syntax tree from a FROM expression. +5602 +5603 Example: +5604 >>> from_("tbl").select("col1", "col2").sql() +5605 'SELECT col1, col2 FROM tbl' +5606 +5607 Args: +5608 *expression: the SQL code string to parse as the FROM expressions of a +5609 SELECT statement. If an Expression instance is passed, this is used as-is. +5610 dialect: the dialect used to parse the input expression (in the case that the +5611 input expression is a SQL string). +5612 **opts: other options to use to parse the input expressions (again, in the case +5613 that the input expression is a SQL string). +5614 +5615 Returns: +5616 Select: the syntax tree for the SELECT statement. +5617 """ +5618 return Select().from_(expression, dialect=dialect, **opts)-5551def update( -5552 table: str | Table, -5553 properties: dict, -5554 where: t.Optional[ExpOrStr] = None, -5555 from_: t.Optional[ExpOrStr] = None, -5556 dialect: DialectType = None, -5557 **opts, -5558) -> Update: -5559 """ -5560 Creates an update statement. -5561 -5562 Example: -5563 >>> update("my_table", {"x": 1, "y": "2", "z": None}, from_="baz", where="id > 1").sql() -5564 "UPDATE my_table SET x = 1, y = '2', z = NULL FROM baz WHERE id > 1" -5565 -5566 Args: -5567 *properties: dictionary of properties to set which are -5568 auto converted to sql objects eg None -> NULL -5569 where: sql conditional parsed into a WHERE statement -5570 from_: sql statement parsed into a FROM statement -5571 dialect: the dialect used to parse the input expressions. -5572 **opts: other options to use to parse the input expressions. -5573 -5574 Returns: -5575 Update: the syntax tree for the UPDATE statement. -5576 """ -5577 update_expr = Update(this=maybe_parse(table, into=Table, dialect=dialect)) -5578 update_expr.set( -5579 "expressions", -5580 [ -5581 EQ(this=maybe_parse(k, dialect=dialect, **opts), expression=convert(v)) -5582 for k, v in properties.items() -5583 ], -5584 ) -5585 if from_: -5586 update_expr.set( -5587 "from", -5588 maybe_parse(from_, into=From, dialect=dialect, prefix="FROM", **opts), -5589 ) -5590 if isinstance(where, Condition): -5591 where = Where(this=where) -5592 if where: -5593 update_expr.set( -5594 "where", -5595 maybe_parse(where, into=Where, dialect=dialect, prefix="WHERE", **opts), -5596 ) -5597 return update_expr +@@ -76852,35 +77709,35 @@ auto converted to sql objects eg None -> NULL5621def update( +5622 table: str | Table, +5623 properties: dict, +5624 where: t.Optional[ExpOrStr] = None, +5625 from_: t.Optional[ExpOrStr] = None, +5626 dialect: DialectType = None, +5627 **opts, +5628) -> Update: +5629 """ +5630 Creates an update statement. +5631 +5632 Example: +5633 >>> update("my_table", {"x": 1, "y": "2", "z": None}, from_="baz", where="id > 1").sql() +5634 "UPDATE my_table SET x = 1, y = '2', z = NULL FROM baz WHERE id > 1" +5635 +5636 Args: +5637 *properties: dictionary of properties to set which are +5638 auto converted to sql objects eg None -> NULL +5639 where: sql conditional parsed into a WHERE statement +5640 from_: sql statement parsed into a FROM statement +5641 dialect: the dialect used to parse the input expressions. +5642 **opts: other options to use to parse the input expressions. +5643 +5644 Returns: +5645 Update: the syntax tree for the UPDATE statement. +5646 """ +5647 update_expr = Update(this=maybe_parse(table, into=Table, dialect=dialect)) +5648 update_expr.set( +5649 "expressions", +5650 [ +5651 EQ(this=maybe_parse(k, dialect=dialect, **opts), expression=convert(v)) +5652 for k, v in properties.items() +5653 ], +5654 ) +5655 if from_: +5656 update_expr.set( +5657 "from", +5658 maybe_parse(from_, into=From, dialect=dialect, prefix="FROM", **opts), +5659 ) +5660 if isinstance(where, Condition): +5661 where = Where(this=where) +5662 if where: +5663 update_expr.set( +5664 "where", +5665 maybe_parse(where, into=Where, dialect=dialect, prefix="WHERE", **opts), +5666 ) +5667 return update_expr-5600def delete( -5601 table: ExpOrStr, -5602 where: t.Optional[ExpOrStr] = None, -5603 returning: t.Optional[ExpOrStr] = None, -5604 dialect: DialectType = None, -5605 **opts, -5606) -> Delete: -5607 """ -5608 Builds a delete statement. -5609 -5610 Example: -5611 >>> delete("my_table", where="id > 1").sql() -5612 'DELETE FROM my_table WHERE id > 1' -5613 -5614 Args: -5615 where: sql conditional parsed into a WHERE statement -5616 returning: sql conditional parsed into a RETURNING statement -5617 dialect: the dialect used to parse the input expressions. -5618 **opts: other options to use to parse the input expressions. -5619 -5620 Returns: -5621 Delete: the syntax tree for the DELETE statement. -5622 """ -5623 delete_expr = Delete().delete(table, dialect=dialect, copy=False, **opts) -5624 if where: -5625 delete_expr = delete_expr.where(where, dialect=dialect, copy=False, **opts) -5626 if returning: -5627 delete_expr = delete_expr.returning(returning, dialect=dialect, copy=False, **opts) -5628 return delete_expr +@@ -76925,49 +77782,49 @@ auto converted to sql objects eg None -> NULL5670def delete( +5671 table: ExpOrStr, +5672 where: t.Optional[ExpOrStr] = None, +5673 returning: t.Optional[ExpOrStr] = None, +5674 dialect: DialectType = None, +5675 **opts, +5676) -> Delete: +5677 """ +5678 Builds a delete statement. +5679 +5680 Example: +5681 >>> delete("my_table", where="id > 1").sql() +5682 'DELETE FROM my_table WHERE id > 1' +5683 +5684 Args: +5685 where: sql conditional parsed into a WHERE statement +5686 returning: sql conditional parsed into a RETURNING statement +5687 dialect: the dialect used to parse the input expressions. +5688 **opts: other options to use to parse the input expressions. +5689 +5690 Returns: +5691 Delete: the syntax tree for the DELETE statement. +5692 """ +5693 delete_expr = Delete().delete(table, dialect=dialect, copy=False, **opts) +5694 if where: +5695 delete_expr = delete_expr.where(where, dialect=dialect, copy=False, **opts) +5696 if returning: +5697 delete_expr = delete_expr.returning(returning, dialect=dialect, copy=False, **opts) +5698 return delete_expr-5631def insert( -5632 expression: ExpOrStr, -5633 into: ExpOrStr, -5634 columns: t.Optional[t.Sequence[ExpOrStr]] = None, -5635 overwrite: t.Optional[bool] = None, -5636 dialect: DialectType = None, -5637 copy: bool = True, -5638 **opts, -5639) -> Insert: -5640 """ -5641 Builds an INSERT statement. -5642 -5643 Example: -5644 >>> insert("VALUES (1, 2, 3)", "tbl").sql() -5645 'INSERT INTO tbl VALUES (1, 2, 3)' -5646 -5647 Args: -5648 expression: the sql string or expression of the INSERT statement -5649 into: the tbl to insert data to. -5650 columns: optionally the table's column names. -5651 overwrite: whether to INSERT OVERWRITE or not. -5652 dialect: the dialect used to parse the input expressions. -5653 copy: whether or not to copy the expression. -5654 **opts: other options to use to parse the input expressions. -5655 -5656 Returns: -5657 Insert: the syntax tree for the INSERT statement. -5658 """ -5659 expr = maybe_parse(expression, dialect=dialect, copy=copy, **opts) -5660 this: Table | Schema = maybe_parse(into, into=Table, dialect=dialect, copy=copy, **opts) -5661 -5662 if columns: -5663 this = _apply_list_builder( -5664 *columns, -5665 instance=Schema(this=this), -5666 arg="expressions", -5667 into=Identifier, -5668 copy=False, -5669 dialect=dialect, -5670 **opts, -5671 ) -5672 -5673 return Insert(this=this, expression=expr, overwrite=overwrite) +@@ -77015,41 +77872,41 @@ auto converted to sql objects eg None -> NULL5701def insert( +5702 expression: ExpOrStr, +5703 into: ExpOrStr, +5704 columns: t.Optional[t.Sequence[ExpOrStr]] = None, +5705 overwrite: t.Optional[bool] = None, +5706 dialect: DialectType = None, +5707 copy: bool = True, +5708 **opts, +5709) -> Insert: +5710 """ +5711 Builds an INSERT statement. +5712 +5713 Example: +5714 >>> insert("VALUES (1, 2, 3)", "tbl").sql() +5715 'INSERT INTO tbl VALUES (1, 2, 3)' +5716 +5717 Args: +5718 expression: the sql string or expression of the INSERT statement +5719 into: the tbl to insert data to. +5720 columns: optionally the table's column names. +5721 overwrite: whether to INSERT OVERWRITE or not. +5722 dialect: the dialect used to parse the input expressions. +5723 copy: whether or not to copy the expression. +5724 **opts: other options to use to parse the input expressions. +5725 +5726 Returns: +5727 Insert: the syntax tree for the INSERT statement. +5728 """ +5729 expr = maybe_parse(expression, dialect=dialect, copy=copy, **opts) +5730 this: Table | Schema = maybe_parse(into, into=Table, dialect=dialect, copy=copy, **opts) +5731 +5732 if columns: +5733 this = _apply_list_builder( +5734 *columns, +5735 instance=Schema(this=this), +5736 arg="expressions", +5737 into=Identifier, +5738 copy=False, +5739 dialect=dialect, +5740 **opts, +5741 ) +5742 +5743 return Insert(this=this, expression=expr, overwrite=overwrite)-5676def condition( -5677 expression: ExpOrStr, dialect: DialectType = None, copy: bool = True, **opts -5678) -> Condition: -5679 """ -5680 Initialize a logical condition expression. -5681 -5682 Example: -5683 >>> condition("x=1").sql() -5684 'x = 1' -5685 -5686 This is helpful for composing larger logical syntax trees: -5687 >>> where = condition("x=1") -5688 >>> where = where.and_("y=1") -5689 >>> Select().from_("tbl").select("*").where(where).sql() -5690 'SELECT * FROM tbl WHERE x = 1 AND y = 1' -5691 -5692 Args: -5693 *expression: the SQL code string to parse. -5694 If an Expression instance is passed, this is used as-is. -5695 dialect: the dialect used to parse the input expression (in the case that the -5696 input expression is a SQL string). -5697 copy: Whether or not to copy `expression` (only applies to expressions). -5698 **opts: other options to use to parse the input expressions (again, in the case -5699 that the input expression is a SQL string). -5700 -5701 Returns: -5702 The new Condition instance -5703 """ -5704 return maybe_parse( -5705 expression, -5706 into=Condition, -5707 dialect=dialect, -5708 copy=copy, -5709 **opts, -5710 ) +@@ -77107,27 +77964,27 @@ that the input expression is a SQL string).5746def condition( +5747 expression: ExpOrStr, dialect: DialectType = None, copy: bool = True, **opts +5748) -> Condition: +5749 """ +5750 Initialize a logical condition expression. +5751 +5752 Example: +5753 >>> condition("x=1").sql() +5754 'x = 1' +5755 +5756 This is helpful for composing larger logical syntax trees: +5757 >>> where = condition("x=1") +5758 >>> where = where.and_("y=1") +5759 >>> Select().from_("tbl").select("*").where(where).sql() +5760 'SELECT * FROM tbl WHERE x = 1 AND y = 1' +5761 +5762 Args: +5763 *expression: the SQL code string to parse. +5764 If an Expression instance is passed, this is used as-is. +5765 dialect: the dialect used to parse the input expression (in the case that the +5766 input expression is a SQL string). +5767 copy: Whether or not to copy `expression` (only applies to expressions). +5768 **opts: other options to use to parse the input expressions (again, in the case +5769 that the input expression is a SQL string). +5770 +5771 Returns: +5772 The new Condition instance +5773 """ +5774 return maybe_parse( +5775 expression, +5776 into=Condition, +5777 dialect=dialect, +5778 copy=copy, +5779 **opts, +5780 )-5713def and_( -5714 *expressions: t.Optional[ExpOrStr], dialect: DialectType = None, copy: bool = True, **opts -5715) -> Condition: -5716 """ -5717 Combine multiple conditions with an AND logical operator. -5718 -5719 Example: -5720 >>> and_("x=1", and_("y=1", "z=1")).sql() -5721 'x = 1 AND (y = 1 AND z = 1)' -5722 -5723 Args: -5724 *expressions: the SQL code strings to parse. -5725 If an Expression instance is passed, this is used as-is. -5726 dialect: the dialect used to parse the input expression. -5727 copy: whether or not to copy `expressions` (only applies to Expressions). -5728 **opts: other options to use to parse the input expressions. -5729 -5730 Returns: -5731 And: the new condition -5732 """ -5733 return t.cast(Condition, _combine(expressions, And, dialect, copy=copy, **opts)) +@@ -77173,27 +78030,27 @@ If an Expression instance is passed, this is used as-is.5783def and_( +5784 *expressions: t.Optional[ExpOrStr], dialect: DialectType = None, copy: bool = True, **opts +5785) -> Condition: +5786 """ +5787 Combine multiple conditions with an AND logical operator. +5788 +5789 Example: +5790 >>> and_("x=1", and_("y=1", "z=1")).sql() +5791 'x = 1 AND (y = 1 AND z = 1)' +5792 +5793 Args: +5794 *expressions: the SQL code strings to parse. +5795 If an Expression instance is passed, this is used as-is. +5796 dialect: the dialect used to parse the input expression. +5797 copy: whether or not to copy `expressions` (only applies to Expressions). +5798 **opts: other options to use to parse the input expressions. +5799 +5800 Returns: +5801 And: the new condition +5802 """ +5803 return t.cast(Condition, _combine(expressions, And, dialect, copy=copy, **opts))-5736def or_( -5737 *expressions: t.Optional[ExpOrStr], dialect: DialectType = None, copy: bool = True, **opts -5738) -> Condition: -5739 """ -5740 Combine multiple conditions with an OR logical operator. -5741 -5742 Example: -5743 >>> or_("x=1", or_("y=1", "z=1")).sql() -5744 'x = 1 OR (y = 1 OR z = 1)' -5745 -5746 Args: -5747 *expressions: the SQL code strings to parse. -5748 If an Expression instance is passed, this is used as-is. -5749 dialect: the dialect used to parse the input expression. -5750 copy: whether or not to copy `expressions` (only applies to Expressions). -5751 **opts: other options to use to parse the input expressions. -5752 -5753 Returns: -5754 Or: the new condition -5755 """ -5756 return t.cast(Condition, _combine(expressions, Or, dialect, copy=copy, **opts)) +@@ -77239,31 +78096,31 @@ If an Expression instance is passed, this is used as-is.5806def or_( +5807 *expressions: t.Optional[ExpOrStr], dialect: DialectType = None, copy: bool = True, **opts +5808) -> Condition: +5809 """ +5810 Combine multiple conditions with an OR logical operator. +5811 +5812 Example: +5813 >>> or_("x=1", or_("y=1", "z=1")).sql() +5814 'x = 1 OR (y = 1 OR z = 1)' +5815 +5816 Args: +5817 *expressions: the SQL code strings to parse. +5818 If an Expression instance is passed, this is used as-is. +5819 dialect: the dialect used to parse the input expression. +5820 copy: whether or not to copy `expressions` (only applies to Expressions). +5821 **opts: other options to use to parse the input expressions. +5822 +5823 Returns: +5824 Or: the new condition +5825 """ +5826 return t.cast(Condition, _combine(expressions, Or, dialect, copy=copy, **opts))-5759def not_(expression: ExpOrStr, dialect: DialectType = None, copy: bool = True, **opts) -> Not: -5760 """ -5761 Wrap a condition with a NOT operator. -5762 -5763 Example: -5764 >>> not_("this_suit='black'").sql() -5765 "NOT this_suit = 'black'" -5766 -5767 Args: -5768 expression: the SQL code string to parse. -5769 If an Expression instance is passed, this is used as-is. -5770 dialect: the dialect used to parse the input expression. -5771 copy: whether to copy the expression or not. -5772 **opts: other options to use to parse the input expressions. -5773 -5774 Returns: -5775 The new condition. -5776 """ -5777 this = condition( -5778 expression, -5779 dialect=dialect, -5780 copy=copy, -5781 **opts, -5782 ) -5783 return Not(this=_wrap(this, Connector)) +@@ -77309,23 +78166,23 @@ If an Expression instance is passed, this is used as-is.5829def not_(expression: ExpOrStr, dialect: DialectType = None, copy: bool = True, **opts) -> Not: +5830 """ +5831 Wrap a condition with a NOT operator. +5832 +5833 Example: +5834 >>> not_("this_suit='black'").sql() +5835 "NOT this_suit = 'black'" +5836 +5837 Args: +5838 expression: the SQL code string to parse. +5839 If an Expression instance is passed, this is used as-is. +5840 dialect: the dialect used to parse the input expression. +5841 copy: whether to copy the expression or not. +5842 **opts: other options to use to parse the input expressions. +5843 +5844 Returns: +5845 The new condition. +5846 """ +5847 this = condition( +5848 expression, +5849 dialect=dialect, +5850 copy=copy, +5851 **opts, +5852 ) +5853 return Not(this=_wrap(this, Connector))-5786def paren(expression: ExpOrStr, copy: bool = True) -> Paren: -5787 """ -5788 Wrap an expression in parentheses. -5789 -5790 Example: -5791 >>> paren("5 + 3").sql() -5792 '(5 + 3)' -5793 -5794 Args: -5795 expression: the SQL code string to parse. -5796 If an Expression instance is passed, this is used as-is. -5797 copy: whether to copy the expression or not. -5798 -5799 Returns: -5800 The wrapped expression. -5801 """ -5802 return Paren(this=maybe_parse(expression, copy=copy)) +@@ -77381,31 +78238,31 @@ If an Expression instance is passed, this is used as-is.5856def paren(expression: ExpOrStr, copy: bool = True) -> Paren: +5857 """ +5858 Wrap an expression in parentheses. +5859 +5860 Example: +5861 >>> paren("5 + 3").sql() +5862 '(5 + 3)' +5863 +5864 Args: +5865 expression: the SQL code string to parse. +5866 If an Expression instance is passed, this is used as-is. +5867 copy: whether to copy the expression or not. +5868 +5869 Returns: +5870 The wrapped expression. +5871 """ +5872 return Paren(this=maybe_parse(expression, copy=copy))-5820def to_identifier(name, quoted=None, copy=True): -5821 """Builds an identifier. -5822 -5823 Args: -5824 name: The name to turn into an identifier. -5825 quoted: Whether or not force quote the identifier. -5826 copy: Whether or not to copy a passed in Identefier node. -5827 -5828 Returns: -5829 The identifier ast node. -5830 """ -5831 -5832 if name is None: -5833 return None -5834 -5835 if isinstance(name, Identifier): -5836 identifier = maybe_copy(name, copy) -5837 elif isinstance(name, str): -5838 identifier = Identifier( -5839 this=name, -5840 quoted=not SAFE_IDENTIFIER_RE.match(name) if quoted is None else quoted, -5841 ) -5842 else: -5843 raise ValueError(f"Name needs to be a string or an Identifier, got: {name.__class__}") -5844 return identifier +@@ -77451,23 +78308,23 @@ If an Expression instance is passed, this is used as-is.5890def to_identifier(name, quoted=None, copy=True): +5891 """Builds an identifier. +5892 +5893 Args: +5894 name: The name to turn into an identifier. +5895 quoted: Whether or not force quote the identifier. +5896 copy: Whether or not to copy a passed in Identefier node. +5897 +5898 Returns: +5899 The identifier ast node. +5900 """ +5901 +5902 if name is None: +5903 return None +5904 +5905 if isinstance(name, Identifier): +5906 identifier = maybe_copy(name, copy) +5907 elif isinstance(name, str): +5908 identifier = Identifier( +5909 this=name, +5910 quoted=not SAFE_IDENTIFIER_RE.match(name) if quoted is None else quoted, +5911 ) +5912 else: +5913 raise ValueError(f"Name needs to be a string or an Identifier, got: {name.__class__}") +5914 return identifier-5850def to_interval(interval: str | Literal) -> Interval: -5851 """Builds an interval expression from a string like '1 day' or '5 months'.""" -5852 if isinstance(interval, Literal): -5853 if not interval.is_string: -5854 raise ValueError("Invalid interval string.") -5855 -5856 interval = interval.this -5857 -5858 interval_parts = INTERVAL_STRING_RE.match(interval) # type: ignore -5859 -5860 if not interval_parts: -5861 raise ValueError("Invalid interval string.") -5862 -5863 return Interval( -5864 this=Literal.string(interval_parts.group(1)), -5865 unit=Var(this=interval_parts.group(2)), -5866 ) +@@ -77487,32 +78344,32 @@ If an Expression instance is passed, this is used as-is.5920def to_interval(interval: str | Literal) -> Interval: +5921 """Builds an interval expression from a string like '1 day' or '5 months'.""" +5922 if isinstance(interval, Literal): +5923 if not interval.is_string: +5924 raise ValueError("Invalid interval string.") +5925 +5926 interval = interval.this +5927 +5928 interval_parts = INTERVAL_STRING_RE.match(interval) # type: ignore +5929 +5930 if not interval_parts: +5931 raise ValueError("Invalid interval string.") +5932 +5933 return Interval( +5934 this=Literal.string(interval_parts.group(1)), +5935 unit=Var(this=interval_parts.group(2)), +5936 )-5879def to_table( -5880 sql_path: t.Optional[str | Table], dialect: DialectType = None, **kwargs -5881) -> t.Optional[Table]: -5882 """ -5883 Create a table expression from a `[catalog].[schema].[table]` sql path. Catalog and schema are optional. -5884 If a table is passed in then that table is returned. -5885 -5886 Args: -5887 sql_path: a `[catalog].[schema].[table]` string. -5888 dialect: the source dialect according to which the table name will be parsed. -5889 kwargs: the kwargs to instantiate the resulting `Table` expression with. -5890 -5891 Returns: -5892 A table expression. -5893 """ -5894 if sql_path is None or isinstance(sql_path, Table): -5895 return sql_path -5896 if not isinstance(sql_path, str): -5897 raise ValueError(f"Invalid type provided for a table: {type(sql_path)}") -5898 -5899 table = maybe_parse(sql_path, into=Table, dialect=dialect) -5900 if table: -5901 for k, v in kwargs.items(): -5902 table.set(k, v) -5903 -5904 return table +@@ -77547,22 +78404,22 @@ If a table is passed in then that table is returned.5949def to_table( +5950 sql_path: t.Optional[str | Table], dialect: DialectType = None, **kwargs +5951) -> t.Optional[Table]: +5952 """ +5953 Create a table expression from a `[catalog].[schema].[table]` sql path. Catalog and schema are optional. +5954 If a table is passed in then that table is returned. +5955 +5956 Args: +5957 sql_path: a `[catalog].[schema].[table]` string. +5958 dialect: the source dialect according to which the table name will be parsed. +5959 kwargs: the kwargs to instantiate the resulting `Table` expression with. +5960 +5961 Returns: +5962 A table expression. +5963 """ +5964 if sql_path is None or isinstance(sql_path, Table): +5965 return sql_path +5966 if not isinstance(sql_path, str): +5967 raise ValueError(f"Invalid type provided for a table: {type(sql_path)}") +5968 +5969 table = maybe_parse(sql_path, into=Table, dialect=dialect) +5970 if table: +5971 for k, v in kwargs.items(): +5972 table.set(k, v) +5973 +5974 return table-5907def to_column(sql_path: str | Column, **kwargs) -> Column: -5908 """ -5909 Create a column from a `[table].[column]` sql path. Schema is optional. -5910 -5911 If a column is passed in then that column is returned. -5912 -5913 Args: -5914 sql_path: `[table].[column]` string -5915 Returns: -5916 Table: A column expression -5917 """ -5918 if sql_path is None or isinstance(sql_path, Column): -5919 return sql_path -5920 if not isinstance(sql_path, str): -5921 raise ValueError(f"Invalid type provided for column: {type(sql_path)}") -5922 return column(*reversed(sql_path.split(".")), **kwargs) # type: ignore +@@ -77596,61 +78453,61 @@ If a table is passed in then that table is returned.5977def to_column(sql_path: str | Column, **kwargs) -> Column: +5978 """ +5979 Create a column from a `[table].[column]` sql path. Schema is optional. +5980 +5981 If a column is passed in then that column is returned. +5982 +5983 Args: +5984 sql_path: `[table].[column]` string +5985 Returns: +5986 Table: A column expression +5987 """ +5988 if sql_path is None or isinstance(sql_path, Column): +5989 return sql_path +5990 if not isinstance(sql_path, str): +5991 raise ValueError(f"Invalid type provided for column: {type(sql_path)}") +5992 return column(*reversed(sql_path.split(".")), **kwargs) # type: ignore-5925def alias_( -5926 expression: ExpOrStr, -5927 alias: str | Identifier, -5928 table: bool | t.Sequence[str | Identifier] = False, -5929 quoted: t.Optional[bool] = None, -5930 dialect: DialectType = None, -5931 copy: bool = True, -5932 **opts, -5933): -5934 """Create an Alias expression. -5935 -5936 Example: -5937 >>> alias_('foo', 'bar').sql() -5938 'foo AS bar' -5939 -5940 >>> alias_('(select 1, 2)', 'bar', table=['a', 'b']).sql() -5941 '(SELECT 1, 2) AS bar(a, b)' -5942 -5943 Args: -5944 expression: the SQL code strings to parse. -5945 If an Expression instance is passed, this is used as-is. -5946 alias: the alias name to use. If the name has -5947 special characters it is quoted. -5948 table: Whether or not to create a table alias, can also be a list of columns. -5949 quoted: whether or not to quote the alias -5950 dialect: the dialect used to parse the input expression. -5951 copy: Whether or not to copy the expression. -5952 **opts: other options to use to parse the input expressions. -5953 -5954 Returns: -5955 Alias: the aliased expression -5956 """ -5957 exp = maybe_parse(expression, dialect=dialect, copy=copy, **opts) -5958 alias = to_identifier(alias, quoted=quoted) -5959 -5960 if table: -5961 table_alias = TableAlias(this=alias) -5962 exp.set("alias", table_alias) -5963 -5964 if not isinstance(table, bool): -5965 for column in table: -5966 table_alias.append("columns", to_identifier(column, quoted=quoted)) -5967 -5968 return exp -5969 -5970 # We don't set the "alias" arg for Window expressions, because that would add an IDENTIFIER node in -5971 # the AST, representing a "named_window" [1] construct (eg. bigquery). What we want is an ALIAS node -5972 # for the complete Window expression. -5973 # -5974 # [1]: https://cloud.google.com/bigquery/docs/reference/standard-sql/window-function-calls -5975 -5976 if "alias" in exp.arg_types and not isinstance(exp, Window): -5977 exp.set("alias", alias) -5978 return exp -5979 return Alias(this=exp, alias=alias) +@@ -77706,32 +78563,32 @@ special characters it is quoted.5995def alias_( +5996 expression: ExpOrStr, +5997 alias: str | Identifier, +5998 table: bool | t.Sequence[str | Identifier] = False, +5999 quoted: t.Optional[bool] = None, +6000 dialect: DialectType = None, +6001 copy: bool = True, +6002 **opts, +6003): +6004 """Create an Alias expression. +6005 +6006 Example: +6007 >>> alias_('foo', 'bar').sql() +6008 'foo AS bar' +6009 +6010 >>> alias_('(select 1, 2)', 'bar', table=['a', 'b']).sql() +6011 '(SELECT 1, 2) AS bar(a, b)' +6012 +6013 Args: +6014 expression: the SQL code strings to parse. +6015 If an Expression instance is passed, this is used as-is. +6016 alias: the alias name to use. If the name has +6017 special characters it is quoted. +6018 table: Whether or not to create a table alias, can also be a list of columns. +6019 quoted: whether or not to quote the alias +6020 dialect: the dialect used to parse the input expression. +6021 copy: Whether or not to copy the expression. +6022 **opts: other options to use to parse the input expressions. +6023 +6024 Returns: +6025 Alias: the aliased expression +6026 """ +6027 exp = maybe_parse(expression, dialect=dialect, copy=copy, **opts) +6028 alias = to_identifier(alias, quoted=quoted) +6029 +6030 if table: +6031 table_alias = TableAlias(this=alias) +6032 exp.set("alias", table_alias) +6033 +6034 if not isinstance(table, bool): +6035 for column in table: +6036 table_alias.append("columns", to_identifier(column, quoted=quoted)) +6037 +6038 return exp +6039 +6040 # We don't set the "alias" arg for Window expressions, because that would add an IDENTIFIER node in +6041 # the AST, representing a "named_window" [1] construct (eg. bigquery). What we want is an ALIAS node +6042 # for the complete Window expression. +6043 # +6044 # [1]: https://cloud.google.com/bigquery/docs/reference/standard-sql/window-function-calls +6045 +6046 if "alias" in exp.arg_types and not isinstance(exp, Window): +6047 exp.set("alias", alias) +6048 return exp +6049 return Alias(this=exp, alias=alias)-5982def subquery( -5983 expression: ExpOrStr, -5984 alias: t.Optional[Identifier | str] = None, -5985 dialect: DialectType = None, -5986 **opts, -5987) -> Select: -5988 """ -5989 Build a subquery expression. -5990 -5991 Example: -5992 >>> subquery('select x from tbl', 'bar').select('x').sql() -5993 'SELECT x FROM (SELECT x FROM tbl) AS bar' -5994 -5995 Args: -5996 expression: the SQL code strings to parse. -5997 If an Expression instance is passed, this is used as-is. -5998 alias: the alias name to use. -5999 dialect: the dialect used to parse the input expression. -6000 **opts: other options to use to parse the input expressions. -6001 -6002 Returns: -6003 A new Select instance with the subquery expression included. -6004 """ -6005 -6006 expression = maybe_parse(expression, dialect=dialect, **opts).subquery(alias) -6007 return Select().from_(expression, dialect=dialect, **opts) +@@ -77777,32 +78634,32 @@ If an Expression instance is passed, this is used as-is.6052def subquery( +6053 expression: ExpOrStr, +6054 alias: t.Optional[Identifier | str] = None, +6055 dialect: DialectType = None, +6056 **opts, +6057) -> Select: +6058 """ +6059 Build a subquery expression. +6060 +6061 Example: +6062 >>> subquery('select x from tbl', 'bar').select('x').sql() +6063 'SELECT x FROM (SELECT x FROM tbl) AS bar' +6064 +6065 Args: +6066 expression: the SQL code strings to parse. +6067 If an Expression instance is passed, this is used as-is. +6068 alias: the alias name to use. +6069 dialect: the dialect used to parse the input expression. +6070 **opts: other options to use to parse the input expressions. +6071 +6072 Returns: +6073 A new Select instance with the subquery expression included. +6074 """ +6075 +6076 expression = maybe_parse(expression, dialect=dialect, **opts).subquery(alias) +6077 return Select().from_(expression, dialect=dialect, **opts)-6010def column( -6011 col: str | Identifier, -6012 table: t.Optional[str | Identifier] = None, -6013 db: t.Optional[str | Identifier] = None, -6014 catalog: t.Optional[str | Identifier] = None, -6015 quoted: t.Optional[bool] = None, -6016) -> Column: -6017 """ -6018 Build a Column. -6019 -6020 Args: -6021 col: Column name. -6022 table: Table name. -6023 db: Database name. -6024 catalog: Catalog name. -6025 quoted: Whether to force quotes on the column's identifiers. -6026 -6027 Returns: -6028 The new Column instance. -6029 """ -6030 return Column( -6031 this=to_identifier(col, quoted=quoted), -6032 table=to_identifier(table, quoted=quoted), -6033 db=to_identifier(db, quoted=quoted), -6034 catalog=to_identifier(catalog, quoted=quoted), -6035 ) +@@ -77838,25 +78695,25 @@ If an Expression instance is passed, this is used as-is.6080def column( +6081 col: str | Identifier, +6082 table: t.Optional[str | Identifier] = None, +6083 db: t.Optional[str | Identifier] = None, +6084 catalog: t.Optional[str | Identifier] = None, +6085 quoted: t.Optional[bool] = None, +6086) -> Column: +6087 """ +6088 Build a Column. +6089 +6090 Args: +6091 col: Column name. +6092 table: Table name. +6093 db: Database name. +6094 catalog: Catalog name. +6095 quoted: Whether to force quotes on the column's identifiers. +6096 +6097 Returns: +6098 The new Column instance. +6099 """ +6100 return Column( +6101 this=to_identifier(col, quoted=quoted), +6102 table=to_identifier(table, quoted=quoted), +6103 db=to_identifier(db, quoted=quoted), +6104 catalog=to_identifier(catalog, quoted=quoted), +6105 )-6038def cast(expression: ExpOrStr, to: str | DataType | DataType.Type, **opts) -> Cast: -6039 """Cast an expression to a data type. -6040 -6041 Example: -6042 >>> cast('x + 1', 'int').sql() -6043 'CAST(x + 1 AS INT)' -6044 -6045 Args: -6046 expression: The expression to cast. -6047 to: The datatype to cast to. -6048 -6049 Returns: -6050 The new Cast instance. -6051 """ -6052 expression = maybe_parse(expression, **opts) -6053 data_type = DataType.build(to, **opts) -6054 expression = Cast(this=expression, to=data_type) -6055 expression.type = data_type -6056 return expression +@@ -77899,31 +78756,31 @@ If an Expression instance is passed, this is used as-is.6108def cast(expression: ExpOrStr, to: str | DataType | DataType.Type, **opts) -> Cast: +6109 """Cast an expression to a data type. +6110 +6111 Example: +6112 >>> cast('x + 1', 'int').sql() +6113 'CAST(x + 1 AS INT)' +6114 +6115 Args: +6116 expression: The expression to cast. +6117 to: The datatype to cast to. +6118 +6119 Returns: +6120 The new Cast instance. +6121 """ +6122 expression = maybe_parse(expression, **opts) +6123 data_type = DataType.build(to, **opts) +6124 expression = Cast(this=expression, to=data_type) +6125 expression.type = data_type +6126 return expression-6059def table_( -6060 table: Identifier | str, -6061 db: t.Optional[Identifier | str] = None, -6062 catalog: t.Optional[Identifier | str] = None, -6063 quoted: t.Optional[bool] = None, -6064 alias: t.Optional[Identifier | str] = None, -6065) -> Table: -6066 """Build a Table. -6067 -6068 Args: -6069 table: Table name. -6070 db: Database name. -6071 catalog: Catalog name. -6072 quote: Whether to force quotes on the table's identifiers. -6073 alias: Table's alias. -6074 -6075 Returns: -6076 The new Table instance. -6077 """ -6078 return Table( -6079 this=to_identifier(table, quoted=quoted) if table else None, -6080 db=to_identifier(db, quoted=quoted) if db else None, -6081 catalog=to_identifier(catalog, quoted=quoted) if catalog else None, -6082 alias=TableAlias(this=to_identifier(alias)) if alias else None, -6083 ) +@@ -77959,37 +78816,37 @@ If an Expression instance is passed, this is used as-is.6129def table_( +6130 table: Identifier | str, +6131 db: t.Optional[Identifier | str] = None, +6132 catalog: t.Optional[Identifier | str] = None, +6133 quoted: t.Optional[bool] = None, +6134 alias: t.Optional[Identifier | str] = None, +6135) -> Table: +6136 """Build a Table. +6137 +6138 Args: +6139 table: Table name. +6140 db: Database name. +6141 catalog: Catalog name. +6142 quote: Whether to force quotes on the table's identifiers. +6143 alias: Table's alias. +6144 +6145 Returns: +6146 The new Table instance. +6147 """ +6148 return Table( +6149 this=to_identifier(table, quoted=quoted) if table else None, +6150 db=to_identifier(db, quoted=quoted) if db else None, +6151 catalog=to_identifier(catalog, quoted=quoted) if catalog else None, +6152 alias=TableAlias(this=to_identifier(alias)) if alias else None, +6153 )-6086def values( -6087 values: t.Iterable[t.Tuple[t.Any, ...]], -6088 alias: t.Optional[str] = None, -6089 columns: t.Optional[t.Iterable[str] | t.Dict[str, DataType]] = None, -6090) -> Values: -6091 """Build VALUES statement. -6092 -6093 Example: -6094 >>> values([(1, '2')]).sql() -6095 "VALUES (1, '2')" -6096 -6097 Args: -6098 values: values statements that will be converted to SQL -6099 alias: optional alias -6100 columns: Optional list of ordered column names or ordered dictionary of column names to types. -6101 If either are provided then an alias is also required. -6102 -6103 Returns: -6104 Values: the Values expression object -6105 """ -6106 if columns and not alias: -6107 raise ValueError("Alias is required when providing columns") -6108 -6109 return Values( -6110 expressions=[convert(tup) for tup in values], -6111 alias=( -6112 TableAlias(this=to_identifier(alias), columns=[to_identifier(x) for x in columns]) -6113 if columns -6114 else (TableAlias(this=to_identifier(alias)) if alias else None) -6115 ), -6116 ) +@@ -78034,28 +78891,28 @@ If either are provided then an alias is also required.6156def values( +6157 values: t.Iterable[t.Tuple[t.Any, ...]], +6158 alias: t.Optional[str] = None, +6159 columns: t.Optional[t.Iterable[str] | t.Dict[str, DataType]] = None, +6160) -> Values: +6161 """Build VALUES statement. +6162 +6163 Example: +6164 >>> values([(1, '2')]).sql() +6165 "VALUES (1, '2')" +6166 +6167 Args: +6168 values: values statements that will be converted to SQL +6169 alias: optional alias +6170 columns: Optional list of ordered column names or ordered dictionary of column names to types. +6171 If either are provided then an alias is also required. +6172 +6173 Returns: +6174 Values: the Values expression object +6175 """ +6176 if columns and not alias: +6177 raise ValueError("Alias is required when providing columns") +6178 +6179 return Values( +6180 expressions=[convert(tup) for tup in values], +6181 alias=( +6182 TableAlias(this=to_identifier(alias), columns=[to_identifier(x) for x in columns]) +6183 if columns +6184 else (TableAlias(this=to_identifier(alias)) if alias else None) +6185 ), +6186 )-6119def var(name: t.Optional[ExpOrStr]) -> Var: -6120 """Build a SQL variable. -6121 -6122 Example: -6123 >>> repr(var('x')) -6124 '(VAR this: x)' -6125 -6126 >>> repr(var(column('x', table='y'))) -6127 '(VAR this: x)' -6128 -6129 Args: -6130 name: The name of the var or an expression who's name will become the var. -6131 -6132 Returns: -6133 The new variable node. -6134 """ -6135 if not name: -6136 raise ValueError("Cannot convert empty name into var.") -6137 -6138 if isinstance(name, Expression): -6139 name = name.name -6140 return Var(this=name) +@@ -78103,24 +78960,24 @@ If either are provided then an alias is also required.6189def var(name: t.Optional[ExpOrStr]) -> Var: +6190 """Build a SQL variable. +6191 +6192 Example: +6193 >>> repr(var('x')) +6194 '(VAR this: x)' +6195 +6196 >>> repr(var(column('x', table='y'))) +6197 '(VAR this: x)' +6198 +6199 Args: +6200 name: The name of the var or an expression who's name will become the var. +6201 +6202 Returns: +6203 The new variable node. +6204 """ +6205 if not name: +6206 raise ValueError("Cannot convert empty name into var.") +6207 +6208 if isinstance(name, Expression): +6209 name = name.name +6210 return Var(this=name)-6143def rename_table(old_name: str | Table, new_name: str | Table) -> AlterTable: -6144 """Build ALTER TABLE... RENAME... expression -6145 -6146 Args: -6147 old_name: The old name of the table -6148 new_name: The new name of the table -6149 -6150 Returns: -6151 Alter table expression -6152 """ -6153 old_table = to_table(old_name) -6154 new_table = to_table(new_name) -6155 return AlterTable( -6156 this=old_table, -6157 actions=[ -6158 RenameTable(this=new_table), -6159 ], -6160 ) +@@ -78153,46 +79010,46 @@ If either are provided then an alias is also required.6213def rename_table(old_name: str | Table, new_name: str | Table) -> AlterTable: +6214 """Build ALTER TABLE... RENAME... expression +6215 +6216 Args: +6217 old_name: The old name of the table +6218 new_name: The new name of the table +6219 +6220 Returns: +6221 Alter table expression +6222 """ +6223 old_table = to_table(old_name) +6224 new_table = to_table(new_name) +6225 return AlterTable( +6226 this=old_table, +6227 actions=[ +6228 RenameTable(this=new_table), +6229 ], +6230 )-6163def convert(value: t.Any, copy: bool = False) -> Expression: -6164 """Convert a python value into an expression object. -6165 -6166 Raises an error if a conversion is not possible. -6167 -6168 Args: -6169 value: A python object. -6170 copy: Whether or not to copy `value` (only applies to Expressions and collections). -6171 -6172 Returns: -6173 Expression: the equivalent expression object. -6174 """ -6175 if isinstance(value, Expression): -6176 return maybe_copy(value, copy) -6177 if isinstance(value, str): -6178 return Literal.string(value) -6179 if isinstance(value, bool): -6180 return Boolean(this=value) -6181 if value is None or (isinstance(value, float) and math.isnan(value)): -6182 return NULL -6183 if isinstance(value, numbers.Number): -6184 return Literal.number(value) -6185 if isinstance(value, datetime.datetime): -6186 datetime_literal = Literal.string( -6187 (value if value.tzinfo else value.replace(tzinfo=datetime.timezone.utc)).isoformat() -6188 ) -6189 return TimeStrToTime(this=datetime_literal) -6190 if isinstance(value, datetime.date): -6191 date_literal = Literal.string(value.strftime("%Y-%m-%d")) -6192 return DateStrToDate(this=date_literal) -6193 if isinstance(value, tuple): -6194 return Tuple(expressions=[convert(v, copy=copy) for v in value]) -6195 if isinstance(value, list): -6196 return Array(expressions=[convert(v, copy=copy) for v in value]) -6197 if isinstance(value, dict): -6198 return Map( -6199 keys=Array(expressions=[convert(k, copy=copy) for k in value]), -6200 values=Array(expressions=[convert(v, copy=copy) for v in value.values()]), -6201 ) -6202 raise ValueError(f"Cannot convert {value}") +@@ -78227,26 +79084,26 @@ If either are provided then an alias is also required.6233def convert(value: t.Any, copy: bool = False) -> Expression: +6234 """Convert a python value into an expression object. +6235 +6236 Raises an error if a conversion is not possible. +6237 +6238 Args: +6239 value: A python object. +6240 copy: Whether or not to copy `value` (only applies to Expressions and collections). +6241 +6242 Returns: +6243 Expression: the equivalent expression object. +6244 """ +6245 if isinstance(value, Expression): +6246 return maybe_copy(value, copy) +6247 if isinstance(value, str): +6248 return Literal.string(value) +6249 if isinstance(value, bool): +6250 return Boolean(this=value) +6251 if value is None or (isinstance(value, float) and math.isnan(value)): +6252 return NULL +6253 if isinstance(value, numbers.Number): +6254 return Literal.number(value) +6255 if isinstance(value, datetime.datetime): +6256 datetime_literal = Literal.string( +6257 (value if value.tzinfo else value.replace(tzinfo=datetime.timezone.utc)).isoformat() +6258 ) +6259 return TimeStrToTime(this=datetime_literal) +6260 if isinstance(value, datetime.date): +6261 date_literal = Literal.string(value.strftime("%Y-%m-%d")) +6262 return DateStrToDate(this=date_literal) +6263 if isinstance(value, tuple): +6264 return Tuple(expressions=[convert(v, copy=copy) for v in value]) +6265 if isinstance(value, list): +6266 return Array(expressions=[convert(v, copy=copy) for v in value]) +6267 if isinstance(value, dict): +6268 return Map( +6269 keys=Array(expressions=[convert(k, copy=copy) for k in value]), +6270 values=Array(expressions=[convert(v, copy=copy) for v in value.values()]), +6271 ) +6272 raise ValueError(f"Cannot convert {value}")-6205def replace_children(expression: Expression, fun: t.Callable, *args, **kwargs) -> None: -6206 """ -6207 Replace children of an expression with the result of a lambda fun(child) -> exp. -6208 """ -6209 for k, v in expression.args.items(): -6210 is_list_arg = type(v) is list -6211 -6212 child_nodes = v if is_list_arg else [v] -6213 new_child_nodes = [] -6214 -6215 for cn in child_nodes: -6216 if isinstance(cn, Expression): -6217 for child_node in ensure_collection(fun(cn, *args, **kwargs)): -6218 new_child_nodes.append(child_node) -6219 child_node.parent = expression -6220 child_node.arg_key = k -6221 else: -6222 new_child_nodes.append(cn) -6223 -6224 expression.args[k] = new_child_nodes if is_list_arg else seq_get(new_child_nodes, 0) +@@ -78266,27 +79123,27 @@ If either are provided then an alias is also required.6275def replace_children(expression: Expression, fun: t.Callable, *args, **kwargs) -> None: +6276 """ +6277 Replace children of an expression with the result of a lambda fun(child) -> exp. +6278 """ +6279 for k, v in expression.args.items(): +6280 is_list_arg = type(v) is list +6281 +6282 child_nodes = v if is_list_arg else [v] +6283 new_child_nodes = [] +6284 +6285 for cn in child_nodes: +6286 if isinstance(cn, Expression): +6287 for child_node in ensure_collection(fun(cn, *args, **kwargs)): +6288 new_child_nodes.append(child_node) +6289 child_node.parent = expression +6290 child_node.arg_key = k +6291 else: +6292 new_child_nodes.append(cn) +6293 +6294 expression.args[k] = new_child_nodes if is_list_arg else seq_get(new_child_nodes, 0)-6227def column_table_names(expression: Expression, exclude: str = "") -> t.Set[str]: -6228 """ -6229 Return all table names referenced through columns in an expression. -6230 -6231 Example: -6232 >>> import sqlglot -6233 >>> sorted(column_table_names(sqlglot.parse_one("a.b AND c.d AND c.e"))) -6234 ['a', 'c'] -6235 -6236 Args: -6237 expression: expression to find table names. -6238 exclude: a table name to exclude -6239 -6240 Returns: -6241 A list of unique names. -6242 """ -6243 return { -6244 table -6245 for table in (column.table for column in expression.find_all(Column)) -6246 if table and table != exclude -6247 } +@@ -78330,33 +79187,33 @@ If either are provided then an alias is also required.6297def column_table_names(expression: Expression, exclude: str = "") -> t.Set[str]: +6298 """ +6299 Return all table names referenced through columns in an expression. +6300 +6301 Example: +6302 >>> import sqlglot +6303 >>> sorted(column_table_names(sqlglot.parse_one("a.b AND c.d AND c.e"))) +6304 ['a', 'c'] +6305 +6306 Args: +6307 expression: expression to find table names. +6308 exclude: a table name to exclude +6309 +6310 Returns: +6311 A list of unique names. +6312 """ +6313 return { +6314 table +6315 for table in (column.table for column in expression.find_all(Column)) +6316 if table and table != exclude +6317 }-6250def table_name(table: Table | str, dialect: DialectType = None) -> str: -6251 """Get the full name of a table as a string. -6252 -6253 Args: -6254 table: Table expression node or string. -6255 dialect: The dialect to generate the table name for. -6256 -6257 Examples: -6258 >>> from sqlglot import exp, parse_one -6259 >>> table_name(parse_one("select * from a.b.c").find(exp.Table)) -6260 'a.b.c' -6261 -6262 Returns: -6263 The table name. -6264 """ -6265 -6266 table = maybe_parse(table, into=Table, dialect=dialect) -6267 -6268 if not table: -6269 raise ValueError(f"Cannot parse {table}") -6270 -6271 return ".".join( -6272 part.sql(dialect=dialect, identify=True) -6273 if not SAFE_IDENTIFIER_RE.match(part.name) -6274 else part.name -6275 for part in table.parts -6276 ) +@@ -78400,34 +79257,34 @@ If either are provided then an alias is also required.6320def table_name(table: Table | str, dialect: DialectType = None) -> str: +6321 """Get the full name of a table as a string. +6322 +6323 Args: +6324 table: Table expression node or string. +6325 dialect: The dialect to generate the table name for. +6326 +6327 Examples: +6328 >>> from sqlglot import exp, parse_one +6329 >>> table_name(parse_one("select * from a.b.c").find(exp.Table)) +6330 'a.b.c' +6331 +6332 Returns: +6333 The table name. +6334 """ +6335 +6336 table = maybe_parse(table, into=Table, dialect=dialect) +6337 +6338 if not table: +6339 raise ValueError(f"Cannot parse {table}") +6340 +6341 return ".".join( +6342 part.sql(dialect=dialect, identify=True) +6343 if not SAFE_IDENTIFIER_RE.match(part.name) +6344 else part.name +6345 for part in table.parts +6346 )-6279def replace_tables(expression: E, mapping: t.Dict[str, str], copy: bool = True) -> E: -6280 """Replace all tables in expression according to the mapping. -6281 -6282 Args: -6283 expression: expression node to be transformed and replaced. -6284 mapping: mapping of table names. -6285 copy: whether or not to copy the expression. -6286 -6287 Examples: -6288 >>> from sqlglot import exp, parse_one -6289 >>> replace_tables(parse_one("select * from a.b"), {"a.b": "c"}).sql() -6290 'SELECT * FROM c' -6291 -6292 Returns: -6293 The mapped expression. -6294 """ -6295 -6296 def _replace_tables(node: Expression) -> Expression: -6297 if isinstance(node, Table): -6298 new_name = mapping.get(table_name(node)) -6299 if new_name: -6300 return to_table( -6301 new_name, -6302 **{k: v for k, v in node.args.items() if k not in ("this", "db", "catalog")}, -6303 ) -6304 return node -6305 -6306 return expression.transform(_replace_tables, copy=copy) +@@ -78472,40 +79329,40 @@ If either are provided then an alias is also required.6349def replace_tables(expression: E, mapping: t.Dict[str, str], copy: bool = True) -> E: +6350 """Replace all tables in expression according to the mapping. +6351 +6352 Args: +6353 expression: expression node to be transformed and replaced. +6354 mapping: mapping of table names. +6355 copy: whether or not to copy the expression. +6356 +6357 Examples: +6358 >>> from sqlglot import exp, parse_one +6359 >>> replace_tables(parse_one("select * from a.b"), {"a.b": "c"}).sql() +6360 'SELECT * FROM c' +6361 +6362 Returns: +6363 The mapped expression. +6364 """ +6365 +6366 def _replace_tables(node: Expression) -> Expression: +6367 if isinstance(node, Table): +6368 new_name = mapping.get(table_name(node)) +6369 if new_name: +6370 return to_table( +6371 new_name, +6372 **{k: v for k, v in node.args.items() if k not in ("this", "db", "catalog")}, +6373 ) +6374 return node +6375 +6376 return expression.transform(_replace_tables, copy=copy)-6309def replace_placeholders(expression: Expression, *args, **kwargs) -> Expression: -6310 """Replace placeholders in an expression. -6311 -6312 Args: -6313 expression: expression node to be transformed and replaced. -6314 args: positional names that will substitute unnamed placeholders in the given order. -6315 kwargs: keyword arguments that will substitute named placeholders. -6316 -6317 Examples: -6318 >>> from sqlglot import exp, parse_one -6319 >>> replace_placeholders( -6320 ... parse_one("select * from :tbl where ? = ?"), -6321 ... exp.to_identifier("str_col"), "b", tbl=exp.to_identifier("foo") -6322 ... ).sql() -6323 "SELECT * FROM foo WHERE str_col = 'b'" -6324 -6325 Returns: -6326 The mapped expression. -6327 """ -6328 -6329 def _replace_placeholders(node: Expression, args, **kwargs) -> Expression: -6330 if isinstance(node, Placeholder): -6331 if node.name: -6332 new_name = kwargs.get(node.name) -6333 if new_name: -6334 return convert(new_name) -6335 else: -6336 try: -6337 return convert(next(args)) -6338 except StopIteration: -6339 pass -6340 return node -6341 -6342 return expression.transform(_replace_placeholders, iter(args), **kwargs) +@@ -78553,39 +79410,39 @@ If either are provided then an alias is also required.6379def replace_placeholders(expression: Expression, *args, **kwargs) -> Expression: +6380 """Replace placeholders in an expression. +6381 +6382 Args: +6383 expression: expression node to be transformed and replaced. +6384 args: positional names that will substitute unnamed placeholders in the given order. +6385 kwargs: keyword arguments that will substitute named placeholders. +6386 +6387 Examples: +6388 >>> from sqlglot import exp, parse_one +6389 >>> replace_placeholders( +6390 ... parse_one("select * from :tbl where ? = ?"), +6391 ... exp.to_identifier("str_col"), "b", tbl=exp.to_identifier("foo") +6392 ... ).sql() +6393 "SELECT * FROM foo WHERE str_col = 'b'" +6394 +6395 Returns: +6396 The mapped expression. +6397 """ +6398 +6399 def _replace_placeholders(node: Expression, args, **kwargs) -> Expression: +6400 if isinstance(node, Placeholder): +6401 if node.name: +6402 new_name = kwargs.get(node.name) +6403 if new_name: +6404 return convert(new_name) +6405 else: +6406 try: +6407 return convert(next(args)) +6408 except StopIteration: +6409 pass +6410 return node +6411 +6412 return expression.transform(_replace_placeholders, iter(args), **kwargs)-6345def expand( -6346 expression: Expression, sources: t.Dict[str, Subqueryable], copy: bool = True -6347) -> Expression: -6348 """Transforms an expression by expanding all referenced sources into subqueries. -6349 -6350 Examples: -6351 >>> from sqlglot import parse_one -6352 >>> expand(parse_one("select * from x AS z"), {"x": parse_one("select * from y")}).sql() -6353 'SELECT * FROM (SELECT * FROM y) AS z /* source: x */' -6354 -6355 >>> expand(parse_one("select * from x AS z"), {"x": parse_one("select * from y"), "y": parse_one("select * from z")}).sql() -6356 'SELECT * FROM (SELECT * FROM (SELECT * FROM z) AS y /* source: y */) AS z /* source: x */' -6357 -6358 Args: -6359 expression: The expression to expand. -6360 sources: A dictionary of name to Subqueryables. -6361 copy: Whether or not to copy the expression during transformation. Defaults to True. -6362 -6363 Returns: -6364 The transformed expression. -6365 """ -6366 -6367 def _expand(node: Expression): -6368 if isinstance(node, Table): -6369 name = table_name(node) -6370 source = sources.get(name) -6371 if source: -6372 subquery = source.subquery(node.alias or name) -6373 subquery.comments = [f"source: {name}"] -6374 return subquery.transform(_expand, copy=False) -6375 return node -6376 -6377 return expression.transform(_expand, copy=copy) +@@ -78636,51 +79493,51 @@ If either are provided then an alias is also required.6415def expand( +6416 expression: Expression, sources: t.Dict[str, Subqueryable], copy: bool = True +6417) -> Expression: +6418 """Transforms an expression by expanding all referenced sources into subqueries. +6419 +6420 Examples: +6421 >>> from sqlglot import parse_one +6422 >>> expand(parse_one("select * from x AS z"), {"x": parse_one("select * from y")}).sql() +6423 'SELECT * FROM (SELECT * FROM y) AS z /* source: x */' +6424 +6425 >>> expand(parse_one("select * from x AS z"), {"x": parse_one("select * from y"), "y": parse_one("select * from z")}).sql() +6426 'SELECT * FROM (SELECT * FROM (SELECT * FROM z) AS y /* source: y */) AS z /* source: x */' +6427 +6428 Args: +6429 expression: The expression to expand. +6430 sources: A dictionary of name to Subqueryables. +6431 copy: Whether or not to copy the expression during transformation. Defaults to True. +6432 +6433 Returns: +6434 The transformed expression. +6435 """ +6436 +6437 def _expand(node: Expression): +6438 if isinstance(node, Table): +6439 name = table_name(node) +6440 source = sources.get(name) +6441 if source: +6442 subquery = source.subquery(node.alias or name) +6443 subquery.comments = [f"source: {name}"] +6444 return subquery.transform(_expand, copy=False) +6445 return node +6446 +6447 return expression.transform(_expand, copy=copy)-6380def func(name: str, *args, dialect: DialectType = None, **kwargs) -> Func: -6381 """ -6382 Returns a Func expression. -6383 -6384 Examples: -6385 >>> func("abs", 5).sql() -6386 'ABS(5)' -6387 -6388 >>> func("cast", this=5, to=DataType.build("DOUBLE")).sql() -6389 'CAST(5 AS DOUBLE)' -6390 -6391 Args: -6392 name: the name of the function to build. -6393 args: the args used to instantiate the function of interest. -6394 dialect: the source dialect. -6395 kwargs: the kwargs used to instantiate the function of interest. -6396 -6397 Note: -6398 The arguments `args` and `kwargs` are mutually exclusive. -6399 -6400 Returns: -6401 An instance of the function of interest, or an anonymous function, if `name` doesn't -6402 correspond to an existing `sqlglot.expressions.Func` class. -6403 """ -6404 if args and kwargs: -6405 raise ValueError("Can't use both args and kwargs to instantiate a function.") -6406 -6407 from sqlglot.dialects.dialect import Dialect -6408 -6409 converted: t.List[Expression] = [maybe_parse(arg, dialect=dialect) for arg in args] -6410 kwargs = {key: maybe_parse(value, dialect=dialect) for key, value in kwargs.items()} -6411 -6412 parser = Dialect.get_or_raise(dialect)().parser() -6413 from_args_list = parser.FUNCTIONS.get(name.upper()) -6414 -6415 if from_args_list: -6416 function = from_args_list(converted) if converted else from_args_list.__self__(**kwargs) # type: ignore -6417 else: -6418 kwargs = kwargs or {"expressions": converted} -6419 function = Anonymous(this=name, **kwargs) -6420 -6421 for error_message in function.error_messages(converted): -6422 raise ValueError(error_message) -6423 -6424 return function +@@ -78738,11 +79595,11 @@ If either are provided then an alias is also required.6450def func(name: str, *args, dialect: DialectType = None, **kwargs) -> Func: +6451 """ +6452 Returns a Func expression. +6453 +6454 Examples: +6455 >>> func("abs", 5).sql() +6456 'ABS(5)' +6457 +6458 >>> func("cast", this=5, to=DataType.build("DOUBLE")).sql() +6459 'CAST(5 AS DOUBLE)' +6460 +6461 Args: +6462 name: the name of the function to build. +6463 args: the args used to instantiate the function of interest. +6464 dialect: the source dialect. +6465 kwargs: the kwargs used to instantiate the function of interest. +6466 +6467 Note: +6468 The arguments `args` and `kwargs` are mutually exclusive. +6469 +6470 Returns: +6471 An instance of the function of interest, or an anonymous function, if `name` doesn't +6472 correspond to an existing `sqlglot.expressions.Func` class. +6473 """ +6474 if args and kwargs: +6475 raise ValueError("Can't use both args and kwargs to instantiate a function.") +6476 +6477 from sqlglot.dialects.dialect import Dialect +6478 +6479 converted: t.List[Expression] = [maybe_parse(arg, dialect=dialect) for arg in args] +6480 kwargs = {key: maybe_parse(value, dialect=dialect) for key, value in kwargs.items()} +6481 +6482 parser = Dialect.get_or_raise(dialect)().parser() +6483 from_args_list = parser.FUNCTIONS.get(name.upper()) +6484 +6485 if from_args_list: +6486 function = from_args_list(converted) if converted else from_args_list.__self__(**kwargs) # type: ignore +6487 else: +6488 kwargs = kwargs or {"expressions": converted} +6489 function = Anonymous(this=name, **kwargs) +6490 +6491 for error_message in function.error_messages(converted): +6492 raise ValueError(error_message) +6493 +6494 return function-6427def true() -> Boolean: -6428 """ -6429 Returns a true Boolean expression. -6430 """ -6431 return Boolean(this=True) + @@ -78762,11 +79619,11 @@ If either are provided then an alias is also required.-6434def false() -> Boolean: -6435 """ -6436 Returns a false Boolean expression. -6437 """ -6438 return Boolean(this=False) + @@ -78786,11 +79643,11 @@ If either are provided then an alias is also required.