Files
spark/src/DataStreamSuite/DataStreamCore/BlueData/ColumnInfo.cs
T

73 lines
2.2 KiB
C#

using System;
using System.Text.Json.Serialization;
namespace BCG {
/// <summary>
/// Resprsents information about a column schema, ie its ordinal, the type, the name and constant value or expression. where applicable
/// </summary>
[Serializable]
public class ColumnInfo : IComparable {
//the default column info does not cach values in a lookup table, therefore it is in group 0
public ColumnInfo(string colName, int colNo, Type colType, object colValue = null) {
myColName = colName;
myColNo = colNo;
myColType = colType;
myColValue = colValue;
}
public ColumnInfo(string col_name, int col_no, TypeCode type_code)
: this(col_name, col_no, BlueDataUtility.get_type(type_code)) {
}
public static bool isAllowedType(Type type) =>
type == typeof(int) ||
type == typeof(long) ||
type == typeof(double) ||
type == typeof(string) ||
type == typeof(DateTime);
public int CompareTo(object obj) {
int otherColNo = ((ColumnInfo)(obj)).colNo;
if (myColNo < otherColNo)
return -1;
else if (myColNo > otherColNo)
return 1;
return 0;
}
public override bool Equals(object obj) {
if (obj is ColumnInfo) {
ColumnInfo other = obj as ColumnInfo;
return (colNo == other.colNo) && (colName == other.colName) && (colType == other.colType);
}
return false;
}
public override string ToString() {
return colName + " " + colNo + " " + colType;
}
// for backwards compatibility to allow build
public bool isConstant {get{return myColValue != null;}}
private int myColNo;
private string myColName;
private Type myColType;
private object myColValue;
[JsonPropertyName("colNo")]
public int colNo { get { return myColNo; } }
[JsonPropertyName("colName")]
public string colName { get { return myColName; } }
[JsonPropertyName("colType")]
public Type colType { get { return myColType; } }
[JsonIgnore]
public object colValue {get{return myColValue;}}
}
}