



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


@dataclass
class 	a__		(    datasets.BuilderConfig  ):
   _lowerCamelCase       				=					None
   _lowerCamelCase       				=					None
   _lowerCamelCase       				=					None
   _lowerCamelCase       				=					True
   _lowerCamelCase       				=					None
   _lowerCamelCase       				=					None
   _lowerCamelCase       				=					None
   _lowerCamelCase       				=					10_000
   _lowerCamelCase       				=					None


   def 							lowercase					(				self   :				Tuple      )     ->							List[str]:
         if self.sql is None:
               raise ValueError('sql must be specified'      )
         if self.con is None:
               raise ValueError('con must be specified'      )


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

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

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






   @property
   def 							lowercase					(				self   :				Union[str, Any]      )     ->							Union[str, Any]:
         lowercase	:   List[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 	a__		(    datasets.ArrowBasedBuilder  ):
   _lowerCamelCase       				=					SqlConfig


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


   def 							lowercase					(				self   :				int,  lowerCAmelCase   :				int      )     ->							Optional[Any]:
         return [datasets.SplitGenerator(name=datasets.Split.TRAIN,  gen_kwargs={}      )]


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






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





"""simple docstring"""




from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


_UpperCamelCase:					Optional[Any]     				=	{
    'configuration_codegen': ['CODEGEN_PRETRAINED_CONFIG_ARCHIVE_MAP', 'CodeGenConfig', 'CodeGenOnnxConfig'],
    'tokenization_codegen': ['CodeGenTokenizer'],
}

try:
     if not is_tokenizers_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     _UpperCamelCase:					Union[str, Any]     				=	['CodeGenTokenizerFast']

try:
     if not is_torch_available():
          raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
     pass
else:
     _UpperCamelCase:					str     				=	[
         'CODEGEN_PRETRAINED_MODEL_ARCHIVE_LIST',
         'CodeGenForCausalLM',
         'CodeGenModel',
         'CodeGenPreTrainedModel',
     ]

if TYPE_CHECKING:
     from .configuration_codegen import CODEGEN_PRETRAINED_CONFIG_ARCHIVE_MAP, CodeGenConfig, CodeGenOnnxConfig
     from .tokenization_codegen import CodeGenTokenizer

     try:
          if not is_tokenizers_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .tokenization_codegen_fast import CodeGenTokenizerFast

     try:
          if not is_torch_available():
               raise OptionalDependencyNotAvailable()
     except OptionalDependencyNotAvailable:
          pass
     else:
          from .modeling_codegen import (
              CODEGEN_PRETRAINED_MODEL_ARCHIVE_LIST,
              CodeGenForCausalLM,
              CodeGenModel,
              CodeGenPreTrainedModel,
          )

else:
     import sys

     _UpperCamelCase:					int     				=	_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)
