2 using System.Collections.Generic;
5 namespace kinetica.Records;
13 private readonly
string _name;
14 private readonly ColumnType _columnType;
15 private readonly IReadOnlyList<string> _properties;
16 private readonly
bool _isNullable;
17 private readonly
bool _isPrimaryKey;
18 private readonly
bool _isShardKey;
25 public Column(
string name, ColumnType columnType)
26 : this(name, columnType,
Array.Empty<string>())
36 public Column(
string name, ColumnType columnType, IEnumerable<string> properties)
38 _name = name ??
throw new ArgumentNullException(nameof(name));
39 _columnType = columnType;
40 _properties = properties?.ToList().AsReadOnly() ?? (IReadOnlyList<string>)
Array.Empty<
string>();
41 _isNullable = _properties.Any(p =>
string.
Equals(p,
"nullable", StringComparison.OrdinalIgnoreCase));
42 _isPrimaryKey = _properties.Any(p =>
string.
Equals(p,
"primary_key", StringComparison.OrdinalIgnoreCase));
43 _isShardKey = _properties.Any(p =>
string.
Equals(p,
"shard_key", StringComparison.OrdinalIgnoreCase));
50 public static Column WithProperties(
string name, ColumnType columnType, IEnumerable<string> properties)
51 =>
new Column(name, columnType, properties);
54 public string Name => _name;
57 public ColumnType ColumnType => _columnType;
84 var newProps = _properties.Concat(additionalProperties).Distinct().ToList();
85 return new Column(_name, _columnType, newProps);
93 if (_isNullable)
return this;
102 if (_isPrimaryKey)
return this;
111 if (_isShardKey)
return this;
117 var props = _properties.Count > 0 ? $
" [{string.Join(",
", _properties)}]" :
"";
118 return $
"{_name}: {_columnType}{props}";
123 if (obj is not
Column other)
return false;
124 return _name == other._name &&
125 _columnType == other._columnType &&
126 _properties.SequenceEqual(other._properties);
131 return HashCode.Combine(_name, _columnType);
override bool Equals(object? obj)
ColumnBaseType
Base column types that map to Avro primitive types.
override string ToString()
Column AsNullable()
Creates a copy of this column marked as nullable.
override int GetHashCode()
bool IsShardKey
Returns true if this column is a shard key.
bool IsPrimaryKey
Returns true if this column is a primary key.
Immutable metadata about a column in a Kinetica type.
Column(string name, ColumnType columnType, IEnumerable< string > properties)
Creates a new column with the given name, type, and properties.
IReadOnlyList< string > Properties
Gets the column properties.
string AvroTypeName
Returns the Avro type name for this column.
Column AsPrimaryKey()
Creates a copy of this column marked as primary key.
Column WithAddedProperties(params string[] additionalProperties)
Creates a copy of this column with the specified properties added.
Column AsShardKey()
Creates a copy of this column marked as shard key.
bool IsNullable
Returns true if this column is nullable.
static Column WithProperties(string name, ColumnType columnType, IEnumerable< string > properties)
Creates a column with properties from a list.
ColumnBaseType BaseType
Gets the base type for this column.
string Name
Gets the column name.
Column(string name, ColumnType columnType)
Creates a new column with the given name and type.