protected override BoundRelation RewriteTableRelation(BoundTableRelation node) { var symbol = node.TableInstance.Table as CommonTableExpressionSymbol; if (symbol == null) { return(base.RewriteTableRelation(node)); } if (IsInstantiatedCommonTableExpression(node)) { return(new BoundConstantRelation()); } var outputValues = node.GetOutputValues().ToImmutableArray(); var instantiatedQuery = symbol.RecursiveMembers.Any() ? InstantiateRecursiveCommonTableExpression(outputValues, symbol) : InstantiateCommonTableExpression(outputValues, symbol); // For regular SELECT queries the output node will be a projection. // We don't need this moving forward so it's safe to omit. // // NOTE: We need to keep this after we added the output slot mapping. // Otherwise the slots will not align. var projection = instantiatedQuery as BoundProjectRelation; var result = projection == null ? instantiatedQuery : projection.Input; return(result); }
protected override BoundRelation RewriteTableRelation(BoundTableRelation node) { var definedValues = RemoveUnusedSlots(node.DefinedValues, d => d.ValueSlot); node = node.Update(node.TableInstance, definedValues); return(base.RewriteTableRelation(node)); }
protected override void VisitTableRelation(BoundTableRelation node) { if (node.TableInstance.Table == _symbol) { Debug.Assert(_instance == null); _instance = node.TableInstance; } base.VisitTableRelation(node); }
private static ShowPlanNode BuildTable(BoundTableRelation node) { var properties = Enumerable.Empty <KeyValuePair <string, string> >(); var children = Enumerable.Empty <ShowPlanNode>(); var name = node.TableInstance.Table.Name; var columns = string.Join(@", ", node.DefinedValues.Select(d => d.ValueSlot.Name)); return(new ShowPlanNode($"Table ({name}), DefinedValues := {columns}", properties, children)); }
private static Iterator BuildTable(BoundTableRelation relation) { var schemaTableSymbol = (SchemaTableSymbol)relation.TableInstance.Table; var tableDefinition = schemaTableSymbol.Definition; var columnInstances = relation.DefinedValues; var definedValues = columnInstances.Select(ci => ci.Column) .Cast <SchemaColumnSymbol>() .Select(c => BuildColumnAccess(c.Definition)); return(new TableIterator(tableDefinition, definedValues)); }
protected override BoundRelation RewriteTableRelation(BoundTableRelation node) { if (!node.DefinedValues.Any()) { return(node); } var factory = node.DefinedValues.First().ValueSlot.Factory; var original = node.TableInstance; var valueSlotMapping = original.ColumnInstances.ToDictionary(c => c.Column, c => _valueSlotMapping[c.ValueSlot]); var instanceName = factory.CreateNamed(original.Name, typeof(int)).Name; var instance = new TableInstanceSymbol(instanceName, original.Table, (t, c) => valueSlotMapping[c]); var columnMapping = instance.ColumnInstances.ToDictionary(c => c.Column); var definedValues = node.DefinedValues.Select(d => columnMapping[d.Column]).ToImmutableArray(); return(node.Update(instance, definedValues)); }
private static CardinalityEstimate EstimateTableRelation(BoundTableRelation relation) { var tableSymbol = relation.TableInstance.Table as SchemaTableSymbol; if (tableSymbol == null) { return(CardinalityEstimate.Unknown); } var collection = tableSymbol.Definition.GetRows() as ICollection; if (collection == null) { return(CardinalityEstimate.Unknown); } return(new CardinalityEstimate(0, collection.Count)); }