Skip to content

Commit dbfb543

Browse files
committed
Make CompositeSchema not an ISchema
1. Remove ISchema interface 2. Rename CompositeSchema to ZipBinding
1 parent 2e67134 commit dbfb543

File tree

4 files changed

+15
-56
lines changed

4 files changed

+15
-56
lines changed

src/Microsoft.ML.Data/DataLoadSave/PartitionedFileLoader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ private Schema CreateSchema(IExceptionContext ectx, Column[] cols, IDataLoader s
333333
colSchema
334334
};
335335

336-
return Schema.Create(new CompositeSchema(schemas));
336+
return new ZipBinding(schemas).OutputSchema;
337337
}
338338
}
339339

src/Microsoft.ML.Data/DataView/CompositeSchema.cs

Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ namespace Microsoft.ML.Data
1313
/// A convenience class for concatenating several schemas together.
1414
/// This would be necessary when combining IDataViews through any type of combining operation, for example, zip.
1515
/// </summary>
16-
internal sealed class CompositeSchema : ISchema
16+
internal sealed class ZipBinding
1717
{
1818
private readonly Schema[] _sources;
1919

20-
public Schema AsSchema { get; }
20+
public Schema OutputSchema { get; }
2121

2222
// Zero followed by cumulative column counts. Zero being used for the empty case.
2323
private readonly int[] _cumulativeColCounts;
2424

25-
public CompositeSchema(Schema[] sources)
25+
public ZipBinding(Schema[] sources)
2626
{
2727
Contracts.AssertNonEmpty(sources);
2828
_sources = sources;
@@ -34,7 +34,11 @@ public CompositeSchema(Schema[] sources)
3434
var schema = sources[i];
3535
_cumulativeColCounts[i + 1] = _cumulativeColCounts[i] + schema.Count;
3636
}
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();
3842
}
3943

4044
public int ColumnCount => _cumulativeColCounts[_cumulativeColCounts.Length - 1];
@@ -74,50 +78,5 @@ public void GetColumnSource(int col, out int srcIndex, out int srcCol)
7478
srcCol = col - _cumulativeColCounts[srcIndex];
7579
Contracts.Assert(0 <= srcCol && srcCol < _sources[srcIndex].Count);
7680
}
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-
}
12281
}
12382
}

src/Microsoft.ML.Data/DataView/ZipDataView.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public sealed class ZipDataView : IDataView
2525

2626
private readonly IHost _host;
2727
private readonly IDataView[] _sources;
28-
private readonly CompositeSchema _compositeSchema;
28+
private readonly ZipBinding _compositeSchema;
2929

3030
public static IDataView Create(IHostEnvironment env, IEnumerable<IDataView> sources)
3131
{
@@ -47,12 +47,12 @@ private ZipDataView(IHost host, IDataView[] sources)
4747

4848
_host.Assert(Utils.Size(sources) > 1);
4949
_sources = sources;
50-
_compositeSchema = new CompositeSchema(_sources.Select(x => x.Schema).ToArray());
50+
_compositeSchema = new ZipBinding(_sources.Select(x => x.Schema).ToArray());
5151
}
5252

5353
public bool CanShuffle { get { return false; } }
5454

55-
public Schema Schema => _compositeSchema.AsSchema;
55+
public Schema Schema => _compositeSchema.OutputSchema;
5656

5757
public long? GetRowCount()
5858
{
@@ -106,7 +106,7 @@ public RowCursor[] GetRowCursorSet(Func<int, bool> predicate, int n, Random rand
106106
private sealed class Cursor : RootCursorBase
107107
{
108108
private readonly RowCursor[] _cursors;
109-
private readonly CompositeSchema _compositeSchema;
109+
private readonly ZipBinding _compositeSchema;
110110
private readonly bool[] _isColumnActive;
111111
private bool _disposed;
112112

@@ -172,7 +172,7 @@ protected override bool MoveManyCore(long count)
172172
return true;
173173
}
174174

175-
public override Schema Schema => _compositeSchema.AsSchema;
175+
public override Schema Schema => _compositeSchema.OutputSchema;
176176

177177
public override bool IsColumnActive(int col)
178178
{

src/Microsoft.ML.Data/Scorers/FeatureContributionCalculation.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ public RowMapper(IHostEnvironment env, BindableMapper parent, RoleMappedSchema s
337337
}
338338

339339
_outputGenericSchema = _genericRowMapper.OutputSchema;
340-
OutputSchema = new CompositeSchema(new Schema[] { _outputGenericSchema, _outputSchema, }).AsSchema;
340+
OutputSchema = new ZipBinding(new Schema[] { _outputGenericSchema, _outputSchema, }).OutputSchema;
341341
}
342342

343343
/// <summary>

0 commit comments

Comments
 (0)