@@ -34,23 +34,59 @@ public enum VectorKind
34
34
public readonly bool IsKey ;
35
35
public readonly string [ ] MetadataKinds ;
36
36
37
- public Column ( string name , VectorKind vecKind , DataKind itemKind , bool isKey , string [ ] metadataKinds )
37
+ public Column ( string name , VectorKind vecKind , DataKind itemKind , bool isKey , string [ ] metadataKinds = null )
38
38
{
39
39
Contracts . CheckNonEmpty ( name , nameof ( name ) ) ;
40
- Contracts . CheckValue ( metadataKinds , nameof ( metadataKinds ) ) ;
40
+ Contracts . CheckValueOrNull ( metadataKinds ) ;
41
41
42
42
Name = name ;
43
43
Kind = vecKind ;
44
44
ItemKind = itemKind ;
45
45
IsKey = isKey ;
46
- MetadataKinds = metadataKinds ;
46
+ MetadataKinds = metadataKinds ?? new string [ 0 ] ;
47
+ }
48
+
49
+ /// <summary>
50
+ /// Returns whether <paramref name="inputColumn"/> is a valid input, if this object represents a
51
+ /// requirement.
52
+ ///
53
+ /// Namely, it returns true iff:
54
+ /// - The <see cref="Name"/>, <see cref="Kind"/>, <see cref="ItemKind"/>, <see cref="IsKey"/> fields match.
55
+ /// - The <see cref="MetadataKinds"/> of <paramref name="inputColumn"/> is a superset of our <see cref="MetadataKinds"/>.
56
+ /// </summary>
57
+ public bool IsCompatibleWith ( Column inputColumn )
58
+ {
59
+ Contracts . CheckValue ( inputColumn , nameof ( inputColumn ) ) ;
60
+ if ( Name != inputColumn . Name )
61
+ return false ;
62
+ if ( Kind != inputColumn . Kind )
63
+ return false ;
64
+ if ( ItemKind != inputColumn . ItemKind )
65
+ return false ;
66
+ if ( IsKey != inputColumn . IsKey )
67
+ return false ;
68
+ if ( inputColumn . MetadataKinds . Except ( MetadataKinds ) . Any ( ) )
69
+ return false ;
70
+ return true ;
71
+ }
72
+
73
+ public string GetTypeString ( )
74
+ {
75
+ string result = ItemKind . ToString ( ) ;
76
+ if ( IsKey )
77
+ result = $ "Key<{ result } >";
78
+ if ( Kind == VectorKind . Vector )
79
+ result = $ "Vector<{ result } >";
80
+ else if ( Kind == VectorKind . VariableVector )
81
+ result = $ "VarVector<{ result } >";
82
+ return result ;
47
83
}
48
84
}
49
85
50
- public SchemaShape ( Column [ ] columns )
86
+ public SchemaShape ( IEnumerable < Column > columns )
51
87
{
52
88
Contracts . CheckValue ( columns , nameof ( columns ) ) ;
53
- Columns = columns ;
89
+ Columns = columns . ToArray ( ) ;
54
90
}
55
91
56
92
/// <summary>
0 commit comments