sqlglot expressions datatypes.
1"""sqlglot expressions datatypes.""" 2 3from __future__ import annotations 4 5import typing as t 6from enum import auto 7 8from sqlglot.helper import AutoName 9from sqlglot.errors import ErrorLevel, ParseError 10from sqlglot.expressions.core import ( 11 Expression, 12 _TimeUnit, 13 Identifier, 14 Dot, 15 maybe_copy, 16) 17from builtins import type as Type 18 19if t.TYPE_CHECKING: 20 from sqlglot.dialects.dialect import DialectType 21 from typing_extensions import Self 22 23 24class DataTypeParam(Expression): 25 arg_types = {"this": True, "expression": False} 26 27 @property 28 def name(self) -> str: 29 return self.this.name 30 31 32class DType(AutoName): 33 ARRAY = auto() 34 AGGREGATEFUNCTION = auto() 35 SIMPLEAGGREGATEFUNCTION = auto() 36 BIGDECIMAL = auto() 37 BIGINT = auto() 38 BIGNUM = auto() 39 BIGSERIAL = auto() 40 BINARY = auto() 41 BIT = auto() 42 BLOB = auto() 43 BOOLEAN = auto() 44 BPCHAR = auto() 45 CHAR = auto() 46 CHARACTER_SET = auto() 47 DATE = auto() 48 DATE32 = auto() 49 DATEMULTIRANGE = auto() 50 DATERANGE = auto() 51 DATETIME = auto() 52 DATETIME2 = auto() 53 DATETIME64 = auto() 54 DECIMAL = auto() 55 DECIMAL32 = auto() 56 DECIMAL64 = auto() 57 DECIMAL128 = auto() 58 DECIMAL256 = auto() 59 DECFLOAT = auto() 60 DOUBLE = auto() 61 DYNAMIC = auto() 62 ENUM = auto() 63 ENUM8 = auto() 64 ENUM16 = auto() 65 FILE = auto() 66 FIXEDSTRING = auto() 67 FLOAT = auto() 68 GEOGRAPHY = auto() 69 GEOGRAPHYPOINT = auto() 70 GEOMETRY = auto() 71 POINT = auto() 72 RING = auto() 73 LINESTRING = auto() 74 MULTILINESTRING = auto() 75 POLYGON = auto() 76 MULTIPOLYGON = auto() 77 HLLSKETCH = auto() 78 HSTORE = auto() 79 IMAGE = auto() 80 INET = auto() 81 INT = auto() 82 INT128 = auto() 83 INT256 = auto() 84 INT4MULTIRANGE = auto() 85 INT4RANGE = auto() 86 INT8MULTIRANGE = auto() 87 INT8RANGE = auto() 88 INTERVAL = auto() 89 IPADDRESS = auto() 90 IPPREFIX = auto() 91 IPV4 = auto() 92 IPV6 = auto() 93 JSON = auto() 94 JSONB = auto() 95 LIST = auto() 96 LONGBLOB = auto() 97 LONGTEXT = auto() 98 LOWCARDINALITY = auto() 99 MAP = auto() 100 MEDIUMBLOB = auto() 101 MEDIUMINT = auto() 102 MEDIUMTEXT = auto() 103 MONEY = auto() 104 NAME = auto() 105 NCHAR = auto() 106 NESTED = auto() 107 NOTHING = auto() 108 NULL = auto() 109 NUMMULTIRANGE = auto() 110 NUMRANGE = auto() 111 NVARCHAR = auto() 112 OBJECT = auto() 113 RANGE = auto() 114 ROWVERSION = auto() 115 SERIAL = auto() 116 SET = auto() 117 SMALLDATETIME = auto() 118 SMALLINT = auto() 119 SMALLMONEY = auto() 120 SMALLSERIAL = auto() 121 STRUCT = auto() 122 SUPER = auto() 123 TEXT = auto() 124 TINYBLOB = auto() 125 TINYTEXT = auto() 126 TIME = auto() 127 TIMETZ = auto() 128 TIME_NS = auto() 129 TIMESTAMP = auto() 130 TIMESTAMPNTZ = auto() 131 TIMESTAMPLTZ = auto() 132 TIMESTAMPTZ = auto() 133 TIMESTAMP_S = auto() 134 TIMESTAMP_MS = auto() 135 TIMESTAMP_NS = auto() 136 TINYINT = auto() 137 TSMULTIRANGE = auto() 138 TSRANGE = auto() 139 TSTZMULTIRANGE = auto() 140 TSTZRANGE = auto() 141 UBIGINT = auto() 142 UINT = auto() 143 UINT128 = auto() 144 UINT256 = auto() 145 UMEDIUMINT = auto() 146 UDECIMAL = auto() 147 UDOUBLE = auto() 148 UNION = auto() 149 UNKNOWN = auto() # Sentinel value, useful for type annotation 150 USERDEFINED = "USER-DEFINED" 151 USMALLINT = auto() 152 UTINYINT = auto() 153 UUID = auto() 154 VARBINARY = auto() 155 VARCHAR = auto() 156 VARIANT = auto() 157 VECTOR = auto() 158 XML = auto() 159 YEAR = auto() 160 TDIGEST = auto() 161 162 def into_expr(self, **kwargs: object) -> DataType: 163 """Converts this `DType` into a `DataType` instance. 164 165 Args: 166 **kwargs (object): additional arguments to pass in the constructor of DataType. 167 Returns: 168 DataType: the resulting `DataType` instance. 169 """ 170 return DataType(this=self).set_kwargs(kwargs) 171 172 173class DataType(Expression): 174 arg_types = { 175 "this": True, 176 "expressions": False, 177 "nested": False, 178 "values": False, 179 "kind": False, 180 "nullable": False, 181 "collate": False, 182 } 183 184 Type: t.ClassVar[Type[DType]] = DType 185 186 STRUCT_TYPES: t.ClassVar[set[DType]] = { 187 DType.FILE, 188 DType.NESTED, 189 DType.OBJECT, 190 DType.STRUCT, 191 DType.UNION, 192 } 193 194 ARRAY_TYPES: t.ClassVar[set[DType]] = { 195 DType.ARRAY, 196 DType.LIST, 197 } 198 199 NESTED_TYPES: t.ClassVar[set[DType]] = { 200 DType.FILE, 201 DType.NESTED, 202 DType.OBJECT, 203 DType.STRUCT, 204 DType.UNION, 205 DType.ARRAY, 206 DType.LIST, 207 DType.MAP, 208 } 209 210 TEXT_TYPES: t.ClassVar[set[DType]] = { 211 DType.CHAR, 212 DType.NCHAR, 213 DType.NVARCHAR, 214 DType.TEXT, 215 DType.VARCHAR, 216 DType.NAME, 217 } 218 219 SIGNED_INTEGER_TYPES: t.ClassVar[set[DType]] = { 220 DType.BIGINT, 221 DType.INT, 222 DType.INT128, 223 DType.INT256, 224 DType.MEDIUMINT, 225 DType.SMALLINT, 226 DType.TINYINT, 227 } 228 229 UNSIGNED_INTEGER_TYPES: t.ClassVar[set[DType]] = { 230 DType.UBIGINT, 231 DType.UINT, 232 DType.UINT128, 233 DType.UINT256, 234 DType.UMEDIUMINT, 235 DType.USMALLINT, 236 DType.UTINYINT, 237 } 238 239 INTEGER_TYPES: t.ClassVar[set[DType]] = { 240 DType.BIGINT, 241 DType.INT, 242 DType.INT128, 243 DType.INT256, 244 DType.MEDIUMINT, 245 DType.SMALLINT, 246 DType.TINYINT, 247 DType.UBIGINT, 248 DType.UINT, 249 DType.UINT128, 250 DType.UINT256, 251 DType.UMEDIUMINT, 252 DType.USMALLINT, 253 DType.UTINYINT, 254 DType.BIT, 255 } 256 257 FLOAT_TYPES: t.ClassVar[set[DType]] = { 258 DType.DOUBLE, 259 DType.FLOAT, 260 } 261 262 REAL_TYPES: t.ClassVar[set[DType]] = { 263 DType.DOUBLE, 264 DType.FLOAT, 265 DType.BIGDECIMAL, 266 DType.DECIMAL, 267 DType.DECIMAL32, 268 DType.DECIMAL64, 269 DType.DECIMAL128, 270 DType.DECIMAL256, 271 DType.DECFLOAT, 272 DType.MONEY, 273 DType.SMALLMONEY, 274 DType.UDECIMAL, 275 DType.UDOUBLE, 276 } 277 278 NUMERIC_TYPES: t.ClassVar[set[DType]] = { 279 DType.BIGINT, 280 DType.INT, 281 DType.INT128, 282 DType.INT256, 283 DType.MEDIUMINT, 284 DType.SMALLINT, 285 DType.TINYINT, 286 DType.UBIGINT, 287 DType.UINT, 288 DType.UINT128, 289 DType.UINT256, 290 DType.UMEDIUMINT, 291 DType.USMALLINT, 292 DType.UTINYINT, 293 DType.BIT, 294 DType.DOUBLE, 295 DType.FLOAT, 296 DType.BIGDECIMAL, 297 DType.DECIMAL, 298 DType.DECIMAL32, 299 DType.DECIMAL64, 300 DType.DECIMAL128, 301 DType.DECIMAL256, 302 DType.DECFLOAT, 303 DType.MONEY, 304 DType.SMALLMONEY, 305 DType.UDECIMAL, 306 DType.UDOUBLE, 307 } 308 309 TEMPORAL_TYPES: t.ClassVar[set[DType]] = { 310 DType.DATE, 311 DType.DATE32, 312 DType.DATETIME, 313 DType.DATETIME2, 314 DType.DATETIME64, 315 DType.SMALLDATETIME, 316 DType.TIME, 317 DType.TIMESTAMP, 318 DType.TIMESTAMPNTZ, 319 DType.TIMESTAMPLTZ, 320 DType.TIMESTAMPTZ, 321 DType.TIMESTAMP_MS, 322 DType.TIMESTAMP_NS, 323 DType.TIMESTAMP_S, 324 DType.TIMETZ, 325 } 326 327 @classmethod 328 def build( 329 cls, 330 dtype: DATA_TYPE, 331 dialect: DialectType = None, 332 udt: bool = False, 333 copy: bool = True, 334 **kwargs: object, 335 ) -> Self: 336 """ 337 Constructs a DataType object. 338 339 Args: 340 dtype: the data type of interest. 341 dialect: the dialect to use for parsing `dtype`, in case it's a string. 342 udt: when set to True, `dtype` will be used as-is if it can't be parsed into a 343 DataType, thus creating a user-defined type. 344 copy: whether to copy the data type. 345 kwargs: additional arguments to pass in the constructor of DataType. 346 347 Returns: 348 The constructed DataType object. 349 """ 350 if isinstance(dtype, str): 351 return cls.from_str(dtype, dialect, udt, **kwargs) 352 elif isinstance(dtype, DType): 353 data_type_exp = cls(this=dtype) 354 if kwargs: 355 for k, v in kwargs.items(): 356 data_type_exp.set(k, v) 357 return data_type_exp 358 elif isinstance(dtype, (Identifier, Dot)) and udt: 359 return cls(this=DType.USERDEFINED, kind=dtype, **kwargs) 360 elif isinstance(dtype, cls): 361 return maybe_copy(dtype, copy) 362 else: 363 raise ValueError(f"Invalid data type: {type(dtype)}. Expected str or DType") 364 365 @classmethod 366 def from_str( 367 cls, dtype: str, dialect: DialectType = None, udt: bool = False, **kwargs: object 368 ) -> Self: 369 """ 370 Constructs a `DataType` object from a `str` representation. 371 372 Args: 373 dtype: the data type of interest. 374 dialect: the dialect to use for parsing `dtype`. 375 udt: when set to True, `dtype` will be used as-is if it can't be parsed into a 376 `DataType`, thus creating a user-defined type. 377 kwargs: additional arguments to pass in the constructor of `DataType`. 378 379 Returns: 380 The constructed `DataType` object. 381 """ 382 from sqlglot import parse_one 383 384 if dtype.upper() == "UNKNOWN": 385 return cls(this=DType.UNKNOWN, **kwargs) 386 try: 387 return parse_one( 388 dtype, read=dialect, into=cls, error_level=ErrorLevel.IGNORE 389 ).set_kwargs(kwargs) 390 except ParseError: 391 if udt: 392 return cls(this=DType.USERDEFINED, kind=dtype, **kwargs) 393 raise 394 395 def is_type(self, *dtypes: DATA_TYPE, check_nullable: bool = False) -> bool: 396 """ 397 Checks whether this DataType matches one of the provided data types. Nested types or precision 398 will be compared using "structural equivalence" semantics, so e.g. array<int> != array<float>. 399 400 Args: 401 dtypes: the data types to compare this DataType to. 402 check_nullable: whether to take the NULLABLE type constructor into account for the comparison. 403 If false, it means that NULLABLE<INT> is equivalent to INT. 404 405 Returns: 406 True, if and only if there is a type in `dtypes` which is equal to this DataType. 407 """ 408 self_is_nullable = self.args.get("nullable") 409 for dtype in dtypes: 410 other_type = DataType.build(dtype, copy=False, udt=True) 411 other_is_nullable = other_type.args.get("nullable") 412 if ( 413 other_type.expressions 414 or (check_nullable and (self_is_nullable or other_is_nullable)) 415 or self.this == DType.USERDEFINED 416 or other_type.this == DType.USERDEFINED 417 ): 418 matches = self == other_type 419 else: 420 matches = self.this == other_type.this 421 422 if matches: 423 return True 424 return False 425 426 427class PseudoType(DataType): 428 arg_types = {"this": True} 429 430 431class ObjectIdentifier(DataType): 432 arg_types = {"this": True} 433 434 435class IntervalSpan(DataType): 436 arg_types = {"this": True, "expression": True} 437 438 439class Interval(_TimeUnit): 440 arg_types = {"this": False, "unit": False} 441 442 443DATA_TYPE = t.Union[str, Identifier, Dot, DataType, DType]
25class DataTypeParam(Expression): 26 arg_types = {"this": True, "expression": False} 27 28 @property 29 def name(self) -> str: 30 return self.this.name
Inherited Members
- sqlglot.expressions.core.Expr
- Expr
- is_var_len_args
- is_subquery
- is_cast
- is_primitive
- dump
- load
- pipe
- apply
- sqlglot.expressions.core.Expression
- this
- expression
- expressions
- text
- is_string
- is_number
- to_py
- is_int
- is_star
- alias
- alias_column_names
- alias_or_name
- output_name
- type
- is_type
- is_leaf
- meta
- copy
- add_comments
- pop_comments
- append
- set
- set_kwargs
- depth
- iter_expressions
- find
- find_all
- find_ancestor
- parent_select
- same_parent
- root
- walk
- dfs
- bfs
- unnest
- unalias
- unnest_operands
- flatten
- to_s
- sql
- transform
- replace
- pop
- assert_is
- error_messages
- and_
- or_
- not_
- update_positions
- as_
- isin
- between
- is_
- like
- ilike
- eq
- neq
- rlike
- div
- asc
- desc
- args
- parent
- arg_key
- index
- comments
33class DType(AutoName): 34 ARRAY = auto() 35 AGGREGATEFUNCTION = auto() 36 SIMPLEAGGREGATEFUNCTION = auto() 37 BIGDECIMAL = auto() 38 BIGINT = auto() 39 BIGNUM = auto() 40 BIGSERIAL = auto() 41 BINARY = auto() 42 BIT = auto() 43 BLOB = auto() 44 BOOLEAN = auto() 45 BPCHAR = auto() 46 CHAR = auto() 47 CHARACTER_SET = auto() 48 DATE = auto() 49 DATE32 = auto() 50 DATEMULTIRANGE = auto() 51 DATERANGE = auto() 52 DATETIME = auto() 53 DATETIME2 = auto() 54 DATETIME64 = auto() 55 DECIMAL = auto() 56 DECIMAL32 = auto() 57 DECIMAL64 = auto() 58 DECIMAL128 = auto() 59 DECIMAL256 = auto() 60 DECFLOAT = auto() 61 DOUBLE = auto() 62 DYNAMIC = auto() 63 ENUM = auto() 64 ENUM8 = auto() 65 ENUM16 = auto() 66 FILE = auto() 67 FIXEDSTRING = auto() 68 FLOAT = auto() 69 GEOGRAPHY = auto() 70 GEOGRAPHYPOINT = auto() 71 GEOMETRY = auto() 72 POINT = auto() 73 RING = auto() 74 LINESTRING = auto() 75 MULTILINESTRING = auto() 76 POLYGON = auto() 77 MULTIPOLYGON = auto() 78 HLLSKETCH = auto() 79 HSTORE = auto() 80 IMAGE = auto() 81 INET = auto() 82 INT = auto() 83 INT128 = auto() 84 INT256 = auto() 85 INT4MULTIRANGE = auto() 86 INT4RANGE = auto() 87 INT8MULTIRANGE = auto() 88 INT8RANGE = auto() 89 INTERVAL = auto() 90 IPADDRESS = auto() 91 IPPREFIX = auto() 92 IPV4 = auto() 93 IPV6 = auto() 94 JSON = auto() 95 JSONB = auto() 96 LIST = auto() 97 LONGBLOB = auto() 98 LONGTEXT = auto() 99 LOWCARDINALITY = auto() 100 MAP = auto() 101 MEDIUMBLOB = auto() 102 MEDIUMINT = auto() 103 MEDIUMTEXT = auto() 104 MONEY = auto() 105 NAME = auto() 106 NCHAR = auto() 107 NESTED = auto() 108 NOTHING = auto() 109 NULL = auto() 110 NUMMULTIRANGE = auto() 111 NUMRANGE = auto() 112 NVARCHAR = auto() 113 OBJECT = auto() 114 RANGE = auto() 115 ROWVERSION = auto() 116 SERIAL = auto() 117 SET = auto() 118 SMALLDATETIME = auto() 119 SMALLINT = auto() 120 SMALLMONEY = auto() 121 SMALLSERIAL = auto() 122 STRUCT = auto() 123 SUPER = auto() 124 TEXT = auto() 125 TINYBLOB = auto() 126 TINYTEXT = auto() 127 TIME = auto() 128 TIMETZ = auto() 129 TIME_NS = auto() 130 TIMESTAMP = auto() 131 TIMESTAMPNTZ = auto() 132 TIMESTAMPLTZ = auto() 133 TIMESTAMPTZ = auto() 134 TIMESTAMP_S = auto() 135 TIMESTAMP_MS = auto() 136 TIMESTAMP_NS = auto() 137 TINYINT = auto() 138 TSMULTIRANGE = auto() 139 TSRANGE = auto() 140 TSTZMULTIRANGE = auto() 141 TSTZRANGE = auto() 142 UBIGINT = auto() 143 UINT = auto() 144 UINT128 = auto() 145 UINT256 = auto() 146 UMEDIUMINT = auto() 147 UDECIMAL = auto() 148 UDOUBLE = auto() 149 UNION = auto() 150 UNKNOWN = auto() # Sentinel value, useful for type annotation 151 USERDEFINED = "USER-DEFINED" 152 USMALLINT = auto() 153 UTINYINT = auto() 154 UUID = auto() 155 VARBINARY = auto() 156 VARCHAR = auto() 157 VARIANT = auto() 158 VECTOR = auto() 159 XML = auto() 160 YEAR = auto() 161 TDIGEST = auto() 162 163 def into_expr(self, **kwargs: object) -> DataType: 164 """Converts this `DType` into a `DataType` instance. 165 166 Args: 167 **kwargs (object): additional arguments to pass in the constructor of DataType. 168 Returns: 169 DataType: the resulting `DataType` instance. 170 """ 171 return DataType(this=self).set_kwargs(kwargs)
An enumeration.
ARRAY =
<DType.ARRAY: 'ARRAY'>
AGGREGATEFUNCTION =
<DType.AGGREGATEFUNCTION: 'AGGREGATEFUNCTION'>
SIMPLEAGGREGATEFUNCTION =
<DType.SIMPLEAGGREGATEFUNCTION: 'SIMPLEAGGREGATEFUNCTION'>
BIGDECIMAL =
<DType.BIGDECIMAL: 'BIGDECIMAL'>
BIGINT =
<DType.BIGINT: 'BIGINT'>
BIGNUM =
<DType.BIGNUM: 'BIGNUM'>
BIGSERIAL =
<DType.BIGSERIAL: 'BIGSERIAL'>
BINARY =
<DType.BINARY: 'BINARY'>
BIT =
<DType.BIT: 'BIT'>
BLOB =
<DType.BLOB: 'BLOB'>
BOOLEAN =
<DType.BOOLEAN: 'BOOLEAN'>
BPCHAR =
<DType.BPCHAR: 'BPCHAR'>
CHAR =
<DType.CHAR: 'CHAR'>
CHARACTER_SET =
<DType.CHARACTER_SET: 'CHARACTER_SET'>
DATE =
<DType.DATE: 'DATE'>
DATE32 =
<DType.DATE32: 'DATE32'>
DATEMULTIRANGE =
<DType.DATEMULTIRANGE: 'DATEMULTIRANGE'>
DATERANGE =
<DType.DATERANGE: 'DATERANGE'>
DATETIME =
<DType.DATETIME: 'DATETIME'>
DATETIME2 =
<DType.DATETIME2: 'DATETIME2'>
DATETIME64 =
<DType.DATETIME64: 'DATETIME64'>
DECIMAL =
<DType.DECIMAL: 'DECIMAL'>
DECIMAL32 =
<DType.DECIMAL32: 'DECIMAL32'>
DECIMAL64 =
<DType.DECIMAL64: 'DECIMAL64'>
DECIMAL128 =
<DType.DECIMAL128: 'DECIMAL128'>
DECIMAL256 =
<DType.DECIMAL256: 'DECIMAL256'>
DECFLOAT =
<DType.DECFLOAT: 'DECFLOAT'>
DOUBLE =
<DType.DOUBLE: 'DOUBLE'>
DYNAMIC =
<DType.DYNAMIC: 'DYNAMIC'>
ENUM =
<DType.ENUM: 'ENUM'>
ENUM8 =
<DType.ENUM8: 'ENUM8'>
ENUM16 =
<DType.ENUM16: 'ENUM16'>
FILE =
<DType.FILE: 'FILE'>
FIXEDSTRING =
<DType.FIXEDSTRING: 'FIXEDSTRING'>
FLOAT =
<DType.FLOAT: 'FLOAT'>
GEOGRAPHY =
<DType.GEOGRAPHY: 'GEOGRAPHY'>
GEOGRAPHYPOINT =
<DType.GEOGRAPHYPOINT: 'GEOGRAPHYPOINT'>
GEOMETRY =
<DType.GEOMETRY: 'GEOMETRY'>
POINT =
<DType.POINT: 'POINT'>
RING =
<DType.RING: 'RING'>
LINESTRING =
<DType.LINESTRING: 'LINESTRING'>
MULTILINESTRING =
<DType.MULTILINESTRING: 'MULTILINESTRING'>
POLYGON =
<DType.POLYGON: 'POLYGON'>
MULTIPOLYGON =
<DType.MULTIPOLYGON: 'MULTIPOLYGON'>
HLLSKETCH =
<DType.HLLSKETCH: 'HLLSKETCH'>
HSTORE =
<DType.HSTORE: 'HSTORE'>
IMAGE =
<DType.IMAGE: 'IMAGE'>
INET =
<DType.INET: 'INET'>
INT =
<DType.INT: 'INT'>
INT128 =
<DType.INT128: 'INT128'>
INT256 =
<DType.INT256: 'INT256'>
INT4MULTIRANGE =
<DType.INT4MULTIRANGE: 'INT4MULTIRANGE'>
INT4RANGE =
<DType.INT4RANGE: 'INT4RANGE'>
INT8MULTIRANGE =
<DType.INT8MULTIRANGE: 'INT8MULTIRANGE'>
INT8RANGE =
<DType.INT8RANGE: 'INT8RANGE'>
INTERVAL =
<DType.INTERVAL: 'INTERVAL'>
IPADDRESS =
<DType.IPADDRESS: 'IPADDRESS'>
IPPREFIX =
<DType.IPPREFIX: 'IPPREFIX'>
IPV4 =
<DType.IPV4: 'IPV4'>
IPV6 =
<DType.IPV6: 'IPV6'>
JSON =
<DType.JSON: 'JSON'>
JSONB =
<DType.JSONB: 'JSONB'>
LIST =
<DType.LIST: 'LIST'>
LONGBLOB =
<DType.LONGBLOB: 'LONGBLOB'>
LONGTEXT =
<DType.LONGTEXT: 'LONGTEXT'>
LOWCARDINALITY =
<DType.LOWCARDINALITY: 'LOWCARDINALITY'>
MAP =
<DType.MAP: 'MAP'>
MEDIUMBLOB =
<DType.MEDIUMBLOB: 'MEDIUMBLOB'>
MEDIUMINT =
<DType.MEDIUMINT: 'MEDIUMINT'>
MEDIUMTEXT =
<DType.MEDIUMTEXT: 'MEDIUMTEXT'>
MONEY =
<DType.MONEY: 'MONEY'>
NAME =
<DType.NAME: 'NAME'>
NCHAR =
<DType.NCHAR: 'NCHAR'>
NESTED =
<DType.NESTED: 'NESTED'>
NOTHING =
<DType.NOTHING: 'NOTHING'>
NULL =
<DType.NULL: 'NULL'>
NUMMULTIRANGE =
<DType.NUMMULTIRANGE: 'NUMMULTIRANGE'>
NUMRANGE =
<DType.NUMRANGE: 'NUMRANGE'>
NVARCHAR =
<DType.NVARCHAR: 'NVARCHAR'>
OBJECT =
<DType.OBJECT: 'OBJECT'>
RANGE =
<DType.RANGE: 'RANGE'>
ROWVERSION =
<DType.ROWVERSION: 'ROWVERSION'>
SERIAL =
<DType.SERIAL: 'SERIAL'>
SET =
<DType.SET: 'SET'>
SMALLDATETIME =
<DType.SMALLDATETIME: 'SMALLDATETIME'>
SMALLINT =
<DType.SMALLINT: 'SMALLINT'>
SMALLMONEY =
<DType.SMALLMONEY: 'SMALLMONEY'>
SMALLSERIAL =
<DType.SMALLSERIAL: 'SMALLSERIAL'>
STRUCT =
<DType.STRUCT: 'STRUCT'>
SUPER =
<DType.SUPER: 'SUPER'>
TEXT =
<DType.TEXT: 'TEXT'>
TINYBLOB =
<DType.TINYBLOB: 'TINYBLOB'>
TINYTEXT =
<DType.TINYTEXT: 'TINYTEXT'>
TIME =
<DType.TIME: 'TIME'>
TIMETZ =
<DType.TIMETZ: 'TIMETZ'>
TIME_NS =
<DType.TIME_NS: 'TIME_NS'>
TIMESTAMP =
<DType.TIMESTAMP: 'TIMESTAMP'>
TIMESTAMPNTZ =
<DType.TIMESTAMPNTZ: 'TIMESTAMPNTZ'>
TIMESTAMPLTZ =
<DType.TIMESTAMPLTZ: 'TIMESTAMPLTZ'>
TIMESTAMPTZ =
<DType.TIMESTAMPTZ: 'TIMESTAMPTZ'>
TIMESTAMP_S =
<DType.TIMESTAMP_S: 'TIMESTAMP_S'>
TIMESTAMP_MS =
<DType.TIMESTAMP_MS: 'TIMESTAMP_MS'>
TIMESTAMP_NS =
<DType.TIMESTAMP_NS: 'TIMESTAMP_NS'>
TINYINT =
<DType.TINYINT: 'TINYINT'>
TSMULTIRANGE =
<DType.TSMULTIRANGE: 'TSMULTIRANGE'>
TSRANGE =
<DType.TSRANGE: 'TSRANGE'>
TSTZMULTIRANGE =
<DType.TSTZMULTIRANGE: 'TSTZMULTIRANGE'>
TSTZRANGE =
<DType.TSTZRANGE: 'TSTZRANGE'>
UBIGINT =
<DType.UBIGINT: 'UBIGINT'>
UINT =
<DType.UINT: 'UINT'>
UINT128 =
<DType.UINT128: 'UINT128'>
UINT256 =
<DType.UINT256: 'UINT256'>
UMEDIUMINT =
<DType.UMEDIUMINT: 'UMEDIUMINT'>
UDECIMAL =
<DType.UDECIMAL: 'UDECIMAL'>
UDOUBLE =
<DType.UDOUBLE: 'UDOUBLE'>
UNION =
<DType.UNION: 'UNION'>
UNKNOWN =
<DType.UNKNOWN: 'UNKNOWN'>
USERDEFINED =
<DType.USERDEFINED: 'USER-DEFINED'>
USMALLINT =
<DType.USMALLINT: 'USMALLINT'>
UTINYINT =
<DType.UTINYINT: 'UTINYINT'>
UUID =
<DType.UUID: 'UUID'>
VARBINARY =
<DType.VARBINARY: 'VARBINARY'>
VARCHAR =
<DType.VARCHAR: 'VARCHAR'>
VARIANT =
<DType.VARIANT: 'VARIANT'>
VECTOR =
<DType.VECTOR: 'VECTOR'>
XML =
<DType.XML: 'XML'>
YEAR =
<DType.YEAR: 'YEAR'>
TDIGEST =
<DType.TDIGEST: 'TDIGEST'>
163 def into_expr(self, **kwargs: object) -> DataType: 164 """Converts this `DType` into a `DataType` instance. 165 166 Args: 167 **kwargs (object): additional arguments to pass in the constructor of DataType. 168 Returns: 169 DataType: the resulting `DataType` instance. 170 """ 171 return DataType(this=self).set_kwargs(kwargs)
174class DataType(Expression): 175 arg_types = { 176 "this": True, 177 "expressions": False, 178 "nested": False, 179 "values": False, 180 "kind": False, 181 "nullable": False, 182 "collate": False, 183 } 184 185 Type: t.ClassVar[Type[DType]] = DType 186 187 STRUCT_TYPES: t.ClassVar[set[DType]] = { 188 DType.FILE, 189 DType.NESTED, 190 DType.OBJECT, 191 DType.STRUCT, 192 DType.UNION, 193 } 194 195 ARRAY_TYPES: t.ClassVar[set[DType]] = { 196 DType.ARRAY, 197 DType.LIST, 198 } 199 200 NESTED_TYPES: t.ClassVar[set[DType]] = { 201 DType.FILE, 202 DType.NESTED, 203 DType.OBJECT, 204 DType.STRUCT, 205 DType.UNION, 206 DType.ARRAY, 207 DType.LIST, 208 DType.MAP, 209 } 210 211 TEXT_TYPES: t.ClassVar[set[DType]] = { 212 DType.CHAR, 213 DType.NCHAR, 214 DType.NVARCHAR, 215 DType.TEXT, 216 DType.VARCHAR, 217 DType.NAME, 218 } 219 220 SIGNED_INTEGER_TYPES: t.ClassVar[set[DType]] = { 221 DType.BIGINT, 222 DType.INT, 223 DType.INT128, 224 DType.INT256, 225 DType.MEDIUMINT, 226 DType.SMALLINT, 227 DType.TINYINT, 228 } 229 230 UNSIGNED_INTEGER_TYPES: t.ClassVar[set[DType]] = { 231 DType.UBIGINT, 232 DType.UINT, 233 DType.UINT128, 234 DType.UINT256, 235 DType.UMEDIUMINT, 236 DType.USMALLINT, 237 DType.UTINYINT, 238 } 239 240 INTEGER_TYPES: t.ClassVar[set[DType]] = { 241 DType.BIGINT, 242 DType.INT, 243 DType.INT128, 244 DType.INT256, 245 DType.MEDIUMINT, 246 DType.SMALLINT, 247 DType.TINYINT, 248 DType.UBIGINT, 249 DType.UINT, 250 DType.UINT128, 251 DType.UINT256, 252 DType.UMEDIUMINT, 253 DType.USMALLINT, 254 DType.UTINYINT, 255 DType.BIT, 256 } 257 258 FLOAT_TYPES: t.ClassVar[set[DType]] = { 259 DType.DOUBLE, 260 DType.FLOAT, 261 } 262 263 REAL_TYPES: t.ClassVar[set[DType]] = { 264 DType.DOUBLE, 265 DType.FLOAT, 266 DType.BIGDECIMAL, 267 DType.DECIMAL, 268 DType.DECIMAL32, 269 DType.DECIMAL64, 270 DType.DECIMAL128, 271 DType.DECIMAL256, 272 DType.DECFLOAT, 273 DType.MONEY, 274 DType.SMALLMONEY, 275 DType.UDECIMAL, 276 DType.UDOUBLE, 277 } 278 279 NUMERIC_TYPES: t.ClassVar[set[DType]] = { 280 DType.BIGINT, 281 DType.INT, 282 DType.INT128, 283 DType.INT256, 284 DType.MEDIUMINT, 285 DType.SMALLINT, 286 DType.TINYINT, 287 DType.UBIGINT, 288 DType.UINT, 289 DType.UINT128, 290 DType.UINT256, 291 DType.UMEDIUMINT, 292 DType.USMALLINT, 293 DType.UTINYINT, 294 DType.BIT, 295 DType.DOUBLE, 296 DType.FLOAT, 297 DType.BIGDECIMAL, 298 DType.DECIMAL, 299 DType.DECIMAL32, 300 DType.DECIMAL64, 301 DType.DECIMAL128, 302 DType.DECIMAL256, 303 DType.DECFLOAT, 304 DType.MONEY, 305 DType.SMALLMONEY, 306 DType.UDECIMAL, 307 DType.UDOUBLE, 308 } 309 310 TEMPORAL_TYPES: t.ClassVar[set[DType]] = { 311 DType.DATE, 312 DType.DATE32, 313 DType.DATETIME, 314 DType.DATETIME2, 315 DType.DATETIME64, 316 DType.SMALLDATETIME, 317 DType.TIME, 318 DType.TIMESTAMP, 319 DType.TIMESTAMPNTZ, 320 DType.TIMESTAMPLTZ, 321 DType.TIMESTAMPTZ, 322 DType.TIMESTAMP_MS, 323 DType.TIMESTAMP_NS, 324 DType.TIMESTAMP_S, 325 DType.TIMETZ, 326 } 327 328 @classmethod 329 def build( 330 cls, 331 dtype: DATA_TYPE, 332 dialect: DialectType = None, 333 udt: bool = False, 334 copy: bool = True, 335 **kwargs: object, 336 ) -> Self: 337 """ 338 Constructs a DataType object. 339 340 Args: 341 dtype: the data type of interest. 342 dialect: the dialect to use for parsing `dtype`, in case it's a string. 343 udt: when set to True, `dtype` will be used as-is if it can't be parsed into a 344 DataType, thus creating a user-defined type. 345 copy: whether to copy the data type. 346 kwargs: additional arguments to pass in the constructor of DataType. 347 348 Returns: 349 The constructed DataType object. 350 """ 351 if isinstance(dtype, str): 352 return cls.from_str(dtype, dialect, udt, **kwargs) 353 elif isinstance(dtype, DType): 354 data_type_exp = cls(this=dtype) 355 if kwargs: 356 for k, v in kwargs.items(): 357 data_type_exp.set(k, v) 358 return data_type_exp 359 elif isinstance(dtype, (Identifier, Dot)) and udt: 360 return cls(this=DType.USERDEFINED, kind=dtype, **kwargs) 361 elif isinstance(dtype, cls): 362 return maybe_copy(dtype, copy) 363 else: 364 raise ValueError(f"Invalid data type: {type(dtype)}. Expected str or DType") 365 366 @classmethod 367 def from_str( 368 cls, dtype: str, dialect: DialectType = None, udt: bool = False, **kwargs: object 369 ) -> Self: 370 """ 371 Constructs a `DataType` object from a `str` representation. 372 373 Args: 374 dtype: the data type of interest. 375 dialect: the dialect to use for parsing `dtype`. 376 udt: when set to True, `dtype` will be used as-is if it can't be parsed into a 377 `DataType`, thus creating a user-defined type. 378 kwargs: additional arguments to pass in the constructor of `DataType`. 379 380 Returns: 381 The constructed `DataType` object. 382 """ 383 from sqlglot import parse_one 384 385 if dtype.upper() == "UNKNOWN": 386 return cls(this=DType.UNKNOWN, **kwargs) 387 try: 388 return parse_one( 389 dtype, read=dialect, into=cls, error_level=ErrorLevel.IGNORE 390 ).set_kwargs(kwargs) 391 except ParseError: 392 if udt: 393 return cls(this=DType.USERDEFINED, kind=dtype, **kwargs) 394 raise 395 396 def is_type(self, *dtypes: DATA_TYPE, check_nullable: bool = False) -> bool: 397 """ 398 Checks whether this DataType matches one of the provided data types. Nested types or precision 399 will be compared using "structural equivalence" semantics, so e.g. array<int> != array<float>. 400 401 Args: 402 dtypes: the data types to compare this DataType to. 403 check_nullable: whether to take the NULLABLE type constructor into account for the comparison. 404 If false, it means that NULLABLE<INT> is equivalent to INT. 405 406 Returns: 407 True, if and only if there is a type in `dtypes` which is equal to this DataType. 408 """ 409 self_is_nullable = self.args.get("nullable") 410 for dtype in dtypes: 411 other_type = DataType.build(dtype, copy=False, udt=True) 412 other_is_nullable = other_type.args.get("nullable") 413 if ( 414 other_type.expressions 415 or (check_nullable and (self_is_nullable or other_is_nullable)) 416 or self.this == DType.USERDEFINED 417 or other_type.this == DType.USERDEFINED 418 ): 419 matches = self == other_type 420 else: 421 matches = self.this == other_type.this 422 423 if matches: 424 return True 425 return False
arg_types =
{'this': True, 'expressions': False, 'nested': False, 'values': False, 'kind': False, 'nullable': False, 'collate': False}
STRUCT_TYPES: ClassVar[set[DType]] =
{<DType.NESTED: 'NESTED'>, <DType.STRUCT: 'STRUCT'>, <DType.FILE: 'FILE'>, <DType.OBJECT: 'OBJECT'>, <DType.UNION: 'UNION'>}
NESTED_TYPES: ClassVar[set[DType]] =
{<DType.NESTED: 'NESTED'>, <DType.STRUCT: 'STRUCT'>, <DType.FILE: 'FILE'>, <DType.LIST: 'LIST'>, <DType.OBJECT: 'OBJECT'>, <DType.ARRAY: 'ARRAY'>, <DType.UNION: 'UNION'>, <DType.MAP: 'MAP'>}
TEXT_TYPES: ClassVar[set[DType]] =
{<DType.NAME: 'NAME'>, <DType.CHAR: 'CHAR'>, <DType.TEXT: 'TEXT'>, <DType.VARCHAR: 'VARCHAR'>, <DType.NVARCHAR: 'NVARCHAR'>, <DType.NCHAR: 'NCHAR'>}
SIGNED_INTEGER_TYPES: ClassVar[set[DType]] =
{<DType.INT: 'INT'>, <DType.INT256: 'INT256'>, <DType.TINYINT: 'TINYINT'>, <DType.MEDIUMINT: 'MEDIUMINT'>, <DType.BIGINT: 'BIGINT'>, <DType.SMALLINT: 'SMALLINT'>, <DType.INT128: 'INT128'>}
UNSIGNED_INTEGER_TYPES: ClassVar[set[DType]] =
{<DType.UTINYINT: 'UTINYINT'>, <DType.UBIGINT: 'UBIGINT'>, <DType.UINT: 'UINT'>, <DType.USMALLINT: 'USMALLINT'>, <DType.UINT256: 'UINT256'>, <DType.UINT128: 'UINT128'>, <DType.UMEDIUMINT: 'UMEDIUMINT'>}
INTEGER_TYPES: ClassVar[set[DType]] =
{<DType.INT: 'INT'>, <DType.UTINYINT: 'UTINYINT'>, <DType.INT256: 'INT256'>, <DType.TINYINT: 'TINYINT'>, <DType.UBIGINT: 'UBIGINT'>, <DType.BIT: 'BIT'>, <DType.MEDIUMINT: 'MEDIUMINT'>, <DType.BIGINT: 'BIGINT'>, <DType.SMALLINT: 'SMALLINT'>, <DType.UINT: 'UINT'>, <DType.USMALLINT: 'USMALLINT'>, <DType.UINT256: 'UINT256'>, <DType.INT128: 'INT128'>, <DType.UINT128: 'UINT128'>, <DType.UMEDIUMINT: 'UMEDIUMINT'>}
REAL_TYPES: ClassVar[set[DType]] =
{<DType.DECIMAL128: 'DECIMAL128'>, <DType.UDECIMAL: 'UDECIMAL'>, <DType.SMALLMONEY: 'SMALLMONEY'>, <DType.DECIMAL: 'DECIMAL'>, <DType.DECFLOAT: 'DECFLOAT'>, <DType.MONEY: 'MONEY'>, <DType.UDOUBLE: 'UDOUBLE'>, <DType.DOUBLE: 'DOUBLE'>, <DType.DECIMAL32: 'DECIMAL32'>, <DType.DECIMAL256: 'DECIMAL256'>, <DType.FLOAT: 'FLOAT'>, <DType.BIGDECIMAL: 'BIGDECIMAL'>, <DType.DECIMAL64: 'DECIMAL64'>}
NUMERIC_TYPES: ClassVar[set[DType]] =
{<DType.MONEY: 'MONEY'>, <DType.UINT: 'UINT'>, <DType.DOUBLE: 'DOUBLE'>, <DType.UINT128: 'UINT128'>, <DType.USMALLINT: 'USMALLINT'>, <DType.DECIMAL128: 'DECIMAL128'>, <DType.UDECIMAL: 'UDECIMAL'>, <DType.INT: 'INT'>, <DType.SMALLMONEY: 'SMALLMONEY'>, <DType.DECIMAL: 'DECIMAL'>, <DType.DECFLOAT: 'DECFLOAT'>, <DType.SMALLINT: 'SMALLINT'>, <DType.DECIMAL32: 'DECIMAL32'>, <DType.UMEDIUMINT: 'UMEDIUMINT'>, <DType.BIGDECIMAL: 'BIGDECIMAL'>, <DType.INT256: 'INT256'>, <DType.BIT: 'BIT'>, <DType.MEDIUMINT: 'MEDIUMINT'>, <DType.BIGINT: 'BIGINT'>, <DType.UDOUBLE: 'UDOUBLE'>, <DType.DECIMAL64: 'DECIMAL64'>, <DType.UTINYINT: 'UTINYINT'>, <DType.TINYINT: 'TINYINT'>, <DType.UBIGINT: 'UBIGINT'>, <DType.UINT256: 'UINT256'>, <DType.INT128: 'INT128'>, <DType.DECIMAL256: 'DECIMAL256'>, <DType.FLOAT: 'FLOAT'>}
TEMPORAL_TYPES: ClassVar[set[DType]] =
{<DType.DATE32: 'DATE32'>, <DType.TIMESTAMP_NS: 'TIMESTAMP_NS'>, <DType.TIMESTAMP_MS: 'TIMESTAMP_MS'>, <DType.TIMESTAMPTZ: 'TIMESTAMPTZ'>, <DType.DATETIME64: 'DATETIME64'>, <DType.TIME: 'TIME'>, <DType.TIMESTAMP: 'TIMESTAMP'>, <DType.TIMETZ: 'TIMETZ'>, <DType.DATETIME: 'DATETIME'>, <DType.TIMESTAMPLTZ: 'TIMESTAMPLTZ'>, <DType.SMALLDATETIME: 'SMALLDATETIME'>, <DType.TIMESTAMPNTZ: 'TIMESTAMPNTZ'>, <DType.TIMESTAMP_S: 'TIMESTAMP_S'>, <DType.DATE: 'DATE'>, <DType.DATETIME2: 'DATETIME2'>}
@classmethod
def
build( cls, dtype: Union[str, sqlglot.expressions.core.Identifier, sqlglot.expressions.core.Dot, DataType, DType], dialect: Union[str, sqlglot.dialects.Dialect, type[sqlglot.dialects.Dialect], NoneType] = None, udt: bool = False, copy: bool = True, **kwargs: object) -> typing_extensions.Self:
328 @classmethod 329 def build( 330 cls, 331 dtype: DATA_TYPE, 332 dialect: DialectType = None, 333 udt: bool = False, 334 copy: bool = True, 335 **kwargs: object, 336 ) -> Self: 337 """ 338 Constructs a DataType object. 339 340 Args: 341 dtype: the data type of interest. 342 dialect: the dialect to use for parsing `dtype`, in case it's a string. 343 udt: when set to True, `dtype` will be used as-is if it can't be parsed into a 344 DataType, thus creating a user-defined type. 345 copy: whether to copy the data type. 346 kwargs: additional arguments to pass in the constructor of DataType. 347 348 Returns: 349 The constructed DataType object. 350 """ 351 if isinstance(dtype, str): 352 return cls.from_str(dtype, dialect, udt, **kwargs) 353 elif isinstance(dtype, DType): 354 data_type_exp = cls(this=dtype) 355 if kwargs: 356 for k, v in kwargs.items(): 357 data_type_exp.set(k, v) 358 return data_type_exp 359 elif isinstance(dtype, (Identifier, Dot)) and udt: 360 return cls(this=DType.USERDEFINED, kind=dtype, **kwargs) 361 elif isinstance(dtype, cls): 362 return maybe_copy(dtype, copy) 363 else: 364 raise ValueError(f"Invalid data type: {type(dtype)}. Expected str or DType")
Constructs a DataType object.
Arguments:
- dtype: the data type of interest.
- dialect: the dialect to use for parsing
dtype, in case it's a string. - udt: when set to True,
dtypewill be used as-is if it can't be parsed into a DataType, thus creating a user-defined type. - copy: whether to copy the data type.
- kwargs: additional arguments to pass in the constructor of DataType.
Returns:
The constructed DataType object.
@classmethod
def
from_str( cls, dtype: str, dialect: Union[str, sqlglot.dialects.Dialect, type[sqlglot.dialects.Dialect], NoneType] = None, udt: bool = False, **kwargs: object) -> typing_extensions.Self:
366 @classmethod 367 def from_str( 368 cls, dtype: str, dialect: DialectType = None, udt: bool = False, **kwargs: object 369 ) -> Self: 370 """ 371 Constructs a `DataType` object from a `str` representation. 372 373 Args: 374 dtype: the data type of interest. 375 dialect: the dialect to use for parsing `dtype`. 376 udt: when set to True, `dtype` will be used as-is if it can't be parsed into a 377 `DataType`, thus creating a user-defined type. 378 kwargs: additional arguments to pass in the constructor of `DataType`. 379 380 Returns: 381 The constructed `DataType` object. 382 """ 383 from sqlglot import parse_one 384 385 if dtype.upper() == "UNKNOWN": 386 return cls(this=DType.UNKNOWN, **kwargs) 387 try: 388 return parse_one( 389 dtype, read=dialect, into=cls, error_level=ErrorLevel.IGNORE 390 ).set_kwargs(kwargs) 391 except ParseError: 392 if udt: 393 return cls(this=DType.USERDEFINED, kind=dtype, **kwargs) 394 raise
Constructs a DataType object from a str representation.
Arguments:
- dtype: the data type of interest.
- dialect: the dialect to use for parsing
dtype. - udt: when set to True,
dtypewill be used as-is if it can't be parsed into aDataType, thus creating a user-defined type. - kwargs: additional arguments to pass in the constructor of
DataType.
Returns:
The constructed
DataTypeobject.
def
is_type( self, *dtypes: Union[str, sqlglot.expressions.core.Identifier, sqlglot.expressions.core.Dot, DataType, DType], check_nullable: bool = False) -> bool:
396 def is_type(self, *dtypes: DATA_TYPE, check_nullable: bool = False) -> bool: 397 """ 398 Checks whether this DataType matches one of the provided data types. Nested types or precision 399 will be compared using "structural equivalence" semantics, so e.g. array<int> != array<float>. 400 401 Args: 402 dtypes: the data types to compare this DataType to. 403 check_nullable: whether to take the NULLABLE type constructor into account for the comparison. 404 If false, it means that NULLABLE<INT> is equivalent to INT. 405 406 Returns: 407 True, if and only if there is a type in `dtypes` which is equal to this DataType. 408 """ 409 self_is_nullable = self.args.get("nullable") 410 for dtype in dtypes: 411 other_type = DataType.build(dtype, copy=False, udt=True) 412 other_is_nullable = other_type.args.get("nullable") 413 if ( 414 other_type.expressions 415 or (check_nullable and (self_is_nullable or other_is_nullable)) 416 or self.this == DType.USERDEFINED 417 or other_type.this == DType.USERDEFINED 418 ): 419 matches = self == other_type 420 else: 421 matches = self.this == other_type.this 422 423 if matches: 424 return True 425 return False
Checks whether this DataType matches one of the provided data types. Nested types or precision
will be compared using "structural equivalence" semantics, so e.g. array
Arguments:
- dtypes: the data types to compare this DataType to.
- check_nullable: whether to take the NULLABLE type constructor into account for the comparison.
If false, it means that NULLABLE
is equivalent to INT.
Returns:
True, if and only if there is a type in
dtypeswhich is equal to this DataType.
Inherited Members
- sqlglot.expressions.core.Expr
- Expr
- is_var_len_args
- is_subquery
- is_cast
- is_primitive
- dump
- load
- pipe
- apply
- sqlglot.expressions.core.Expression
- this
- expression
- expressions
- text
- is_string
- is_number
- to_py
- is_int
- is_star
- alias
- alias_column_names
- name
- alias_or_name
- output_name
- type
- is_leaf
- meta
- copy
- add_comments
- pop_comments
- append
- set
- set_kwargs
- depth
- iter_expressions
- find
- find_all
- find_ancestor
- parent_select
- same_parent
- root
- walk
- dfs
- bfs
- unnest
- unalias
- unnest_operands
- flatten
- to_s
- sql
- transform
- replace
- pop
- assert_is
- error_messages
- and_
- or_
- not_
- update_positions
- as_
- isin
- between
- is_
- like
- ilike
- eq
- neq
- rlike
- div
- asc
- desc
- args
- parent
- arg_key
- index
- comments
Inherited Members
- sqlglot.expressions.core.Expr
- Expr
- is_var_len_args
- is_subquery
- is_cast
- is_primitive
- dump
- load
- pipe
- apply
- DataType
- Type
- STRUCT_TYPES
- ARRAY_TYPES
- NESTED_TYPES
- TEXT_TYPES
- SIGNED_INTEGER_TYPES
- UNSIGNED_INTEGER_TYPES
- INTEGER_TYPES
- FLOAT_TYPES
- REAL_TYPES
- NUMERIC_TYPES
- TEMPORAL_TYPES
- build
- from_str
- is_type
- sqlglot.expressions.core.Expression
- this
- expression
- expressions
- text
- is_string
- is_number
- to_py
- is_int
- is_star
- alias
- alias_column_names
- name
- alias_or_name
- output_name
- type
- is_leaf
- meta
- copy
- add_comments
- pop_comments
- append
- set
- set_kwargs
- depth
- iter_expressions
- find
- find_all
- find_ancestor
- parent_select
- same_parent
- root
- walk
- dfs
- bfs
- unnest
- unalias
- unnest_operands
- flatten
- to_s
- sql
- transform
- replace
- pop
- assert_is
- error_messages
- and_
- or_
- not_
- update_positions
- as_
- isin
- between
- is_
- like
- ilike
- eq
- neq
- rlike
- div
- asc
- desc
- args
- parent
- arg_key
- index
- comments
Inherited Members
- sqlglot.expressions.core.Expr
- Expr
- is_var_len_args
- is_subquery
- is_cast
- is_primitive
- dump
- load
- pipe
- apply
- DataType
- Type
- STRUCT_TYPES
- ARRAY_TYPES
- NESTED_TYPES
- TEXT_TYPES
- SIGNED_INTEGER_TYPES
- UNSIGNED_INTEGER_TYPES
- INTEGER_TYPES
- FLOAT_TYPES
- REAL_TYPES
- NUMERIC_TYPES
- TEMPORAL_TYPES
- build
- from_str
- is_type
- sqlglot.expressions.core.Expression
- this
- expression
- expressions
- text
- is_string
- is_number
- to_py
- is_int
- is_star
- alias
- alias_column_names
- name
- alias_or_name
- output_name
- type
- is_leaf
- meta
- copy
- add_comments
- pop_comments
- append
- set
- set_kwargs
- depth
- iter_expressions
- find
- find_all
- find_ancestor
- parent_select
- same_parent
- root
- walk
- dfs
- bfs
- unnest
- unalias
- unnest_operands
- flatten
- to_s
- sql
- transform
- replace
- pop
- assert_is
- error_messages
- and_
- or_
- not_
- update_positions
- as_
- isin
- between
- is_
- like
- ilike
- eq
- neq
- rlike
- div
- asc
- desc
- args
- parent
- arg_key
- index
- comments
Inherited Members
- sqlglot.expressions.core.Expr
- Expr
- is_var_len_args
- is_subquery
- is_cast
- is_primitive
- dump
- load
- pipe
- apply
- DataType
- Type
- STRUCT_TYPES
- ARRAY_TYPES
- NESTED_TYPES
- TEXT_TYPES
- SIGNED_INTEGER_TYPES
- UNSIGNED_INTEGER_TYPES
- INTEGER_TYPES
- FLOAT_TYPES
- REAL_TYPES
- NUMERIC_TYPES
- TEMPORAL_TYPES
- build
- from_str
- is_type
- sqlglot.expressions.core.Expression
- this
- expression
- expressions
- text
- is_string
- is_number
- to_py
- is_int
- is_star
- alias
- alias_column_names
- name
- alias_or_name
- output_name
- type
- is_leaf
- meta
- copy
- add_comments
- pop_comments
- append
- set
- set_kwargs
- depth
- iter_expressions
- find
- find_all
- find_ancestor
- parent_select
- same_parent
- root
- walk
- dfs
- bfs
- unnest
- unalias
- unnest_operands
- flatten
- to_s
- sql
- transform
- replace
- pop
- assert_is
- error_messages
- and_
- or_
- not_
- update_positions
- as_
- isin
- between
- is_
- like
- ilike
- eq
- neq
- rlike
- div
- asc
- desc
- args
- parent
- arg_key
- index
- comments
Inherited Members
- sqlglot.expressions.core.Expression
- this
- expression
- expressions
- text
- is_string
- is_number
- to_py
- is_int
- is_star
- alias
- alias_column_names
- name
- alias_or_name
- output_name
- type
- is_type
- is_leaf
- meta
- copy
- add_comments
- pop_comments
- append
- set
- set_kwargs
- depth
- iter_expressions
- find
- find_all
- find_ancestor
- parent_select
- same_parent
- root
- walk
- dfs
- bfs
- unnest
- unalias
- unnest_operands
- flatten
- to_s
- sql
- transform
- replace
- pop
- assert_is
- error_messages
- and_
- or_
- not_
- update_positions
- as_
- isin
- between
- is_
- like
- ilike
- eq
- neq
- rlike
- div
- asc
- desc
- args
- parent
- arg_key
- index
- comments
DATA_TYPE =
typing.Union[str, sqlglot.expressions.core.Identifier, sqlglot.expressions.core.Dot, DataType, DType]