in src/app/AthenaNetCore/AthenaNetCore.BusinessLogic/Extentions/AmazonAthenaClientExtentions.cs [228:277]
private static T ProcessRow<T>(IReadOnlyList<Datum> columnsData, IReadOnlyDictionary<string, ColumnPositionInfo> columnsPositionMap) where T : new()
{
//Debug.WriteLine(string.Join(" | ", columnsData.Select(s => s.VarCharValue)));
var entityItem = new T();
foreach (var prop in entityItem.GetType().GetProperties())
{
var propColumnName = prop.Name.ToLower();
var att = prop.GetCustomAttributes(typeof(AthenaColumnAttribute), false)?.FirstOrDefault();
if (att is AthenaColumnAttribute attribute)
{
propColumnName = attribute.ColumnName;
}
if (columnsPositionMap.ContainsKey(propColumnName))
{
var mapped = columnsPositionMap[propColumnName];
var athenaColumnInfo = mapped.ColumnInfo;
var i = mapped.IndexPosition;
//For more detail about Amazon Athena Data Type, check: https://docs.aws.amazon.com/athena/latest/ug/data-types.html
if (athenaColumnInfo.Type == "integer" || athenaColumnInfo.Type == "tinyint" || athenaColumnInfo.Type == "smallint")
{
prop.SetValue(entityItem, Convert.ToInt32(columnsData[i]?.VarCharValue));
}
else if (athenaColumnInfo.Type == "bigint")
{
prop.SetValue(entityItem, Convert.ToInt64(columnsData[i]?.VarCharValue));
}
else if (athenaColumnInfo.Type == "double" || athenaColumnInfo.Type == "float")
{
prop.SetValue(entityItem, Convert.ToDouble(columnsData[i]?.VarCharValue));
}
else if (athenaColumnInfo.Type == "decimal")
{
prop.SetValue(entityItem, Convert.ToDecimal(columnsData[i]?.VarCharValue));
}
else if (athenaColumnInfo.Type == "date" || athenaColumnInfo.Type == "timestamp")
{
prop.SetValue(entityItem, Convert.ToDateTime(columnsData[i]?.VarCharValue));
}
else
{
prop.SetValue(entityItem, columnsData[i]?.VarCharValue);
}
}
}
return entityItem;
}