Skip to content

Commit 9e10004

Browse files
author
Prashanth Govindarajan
authored
Explode column types and generate converters (dotnet#2857)
* Explode column types and generate converters * Clean this * sq * sq * Cherry pick for next commit * sq * Undo unnecessary change
1 parent 355d3fb commit 9e10004

22 files changed

+1772
-381
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Text;
8+
9+
namespace Microsoft.Data.Analysis
10+
{
11+
public partial class BooleanDataFrameColumn : PrimitiveDataFrameColumn<bool>
12+
{
13+
public BooleanDataFrameColumn(string name, IEnumerable<bool?> values) : base(name, values) { }
14+
15+
public BooleanDataFrameColumn(string name, IEnumerable<bool> values) : base(name, values) { }
16+
17+
public BooleanDataFrameColumn(string name, long length = 0) : base(name, length) { }
18+
19+
public BooleanDataFrameColumn(string name, ReadOnlyMemory<byte> buffer, ReadOnlyMemory<byte> nullBitMap, int length = 0, int nullCount = 0) : base(name, buffer, nullBitMap, length, nullCount) { }
20+
21+
internal BooleanDataFrameColumn(string name, PrimitiveColumnContainer<bool> values) : base(name, values) { }
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Text;
8+
9+
namespace Microsoft.Data.Analysis
10+
{
11+
public partial class ByteDataFrameColumn : PrimitiveDataFrameColumn<byte>
12+
{
13+
public ByteDataFrameColumn(string name, IEnumerable<byte?> values) : base(name, values) { }
14+
15+
public ByteDataFrameColumn(string name, IEnumerable<byte> values) : base(name, values) { }
16+
17+
public ByteDataFrameColumn(string name, long length = 0) : base(name, length) { }
18+
19+
public ByteDataFrameColumn(string name, ReadOnlyMemory<byte> buffer, ReadOnlyMemory<byte> nullBitMap, int length = 0, int nullCount = 0) : base(name, buffer, nullBitMap, length, nullCount) { }
20+
21+
internal ByteDataFrameColumn(string name, PrimitiveColumnContainer<byte> values) : base(name, values) { }
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Text;
8+
9+
namespace Microsoft.Data.Analysis
10+
{
11+
public partial class CharDataFrameColumn : PrimitiveDataFrameColumn<char>
12+
{
13+
public CharDataFrameColumn(string name, IEnumerable<char?> values) : base(name, values) { }
14+
15+
public CharDataFrameColumn(string name, IEnumerable<char> values) : base(name, values) { }
16+
17+
public CharDataFrameColumn(string name, long length = 0) : base(name, length) { }
18+
19+
public CharDataFrameColumn(string name, ReadOnlyMemory<byte> buffer, ReadOnlyMemory<byte> nullBitMap, int length = 0, int nullCount = 0) : base(name, buffer, nullBitMap, length, nullCount) { }
20+
21+
internal CharDataFrameColumn(string name, PrimitiveColumnContainer<char> values) : base(name, values) { }
22+
}
23+
}

src/Microsoft.Data.Analysis/ColumnArithmeticTemplate.ttinclude

+74
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,56 @@
3838
return $"{keyword} (typeof(T) == typeof({type.TypeName}))";
3939
}
4040

41+
// A way to discern implicit conversions. For ex: short has primitivitty 2. int has primitivitty 3. primitivitty(short) + primitivitty(int) > 2 * primitivitty(short) implying that a conversion has to take place
42+
public Dictionary<string, int> primitiveTypeToPrimitivityLevelMap = new Dictionary<string, int> {
43+
{"byte", 1},
44+
{"sbyte", 1},
45+
{"short", 2},
46+
{"ushort", 2},
47+
{"int", 3},
48+
{"uint", 3},
49+
{"long", 4},
50+
{"ulong", 4},
51+
{"float", 5},
52+
{"double", 6},
53+
{"decimal", 7}
54+
};
55+
56+
public string GetCapitalizedPrimitiveTypes(string type)
57+
{
58+
string typeFirstCharUpper;
59+
if (type.First() == 'u' || type == "sbyte")
60+
{
61+
typeFirstCharUpper = type[0].ToString().ToUpper() + type[1].ToString().ToUpper() + type.Substring(2);
62+
}
63+
else
64+
{
65+
typeFirstCharUpper = type[0].ToString().ToUpper() + type.Substring(1);
66+
}
67+
return typeFirstCharUpper;
68+
}
69+
70+
public bool IsMixedSignedAndUnsignedTypePair(string t1, string t2)
71+
{
72+
if (t1 == "byte" && t2 == "sbyte")
73+
{
74+
return true;
75+
}
76+
if (t2 == "byte" && t1 == "sbyte")
77+
{
78+
return true;
79+
}
80+
if (("u" + t1) == t2)
81+
{
82+
return true;
83+
}
84+
if (("u" + t2) == t1)
85+
{
86+
return true;
87+
}
88+
return false;
89+
}
90+
4191
public TypeConfiguration[] typeConfiguration = new []
4292
{
4393
new TypeConfiguration("bool", oneLiteral:"true", zeroLiteral:"false", supportsNumeric: false, unsupportedMethods: new[] {"LeftShift", "RightShift"}),
@@ -55,6 +105,30 @@
55105
new TypeConfiguration("ushort", classPrefix:"UShort", unsupportedMethods: new[] {"UnaryMinus", "All", "Any"})
56106
};
57107

108+
public string GetBinaryOperationReturnType(TypeConfiguration t1, TypeConfiguration t2)
109+
{
110+
int t1Level;
111+
if (!primitiveTypeToPrimitivityLevelMap.TryGetValue(t1.TypeName, out t1Level))
112+
{
113+
throw new Exception("Unknown type");
114+
}
115+
int t2Level;
116+
if (!primitiveTypeToPrimitivityLevelMap.TryGetValue(t2.TypeName, out t2Level))
117+
{
118+
throw new Exception("Unknown type");
119+
}
120+
if (t1Level + t2Level <= 2 * t1Level)
121+
{
122+
return t1.TypeName;
123+
}
124+
if (t1Level + t2Level <= 2 * t2Level)
125+
{
126+
return t2.TypeName;
127+
}
128+
throw new Exception("Bug in GetBinaryOperationReturnType");
129+
return "";
130+
}
131+
58132
public enum MethodType
59133
{
60134
Unary,

0 commit comments

Comments
 (0)