@@ -166,6 +166,29 @@ def pyarrow2postgresql( # pylint: disable=too-many-branches,too-many-return-sta
166166 raise exceptions .UnsupportedType (f"Unsupported PostgreSQL type: { dtype } " )
167167
168168
169+ def pyarrow2timestream (dtype : pa .DataType ) -> str : # pylint: disable=too-many-branches,too-many-return-statements
170+ """Pyarrow to Amazon Timestream data types conversion."""
171+ if pa .types .is_int8 (dtype ):
172+ return "BIGINT"
173+ if pa .types .is_int16 (dtype ) or pa .types .is_uint8 (dtype ):
174+ return "BIGINT"
175+ if pa .types .is_int32 (dtype ) or pa .types .is_uint16 (dtype ):
176+ return "BIGINT"
177+ if pa .types .is_int64 (dtype ) or pa .types .is_uint32 (dtype ):
178+ return "BIGINT"
179+ if pa .types .is_uint64 (dtype ):
180+ return "BIGINT"
181+ if pa .types .is_float32 (dtype ):
182+ return "DOUBLE"
183+ if pa .types .is_float64 (dtype ):
184+ return "DOUBLE"
185+ if pa .types .is_boolean (dtype ):
186+ return "BOOLEAN"
187+ if pa .types .is_string (dtype ):
188+ return "VARCHAR"
189+ raise exceptions .UnsupportedType (f"Unsupported Amazon Timestream measure type: { dtype } " )
190+
191+
169192def athena2pyarrow (dtype : str ) -> pa .DataType : # pylint: disable=too-many-return-statements
170193 """Athena to PyArrow data types conversion."""
171194 dtype = dtype .lower ().replace (" " , "" )
@@ -587,3 +610,13 @@ def database_types_from_pandas(
587610 database_types [col_name ] = converter_func (col_dtype , string_type )
588611 _logger .debug ("database_types: %s" , database_types )
589612 return database_types
613+
614+
615+ def timestream_type_from_pandas (df : pd .DataFrame ) -> str :
616+ """Extract Amazon Timestream types from a Pandas DataFrame."""
617+ pyarrow_types : Dict [str , Optional [pa .DataType ]] = pyarrow_types_from_pandas (df = df , index = False , ignore_cols = [])
618+ if len (pyarrow_types ) != 1 or list (pyarrow_types .values ())[0 ] is None :
619+ raise RuntimeError (f"Invalid pyarrow_types: { pyarrow_types } " )
620+ pyarrow_type : pa .DataType = list (pyarrow_types .values ())[0 ]
621+ _logger .debug ("pyarrow_type: %s" , pyarrow_type )
622+ return pyarrow2timestream (dtype = pyarrow_type )
0 commit comments