public static void SaveDataView(IChannel ch, IDataSaver saver, IDataView view, Stream stream, bool keepHidden = false) { Contracts.CheckValue(ch, nameof(ch)); ch.CheckValue(saver, nameof(saver)); ch.CheckValue(view, nameof(view)); ch.CheckValue(stream, nameof(stream)); var cols = new List <int>(); for (int i = 0; i < view.Schema.ColumnCount; i++) { if (!keepHidden && view.Schema.IsHidden(i)) { continue; } var type = view.Schema.GetColumnType(i); if (saver.IsColumnSavable(type)) { cols.Add(i); } else { ch.Info(MessageSensitivity.Schema, "The column '{0}' will not be written as it has unsavable column type.", view.Schema.GetColumnName(i)); } } ch.Check(cols.Count > 0, "No valid columns to save"); saver.SaveData(stream, view, cols.ToArray()); }
public bool IsColumnSavable(ColumnType type) { _host.CheckValue(type, nameof(type)); // We can't transpose variable length columns at all, so nor can we save them. if (type.IsVector && !type.IsKnownSizeVector) { return(false); } // Since we'll be presumably saving vectors of these, attempt to construct // an artificial vector type out of this. Obviously if you can't make a vector // out of the items, then you could not save each slot's values. var itemType = type.ItemType; var primitiveType = itemType as PrimitiveType; if (primitiveType == null) { return(false); } var vectorType = new VectorType(primitiveType, size: 2); return(_internalSaver.IsColumnSavable(vectorType)); }