Skip to content

Commit 6553331

Browse files
Ivan Gavryliukazurecoder
Ivan Gavryliuk
authored andcommitted
add support for floats and doubles (tensorflow#104)
1 parent 39715db commit 6553331

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

src/Parquet.Test/EndToEndTypeTest.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,36 @@ public void Strings(string input)
3434

3535
Assert.Equal(ds[0].GetString(0), ds1[0].GetString(0));
3636
}
37+
38+
[Fact]
39+
public void Floats()
40+
{
41+
var ds = new DataSet(new SchemaElement<float>("f"));
42+
ds.Add((float)1.23);
43+
44+
var ms = new MemoryStream();
45+
ParquetWriter.Write(ds, ms);
46+
47+
ms.Position = 0;
48+
DataSet ds1 = ParquetReader.Read(ms);
49+
50+
Assert.Equal(ds[0].GetFloat(0), ds1[0].GetFloat(0));
51+
}
52+
53+
[Fact]
54+
public void Doubles()
55+
{
56+
var ds = new DataSet(new SchemaElement<double>("d"));
57+
ds.Add((double)12.34);
58+
59+
var ms = new MemoryStream();
60+
ParquetWriter.Write(ds, ms);
61+
62+
ms.Position = 0;
63+
DataSet ds1 = ParquetReader.Read(ms);
64+
65+
Assert.Equal(ds[0].GetDouble(0), ds1[0].GetDouble(0));
66+
}
67+
3768
}
3869
}

src/Parquet/File/TypeFactory.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public TypeTag(Thrift.Type ptype, Thrift.ConvertedType? convertedType)
2727
{ typeof(int), new TypeTag(Thrift.Type.INT32, null) },
2828
{ typeof(bool), new TypeTag(Thrift.Type.BOOLEAN, null) },
2929
{ typeof(string), new TypeTag(Thrift.Type.BYTE_ARRAY, Thrift.ConvertedType.UTF8) },
30+
{ typeof(float), new TypeTag(Thrift.Type.FLOAT, null) },
31+
{ typeof(double), new TypeTag(Thrift.Type.DOUBLE, null) },
3032
// is the coerced type TIMESTAMP_MILLS but holds backward-compatilibility with Impala and HIVE
3133
{ typeof(DateTimeOffset), new TypeTag(Thrift.Type.INT96, null) }
3234
};
@@ -37,7 +39,7 @@ public static void AdjustSchema(Thrift.SchemaElement schema, Type systemType)
3739
{
3840
string supportedTypes = string.Join(", ", TypeToTag.Keys.Select(t => t.ToString()));
3941

40-
throw new NotSupportedException($"system type {systemType} is not supported, we currently support only these types: '{supportedTypes}'");
42+
throw new NotSupportedException($"system type {systemType} is not supported, list of supported types: '{supportedTypes}'");
4143
}
4244

4345
schema.Type = tag.PType;

src/Parquet/File/Values/PlainValuesWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ private void WriteInt96(BinaryWriter writer, SchemaElement schema, IList data)
180180
private static void WriteDouble(BinaryWriter writer, SchemaElement schema, IList data)
181181
{
182182
var lst = (List<double>)data;
183-
foreach (float d in lst)
183+
foreach (double d in lst)
184184
{
185185
writer.Write(d);
186186
}

0 commit comments

Comments
 (0)