@@ -13,16 +13,16 @@ namespace Microsoft.ML.Data
13
13
/// A convenience class for concatenating several schemas together.
14
14
/// This would be necessary when combining IDataViews through any type of combining operation, for example, zip.
15
15
/// </summary>
16
- internal sealed class CompositeSchema : ISchema
16
+ internal sealed class ZipBinding
17
17
{
18
18
private readonly Schema [ ] _sources ;
19
19
20
- public Schema AsSchema { get ; }
20
+ public Schema OutputSchema { get ; }
21
21
22
22
// Zero followed by cumulative column counts. Zero being used for the empty case.
23
23
private readonly int [ ] _cumulativeColCounts ;
24
24
25
- public CompositeSchema ( Schema [ ] sources )
25
+ public ZipBinding ( Schema [ ] sources )
26
26
{
27
27
Contracts . AssertNonEmpty ( sources ) ;
28
28
_sources = sources ;
@@ -34,7 +34,11 @@ public CompositeSchema(Schema[] sources)
34
34
var schema = sources [ i ] ;
35
35
_cumulativeColCounts [ i + 1 ] = _cumulativeColCounts [ i ] + schema . Count ;
36
36
}
37
- AsSchema = Schema . Create ( this ) ;
37
+
38
+ var schemaBuilder = new SchemaBuilder ( ) ;
39
+ foreach ( var sourceSchema in sources )
40
+ schemaBuilder . AddColumns ( sourceSchema ) ;
41
+ OutputSchema = schemaBuilder . GetSchema ( ) ;
38
42
}
39
43
40
44
public int ColumnCount => _cumulativeColCounts [ _cumulativeColCounts . Length - 1 ] ;
@@ -74,50 +78,5 @@ public void GetColumnSource(int col, out int srcIndex, out int srcCol)
74
78
srcCol = col - _cumulativeColCounts [ srcIndex ] ;
75
79
Contracts . Assert ( 0 <= srcCol && srcCol < _sources [ srcIndex ] . Count ) ;
76
80
}
77
-
78
- public bool TryGetColumnIndex ( string name , out int col )
79
- {
80
- for ( int i = _sources . Length ; -- i >= 0 ; )
81
- {
82
- if ( _sources [ i ] . TryGetColumnIndex ( name , out col ) )
83
- {
84
- col += _cumulativeColCounts [ i ] ;
85
- return true ;
86
- }
87
- }
88
-
89
- col = - 1 ;
90
- return false ;
91
- }
92
-
93
- public string GetColumnName ( int col )
94
- {
95
- GetColumnSource ( col , out int dv , out int srcCol ) ;
96
- return _sources [ dv ] [ srcCol ] . Name ;
97
- }
98
-
99
- public ColumnType GetColumnType ( int col )
100
- {
101
- GetColumnSource ( col , out int dv , out int srcCol ) ;
102
- return _sources [ dv ] [ srcCol ] . Type ;
103
- }
104
-
105
- public IEnumerable < KeyValuePair < string , ColumnType > > GetMetadataTypes ( int col )
106
- {
107
- GetColumnSource ( col , out int dv , out int srcCol ) ;
108
- return _sources [ dv ] [ srcCol ] . Metadata . Schema . Select ( c => new KeyValuePair < string , ColumnType > ( c . Name , c . Type ) ) ;
109
- }
110
-
111
- public ColumnType GetMetadataTypeOrNull ( string kind , int col )
112
- {
113
- GetColumnSource ( col , out int dv , out int srcCol ) ;
114
- return _sources [ dv ] [ srcCol ] . Metadata . Schema . GetColumnOrNull ( kind ) ? . Type ;
115
- }
116
-
117
- public void GetMetadata < TValue > ( string kind , int col , ref TValue value )
118
- {
119
- GetColumnSource ( col , out int dv , out int srcCol ) ;
120
- _sources [ dv ] [ srcCol ] . Metadata . GetValue ( kind , ref value ) ;
121
- }
122
81
}
123
82
}
0 commit comments