




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


__a							= datasets.utils.logging.get_logger(__name__)

@dataclass
class   __a(     datasets.BuilderConfig   ):






    """simple docstring"""





    lowerCAmelCase  			=      None
    lowerCAmelCase  			=      None
    lowerCAmelCase  			=      None
    lowerCAmelCase  			=      True
    lowerCAmelCase  			=      None
    lowerCAmelCase  			=      None
    lowerCAmelCase  			=      None
    lowerCAmelCase  			=      1_0000
    lowerCAmelCase  			=      None





    def 							a__      (      self  ) ->		Dict:







         if self.sql is None:
              raise ValueError('''sql must be specified'''  )
         if self.con is None:
              raise ValueError('''con must be specified'''  )





    def 							a__      (      self   ,_SCREAMING_SNAKE_CASE   ,_SCREAMING_SNAKE_CASE = None   ,) ->		str:
         UpperCAmelCase_			:							List[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
         UpperCAmelCase_			:							Dict   =			config_kwargs['''sql''']
         if not isinstance(a__   ,a__  ):
              if datasets.config.SQLALCHEMY_AVAILABLE and "sqlalchemy" in sys.modules:
                   import sqlalchemy

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

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





    @property
    def 							a__      (      self  ) ->		Optional[Any]:
         UpperCAmelCase_			:							Optional[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   __a(     datasets.ArrowBasedBuilder   ):






    """simple docstring"""





    lowerCAmelCase  			=      SqlConfig





    def 							a__      (      self  ) ->		int:
         return datasets.DatasetInfo(features=self.config.features  )





    def 							a__      (      self   ,_SCREAMING_SNAKE_CASE  ) ->		List[str]:
         return [datasets.SplitGenerator(name=datasets.Split.TRAIN   ,gen_kwargs={}  )]





    def 							a__      (      self   ,_SCREAMING_SNAKE_CASE  ) ->		pa.Table:







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





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



"""simple docstring"""


def    a__       ( __lowercase = 20      )		->		int:

				try:
								_A         =	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         =	0
				while 1:
								i += n * (n - 1)
								_A         =	0
								for j in range(2   ,	__lowercase      ):
												if i % j != 0:
																_A         =	1
																break
								if nfound == 0:
												if i == 0:
																_A         =	1
												return i
				return None


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