1212from sqlglot .dialects import DIALECT_MODULE_NAMES
1313from sqlglot .errors import ParseError
1414from sqlglot .generator import Generator , unsupported_args
15- from sqlglot .helper import AutoName , flatten , is_int , seq_get , subclasses , to_bool
15+ from sqlglot .helper import (
16+ AutoName ,
17+ flatten ,
18+ is_int ,
19+ seq_get ,
20+ subclasses ,
21+ suggest_closest_match_and_fail ,
22+ to_bool ,
23+ )
1624from sqlglot .jsonpath import JSONPathTokenizer , parse as parse_json_path
1725from sqlglot .parser import Parser
1826from sqlglot .time import TIMEZONES , format_time , subsecond_precision
@@ -794,6 +802,12 @@ class Dialect(metaclass=_Dialect):
794802 # Specifies what types a given type can be coerced into
795803 COERCES_TO : t .Dict [exp .DataType .Type , t .Set [exp .DataType .Type ]] = {}
796804
805+ # Determines the supported Dialect instance settings
806+ SUPPORTED_SETTINGS = {
807+ "normalization_strategy" ,
808+ "version" ,
809+ }
810+
797811 @classmethod
798812 def get_or_raise (cls , dialect : DialectType ) -> Dialect :
799813 """
@@ -843,16 +857,9 @@ def get_or_raise(cls, dialect: DialectType) -> Dialect:
843857
844858 result = cls .get (dialect_name .strip ())
845859 if not result :
846- from difflib import get_close_matches
847-
848- close_matches = get_close_matches (dialect_name , list (DIALECT_MODULE_NAMES ), n = 1 )
849-
850- similar = seq_get (close_matches , 0 ) or ""
851- if similar :
852- similar = f" Did you mean { similar } ?"
853-
854- raise ValueError (f"Unknown dialect '{ dialect_name } '.{ similar } " )
860+ suggest_closest_match_and_fail ("dialect" , dialect_name , list (DIALECT_MODULE_NAMES ))
855861
862+ assert result is not None
856863 return result (** kwargs )
857864
858865 raise ValueError (f"Invalid dialect type for '{ dialect } ': '{ type (dialect )} '." )
@@ -874,15 +881,19 @@ def format_time(
874881 return expression
875882
876883 def __init__ (self , ** kwargs ) -> None :
877- normalization_strategy = kwargs .pop ("normalization_strategy " , None )
884+ self . version = Version ( kwargs .pop ("version " , None ) )
878885
886+ normalization_strategy = kwargs .pop ("normalization_strategy" , None )
879887 if normalization_strategy is None :
880888 self .normalization_strategy = self .NORMALIZATION_STRATEGY
881889 else :
882890 self .normalization_strategy = NormalizationStrategy (normalization_strategy .upper ())
883891
884892 self .settings = kwargs
885893
894+ for unsupported_setting in kwargs .keys () - self .SUPPORTED_SETTINGS :
895+ suggest_closest_match_and_fail ("setting" , unsupported_setting , self .SUPPORTED_SETTINGS )
896+
886897 def __eq__ (self , other : t .Any ) -> bool :
887898 # Does not currently take dialect state into account
888899 return type (self ) == other
@@ -1026,10 +1037,6 @@ def parser(self, **opts) -> Parser:
10261037 def generator (self , ** opts ) -> Generator :
10271038 return self .generator_class (dialect = self , ** opts )
10281039
1029- @property
1030- def version (self ) -> Version :
1031- return Version (self .settings .get ("version" , None ))
1032-
10331040 def generate_values_aliases (self , expression : exp .Values ) -> t .List [exp .Identifier ]:
10341041 return [
10351042 exp .to_identifier (f"_col_{ i } " )
0 commit comments