public static Pair <ExprTableAccessNode, ExprDotNode> MapPropertyToTableNested( TableCompileTimeResolver resolver, string stream, string subproperty) { var table = resolver.Resolve(stream); int?indexIfIndexed = null; if (table == null) { // try indexed property var pair = MapPropertyToTable(stream, resolver); if (pair == null) { return(null); } table = pair.Second; indexIfIndexed = pair.First.Index; } if (table.IsKeyed && indexIfIndexed == null) { return(null); } if (!table.IsKeyed && indexIfIndexed != null) { return(null); } var index = StringValue.UnescapedIndexOfDot(subproperty); if (index == -1) { var tableNodeX = new ExprTableAccessNodeSubprop(table.TableName, subproperty); if (indexIfIndexed != null) { tableNodeX.AddChildNode(new ExprConstantNodeImpl(indexIfIndexed)); } return(new Pair <ExprTableAccessNode, ExprDotNode>(tableNodeX, null)); } // we have a nested subproperty such as "tablename.subproperty.abc" IList <Chainable> chainedSpecs = new List <Chainable>(1); chainedSpecs.Add(new ChainableName(subproperty.Substring(index + 1))); var tableNode = new ExprTableAccessNodeSubprop(table.TableName, subproperty.Substring(0, index)); if (indexIfIndexed != null) { tableNode.AddChildNode(new ExprConstantNodeImpl(indexIfIndexed)); } ExprDotNode dotNode = new ExprDotNodeImpl(chainedSpecs, false, false); dotNode.AddChildNode(tableNode); return(new Pair <ExprTableAccessNode, ExprDotNode>(tableNode, dotNode)); }
/// <summary> /// Resolve "table.property", not chainable /// </summary> public static Pair <ExprTableAccessNode, ExprDotNode> CheckTableNameGetExprForSubproperty(TableService tableService, string tableName, string subproperty) { var metadata = tableService.GetTableMetadata(tableName); if (metadata == null) { return(null); } var index = ASTUtil.UnescapedIndexOfDot(subproperty); if (index == -1) { if (metadata.KeyTypes.Length > 0) { return(null); } var tableNodeX = new ExprTableAccessNodeSubprop(tableName, subproperty); return(new Pair <ExprTableAccessNode, ExprDotNode>(tableNodeX, null)); } // we have a nested subproperty such as "tablename.subproperty.abc" IList <ExprChainedSpec> chainedSpecs = new List <ExprChainedSpec>(1); chainedSpecs.Add(new ExprChainedSpec(subproperty.Substring(index + 1), Collections.GetEmptyList <ExprNode>(), true)); var tableNode = new ExprTableAccessNodeSubprop(tableName, subproperty.Substring(0, index)); var dotNode = new ExprDotNode(chainedSpecs, false, false); dotNode.AddChildNode(tableNode); return(new Pair <ExprTableAccessNode, ExprDotNode>(tableNode, dotNode)); }
private static ExprTableAccessEvalStrategy GetTableAccessSubprop( ExprTableAccessNodeSubprop subprop, TableMetadataColumn column, TableAndLockProviderUngrouped ungrouped, TableAndLockProviderGrouped grouped) { if (column is TableMetadataColumnPlain) { var plain = (TableMetadataColumnPlain)column; if (ungrouped != null) { return(new ExprTableEvalStrategyUngroupedProp( ungrouped, plain.IndexPlain, subprop.OptionalPropertyEnumEvaluator)); } if (subprop.GroupKeyEvaluators.Length > 1) { return(new ExprTableEvalStrategyGroupByPropMulti( grouped, plain.IndexPlain, subprop.OptionalPropertyEnumEvaluator, subprop.GroupKeyEvaluators)); } return(new ExprTableEvalStrategyGroupByPropSingle( grouped, plain.IndexPlain, subprop.OptionalPropertyEnumEvaluator, subprop.GroupKeyEvaluators[0])); } var aggcol = (TableMetadataColumnAggregation)column; if (ungrouped != null) { if (!aggcol.Factory.IsAccessAggregation) { return(new ExprTableEvalStrategyUngroupedMethod(ungrouped, aggcol.MethodOffset)); } var pair = aggcol.AccessAccessorSlotPair; return(new ExprTableEvalStrategyUngroupedAccess(ungrouped, pair.Slot, pair.Accessor)); } var columnAggregation = (TableMetadataColumnAggregation)column; if (!columnAggregation.Factory.IsAccessAggregation) { if (subprop.GroupKeyEvaluators.Length > 1) { return(new ExprTableEvalStrategyGroupByMethodMulti( grouped, columnAggregation.MethodOffset, subprop.GroupKeyEvaluators)); } return(new ExprTableEvalStrategyGroupByMethodSingle( grouped, columnAggregation.MethodOffset, subprop.GroupKeyEvaluators[0])); } if (subprop.GroupKeyEvaluators.Length > 1) { return(new ExprTableEvalStrategyGroupByAccessMulti( grouped, columnAggregation.AccessAccessorSlotPair, subprop.GroupKeyEvaluators)); } return(new ExprTableEvalStrategyGroupByAccessSingle( grouped, columnAggregation.AccessAccessorSlotPair, subprop.GroupKeyEvaluators[0])); }
public static Pair <ExprTableAccessNode, IList <Chainable> > HandleTableAccessNode( LazyAllocatedMap <ConfigurationCompilerPlugInAggregationMultiFunction, AggregationMultiFunctionForge> plugInAggregations, string tableName, string sub, IList <Chainable> chain) { ExprTableAccessNode node = new ExprTableAccessNodeSubprop(tableName, sub); var subchain = chain.SubList(1, chain.Count); return(new Pair <ExprTableAccessNode, IList <Chainable> >(node, subchain)); }
private static Pair <ExprNode, ExprTableAccessNode> HandleTableSubchain( IList <ExprNode> tableKeys, IList <Chainable> chain, TableMetaData table, Func <IList <Chainable>, ExprDotNodeImpl> dotNodeFunction) { if (chain.IsEmpty()) { var nodeX = new ExprTableAccessNodeTopLevel(table.TableName); nodeX.AddChildNodes(tableKeys); return(new Pair <ExprNode, ExprTableAccessNode>(nodeX, nodeX)); } // We make an exception when the table is keyed and the column is found and there are no table keys provided. // This accommodates the case "select MyTable.a from MyTable". var columnOrOtherName = chain[0].GetRootNameOrEmptyString(); var tableColumn = table.Columns.Get(columnOrOtherName); if (tableColumn != null && table.IsKeyed && tableKeys.IsEmpty()) { return(null); // let this be resolved as an identifier } if (chain.Count == 1) { if (chain[0] is ChainableName) { var nodeX = new ExprTableAccessNodeSubprop(table.TableName, columnOrOtherName); nodeX.AddChildNodes(tableKeys); return(new Pair <ExprNode, ExprTableAccessNode>(nodeX, nodeX)); } if (columnOrOtherName.Equals("keys", StringComparison.InvariantCultureIgnoreCase)) { var nodeX = new ExprTableAccessNodeKeys(table.TableName); nodeX.AddChildNodes(tableKeys); return(new Pair <ExprNode, ExprTableAccessNode>(nodeX, nodeX)); } else { throw new ValidationException( "Invalid use of table '" + table.TableName + "', unrecognized use of function '" + columnOrOtherName + "', expected 'keys()'"); } } var node = new ExprTableAccessNodeSubprop(table.TableName, columnOrOtherName); node.AddChildNodes(tableKeys); var subchain = chain.SubList(1, chain.Count); ExprNode exprNode = dotNodeFunction.Invoke(subchain); exprNode.AddChildNode(node); return(new Pair <ExprNode, ExprTableAccessNode>(exprNode, node)); }
public ExprDotNodeAggregationMethodForgeTableAccess( ExprDotNodeImpl parent, string aggregationMethodName, ExprNode[] parameters, AggregationPortableValidation validation, ExprTableAccessNodeSubprop subprop, TableMetadataColumnAggregation column) : base(parent, aggregationMethodName, parameters, validation) { this.subprop = subprop; this.column = column; }
public static Pair <ExprTableAccessNode, IList <ExprChainedSpec> > GetTableExprChainable( EngineImportService engineImportService, LazyAllocatedMap <ConfigurationPlugInAggregationMultiFunction, PlugInAggregationMultiFunctionFactory> plugInAggregations, string engineURI, string tableName, IList <ExprChainedSpec> chain) { // handle just "variable[...].sub" var subpropName = chain[0].Name; if (chain.Count == 1) { chain.RemoveAt(0); var tableNode = new ExprTableAccessNodeSubprop(tableName, subpropName); return(new Pair <ExprTableAccessNode, IList <ExprChainedSpec> >(tableNode, chain)); } // we have a chain "variable[...].sub.xyz" return(HandleTable(engineImportService, plugInAggregations, engineURI, tableName, subpropName, chain)); }
private static Pair <ExprTableAccessNode, IList <ExprChainedSpec> > HandleTable( EngineImportService engineImportService, LazyAllocatedMap <ConfigurationPlugInAggregationMultiFunction, PlugInAggregationMultiFunctionFactory> plugInAggregations, string engineURI, string tableName, string sub, IList <ExprChainedSpec> chain) { ExprTableAccessNode node = new ExprTableAccessNodeSubprop(tableName, sub); IList <ExprChainedSpec> subchain = chain.SubList(1, chain.Count); var candidateAccessor = subchain[0].Name; var exprNode = (ExprAggregateNodeBase)ASTAggregationHelper.TryResolveAsAggregation(engineImportService, false, candidateAccessor, plugInAggregations, engineURI); if (exprNode != null) { node = new ExprTableAccessNodeSubpropAccessor(tableName, sub, exprNode); exprNode.AddChildNodes(subchain[0].Parameters); subchain.RemoveAt(0); } return(new Pair <ExprTableAccessNode, IList <ExprChainedSpec> >(node, subchain)); }
private static ExprTableAccessEvalStrategy GetTableAccessSubprop(ILockable @lock, ExprTableAccessNodeSubprop subprop, TableMetadataColumn column, TableStateInstanceGroupBy grouped, TableStateInstanceUngrouped ungrouped) { if (column is TableMetadataColumnPlain) { var plain = (TableMetadataColumnPlain)column; if (ungrouped != null) { return(new ExprTableEvalStrategyUngroupedProp(@lock, ungrouped.EventReference, plain.IndexPlain, subprop.OptionalPropertyEnumEvaluator)); } if (subprop.GroupKeyEvaluators.Length > 1) { return(new ExprTableEvalStrategyGroupByPropMulti(@lock, grouped.Rows, plain.IndexPlain, subprop.OptionalPropertyEnumEvaluator, subprop.GroupKeyEvaluators)); } return(new ExprTableEvalStrategyGroupByPropSingle(@lock, grouped.Rows, plain.IndexPlain, subprop.OptionalPropertyEnumEvaluator, subprop.GroupKeyEvaluators[0])); } var aggcol = (TableMetadataColumnAggregation)column; if (ungrouped != null) { if (!aggcol.Factory.IsAccessAggregation) { return(new ExprTableEvalStrategyUngroupedMethod(@lock, ungrouped.EventReference, aggcol.MethodOffset)); } var pair = aggcol.AccessAccessorSlotPair; return(new ExprTableEvalStrategyUngroupedAccess(@lock, ungrouped.EventReference, pair.Slot, pair.Accessor)); } var columnAggregation = (TableMetadataColumnAggregation)column; if (!columnAggregation.Factory.IsAccessAggregation) { if (subprop.GroupKeyEvaluators.Length > 1) { return(new ExprTableEvalStrategyGroupByMethodMulti(@lock, grouped.Rows, columnAggregation.MethodOffset, subprop.GroupKeyEvaluators)); } return(new ExprTableEvalStrategyGroupByMethodSingle(@lock, grouped.Rows, columnAggregation.MethodOffset, subprop.GroupKeyEvaluators[0])); } if (subprop.GroupKeyEvaluators.Length > 1) { return(new ExprTableEvalStrategyGroupByAccessMulti(@lock, grouped.Rows, columnAggregation.AccessAccessorSlotPair, subprop.GroupKeyEvaluators)); } return(new ExprTableEvalStrategyGroupByAccessSingle(@lock, grouped.Rows, columnAggregation.AccessAccessorSlotPair, subprop.GroupKeyEvaluators[0])); }