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


lowerCamelCase_				:		Optional[int]       						=       datasets.utils.logging.get_logger(__name__)


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



			def __SCREAMING_SNAKE_CASE							(						self    ) ->    Optional[int]:
								if self.sql is None:
													raise ValueError('sql must be specified'    )
								if self.con is None:
													raise ValueError('con must be specified'    )



			def __SCREAMING_SNAKE_CASE							(						self      ,						UpperCAmelCase      ,						UpperCAmelCase = None      ,						) ->    str:
								__a							=   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							=   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							=   sqlalchemy.create_engine(config_kwargs['con'].split('://'    )[0] + '://'    )
																							__a							=   str(sql.compile(dialect=engine.dialect    )    )
																							__a							=   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							=   config_kwargs['con']
								if not isinstance(UpperCAmelCase      ,						UpperCAmelCase    ):
													__a							=   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 __SCREAMING_SNAKE_CASE							(						self    ) ->    Tuple:
								__a							=   {
								    '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		):
			A__				:   int								=			SqlConfig



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



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



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







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





def 							lowerCAmelCase(	__lowerCamelCase      ,				__lowerCamelCase						):
					sequence.append(__lowerCamelCase						)

					__a							=   0
					while sequence[index] != target:
										index += 1

					sequence.pop()

					if index == len(__lowerCamelCase						):
										return None

					return index


if __name__ == "__main__":
	lowerCamelCase_				:		List[str]       						=       input("""Enter numbers separated by comma:\n""").strip()
	lowerCamelCase_				:		str       						=       [int(item) for item in user_input.split(""",""")]

	lowerCamelCase_				:		Tuple       						=       input("""Enter a single number to be found in the list:\n""")
	lowerCamelCase_				:		Optional[int]       						=       int(target_input)
	lowerCamelCase_				:		List[Any]       						=       sentinel_linear_search(sequence, target)
	if result is not None:
		print(F'''{target} found at positions: {result}''')
	else:
		print("""Not found""")




