public PracticeDatabaseReader(string filename, IndexManager indexManager, IEnumerable<IWhereQueryConstraint> constraints, QueryMode queryMode = QueryMode.Auto) : base(filename, indexManager, constraints, queryMode) { recordMetaData = new RecordMetaData(); recordMetaData.AddField("date", ColumnType.Int); recordMetaData.AddField("id", ColumnType.String, 6); recordMetaData.AddField("name", ColumnType.String, 40); recordMetaData.AddField("center_name", ColumnType.String, 40); recordMetaData.AddField("address", ColumnType.String, 40); recordMetaData.AddField("city", ColumnType.String, 40); recordMetaData.AddField("region", ColumnType.String, 40); recordMetaData.AddField("postal_code", ColumnType.String, 10); RecordWidth = recordMetaData.RecordWitdh; }
public JoinRecordProvider(IRecordProvider leftProvider, IRecordProvider rightProvider, string leftField, string rightField) { this.leftProvider = leftProvider; this.rightProvider = rightProvider; this.leftField = leftField; this.rightField = rightField; if (!leftProvider.MetaData.ColumnDescriptors.ContainsKey(leftField)) { throw new MalformedQueryException($"No field named {leftField} found."); } if (!rightProvider.MetaData.ColumnDescriptors.ContainsKey(rightField)) { throw new MalformedQueryException($"No field named {rightField} found."); } var leftDescriptor = leftProvider.MetaData.ColumnDescriptors[leftField]; var rightDescriptor = rightProvider.MetaData.ColumnDescriptors[rightField]; if (leftDescriptor.Type != rightDescriptor.Type) { throw new MalformedQueryException($"Field types {leftDescriptor.Type} and {rightDescriptor.Type} dont't match."); } var allKeys = leftProvider.MetaData.ColumnDescriptors.Keys.Union(rightProvider.MetaData.ColumnDescriptors.Keys); MetaData = new RecordMetaData(); foreach (var key in allKeys) { if (leftProvider.MetaData.ColumnDescriptors.Keys.Contains(key)) { MetaData.AddField( key, leftProvider.MetaData.ColumnDescriptors[key].Type, leftProvider.MetaData.ColumnDescriptors[key].Width ); } else { MetaData.AddField( key, rightProvider.MetaData.ColumnDescriptors[key].Type, rightProvider.MetaData.ColumnDescriptors[key].Width ); } } }
public SelectionRecordProvider(IEnumerable<string> fields, IRecordProvider provider) : base(provider) { this.fields = fields; MetaData = new RecordMetaData(); foreach (string field in fields) { try { var underlyingColumn = provider.MetaData.ColumnDescriptors[field]; MetaData.AddField(field, underlyingColumn.Type, underlyingColumn.Width); } catch (Exception e) { throw new MalformedQueryException($"No field named {field} found."); } } }
public OrderDatabaseReader(string filename, IndexManager indexManager, QueryMode queryMode, IEnumerable<IWhereQueryConstraint> constraints) : base(filename, indexManager, constraints, queryMode) { recordMetaData = new RecordMetaData { ColumnDescriptors = new Dictionary<string, ColumnData> { {"sha", new ColumnData {Offset = 0, Width = 4, Type = ColumnType.String}}, {"pct", new ColumnData {Offset = 4, Width = 4, Type = ColumnType.String}}, {"practice", new ColumnData {Offset = 8, Width = 6, Type = ColumnType.String}}, {"bnf_code", new ColumnData {Offset = 14, Width = 10, Type = ColumnType.String}}, {"bnf_name", new ColumnData {Offset = 24, Width = 40, Type = ColumnType.String}}, {"items", new ColumnData {Offset = 64, Width = sizeof (int), Type = ColumnType.Int}}, { "nic", new ColumnData {Offset = 64 + sizeof (int), Width = sizeof (float), Type = ColumnType.Float} }, { "cost", new ColumnData { Offset = 64 + sizeof (int) + sizeof (float), Width = sizeof (float), Type = ColumnType.Float } }, { "period", new ColumnData { Offset = 64 + sizeof (int) + sizeof (float) + sizeof (int), Width = sizeof (int), Type = ColumnType.Int } } } }; RecordWidth = recordMetaData.RecordWitdh; }
protected AggregateRecordProvider(string groupBy, string aggregatedField, IRecordProvider provider) : base(provider) { this.groupBy = groupBy; this.aggregatedField = aggregatedField; if (!provider.MetaData.ColumnDescriptors.ContainsKey(groupBy)) { throw new MalformedQueryException($"Aggregated table does not contain a field '{groupBy}'"); } if (!provider.MetaData.ColumnDescriptors.ContainsKey(aggregatedField)) { throw new MalformedQueryException($"Aggregated table does not contain a field '{aggregatedField}'"); } MetaData = new RecordMetaData(); MetaData.AddField(groupBy, ColumnType.String, provider.MetaData.ColumnDescriptors[groupBy].Width); if (provider.MetaData.ColumnDescriptors.Count > 2) { this.provider = new SelectionRecordProvider(new List<string> {groupBy, aggregatedField}, provider); } }
public bool IsValid(byte[] record, RecordMetaData metaData) { string haystack = Encoding.ASCII.GetString(record, metaData.ColumnDescriptors[Property].Offset, metaData.ColumnDescriptors[Property].Width); return haystack.Contains(search); }