sqlglot.dialects.fabric
1from __future__ import annotations 2 3 4from sqlglot import exp 5from sqlglot.dialects.dialect import AliasPrecedence, NormalizationStrategy 6from sqlglot.dialects.tsql import TSQL 7from sqlglot.generators.fabric import FabricGenerator 8from sqlglot.parsers.fabric import FabricParser 9from sqlglot.tokens import TokenType 10 11 12class Fabric(TSQL): 13 """ 14 Microsoft Fabric Data Warehouse dialect that inherits from T-SQL. 15 16 Microsoft Fabric is a cloud-based analytics platform that provides a unified 17 data warehouse experience. While it shares much of T-SQL's syntax, it has 18 specific differences and limitations that this dialect addresses. 19 20 Key differences from T-SQL: 21 - Case-sensitive identifiers (unlike T-SQL which is case-insensitive) 22 - Limited data type support with mappings to supported alternatives 23 - Temporal types (DATETIME2, DATETIMEOFFSET, TIME) limited to 6 digits precision 24 - Certain legacy types (MONEY, SMALLMONEY, etc.) are not supported 25 - Unicode types (NCHAR, NVARCHAR) are mapped to non-unicode equivalents 26 27 References: 28 - Data Types: https://learn.microsoft.com/en-us/fabric/data-warehouse/data-types 29 - T-SQL Surface Area: https://learn.microsoft.com/en-us/fabric/data-warehouse/tsql-surface-area 30 """ 31 32 COLUMN_ALIAS_PRECEDENCE = { 33 **TSQL.COLUMN_ALIAS_PRECEDENCE, 34 exp.Having: AliasPrecedence.ALIAS, 35 exp.Qualify: AliasPrecedence.ALIAS, 36 } 37 38 # Fabric is case-sensitive unlike T-SQL which is case-insensitive 39 NORMALIZATION_STRATEGY = NormalizationStrategy.CASE_SENSITIVE 40 41 class Tokenizer(TSQL.Tokenizer): 42 # Override T-SQL tokenizer to handle TIMESTAMP differently 43 # In T-SQL, TIMESTAMP is a synonym for ROWVERSION, but in Fabric we want it to be a datetime type 44 # Also add UTINYINT keyword mapping since T-SQL doesn't have it 45 KEYWORDS = { 46 **TSQL.Tokenizer.KEYWORDS, 47 "TIMESTAMP": TokenType.TIMESTAMP, 48 "UTINYINT": TokenType.UTINYINT, 49 } 50 51 Parser = FabricParser 52 53 Generator = FabricGenerator
13class Fabric(TSQL): 14 """ 15 Microsoft Fabric Data Warehouse dialect that inherits from T-SQL. 16 17 Microsoft Fabric is a cloud-based analytics platform that provides a unified 18 data warehouse experience. While it shares much of T-SQL's syntax, it has 19 specific differences and limitations that this dialect addresses. 20 21 Key differences from T-SQL: 22 - Case-sensitive identifiers (unlike T-SQL which is case-insensitive) 23 - Limited data type support with mappings to supported alternatives 24 - Temporal types (DATETIME2, DATETIMEOFFSET, TIME) limited to 6 digits precision 25 - Certain legacy types (MONEY, SMALLMONEY, etc.) are not supported 26 - Unicode types (NCHAR, NVARCHAR) are mapped to non-unicode equivalents 27 28 References: 29 - Data Types: https://learn.microsoft.com/en-us/fabric/data-warehouse/data-types 30 - T-SQL Surface Area: https://learn.microsoft.com/en-us/fabric/data-warehouse/tsql-surface-area 31 """ 32 33 COLUMN_ALIAS_PRECEDENCE = { 34 **TSQL.COLUMN_ALIAS_PRECEDENCE, 35 exp.Having: AliasPrecedence.ALIAS, 36 exp.Qualify: AliasPrecedence.ALIAS, 37 } 38 39 # Fabric is case-sensitive unlike T-SQL which is case-insensitive 40 NORMALIZATION_STRATEGY = NormalizationStrategy.CASE_SENSITIVE 41 42 class Tokenizer(TSQL.Tokenizer): 43 # Override T-SQL tokenizer to handle TIMESTAMP differently 44 # In T-SQL, TIMESTAMP is a synonym for ROWVERSION, but in Fabric we want it to be a datetime type 45 # Also add UTINYINT keyword mapping since T-SQL doesn't have it 46 KEYWORDS = { 47 **TSQL.Tokenizer.KEYWORDS, 48 "TIMESTAMP": TokenType.TIMESTAMP, 49 "UTINYINT": TokenType.UTINYINT, 50 } 51 52 Parser = FabricParser 53 54 Generator = FabricGenerator
Microsoft Fabric Data Warehouse dialect that inherits from T-SQL.
Microsoft Fabric is a cloud-based analytics platform that provides a unified data warehouse experience. While it shares much of T-SQL's syntax, it has specific differences and limitations that this dialect addresses.
Key differences from T-SQL:
- Case-sensitive identifiers (unlike T-SQL which is case-insensitive)
- Limited data type support with mappings to supported alternatives
- Temporal types (DATETIME2, DATETIMEOFFSET, TIME) limited to 6 digits precision
- Certain legacy types (MONEY, SMALLMONEY, etc.) are not supported
- Unicode types (NCHAR, NVARCHAR) are mapped to non-unicode equivalents
References:
Alias lookup policies for HAVING, QUALIFY, ORDER BY and DISTINCT ON.
Unspecified clauses prefer aliases. GROUPED_SOURCE prefers grouped input columns and input columns inside aggregates, then aliases. MERGED_SOURCE prefers merged USING keys over other input columns. Standalone ORDER BY / DISTINCT ON names prefer aliases regardless of their clause's expression precedence.
Specifies the strategy according to which identifiers should be normalized.
Whether string literals support escape sequences (e.g. \n). Set by the metaclass based on the tokenizer's STRING_ESCAPES.
Whether byte string literals support escape sequences. Set by the metaclass based on the tokenizer's BYTE_STRING_ESCAPES.
Mapping of an identifier escape char (\) to its escaped version (\\). Set by the metaclass based on the tokenizer's IDENTIFIER_ESCAPES.
Inherited Members
- sqlglot.dialects.tsql.TSQL
- WEEK_OFFSET
- LOG_BASE_FIRST
- TYPED_DIVISION
- CONCAT_COALESCE
- CONCAT_WS_COALESCE
- JSON_EXTRACT_SCALAR_SCALAR_ONLY
- ALTER_TABLE_ADD_REQUIRED_FOR_EACH_COLUMN
- ALTER_TABLE_DROP_REQUIRED_FOR_EACH_COLUMN
- TIME_FORMAT
- EXPRESSION_METADATA
- DATE_PART_MAPPING
- TIME_MAPPING
- CONVERT_FORMAT_MAPPING
- FORMAT_TIME_MAPPING
42 class Tokenizer(TSQL.Tokenizer): 43 # Override T-SQL tokenizer to handle TIMESTAMP differently 44 # In T-SQL, TIMESTAMP is a synonym for ROWVERSION, but in Fabric we want it to be a datetime type 45 # Also add UTINYINT keyword mapping since T-SQL doesn't have it 46 KEYWORDS = { 47 **TSQL.Tokenizer.KEYWORDS, 48 "TIMESTAMP": TokenType.TIMESTAMP, 49 "UTINYINT": TokenType.UTINYINT, 50 }
Inherited Members
- sqlglot.tokens.Tokenizer
- Tokenizer
- SINGLE_TOKENS
- BIT_STRINGS
- BYTE_STRINGS
- NATIONAL_RAW_STRINGS
- RAW_STRINGS
- HEREDOC_STRINGS
- UNICODE_STRINGS
- UNICODE_IDENTIFIERS
- STRING_ESCAPES
- IDENTIFIER_ESCAPES
- HEREDOC_TAG_IS_IDENTIFIER
- HEREDOC_STRING_ALTERNATIVE
- STRING_ESCAPES_ALLOWED_IN_RAW_STRINGS
- NUMERIC_ESCAPES
- DROP_UNKNOWN_ESCAPES
- NUMERIC_ESCAPES_ARE_BYTES
- LONE_SURROGATE_REPLACEMENT
- NESTED_COMMENTS
- DASH_COMMENT_REQUIRES_BOUNDARY
- COMMENTS_TERMINATE_AT_NEWLINE_ONLY
- UNQUOTED_PATH_TERMINATORS
- HINT_START
- TOKENS_PRECEDING_HINT
- COMMAND_PREFIX_TOKENS
- NUMERIC_LITERALS
- NUMBERS_CAN_HAVE_DECIMALS
- COMMENTS
- dialect
- tokenize
- sql
- size
- tokens