
'''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


__SCREAMING_SNAKE_CASE		:  Any        =      datasets.utils.logging.get_logger(__name__)
@dataclass
class  SCREAMING_SNAKE_CASE__       (  datasets.BuilderConfig   ):
	lowercase__	    =							None
	lowercase__	    =							None
	lowercase__	    =							None
	lowercase__	    =							True
	lowercase__	    =							None
	lowercase__	    =							None
	lowercase__	    =							None
	lowercase__	    =							1_00_00
	lowercase__	    =							None
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					if self.sql is None:
									raise ValueError("""sql must be specified"""			)
					if self.con is None:
									raise ValueError("""con must be specified"""			)
	def __lowerCamelCase    (				self  ,    __UpperCamelCase  ,    __UpperCamelCase = None  ,    ):



					'''simple docstring'''






					__a       :     Union[str, Any]								=	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
					__a       :     str								=	config_kwargs["""sql"""]
					if not isinstance(__UpperCamelCase  ,    __UpperCamelCase			):
									if datasets.config.SQLALCHEMY_AVAILABLE and "sqlalchemy" in sys.modules:
													import sqlalchemy

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

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

	@property
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     Union[str, Any]								=	{
					    """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  SCREAMING_SNAKE_CASE__       (  datasets.ArrowBasedBuilder   ):
	lowercase__	    =							SqlConfig
	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					return datasets.DatasetInfo(features=self.config.features			)
	def __lowerCamelCase    (				self  ,    __UpperCamelCase			):



					'''simple docstring'''






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



					'''simple docstring'''






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

	def __lowerCamelCase    (				self			):



					'''simple docstring'''






					__a       :     List[str]								=	self.config.chunksize
					__a       :     Optional[Any]								=	pd.read_sql(
					    self.config.sql  ,    self.config.con  ,    chunksize=__UpperCamelCase  ,    **self.config.pd_read_sql_kwargs			)
					__a       :     Union[str, Any]								=	[sql_reader] if chunksize is None else sql_reader
					for chunk_idx, df in enumerate(__UpperCamelCase			):
									__a       :     int								=	pa.Table.from_pandas(__UpperCamelCase			)
									yield chunk_idx, self._cast_table(__UpperCamelCase			)

'''simple docstring'''







def 				_snake_case (		lowercase						)       ->       int:
				if not isinstance(lowercase			,    lowercase						):
								__a       :     Union[str, Any]								=	F"""Input value of [number={number}] must be an integer"""
								raise TypeError(lowercase						)
				if number < 1:
								raise ValueError("""Input must be a positive integer"""						)
				return number * (2 * number - 1)


if __name__ == "__main__":
					import doctest

					doctest.testmod()