/// <summary> /// Joins the header with the specified one. /// </summary> /// <param name="joined">The header to join.</param> /// <returns>The joined header.</returns> public RecordSetHeader Join(RecordSetHeader joined) { var columns = new List <Column>(Columns); var originalColumnsCount = Columns.Count; columns.AddRange( from c in joined.Columns select c.Clone(originalColumnsCount + c.Index)); var types = new List <Type>(TupleDescriptor); types.AddRange(joined.TupleDescriptor); var groups = new List <ColumnGroup>(ColumnGroups); groups.AddRange( joined.ColumnGroups .Select(g => new ColumnGroup( g.TypeInfoRef, g.Keys.Select(i => originalColumnsCount + i), g.Columns.Select(i => originalColumnsCount + i)))); return(new RecordSetHeader( TupleDescriptor.Create(types), columns, groups, OrderTupleDescriptor, Order)); }
private void CreateTupleDescriptors() { tupleDescriptor = TupleDescriptor.Create( from c in Columns select c.ValueType); keyTupleDescriptor = TupleDescriptor.Create( from c in KeyColumns select c.Key.ValueType); }
private void BuildConverter() { Type itemType = isKeyConverter ? entityTypestoredInKey : typeof(TItem); int index = 0; ParameterExpression parameterExpression = Expression.Parameter(itemType, "item"); IEnumerable <Type> types = EnumerableUtils <Type> .Empty; if (IsPersistableType(itemType)) { Expression = (Expression)BuildField(itemType, ref index, ref types); TupleDescriptor = TupleDescriptor.Create(types); } else { Xtensive.Collections.ISet <Type> processedTypes = new Set <Type>(); LocalCollectionExpression itemExpression = BuildLocalCollectionExpression(itemType, processedTypes, ref index, null, ref types); TupleDescriptor = TupleDescriptor.Create(types); Expression = itemExpression; } Func <TItem, Tuple> converter = delegate(TItem item) { RegularTuple tuple = Tuple.Create(TupleDescriptor); if (ReferenceEquals(item, null)) { return(tuple); } int offset = 0; FillLocalCollectionField(item, tuple, Expression); return(tuple); }; this.converter = converter; }
public void RandomTest() { const int IterationCount = 10; int iteration = 0; Random random = RandomManager.CreateRandom(SeedVariatorType.CallingMethod); MethodInfo setValueMethodGeneric = typeof(TupleBehaviorTestBase).GetMethod("SetValue", BindingFlags.NonPublic | BindingFlags.Static); IList <TupleDescriptor> descriptorList = new List <TupleDescriptor>(); while (iteration++ < IterationCount) { int fieldCount = random.Next(0, MaxFieldCount); List <Type> fields = new List <Type>(fieldCount); for (int i = 0; i < fieldCount; i++) { fields.Add(fieldTypes[random.Next(0, fieldTypes.Length - 1)]); } TupleDescriptor descriptor = TupleDescriptor.Create(fields); descriptorList.Add(descriptor); } foreach (TupleDescriptor descriptor in descriptorList) { DummyTuple dummyTuple = new DummyTuple(descriptor); ITuple tuple = CreateTestTuple(descriptor); for (int fieldIndex = 0; fieldIndex < tuple.Count / 2; fieldIndex++) { Type type = descriptor[fieldIndex]; MethodInfo setValueMethod = setValueMethodGeneric.MakeGenericMethod(type); setValueMethod.Invoke(null, new object[] { dummyTuple, tuple, fieldIndex, random }); } AssertAreSame(dummyTuple, tuple); } }
public FreeTextProvider(FullTextIndexInfo index, Func <string> searchCriteria, string rankColumnName, Func <int> topN, bool fullFeatured) : base(ProviderType.FreeText) { SearchCriteria = searchCriteria; FullFeatured = fullFeatured; TopN = topN; PrimaryIndex = new IndexInfoRef(index.PrimaryIndex); if (FullFeatured) { var primaryIndexRecordsetHeader = index.PrimaryIndex.ReflectedType.Indexes.PrimaryIndex.GetRecordSetHeader(); var rankColumn = new MappedColumn(rankColumnName, primaryIndexRecordsetHeader.Length, typeof(double)); indexHeader = primaryIndexRecordsetHeader.Add(rankColumn); } else { var primaryIndexKeyColumns = index.PrimaryIndex.KeyColumns; if (primaryIndexKeyColumns.Count != 1) { throw new InvalidOperationException(Strings.ExOnlySingleColumnKeySupported); } var fieldTypes = primaryIndexKeyColumns .Select(columnInfo => columnInfo.Key.ValueType) .AddOne(typeof(double)) .ToArray(primaryIndexKeyColumns.Count + 1); var tupleDescriptor = TupleDescriptor.Create(fieldTypes); var columns = primaryIndexKeyColumns .Select((c, i) => (Column) new MappedColumn("KEY", i, c.Key.ValueType)) .AddOne(new MappedColumn("RANK", tupleDescriptor.Count, typeof(double))); indexHeader = new RecordSetHeader(tupleDescriptor, columns); } Initialize(); }
public void GeneratorAdvancedTest() { var types = new[] { typeof(int), typeof(long), typeof(float), typeof(double), typeof(string), typeof(DateTime), typeof(TimeSpan), typeof(byte[]) }; var sizeRandomizer = new Random(); var typeRandomizer = new Random(); const int maxSize = 30; const int runCount = 10000; using (new Measurement("Create tuple with random descriptor", runCount)) for (int i = 0; i < runCount; i++) { var count = sizeRandomizer.Next(maxSize + 1); var tupleTypes = Enumerable.Repeat(0, count) .Select(_ => types[typeRandomizer.Next(types.Length)]) .ToArray(count); var descriptor = TupleDescriptor.Create(tupleTypes); var tuple = Tuple.Create(descriptor); } }
private static RecordSetHeader CreateHeader(IndexInfo indexInfo) { TupleDescriptor resultTupleDescriptor = TupleDescriptor.Create( indexInfo.Columns.Select(columnInfo => columnInfo.ValueType)); var keyOrder = new List <KeyValuePair <int, Direction> >( indexInfo.KeyColumns.Select((p, i) => new KeyValuePair <int, Direction>(i, p.Value))); if (!indexInfo.IsPrimary) { var pkKeys = indexInfo.ReflectedType.Indexes.PrimaryIndex.KeyColumns; keyOrder.AddRange( indexInfo.ValueColumns .Select((c, i) => new Pair <Orm.Model.ColumnInfo, int>(c, i + indexInfo.KeyColumns.Count)) .Where(pair => pair.First.IsPrimaryKey) .Select(pair => new KeyValuePair <int, Direction>(pair.Second, pkKeys[pair.First]))); } var order = new DirectionCollection <int>(keyOrder); var keyDescriptor = TupleDescriptor.Create(indexInfo.KeyColumns.Select(columnInfo => columnInfo.Key.ValueType)); var resultColumns = indexInfo.Columns.Select((c, i) => (Column) new MappedColumn(c, i, c.ValueType)); var resultGroups = new[] { indexInfo.Group }; return(new RecordSetHeader( resultTupleDescriptor, resultColumns, resultGroups, keyDescriptor, order)); }
/// <summary> /// Joins the header with the specified one. /// </summary> /// <param name="joined">The header to join.</param> /// <returns>The joined header.</returns> public RecordSetHeader Join(RecordSetHeader joined) { var columnCount = Columns.Count; var newColumns = new List <Column>(Columns); newColumns.AddRange( from c in joined.Columns select c.Clone(columnCount + c.Index)); var newFieldTypes = new Type[newColumns.Count]; for (var i = 0; i < newColumns.Count; i++) { newFieldTypes[i] = newColumns[i].Type; } var newTupleDescriptor = TupleDescriptor.Create(newFieldTypes); var groups = new List <ColumnGroup>(ColumnGroups); groups.AddRange( joined.ColumnGroups .Select(g => new ColumnGroup( g.TypeInfoRef, g.Keys.Select(i => columnCount + i), g.Columns.Select(i => columnCount + i)))); return(new RecordSetHeader( newTupleDescriptor, newColumns, groups, OrderTupleDescriptor, Order)); }
private static EntitySetTypeState BuildEntitySetTypeState(object key, EntitySetBase entitySet) { var field = ((Pair <object, FieldInfo>)key).Second; var association = field.Associations.Last(); var query = association.UnderlyingIndex.GetQuery().Seek(() => keyParameter.Value); var seek = entitySet.Session.Compile(query); var ownerDescriptor = association.OwnerType.Key.TupleDescriptor; var targetDescriptor = association.TargetType.Key.TupleDescriptor; var itemColumnOffsets = association.AuxiliaryType == null ? association.UnderlyingIndex.ValueColumns .Where(ci => ci.IsPrimaryKey) .Select(ci => ci.Field.MappingInfo.Offset) .ToList() : Enumerable.Range(0, targetDescriptor.Count).ToList(); var keyDescriptor = TupleDescriptor.Create(ownerDescriptor .Concat(itemColumnOffsets.Select(i => targetDescriptor[i])) .ToList()); var map = Enumerable.Range(0, ownerDescriptor.Count) .Select(i => new Pair <int, int>(0, i)) .Concat(itemColumnOffsets.Select(i => new Pair <int, int>(1, i))) .ToArray(); var seekTransform = new MapTransform(true, keyDescriptor, map); Func <Tuple, Entity> itemCtor = null; if (association.AuxiliaryType != null) { itemCtor = DelegateHelper.CreateDelegate <Func <Tuple, Entity> >(null, association.AuxiliaryType.UnderlyingType, DelegateHelper.AspectedFactoryMethodName, ArrayUtils <Type> .EmptyArray); } return(new EntitySetTypeState(seek, seekTransform, itemCtor, entitySet.GetItemCountQueryDelegate(field))); }
private void CreateTupleDescriptors() { tupleDescriptor = TupleDescriptor.Create( Columns.Select(c => c.ValueType).ToArray(Columns.Count)); keyTupleDescriptor = TupleDescriptor.Create( KeyColumns.Select(c => c.Key.ValueType).ToArray(KeyColumns.Count)); }
public ContainsTableProvider(FullTextIndexInfo index, Func <ParameterContext, string> searchCriteria, string rankColumnName, IList <ColumnInfo> targetColumns, Func <ParameterContext, int> topNByRank, bool fullFeatured) : base(ProviderType.ContainsTable) { SearchCriteria = searchCriteria; FullFeatured = fullFeatured; PrimaryIndex = new IndexInfoRef(index.PrimaryIndex); TargetColumns = new ReadOnlyList <FullTextColumnInfo>(targetColumns.Select(tc => index.Columns.First(c => c.Column == tc)).ToList()); TopN = topNByRank; if (FullFeatured) { var primaryIndexRecordsetHeader = index.PrimaryIndex.ReflectedType.Indexes.PrimaryIndex.GetRecordSetHeader(); var rankColumn = new MappedColumn(rankColumnName, primaryIndexRecordsetHeader.Length, WellKnownTypes.Double); indexHeader = primaryIndexRecordsetHeader.Add(rankColumn); } else { var primaryIndexKeyColumns = index.PrimaryIndex.KeyColumns; if (primaryIndexKeyColumns.Count != 1) { throw new InvalidOperationException(Strings.ExOnlySingleColumnKeySupported); } var fieldTypes = primaryIndexKeyColumns .Select(columnInfo => columnInfo.Key.ValueType) .Append(WellKnownTypes.Double) .ToArray(primaryIndexKeyColumns.Count + 1); var tupleDescriptor = TupleDescriptor.Create(fieldTypes); var columns = primaryIndexKeyColumns .Select((c, i) => (Column) new MappedColumn("KEY", i, c.Key.ValueType)) .Append(new MappedColumn("RANK", tupleDescriptor.Count, WellKnownTypes.Double)); indexHeader = new RecordSetHeader(tupleDescriptor, columns); } Initialize(); }
/// <inheritdoc/> protected override void Initialize() { base.Initialize(); var comparisonRules = new ComparisonRules[Order.Count]; for (int i = 0; i < Order.Count; i++) { var orderItem = Order[i]; var culture = CultureInfo.InvariantCulture; var column = Header.Columns[orderItem.Key]; var mappedColumn = column as MappedColumn; if (mappedColumn != null && mappedColumn.ColumnInfoRef != null) { culture = mappedColumn.ColumnInfoRef.CultureInfo; } comparisonRules[i] = new ComparisonRule(orderItem.Value, culture); } var fieldTypes = new Type[Order.Count]; var map = new int[Order.Count]; for (var i = 0; i < Order.Count; i++) { var p = Order[i]; fieldTypes[i] = Header.Columns[p.Key].Type; map[i] = p.Key; } var orderKeyDescriptor = TupleDescriptor.Create(fieldTypes); OrderKeyExtractorTransform = new MapTransform(true, orderKeyDescriptor, map); }
private void BuildConverter() { var itemType = isKeyConverter ? entityTypestoredInKey : typeof(TItem); var index = 0; var types = new TupleTypeCollection(); if (IsPersistableType(itemType)) { Expression = (Expression)BuildField(itemType, ref index, types); TupleDescriptor = TupleDescriptor.Create(types.ToArray(types.Count)); } else { var processedTypes = new HashSet <Type>(); var itemExpression = BuildLocalCollectionExpression(itemType, processedTypes, ref index, null, types); TupleDescriptor = TupleDescriptor.Create(types.ToArray(types.Count)); Expression = itemExpression; } converter = delegate(TItem item) { Tuple tuple = Tuple.Create(TupleDescriptor); if (ReferenceEquals(item, null)) { return(tuple); } FillLocalCollectionField(item, tuple, Expression); return(tuple); }; }
private void CreateTupleDescriptor() { var orderedColumns = columns.OrderBy(c => c.Field.MappingInfo.Offset).ToList(); columns = new ColumnInfoCollection(this, "Columns"); columns.AddRange(orderedColumns); TupleDescriptor = TupleDescriptor.Create(Columns.Select(c => c.ValueType)); }
public void BehaviorTest() { var types = new Type[] { typeof(int), typeof(bool), typeof(string) }; var d = TupleDescriptor.Create(types); TestTuple(CreateTestTuple(d)); TestTuple(new DummyTuple(d)); }
public void EmptyFieldsTest() { var d = TupleDescriptor.Create(Array.Empty <Type>()); var dummyTuple = new DummyTuple(d); var tuple = CreateTestTuple(d); Assert.AreEqual(0, tuple.Count); }
/// <inheritdoc/> protected override RecordSetHeader BuildHeader() { var newHeader = Source.Header.Add(new SystemColumn(ResultColumnName, 0, typeof(bool))); var types = FilteredColumns.Select(m => newHeader.Columns[m].Type); FilteredColumnsExtractionTransform = new MapTransform(true, TupleDescriptor.Create(types), FilteredColumns); ResultTransform = new CombineTransform(true, Source.Header.TupleDescriptor, TupleDescriptor.Create(new [] { typeof(bool) })); return(newHeader); }
public void EmptyFieldsTest() { List <Type> fields = new List <Type>(); TupleDescriptor descriptor = TupleDescriptor.Create(fields); DummyTuple dummyTuple = new DummyTuple(descriptor); ITuple tuple = CreateTestTuple(descriptor); Assert.AreEqual(0, tuple.Count); }
public void MainTest() { Xtensive.Tuples.Tuple source = Tuple.Create(1); MapTransform transform = new MapTransform(true, TupleDescriptor.Create <byte, int, string>(), new[] { -1, 0 }); Xtensive.Tuples.Tuple result = transform.Apply(TupleTransformType.TransformedTuple, source); Assert.AreEqual(TupleFieldState.Default, result.GetFieldState(0)); Assert.AreEqual(TupleFieldState.Available, result.GetFieldState(1)); Assert.AreEqual(TupleFieldState.Default, result.GetFieldState(2)); }
public void Test() { var types = Enumerable.Range(0, 4).Select(_ => typeof(short)).ToArray(); var d = TupleDescriptor.Create(types); var dummyTuple = new DummyTuple(d); var tuple = CreateTestTuple(d); PopulateData(types, dummyTuple, tuple); AssertAreSame(dummyTuple, tuple); }
public void BehaviorTest() { List <Type> fields = new List <Type>(3); fields.AddRange(new Type[] { typeof(int), typeof(bool), typeof(string) }); TupleDescriptor d = TupleDescriptor.Create(fields); TestTuple(CreateTestTuple(d)); TestTuple(new DummyTuple(d)); }
// Constructors /// <summary> /// Initializes a new instance of this type. /// </summary> /// <param name="isReadOnly"><see cref="MapTransform.IsReadOnly"/> property value.</param> /// <param name="index">Start index.</param> /// <param name="sources">Source tuple descriptors.</param> public CutInTransform(bool isReadOnly, int index, params TupleDescriptor[] sources) : base(isReadOnly) { this.index = index; int totalLength = sources.Sum(s => s.Count); Type[] types = new Type[totalLength]; Pair <int, int>[] map = new Pair <int, int> [totalLength]; TupleDescriptor sourceDescriptor = sources[0]; TupleDescriptor cutInDescriptor = sources[1]; int sourceCount = sourceDescriptor.Count; int cutInCount = cutInDescriptor.Count; bool isIndex = false; bool isEndOfTuple = false; int ind = 0; if (index == sourceCount) { sourceCount++; isEndOfTuple = true; } else if (index < 0 || index > sourceCount) { throw new ArgumentOutOfRangeException("index"); } for (int i = 0; i < sourceCount; i++) { if ((i == index) && !isIndex) { for (int j = 0; j < cutInCount; j++) { types[ind] = cutInDescriptor[j]; map[ind++] = new Pair <int, int>(1, j); } if (!isEndOfTuple) { i--; isIndex = true; } } else { types[ind] = sourceDescriptor[i]; map[ind++] = new Pair <int, int>(0, i); } } this.sources = sources; Descriptor = TupleDescriptor.Create(types); Map = map; }
public void BasicTest() { Xtensive.Tuples.Tuple t = Xtensive.Tuples.Tuple.Create(TupleDescriptor.Create <string, int, string, TimeSpan, string, string>()); t.SetValue(0, string.Empty); t.SetValue(2, "n\\a"); t.SetValue(3, new TimeSpan()); t.SetValue(4, null); t.SetValue(5, "null"); var s = t.Format(); var tt = Xtensive.Tuples.Tuple.Parse(t.Descriptor, s); Assert.AreEqual(t, tt); }
// Constructors /// <summary> /// Initializes a new instance of this type. /// </summary> /// <param name="isReadOnly"><see cref="MapTransform.IsReadOnly"/> property value.</param> /// <param name="sourceDescriptor">Source tuple descriptor.</param> /// <param name="segment">The segment to extract.</param> public SegmentTransform(bool isReadOnly, TupleDescriptor sourceDescriptor, Segment <int> segment) : base(isReadOnly) { this.segment = segment; Type[] fields = new Type[segment.Length]; int[] map = new int[segment.Length]; for (int i = 0, j = segment.Offset; i < segment.Length; i++, j++) { fields[i] = sourceDescriptor[j]; map[i] = j; } Descriptor = TupleDescriptor.Create(fields); SingleSourceMap = map; }
/// <inheritdoc/> protected override void Initialize() { base.Initialize(); var types = new List <Type>(); int i = 0; var columnIndexes = new int[GroupColumnIndexes.Length]; foreach (var index in GroupColumnIndexes) { types.Add(Source.Header.Columns[index].Type); columnIndexes[i++] = index; } Transform = new MapTransform(false, TupleDescriptor.Create(types), columnIndexes); }
/// <inheritdoc/> protected override void Initialize() { base.Initialize(); var fieldTypes = new Type[GroupColumnIndexes.Length]; var columnIndexes = new int[GroupColumnIndexes.Length]; var i = 0; foreach (var index in GroupColumnIndexes) { fieldTypes[i] = Source.Header.Columns[index].Type; columnIndexes[i] = index; i++; } Transform = new MapTransform(false, TupleDescriptor.Create(fieldTypes), columnIndexes); }
/// <inheritdoc/> protected override RecordSetHeader BuildHeader() { var newHeader = Source.Header.Add(new SystemColumn(ResultColumnName, 0, BoolType)); var fieldTypes = new Type[FilteredColumns.Count]; for (var index = 0; index < fieldTypes.Length; index++) { fieldTypes[index] = newHeader.Columns[FilteredColumns[index]].Type; } var tupleDescriptor = TupleDescriptor.Create(fieldTypes); FilteredColumnsExtractionTransform = new MapTransform(true, tupleDescriptor, FilteredColumns); ResultTransform = new CombineTransform(true, Source.Header.TupleDescriptor, BoolTupleDescriptor); return(newHeader); }
public void Test() { IList <Type> types = new List <Type>(); for (int i = 0; i < 4; i++) { types.Add(typeof(short)); } TupleDescriptor descriptor = TupleDescriptor.Create(types); DummyTuple dummyTuple = new DummyTuple(descriptor); ITuple tuple = CreateTestTuple(descriptor); PopulateData(types, dummyTuple, tuple); AssertAreSame(dummyTuple, tuple); }
private void BuildVersionExtractor() { // Building version tuple extractor var versionColumns = GetVersionColumns(); if (versionColumns == null || versionColumns.Count == 0) { VersionExtractor = null; return; } var types = versionColumns.Select(c => c.ValueType).ToArray(); var map = versionColumns.Select(c => c.Field.MappingInfo.Offset).ToArray(); var versionTupleDescriptor = TupleDescriptor.Create(types); VersionExtractor = new MapTransform(true, versionTupleDescriptor, map); }
public void PerformanceTest() { Random r = RandomManager.CreateRandom(SeedVariatorType.CallingMethod); int count = 100; List <Type> types = new List <Type>(); List <TupleDescriptor> descriptors = new List <TupleDescriptor>(); using (new Measurement("Creating descriptors {T1}, {T1,T2}, ...", count)) { for (int i = 0; i < count; i++) { types.Add(typeof(bool)); descriptors.Add(TupleDescriptor.Create(types)); } } count = 1000; int maxSize = 10; int size; using (new Measurement("Creating random descriptors", count)) { for (int i = 0; i < count; i++) { size = r.Next(maxSize); types = new List <Type>(size); for (int j = 0; j < size; j++) { types.Add(FieldTypes[r.Next(FieldTypes.Length)]); } descriptors.Add(TupleDescriptor.Create(types)); } } count = 100000; size = 10; types = new List <Type>(size); for (int j = 0; j < size; j++) { types.Add(FieldTypes[r.Next(FieldTypes.Length)]); } using (new Measurement("Creating the same descriptor", count)) { for (int i = 0; i < count; i++) { descriptors.Add(TupleDescriptor.Create(types)); } } }