



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_          =				datasets.utils.logging.get_logger(__name__)





@dataclass
class 		UpperCAmelCase    (    datasets.BuilderConfig					):
   SCREAMING_SNAKE_CASE__					      =  None
   SCREAMING_SNAKE_CASE__					      =  None
   SCREAMING_SNAKE_CASE__					      =  None
   SCREAMING_SNAKE_CASE__					      =  True
   SCREAMING_SNAKE_CASE__					      =  None
   SCREAMING_SNAKE_CASE__					      =  None
   SCREAMING_SNAKE_CASE__					      =  None
   SCREAMING_SNAKE_CASE__					      =  1_0_0_0_0
   SCREAMING_SNAKE_CASE__					      =  None





   def 						__lowerCAmelCase				(						self      ):






         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							,  _lowerCAmelCase							,  _lowerCAmelCase = None							,  ):
         _lowerCAmelCase			      =	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
         _lowerCAmelCase			      =	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      ):
                           _lowerCAmelCase			      =	sqlalchemy.create_engine(config_kwargs['''con'''].split('''://'''      )[0] + '''://'''      )
                           _lowerCAmelCase			      =	str(sql.compile(dialect=engine.dialect      )      )
                           _lowerCAmelCase			      =	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}'''      )
         _lowerCAmelCase			      =	config_kwargs["""con"""]
         if not isinstance(__UpperCamelCase							,  __UpperCamelCase      ):
               _lowerCAmelCase			      =	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      ):
         _lowerCAmelCase			      =	{
             """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 		UpperCAmelCase    (    datasets.ArrowBasedBuilder					):
   SCREAMING_SNAKE_CASE__					      =  SqlConfig





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





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





   def 						__lowerCAmelCase				(						self							,  _lowerCAmelCase      ):






         if self.config.features is not None:
               _lowerCAmelCase			      =	self.config.features.arrow_schema
               if all(not require_storage_cast(__UpperCamelCase      ) for feature in self.config.features.values()      ):
                     # cheaper cast
                     _lowerCAmelCase			      =	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
                     _lowerCAmelCase			      =	table_cast(__UpperCamelCase							,  __UpperCamelCase      )
         return pa_table





   def 						__lowerCAmelCase				(						self      ):
         _lowerCAmelCase			      =	self.config.chunksize
         _lowerCAmelCase			      =	pd.read_sql(
             self.config.sql							,  self.config.con							,  chunksize=__UpperCamelCase							,  **self.config.pd_read_sql_kwargs      )
         _lowerCAmelCase			      =	[sql_reader] if chunksize is None else sql_reader
         for chunk_idx, df in enumerate(__UpperCamelCase      ):
               _lowerCAmelCase			      =	pa.Table.from_pandas(__UpperCamelCase      )
               yield chunk_idx, self._cast_table(__UpperCamelCase      )

'''simple docstring'''







def 				_snake_case (		lowercase = 2_0						)       ->       int:

				try:
								__a       :     Optional[Any]								=	int(lowercase						)
				except (TypeError, ValueError):
								raise TypeError("""Parameter n must be int or castable to int."""						)
				if n <= 0:
								raise ValueError("""Parameter n must be greater than or equal to one."""						)
				__a       :     List[Any]								=	0
				while 1:
								i += n * (n - 1)
								__a       :     Union[str, Any]								=	0
								for j in range(2			,    lowercase						):
												if i % j != 0:
																__a       :     Any								=	1
																break
								if nfound == 0:
												if i == 0:
																__a       :     List[str]								=	1
												return i
				return None


if __name__ == "__main__":
					print(f'''{solution() = }''')