/// <summary> /// /// </summary> /// <param name="ce"></param> /// <returns></returns> /// <remarks></remarks> public static ColumnReference Interpret(ColumnExpression ce) { var exp = ce.FindDescendant <Expression>(); var cr = new ColumnReference(); if (exp.IsSingleColumn) { cr.isComplexExpression = false; cr = Interpret(exp.FindDescendantRecursive <ColumnIdentifier>()); } else { cr.isComplexExpression = true; } ColumnAlias ca = ce.FindDescendant <ColumnAlias>(); if (ca != null) { cr.columnAlias = ca.Value; } cr.columnExpression = ce; return(cr); }
public bool Compare(ColumnReference other) { // other must be a direct column reference, ie having a TableReference set // or must be a complex expression with an alias set if (other.tableReference == null && !other.isComplexExpression) { throw new InvalidOperationException(); } bool res = true; if (this.tableReference == null && !this.isComplexExpression) { // compare to a complex expression by alias res &= SchemaManager.Comparer.Compare(this.columnName, other.columnName) == 0 || SchemaManager.Comparer.Compare(this.columnName, other.columnAlias) == 0; } else if (other.tableReference == null) { // if this is an alias res &= this.tableReference == null && StringComparer.CurrentCultureIgnoreCase.Compare(this.columnName, other.columnAlias) == 0; } else { // Now both have the table reference set, make sure they are equal // compare the two table references res &= (this.tableReference.Compare(other.tableReference)); // compare the two names res &= (StringComparer.CurrentCultureIgnoreCase.Compare(this.columnName, other.columnName) == 0); // either only one of them has column alias, or // if both do, the aliases are equat res &= (this.columnAlias == null || other.columnAlias == null || (StringComparer.CurrentCultureIgnoreCase.Compare(this.columnAlias, other.columnAlias) == 0)); // none of them have column aliases res &= this.columnAlias == null && other.columnAlias == null || this.columnAlias == null && other.columnAlias != null && StringComparer.CurrentCultureIgnoreCase.Compare(this.columnName, other.columnName) == 0 || this.columnAlias != null; // this one doesn't have an alias, so it's name must match the other name // **** this seems to be the tricky one //this.columnAlias == null && other.columnAlias != null && StringComparer.CurrentCultureIgnoreCase.Compare(other.columnAlias, other.ColumnName) == 0 || // ??? //this.columnAlias != null; } return(res); }
private void LoadUdfColumnReferences(SchemaManager schemaManager) { // TVF calls can have a column alias list List <ColumnAlias> calist = null; var cal = this.Node.FindDescendant <ColumnAliasList>(); if (cal != null) { calist = new List <ColumnAlias>(cal.EnumerateDescendants <ColumnAlias>()); } // Get dataset description DatasetBase ds; try { ds = schemaManager.Datasets[DatasetName]; } catch (SchemaException ex) { throw new NameResolverException(String.Format(ExceptionMessages.UnresolvableDatasetReference, DatasetName, Node.Line, Node.Col), ex); } int q = 0; TableValuedFunction tvf; if (ds.TableValuedFunctions.ContainsKey(DatabaseName, SchemaName, DatabaseObjectName)) { tvf = ds.TableValuedFunctions[DatabaseName, SchemaName, DatabaseObjectName]; } else { // TODO: move this to name resolver instead throw new NameResolverException(String.Format(ExceptionMessages.UnresolvableUdfReference, DatabaseObjectName, Node.Line, Node.Col)); } foreach (var cd in tvf.Columns.Values) { var cr = new ColumnReference(this, cd); // if column alias list is present, use the alias instead of the original name if (calist != null) { cr.ColumnName = Util.RemoveIdentifierQuotes(calist[q].Value); } this.columnReferences.Add(cr); q++; } }
private void CopyMembers(ColumnReference old) { this.columnExpression = old.columnExpression; this.columnIdentifier = old.columnIdentifier; this.tableReference = old.tableReference; this.columnName = old.columnName; this.dataType = old.dataType; this.columnAlias = old.columnAlias; this.isStar = old.isStar; this.isComplexExpression = old.isComplexExpression; this.selectListIndex = old.selectListIndex; this.columnContext = old.columnContext; }
/// <summary> /// /// </summary> /// <param name="column"></param> /// <returns></returns> /// <remarks> /// In this function call, tables are always referenced by /// their aliases, if they have one. /// </remarks> public string GetResolvedColumnName(ColumnReference column) { string tablename; if (!String.IsNullOrEmpty(column.TableReference.Alias)) { tablename = QuoteIdentifier(column.TableReference.Alias); } else { tablename = GetResolvedTableName(column.TableReference); } return GetResolvedColumnName(tablename, column.ColumnName); }
public static ColumnIdentifier Create(ColumnReference cr) { var nci = new ColumnIdentifier(); nci.ColumnReference = cr; if (String.IsNullOrEmpty(cr.TableReference.Alias)) { nci.Stack.AddLast(TableName.Create(cr.TableReference.DatabaseObjectName)); } else { nci.Stack.AddLast(TableName.Create(cr.TableReference.Alias)); } nci.Stack.AddLast(Dot.Create()); nci.Stack.AddLast(ColumnName.Create(cr.ColumnName)); return nci; }
public static SelectList Create(ColumnReference cr) { // Create new expression var nsl = new SelectList(); var nce = new ColumnExpression(); nce.ColumnReference = new ColumnReference(cr); nsl.Stack.AddLast(nce); var nex = new Expression(); nce.Stack.AddLast(nex); var nav = new AnyVariable(); nex.Stack.AddLast(nav); nav.Stack.AddLast(ColumnIdentifier.Create(new ColumnReference(cr))); return nsl; }
public static ColumnIdentifier Create(ColumnReference cr) { var nci = new ColumnIdentifier(); nci.ColumnReference = cr; if (String.IsNullOrEmpty(cr.TableReference.Alias)) { nci.Stack.AddLast(TableName.Create(cr.TableReference.DatabaseObjectName)); } else { nci.Stack.AddLast(TableName.Create(cr.TableReference.Alias)); } nci.Stack.AddLast(Dot.Create()); nci.Stack.AddLast(ColumnName.Create(cr.ColumnName)); return(nci); }
private void CopyMembers(TableReference old) { this.alias = old.alias; this.isTableOrView = old.isTableOrView; this.isUdf = old.isUdf; this.isSubquery = old.isSubquery; this.isComputed = old.isComputed; // Deep copy of column references this.columnReferences = new List <ColumnReference>(); foreach (var cr in old.columnReferences) { var ncr = new ColumnReference(cr) { TableReference = this }; this.columnReferences.Add(ncr); } this.statistics = old.statistics == null ? null : new TableStatistics(old.statistics); }
public static SelectList Create(ColumnReference cr) { // Create new expression var nsl = new SelectList(); var nce = new ColumnExpression(); nce.ColumnReference = new ColumnReference(cr); nsl.Stack.AddLast(nce); var nex = new Expression(); nce.Stack.AddLast(nex); var nav = new AnyVariable(); nex.Stack.AddLast(nav); nav.Stack.AddLast(ColumnIdentifier.Create(new ColumnReference(cr))); return(nsl); }
public static ColumnReference Interpret(ColumnIdentifier ci) { var cr = new ColumnReference(); cr.columnIdentifier = ci; cr.tableReference = new TableReference(ci); var star = ci.FindDescendant <Mul>(); if (star != null) { cr.isStar = true; cr.columnName = star.Value; } else { cr.isStar = false; cr.columnName = Util.RemoveIdentifierQuotes(ci.FindDescendant <ColumnName>().Value); } cr.isComplexExpression = false; return(cr); }
private void LoadUdfColumnReferences(SchemaManager schemaManager) { // TVF calls can have a column alias list List<ColumnAlias> calist = null; var cal = this.node.FindDescendant<ColumnAliasList>(); if (cal != null) { calist = new List<ColumnAlias>(cal.EnumerateDescendants<ColumnAlias>()); } // Get dataset description DatasetBase ds; try { ds = schemaManager.Datasets[datasetName]; } catch (SchemaException ex) { throw new NameResolverException(String.Format(ExceptionMessages.UnresolvableDatasetReference, datasetName, node.Line, node.Col), ex); } int q = 0; TableValuedFunction tvf; if (ds.TableValuedFunctions.ContainsKey(databaseName, schemaName, databaseObjectName)) { tvf = ds.TableValuedFunctions[databaseName, schemaName, databaseObjectName]; } else { // TODO: move this to name resolver instead throw new NameResolverException(String.Format(ExceptionMessages.UnresolvableUdfReference, databaseObjectName, node.Line, node.Col)); } foreach (var cd in tvf.Columns.Values) { var cr = new ColumnReference(this, cd); // if column alias list is present, use the alias instead of the original name if (calist != null) { cr.ColumnName = Util.RemoveIdentifierQuotes(calist[q].Value); } this.columnReferences.Add(cr); q++; } }
public ColumnReference(ColumnReference old) { CopyMembers(old); }
private void ResolveColumnReference(QuerySpecification qs, IColumnReference cr, ColumnContext context) { // Try to resolve the table belonging to a column based solely on // column name. This function is called only on column references with // unspecified table parts. // Star columns cannot be resolved, treat them separately if (!cr.ColumnReference.IsStar && !cr.ColumnReference.IsComplexExpression) { ColumnReference ncr = null; int q = 0; if (cr.ColumnReference.TableReference.IsUndefined) { // This has an empty table reference (only column name specified) // Look for a match based on column name only foreach (var tr in qs.SourceTableReferences.Values) { foreach (var ccr in tr.ColumnReferences) { if (cr.ColumnReference.Compare(ccr)) { if (q != 0) { throw CreateException(ExceptionMessages.AmbigousColumnReference, null, cr.ColumnReference.ColumnName, (Node)cr); } ncr = ccr; q++; } } } } else if (!cr.ColumnReference.TableReference.IsUndefined) { foreach (var ccr in cr.ColumnReference.TableReference.ColumnReferences) { if (cr.ColumnReference.Compare(ccr)) { if (q != 0) { throw CreateException(ExceptionMessages.AmbigousColumnReference, null, cr.ColumnReference.ColumnName, (Node)cr); } ncr = ccr; q++; } } } if (q == 0) { throw CreateException(ExceptionMessages.UnresolvableColumnReference, null, cr.ColumnReference.ColumnName, (Node)cr); } // Make copy here and preserve alias! ncr.ColumnContext |= context; ncr = new ColumnReference(ncr); if (cr.ColumnReference != null && cr.ColumnReference.ColumnAlias != null) { ncr.ColumnAlias = cr.ColumnReference.ColumnAlias; } cr.ColumnReference = ncr; } }
private void CopyMembers(TableReference old) { this.node = old.node; this.databaseObject = old.databaseObject; this.datasetName = old.datasetName; this.databaseName = old.databaseName; this.schemaName = old.schemaName; this.databaseObjectName = old.databaseObjectName; this.alias = old.alias; this.isTableOrView = old.isTableOrView; this.isUdf = old.isUdf; this.isSubquery = old.isSubquery; this.isComputed = old.isComputed; // Deep copy of column references this.columnReferences = new List<ColumnReference>(); foreach (var cr in old.columnReferences) { var ncr = new ColumnReference(cr) { TableReference = this }; this.columnReferences.Add(ncr); } //this.conditionReferences = new List<SearchConditionReference>(old.conditionReferences); this.statistics = old.statistics == null ? null : new TableStatistics(old.statistics); }
public ColumnReference(ColumnReference old) { CopyMembers(old); }
private void ResolveColumnReference(QuerySpecification qs, IColumnReference cr, ColumnContext context) { // Try to resolve the table belonging to a column based solely on // column name. This function is called only on column references with // unspecified table parts. // Star columns cannot be resolved, treat them separately if (!cr.ColumnReference.IsStar && !cr.ColumnReference.IsComplexExpression) { ColumnReference ncr = null; int q = 0; if (cr.ColumnReference.TableReference.IsUndefined) { // This has an empty table reference (only column name specified) // Look for a match based on column name only foreach (var tr in qs.SourceTableReferences.Values) { foreach (var ccr in tr.ColumnReferences) { if (cr.ColumnReference.Compare(ccr)) { if (q != 0) { throw CreateException(ExceptionMessages.AmbigousColumnReference, null, cr.ColumnReference.ColumnName, (Node)cr); } ncr = ccr; q++; } } } } else if (!cr.ColumnReference.TableReference.IsUndefined) { foreach (var ccr in cr.ColumnReference.TableReference.ColumnReferences) { if (cr.ColumnReference.Compare(ccr)) { if (q != 0) { throw CreateException(ExceptionMessages.AmbigousColumnReference, null, cr.ColumnReference.ColumnName, (Node)cr); } ncr = ccr; q++; } } } if (q == 0) { throw CreateException(ExceptionMessages.UnresolvableColumnReference, null, cr.ColumnReference.ColumnName, (Node)cr); } // Make copy here and preserve alias! ncr.ColumnContext |= context; ncr = new ColumnReference(ncr); if (cr.ColumnReference != null && cr.ColumnReference.ColumnAlias != null) { ncr.ColumnAlias = cr.ColumnReference.ColumnAlias; } cr.ColumnReference = ncr; } }
private void CopyMembers(ColumnReference old) { this.columnExpression = old.columnExpression; this.columnIdentifier = old.columnIdentifier; this.tableReference = old.tableReference; this.columnName = old.columnName; this.dataType = old.dataType; this.columnAlias = old.columnAlias; this.isStar = old.isStar; this.isComplexExpression = old.isComplexExpression; this.selectListIndex = old.selectListIndex; this.columnContext = old.columnContext; }
public bool Compare(ColumnReference other) { // other must be a direct column reference, ie having a TableReference set // or must be a complex expression with an alias set if (other.tableReference == null && !other.isComplexExpression) { throw new InvalidOperationException(); } bool res = true; if (this.tableReference == null && !this.isComplexExpression) { // compare to a complex expression by alias res &= SchemaManager.Comparer.Compare(this.columnName, other.columnName) == 0 || SchemaManager.Comparer.Compare(this.columnName, other.columnAlias) == 0; } else if (other.tableReference == null) { // if this is an alias res &= this.tableReference == null && StringComparer.CurrentCultureIgnoreCase.Compare(this.columnName, other.columnAlias) == 0; } else { // Now both have the table reference set, make sure they are equal // compare the two table references res &= (this.tableReference.Compare(other.tableReference)); // compare the two names res &= (StringComparer.CurrentCultureIgnoreCase.Compare(this.columnName, other.columnName) == 0); // either only one of them has column alias, or // if both do, the aliases are equat res &= (this.columnAlias == null || other.columnAlias == null || (StringComparer.CurrentCultureIgnoreCase.Compare(this.columnAlias, other.columnAlias) == 0)); // none of them have column aliases res &= this.columnAlias == null && other.columnAlias == null || this.columnAlias == null && other.columnAlias != null && StringComparer.CurrentCultureIgnoreCase.Compare(this.columnName, other.columnName) == 0 || this.columnAlias != null; // this one doesn't have an alias, so it's name must match the other name // **** this seems to be the tricky one //this.columnAlias == null && other.columnAlias != null && StringComparer.CurrentCultureIgnoreCase.Compare(other.columnAlias, other.ColumnName) == 0 || // ??? //this.columnAlias != null; } return res; }
private void CopyMembers(TableReference old) { this.alias = old.alias; this.isTableOrView = old.isTableOrView; this.isUdf = old.isUdf; this.isSubquery = old.isSubquery; this.isComputed = old.isComputed; // Deep copy of column references this.columnReferences = new List<ColumnReference>(); foreach (var cr in old.columnReferences) { var ncr = new ColumnReference(cr) { TableReference = this }; this.columnReferences.Add(ncr); } this.statistics = old.statistics == null ? null : new TableStatistics(old.statistics); }
public override Node Interpret() { this.columnReference = ColumnReference.Interpret(this); return base.Interpret(); }
private void InitializeMembers() { this.columnReference = null; }
public override Node Interpret() { this.columnReference = ColumnReference.Interpret(this); return(base.Interpret()); }
public static ColumnReference Interpret(ColumnIdentifier ci) { var cr = new ColumnReference(); cr.columnIdentifier = ci; cr.tableReference = new TableReference(ci); var star = ci.FindDescendant<Mul>(); if (star != null) { cr.isStar = true; cr.columnName = star.Value; } else { cr.isStar = false; cr.columnName = Util.RemoveIdentifierQuotes(ci.FindDescendant<ColumnName>().Value); } cr.isComplexExpression = false; return cr; }
private void InitializeMembers() { this.columnReference = null; }
/// <summary> /// /// </summary> /// <param name="ce"></param> /// <returns></returns> /// <remarks></remarks> public static ColumnReference Interpret(ColumnExpression ce) { var exp = ce.FindDescendant<Expression>(); var cr = new ColumnReference(); if (exp.IsSingleColumn) { cr.isComplexExpression = false; cr = Interpret(exp.FindDescendantRecursive<ColumnIdentifier>()); } else { cr.isComplexExpression = true; } ColumnAlias ca = ce.FindDescendant<ColumnAlias>(); if (ca != null) { cr.columnAlias = ca.Value; } cr.columnExpression = ce; return cr; }