




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


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





@dataclass
class __magic_name__(						datasets.BuilderConfig      ):
						UpperCAmelCase_		:					Union[str, "sqlalchemy.sql.Selectable"]    =  None
						UpperCAmelCase_		:					Union[str, "sqlalchemy.engine.Connection", "sqlalchemy.engine.Engine", "sqlite3.Connection"]    =  None
						UpperCAmelCase_		:					Optional[Union[str, List[str]]]    =  None
						UpperCAmelCase_		:					bool    =  True
						UpperCAmelCase_		:					Optional[Union[List, Tuple, Dict]]    =  None
						UpperCAmelCase_		:					Optional[Union[List, Dict]]    =  None
						UpperCAmelCase_		:					Optional[List[str]]    =  None
						UpperCAmelCase_		:					Optional[int]    =  10_000
						UpperCAmelCase_		:					Optional[datasets.Features]    =  None






						def       __lowerCAmelCase(   self						:						Dict       ):



									'''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						:						Any					,   __UpperCamelCase						:						dict					,   __UpperCamelCase						:						Optional[datasets.Features] = None					,   ):



									'''simple docstring'''






									snake_case__          =						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
									snake_case__          =						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       ):
																		snake_case__          =						sqlalchemy.create_engine(config_kwargs["""con"""].split("""://"""       )[0] + """://"""       )
																		snake_case__          =						str(sql.compile(dialect=engine.dialect       )       )
																		snake_case__          =						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}"""       )
									snake_case__          =						config_kwargs["""con"""]
									if not isinstance(__UpperCamelCase					,   __UpperCamelCase       ):
												snake_case__          =						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						:						List[Any]       ):



									'''simple docstring'''






									snake_case__          =						{
									    """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 __magic_name__(						datasets.ArrowBasedBuilder      ):
						UpperCAmelCase_		:					List[Any]    =  SqlConfig






						def       __lowerCAmelCase(   self						:						Any       ):



									'''simple docstring'''






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






						def       __lowerCAmelCase(   self						:						Tuple					,   __UpperCamelCase						:						List[str]       ):



									'''simple docstring'''






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






						def       __lowerCAmelCase(   self						:						Union[str, Any]					,   __UpperCamelCase						:						pa.Table       ):



									'''simple docstring'''






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







						def       __lowerCAmelCase(   self						:						Any       ):



									'''simple docstring'''






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





'''simple docstring'''

import unittest
import warnings

from datasets.utils import experimental




@experimental
def    snake_case__     (  )			->       Union[str, Any]:





			'''simple docstring'''






			return "success"





class __magic_name__(						unittest.TestCase      ):






						def       __lowerCAmelCase(   self						:						List[Any]       ):



									'''simple docstring'''






									with warnings.catch_warnings(record=__UpperCamelCase       ) as w:
												warnings.simplefilter("""always"""       )
												self.assertEqual(dummy_function()					,   """success"""       )
									self.assertEqual(len(__UpperCamelCase       )					,   1       )