/// <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); } }
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); }
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 void ParseSelectStatement(ParsedRequest parsedRequest, ParseTreeNode selectStmt) { // get FROM entity name var fromClause = selectStmt.RequireChild("fromClauseOpt", 4); var fromEntityNode = fromClause.RequireChild("Id", 1, 0); parsedRequest.TargetEntity = GetTargetEntity(fromEntityNode); var ctx = GetTreeIteratorContext(parsedRequest, m_containerDescriptor); ctx.Functor = FieldExtractor; // get field names for select clause var selectColumnItemList = selectStmt.TryGetChild(null, 2, 0); if (selectColumnItemList == null) { throw new CompilationException("Could not find select clause", selectStmt); } if (0 == StringComparer.Ordinal.Compare("columnItemList", selectColumnItemList.Term.Name)) { // iterator callback will place all referenced column IDs into "select" list // later on, "select" list is used along with "where" list to create driver fetch list ctx.Argument = 1; foreach (var columnItem in selectColumnItemList.ChildNodes) { // column or column with alias columnItem.RequireChildren(1, 2); var columnSource = columnItem.RequireChild("columnSource", 0); // store a reference to every column item and its alias, // since we may need to compile it into an expression or do something else later parsedRequest.Select.SelectClauses.Add(columnItem); // preprocess identifiers m_preprocessor.ProcessIdentifierAliases(columnSource, parsedRequest.TargetEntity); // extract field names from a regular select clause (but do not look into "as" alias) IterateTree(columnSource, 0, ctx); } } else if (selectColumnItemList.ChildNodes.Count == 0 && selectColumnItemList.Token != null && "*".Equals(selectColumnItemList.Token.Text)) { // they ask for all fields (wildcard) // let's extract only unpacked blobs var docTypeDescriptor = parsedRequest.TargetEntity; foreach (var field in m_containerDescriptor.EnumerateFields().Where(x => x.OwnerDocumentType == docTypeDescriptor.DocumentType)) { ctx.ParsedRequest.Select.SelectFields.Add(field); ctx.ParsedRequest.Select.SelectClauses.Add(m_simpleFieldAccessorNodes[field.FieldId]); } } else { throw new CompilationException("Must have list of columns or an asterisk in select clause", selectColumnItemList); } // get field names for where clause var whereClause = selectStmt.TryGetChild("whereClauseOpt", 5); ParseWhereClause(whereClause, ctx); // get field names for order clause ctx.ParsedRequest.BaseDataset.OrderClause = selectStmt.TryGetChild("orderList", 8, 2); ParseOrderClause(ctx); ReadPagingOptions(selectStmt, ctx.ParsedRequest); }