// Constructors public DummyTuple(TupleDescriptor descriptor) { ArgumentValidator.EnsureArgumentNotNull(descriptor, "descriptor"); this.descriptor = descriptor; values = new object[descriptor.Count]; available = new BitArray(new bool[descriptor.Count]); }
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 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); }
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 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))); }
/// <summary> /// Initializes a new instance of this type. /// </summary> /// <param name="isReadOnly"><see cref="IsReadOnly"/> property value.</param> /// <param name="descriptor">Initial <see cref="TupleTransformBase.Descriptor"/> property value.</param> protected MapTransform(bool isReadOnly, TupleDescriptor descriptor) : this(isReadOnly) { ArgumentValidator.EnsureArgumentNotNull(descriptor, "descriptor"); Descriptor = descriptor; this.isReadOnly = isReadOnly; }
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)); }
private void CreateTupleDescriptors() { tupleDescriptor = TupleDescriptor.Create( from c in Columns select c.ValueType); keyTupleDescriptor = TupleDescriptor.Create( from c in KeyColumns select c.Key.ValueType); }
/// <summary> /// Initializes a new instance of this class. /// </summary> /// <param name="tupleDescriptor">Descriptor of the result item.</param> /// <param name="columns">Result columns.</param> /// <param name="columnGroups">Column groups.</param> /// <param name="orderKeyDescriptor">Descriptor of ordered columns.</param> /// <param name="order">Result sort order.</param> /// <exception cref="ArgumentOutOfRangeException"><c>columns.Count</c> is out of range.</exception> public RecordSetHeader( TupleDescriptor tupleDescriptor, IEnumerable <Column> columns, IEnumerable <ColumnGroup> columnGroups, TupleDescriptor orderKeyDescriptor, DirectionCollection <int> order) { ArgumentValidator.EnsureArgumentNotNull(tupleDescriptor, "tupleDescriptor"); ArgumentValidator.EnsureArgumentNotNull(columns, "columns"); TupleDescriptor = tupleDescriptor; // Unsafe perf. optimization: if you pass a list, it should be immutable! Columns = columns is List <Column> columnList ? new ColumnCollection(columnList) : new ColumnCollection(columns); if (tupleDescriptor.Count != Columns.Count) { throw new ArgumentOutOfRangeException("columns.Count"); } ColumnGroups = columnGroups == null ? ColumnGroupCollection.Empty // Unsafe perf. optimization: if you pass a list, it should be immutable! : (columnGroups is List <ColumnGroup> columnGroupList ? new ColumnGroupCollection(columnGroupList) : new ColumnGroupCollection(columnGroups)); orderTupleDescriptor = orderKeyDescriptor ?? TupleDescriptor.Empty; Order = order ?? new DirectionCollection <int>(); Order.Lock(true); }
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> /// Initializes a new instance of this class. /// </summary> /// <param name="tupleDescriptor">Descriptor of the result item.</param> /// <param name="columns">Result columns.</param> /// <param name="columnGroups">Column groups.</param> public RecordSetHeader( TupleDescriptor tupleDescriptor, IEnumerable <Column> columns, IEnumerable <ColumnGroup> columnGroups) : this(tupleDescriptor, columns, columnGroups, null, null) { }
/// <summary> /// Initializes a new instance of this class. /// </summary> /// <param name="tupleDescriptor">Descriptor of the result item.</param> /// <param name="columns">Result columns.</param> /// <param name="groups">Column groups.</param> /// <param name="orderKeyDescriptor">Descriptor of ordered columns.</param> /// <param name="order">Result sort order.</param> /// <exception cref="ArgumentOutOfRangeException"><c>columns.Count</c> is out of range.</exception> public RecordSetHeader( TupleDescriptor tupleDescriptor, IEnumerable <Column> columns, IEnumerable <ColumnGroup> groups, TupleDescriptor orderKeyDescriptor, DirectionCollection <int> order) { ArgumentValidator.EnsureArgumentNotNull(tupleDescriptor, "tupleDescriptor"); ArgumentValidator.EnsureArgumentNotNull(columns, "columns"); TupleDescriptor = tupleDescriptor; Columns = new ColumnCollection(columns); if (tupleDescriptor.Count != Columns.Count) { throw new ArgumentOutOfRangeException("columns.Count"); } ColumnGroups = groups == null ? ColumnGroupCollection.Empty : new ColumnGroupCollection(groups); orderTupleDescriptor = orderKeyDescriptor ?? TupleDescriptor.Empty; Order = order ?? new DirectionCollection <int>(); Order.Lock(true); }
private Table CreateTemporaryTable(Schema schema, string name, TupleDescriptor source, TypeMapping[] typeMappings, string[] fieldNames, Collation collation) { var tableName = Handlers.NameBuilder.ApplyNamingRules(string.Format(TableNamePattern, name)); var table = backEnd.CreateTemporaryTable(schema, tableName); if (source.Count > 0) { var fieldIndex = 0; foreach (var mapping in typeMappings) { var column = table.CreateColumn(fieldNames[fieldIndex], mapping.MapType()); column.IsNullable = true; // TODO: Dmitry Maximov, remove this workaround than collation problem will be fixed if (mapping.Type == WellKnownTypes.String) { column.Collation = collation; } fieldIndex++; } } else { table.CreateColumn("dummy", new SqlValueType(SqlType.Int32)); } return(table); }
/// <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 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; }
/// <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)); }
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(); }
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); }; }
public void EmptyFieldsTest() { var d = TupleDescriptor.Create(Array.Empty <Type>()); var dummyTuple = new DummyTuple(d); var tuple = CreateTestTuple(d); Assert.AreEqual(0, tuple.Count); }
/// <summary> /// Initializes a new instance of this class. /// </summary> /// <param name="tupleDescriptor">Descriptor of the result item.</param> /// <param name="columns">Result columns.</param> /// <param name="orderKeyDescriptor">Descriptor of ordered columns.</param> /// <param name="order">Result sort order.</param> public RecordSetHeader( TupleDescriptor tupleDescriptor, IEnumerable <Column> columns, TupleDescriptor orderKeyDescriptor, DirectionCollection <int> order) : this(tupleDescriptor, columns, null, orderKeyDescriptor, order) { }
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)); }
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 override void Initialize(Domain ownerDomain, TupleDescriptor keyTupleDescriptor) { var accessor = ownerDomain.Services.Demand <IStorageSequenceAccessor>(); sequenceProvider = ownerDomain.StorageProviderInfo.Supports(ProviderFeatures.TransactionalKeyGenerators) ? new SessionCachingSequenceProvider <TValue>(accessor) : (ICachingSequenceProvider <TValue>) new DomainCachingSequenceProvider <TValue>(accessor); }
/// <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 PackedTuple(TupleDescriptor descriptor) { PackedDescriptor = descriptor; Values = new long[PackedDescriptor.ValuesLength]; Objects = PackedDescriptor.ObjectsLength > 0 ? new object[PackedDescriptor.ObjectsLength] : EmptyObjectArray; }
protected QueryRequest CreateQueryRequest(StorageDriver driver, SqlSelect statement, IEnumerable <QueryParameterBinding> parameterBindings, TupleDescriptor tupleDescriptor, QueryRequestOptions options) { if (Handlers.Domain.Configuration.ShareStorageSchemaOverNodes) { return(new QueryRequest(driver, statement, parameterBindings, tupleDescriptor, options, NodeConfiguration)); } return(new QueryRequest(driver, statement, parameterBindings, tupleDescriptor, options)); }
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); }
private PackedTuple(PackedTuple origin) { PackedDescriptor = origin.PackedDescriptor; Values = (long[])origin.Values.Clone(); Objects = PackedDescriptor.ObjectsLength > 0 ? (object[])origin.Objects.Clone() : EmptyObjectArray; }
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); }