public static DataContainerDescriptor BuildContainerDescriptor() { var result = new DataContainerDescriptor(); result.AddDocumentTypeName("testDoc"); var testDocId = result.RequireDocumentTypeName("testDoc"); var fieldId = 1; for (var i = 0; i < 2; i++) { result.AddField(new FieldMetadata(fieldId, "FieldByte" + fieldId, "Byte" + fieldId, DbType.Byte, testDocId)); fieldId++; result.AddField(new FieldMetadata(fieldId, "FieldGuid" + fieldId, "Guid" + fieldId, DbType.Guid, testDocId)); fieldId++; result.AddField(new FieldMetadata(fieldId, "FieldString" + fieldId, "String" + fieldId, DbType.String, testDocId)); fieldId++; result.AddField(new FieldMetadata(fieldId, "FieldBinary" + fieldId, "Binary" + fieldId, DbType.Binary, testDocId)); fieldId++; result.AddField(new FieldMetadata(fieldId, "FieldDecimal" + fieldId, "Decimal" + fieldId, DbType.Decimal, testDocId)); fieldId++; result.AddField(new FieldMetadata(fieldId, "FieldBool" + fieldId, "Bool" + fieldId, DbType.Boolean, testDocId)); fieldId++; result.AddField(new FieldMetadata(fieldId, "FieldDate" + fieldId, "Date" + fieldId, DbType.DateTime, testDocId)); fieldId++; result.AddField(new FieldMetadata(fieldId, "FieldTime" + fieldId, "Time" + fieldId, DbType.Time, testDocId)); fieldId++; result.AddField(new FieldMetadata(fieldId, "FieldDateTimeOffset" + fieldId, "DateTimeOffset" + fieldId, DbType.DateTimeOffset, testDocId)); fieldId++; } result.AddField(new FieldMetadata(fieldId + 1, "id", "primary key", DbType.Int64, testDocId)); var fieldIds = result.EnumerateFields().Select(x => x.FieldId).ToArray(); result.AddDocumentTypeDescriptor(new DocumentTypeDescriptor("testDoc", "testDoc", 1, "id", fieldIds)); result.AddIdentifierAlias("testDoc", new List<string> { "id", "ALIAS1" }, new[] { "id" }); return result; }
private static DataContainerDescriptor BuildDemoContainerDescriptor() { var result = new DataContainerDescriptor(); result.AddDocumentTypeName("testDoc"); var testDocId = result.RequireDocumentTypeName("testDoc"); var count = 12; for (var fieldId = 1; fieldId <= count; ) { result.AddField(new FieldMetadata(fieldId, "Field" + fieldId, "Byte" + fieldId, DbType.Byte, testDocId)); fieldId++; result.AddField(new FieldMetadata(fieldId, "Field" + fieldId, "Guid" + fieldId, DbType.Guid, testDocId)); fieldId++; result.AddField(new FieldMetadata(fieldId, "Field" + fieldId, "String" + fieldId, DbType.String, testDocId)); fieldId++; result.AddField(new FieldMetadata(fieldId, "Field" + fieldId, "Binary" + fieldId, DbType.Binary, testDocId)); fieldId++; result.AddField(new FieldMetadata(fieldId, "Field" + fieldId, "Decimal" + fieldId, DbType.Decimal, testDocId)); fieldId++; result.AddField(new FieldMetadata(fieldId, "Field" + fieldId, "Bool" + fieldId, DbType.Boolean, testDocId)); fieldId++; } result.AddField(new FieldMetadata(count + 1, "id", "primary key", DbType.Int64, testDocId)); var fieldIds = result.EnumerateFields().Select(x => x.FieldId).ToArray(); result.AddDocumentTypeDescriptor(new DocumentTypeDescriptor("testDoc", "testDoc", 1, "id", fieldIds)); return result; }
/// <summary> /// Ctr. /// </summary> public QueryParser(DataContainerDescriptor containerDescriptor, int maxConcurrency) { if (containerDescriptor == null) { throw new ArgumentNullException("containerDescriptor"); } m_parsers = new ObjectPool<Irony.Parsing.Parser>(maxConcurrency, null); for (var i = 0; i < maxConcurrency; i++) { m_parsers.Return(new Irony.Parsing.Parser(LangData, PqlNonTerminal)); } m_containerDescriptor = containerDescriptor; m_preprocessor = new QueryPreprocessor(containerDescriptor); // these predefined instances of ParseTreeNode are substituted when parsing "select * from .." statement, // in order to avoid allocating them every time m_simpleFieldAccessorNodes = new Dictionary<int, ParseTreeNode>(); foreach (var field in m_containerDescriptor.EnumerateFields()) { // generate columnItem -> columnSource -> Id -> id_simple hierarchy, exactly same structure as it comes out of grammar-based parser var idNode = new ParseTreeNode(new NonTerminal("Id"), new SourceSpan()); idNode.ChildNodes.Add(new ParseTreeNode(new Token(new Terminal("id_simple"), new SourceLocation(), field.Name, field.Name))); var columnSourceNode = new ParseTreeNode(new NonTerminal("columnSource"), new SourceSpan()); columnSourceNode.ChildNodes.Add(idNode); var columnItemNode = new ParseTreeNode(new NonTerminal("columnItem"), new SourceSpan()); columnItemNode.ChildNodes.Add(columnSourceNode); m_simpleFieldAccessorNodes.Add(field.FieldId, columnItemNode); } }