






"""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							:       List[str]       					=		datasets.utils.logging.get_logger(__name__)






@dataclass
class 		snake_case    (    datasets.BuilderConfig			):
    __magic_name__       	=	None
    __magic_name__       	=	None
    __magic_name__       	=	None
    __magic_name__       	=	True
    __magic_name__       	=	None
    __magic_name__       	=	None
    __magic_name__       	=	None
    __magic_name__       	=	1_0000
    __magic_name__       	=	None





    def 							lowerCamelCase__ (				self      :   str     ):


      '''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      :   Optional[Any]							,						A      :   int							,						A      :   str = None							,						):


      '''simple docstring'''




      a	:     Optional[int]							=  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	:     Union[str, Any]							=  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[Any]							=  sqlalchemy.create_engine(config_kwargs['con'].split('://'     )[0] + '://'     )
            a	:     Any							=  str(sql.compile(dialect=engine.dialect     )     )
            a	:     str							=  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	:     List[Any]							=  config_kwargs['con']
      if not isinstance(_UpperCAmelCase							,						_UpperCAmelCase     ):
        a	:     Dict							=  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      :   Any     ):


      '''simple docstring'''




      a	:     str							=  {
          '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 		snake_case    (    datasets.ArrowBasedBuilder			):
    __magic_name__       	=	SqlConfig





    def 							lowerCamelCase__ (				self      :   List[Any]     ):


      '''simple docstring'''




      return datasets.DatasetInfo(features=self.config.features     )





    def 							lowerCamelCase__ (				self      :   Any							,						A      :   int     ):


      '''simple docstring'''




      return [datasets.SplitGenerator(name=datasets.Split.TRAIN							,						gen_kwargs={}     )]





    def 							lowerCamelCase__ (				self      :   int							,						A      :   Any     ):


      '''simple docstring'''




      if self.config.features is not None:
        a	:     List[Any]							=  self.config.features.arrow_schema
        if all(not require_storage_cast(_UpperCAmelCase     ) for feature in self.config.features.values()     ):
          # cheaper cast
          a	:     Dict							=  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	:     List[Any]							=  table_cast(_UpperCAmelCase							,						_UpperCAmelCase     )
      return pa_table





    def 							lowerCamelCase__ (				self      :   Optional[int]     ):


      '''simple docstring'''




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








import math
def 			__SCREAMING_SNAKE_CASE							(					lowercase__	:int					)							->	list:
						if n <= 0:
												raise ValueError('Only positive integers have prime factors'					)
						__magic_name__					:				Union[str, Any]				=   []
						while n % 2 == 0:
												pf.append(2					)
												__magic_name__					:				Union[str, Any]				=   int(n / 2					)
						for i in range(3   ,    int(math.sqrt(lowercase__					)					) + 1   ,    2					):
												while n % i == 0:
																		pf.append(lowercase__					)
																		__magic_name__					:				List[str]				=   int(n / i					)
						if n > 2:
												pf.append(lowercase__					)
						return pf
def 			__SCREAMING_SNAKE_CASE							(					lowercase__	:int					)							->	int:
						if n <= 0:
												raise ValueError('Only positive numbers are accepted'					)
						__magic_name__					:				Union[str, Any]				=   1
						__magic_name__					:				Tuple				=   1
						while n % 2 == 0:
												temp += 1
												__magic_name__					:				Any				=   int(n / 2					)
						div *= temp
						for i in range(3   ,    int(math.sqrt(lowercase__					)					) + 1   ,    2					):
												__magic_name__					:				List[Any]				=   1
												while n % i == 0:
																		temp += 1
																		__magic_name__					:				Any				=   int(n / i					)
												div *= temp
						if n > 1:
												div *= 2
						return div
def 			__SCREAMING_SNAKE_CASE							(					lowercase__	:int					)							->	int:
						if n <= 0:
												raise ValueError('Only positive numbers are accepted'					)
						__magic_name__					:				int				=   1
						__magic_name__					:				List[str]				=   1
						while n % 2 == 0:
												temp += 1
												__magic_name__					:				List[Any]				=   int(n / 2					)
						if temp > 1:
												s *= (2**temp - 1) / (2 - 1)
						for i in range(3   ,    int(math.sqrt(lowercase__					)					) + 1   ,    2					):
												__magic_name__					:				int				=   1
												while n % i == 0:
																		temp += 1
																		__magic_name__					:				Optional[Any]				=   int(n / i					)
												if temp > 1:
																		s *= (i**temp - 1) / (i - 1)
						return int(lowercase__					)
def 			__SCREAMING_SNAKE_CASE							(					lowercase__	:int					)							->	int:
						__magic_name__					:				Dict				=   n
						for x in set(prime_factors(lowercase__					)					):
												s *= (x - 1) / x
						return int(lowercase__					)


if __name__ == "__main__":
			import doctest

			doctest.testmod()


