


'''simple docstring'''


import sys
from dataclasses import dataclass
from typing import TYPE_CHECKING, Dict, List, Optional, Tuple, Union

import pandas as pd
import pyarrow as pa

import datasets
import datasets.config
from datasets.features.features import require_storage_cast
from datasets.table import table_cast


if TYPE_CHECKING:
				import sqlitea

				import sqlalchemy


UpperCAmelCase_	:     str							     =	datasets.utils.logging.get_logger(__name__)





@dataclass
class 					lowercase__						(		datasets.BuilderConfig      ):





							'''simple docstring'''


							A_							:   Union[str, "sqlalchemy.sql.Selectable"]   			=						None
							A_							:   Union[str, "sqlalchemy.engine.Connection", "sqlalchemy.engine.Engine", "sqlite3.Connection"]   			=						None
							A_							:   Optional[Union[str, List[str]]]   			=						None
							A_							:   bool   			=						True
							A_							:   Optional[Union[List, Tuple, Dict]]   			=						None
							A_							:   Optional[Union[List, Dict]]   			=						None
							A_							:   Optional[List[str]]   			=						None
							A_							:   Optional[int]   			=						1_0000
							A_							:   Optional[datasets.Features]   			=						None






							def UpperCAmelCase_			(					self						):
											if self.sql is None:
															raise ValueError("""sql must be specified"""						)
											if self.con is None:
															raise ValueError("""con must be specified"""						)






							def UpperCAmelCase_			(					self					,      __snake_case					,      __snake_case = None					,      ):
											_SCREAMING_SNAKE_CASE				: str  	=   config_kwargs.copy()
											# We need to stringify the Selectable object to make its hash deterministic

											# The process of stringifying is explained here: http://docs.sqlalchemy.org/en/latest/faq/sqlexpressions.html
											_SCREAMING_SNAKE_CASE				: Optional[Any]  	=   config_kwargs["""sql"""]
											if not isinstance(__snake_case					,      __snake_case						):
															if datasets.config.SQLALCHEMY_AVAILABLE and "sqlalchemy" in sys.modules:
																			import sqlalchemy

																			if isinstance(__snake_case					,      sqlalchemy.sql.Selectable						):
																							_SCREAMING_SNAKE_CASE				: Optional[int]  	=   sqlalchemy.create_engine(config_kwargs["""con"""].split("""://"""						)[0] + """://"""						)
																							_SCREAMING_SNAKE_CASE				: int  	=   str(sql.compile(dialect=engine.dialect						)						)
																							_SCREAMING_SNAKE_CASE				: Optional[Any]  	=   sql_str
																			else:
																							raise TypeError(
																							    f"""Supported types for 'sql' are string and sqlalchemy.sql.Selectable but got {type(__snake_case						)}: {sql}"""						)
															else:
																			raise TypeError(
																			    f"""Supported types for 'sql' are string and sqlalchemy.sql.Selectable but got {type(__snake_case						)}: {sql}"""						)
											_SCREAMING_SNAKE_CASE				: List[Any]  	=   config_kwargs["""con"""]
											if not isinstance(__snake_case					,      __snake_case						):
															_SCREAMING_SNAKE_CASE				: List[str]  	=   id(__snake_case						)
															logger.info(
															    f"""SQL connection 'con' of type {type(__snake_case						)} couldn't be hashed properly. To enable hashing, specify 'con' as URI string instead."""						)

											return super().create_config_id(__snake_case					,      custom_features=__snake_case						)






							@property
							def UpperCAmelCase_			(					self						):
											_SCREAMING_SNAKE_CASE				: Optional[int]  	=   {
											    """index_col""": self.index_col,
											    """columns""": self.columns,
											    """params""": self.params,
											    """coerce_float""": self.coerce_float,
											    """parse_dates""": self.parse_dates,
											}
											return pd_read_sql_kwargs





class 					lowercase__						(		datasets.ArrowBasedBuilder      ):





							'''simple docstring'''


							A_							:   Dict   			=						SqlConfig






							def UpperCAmelCase_			(					self						):
											return datasets.DatasetInfo(features=self.config.features						)






							def UpperCAmelCase_			(					self					,      __snake_case						):
											return [datasets.SplitGenerator(name=datasets.Split.TRAIN					,      gen_kwargs={}						)]






							def UpperCAmelCase_			(					self					,      __snake_case						):
											if self.config.features is not None:
															_SCREAMING_SNAKE_CASE				: Tuple  	=   self.config.features.arrow_schema
															if all(not require_storage_cast(__snake_case						) for feature in self.config.features.values()						):
																			# cheaper cast
																			_SCREAMING_SNAKE_CASE				: Any  	=   pa.Table.from_arrays([pa_table[field.name] for field in schema]					,      schema=__snake_case						)
															else:
																			# more expensive cast; allows str <-> int/float or str to Audio for example
																			_SCREAMING_SNAKE_CASE				: List[Any]  	=   table_cast(__snake_case					,      __snake_case						)
											return pa_table






							def UpperCAmelCase_			(					self						):
											_SCREAMING_SNAKE_CASE				: Tuple  	=   self.config.chunksize
											_SCREAMING_SNAKE_CASE				: int  	=   pd.read_sql(
											    self.config.sql					,      self.config.con					,      chunksize=__snake_case					,      **self.config.pd_read_sql_kwargs						)
											_SCREAMING_SNAKE_CASE				: Any  	=   [sql_reader] if chunksize is None else sql_reader
											for chunk_idx, df in enumerate(__snake_case						):
															_SCREAMING_SNAKE_CASE				: Tuple  	=   pa.Table.from_pandas(__snake_case						)
															yield chunk_idx, self._cast_table(__snake_case						)








'''simple docstring'''


from ..utils import DummyObject, requires_backends





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Any   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   List[str]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Any   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Any   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   str   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Union[str, Any]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   List[str]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Any   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   List[Any]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Tuple   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Any   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Optional[int]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Optional[int]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Optional[Any]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Optional[int]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Tuple   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   List[Any]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   str   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Any   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Dict   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   List[Any]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   List[Any]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   str   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Optional[int]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Any   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   str   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   List[Any]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   List[Any]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Tuple   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   List[Any]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Any   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   List[Any]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   List[str]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   List[Any]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   List[Any]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Any   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Optional[int]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   List[str]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   int   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Optional[int]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Tuple   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Dict   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Optional[int]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Union[str, Any]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   List[str]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Any   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Dict   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Tuple   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Any   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   List[str]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Any   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   List[Any]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Any   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Dict   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Union[str, Any]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   Optional[Any]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   List[Any]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)





class 					lowercase__						(		metaclass=_snake_case      ):





							'''simple docstring'''


							A_							:   List[Any]   			=						["""tokenizers"""]






							def __init__(					self					,      *__snake_case					,      **__snake_case						):
											requires_backends(self					,      ["""tokenizers"""]						)




