public override Task <SqlObject> GetValueAsync(long row, int column) { int tableNum = JoinedTableInfo.GetTableOffset(column); var parentTable = Tables[tableNum]; var resolvedRow = ResolveTableRow(row, tableNum); return(parentTable.GetValueAsync(resolvedRow, JoinedTableInfo.GetColumnOffset(column))); }
protected JoinedTable(ObjectName tableName, ITable[] tables, int sortColumn) { var tableInfos = tables.Select(x => x.ObjectInfo).Cast <TableInfo>().ToArray(); JoinedTableInfo = new JoinedTableInfo(tableName, tableInfos); Tables = tables; Indexes = new TableIndex[JoinedTableInfo.Columns.Count]; SortColumn = sortColumn; }
protected override TableIndex GetColumnIndex(int column, int originalColumn, ITable ancestor) { // First check if the given SelectableScheme is in the column_scheme array var scheme = Indexes[column]; if (scheme != null) { if (ancestor == this) { return(scheme); } return(scheme.Subset(ancestor, originalColumn)); } // If it isn't then we need to calculate it TableIndex index; // Optimization: The table may be naturally ordered by a column. If it // is we don't try to generate an ordered set. if (SortColumn != -1 && SortColumn == column) { var columnName = JoinedTableInfo.Columns[column].ColumnName; var indexInfo = new IndexInfo($"#COLIDX[{column}]", TableInfo.TableName, columnName); index = new InsertSearchIndex(indexInfo, this, CalculateTableRows()); Indexes[column] = index; if (ancestor != this) { index = index.Subset(ancestor, originalColumn); } } else { // Otherwise we must generate the ordered set from the information in // a parent index. var parentTable = Tables[JoinedTableInfo.GetTableOffset(column)]; index = parentTable.GetColumnIndex(JoinedTableInfo.GetColumnOffset(column), originalColumn, ancestor); if (ancestor == this) { Indexes[column] = index; } } return(index); }
protected override IEnumerable <long> ResolveRows(int column, IEnumerable <long> rowSet, ITable ancestor) { if (ancestor == this) { return(new BigArray <long>(0)); } int tableNum = JoinedTableInfo.GetTableOffset(column); var parentTable = Tables[tableNum]; if (!(parentTable is IVirtualTable)) { throw new InvalidOperationException(); } // Resolve the rows into the parents indices var rows = ResolveTableRows(rowSet, tableNum); return(parentTable.ResolveRows(JoinedTableInfo.GetColumnOffset(column), rows, ancestor)); }
public override Task <SqlObject> GetValueAsync(long row, int column) { int tableNum = JoinedTableInfo.GetTableOffset(column); var parentTable = Tables[tableNum]; if (row >= outerRowCount) { row = Rows[tableNum][row - outerRowCount]; return(parentTable.GetValueAsync(row, JoinedTableInfo.GetColumnOffset(column))); } if (outerRows[tableNum] == null) { // Special case, handling outer entries (NULL) return(Task.FromResult(new SqlObject(TableInfo.Columns[column].ColumnType, null))); } row = outerRows[tableNum][row]; return(parentTable.GetValueAsync(row, JoinedTableInfo.GetColumnOffset(column))); }
public JoinedColumnList(JoinedTableInfo tableInfo) { this.tableInfo = tableInfo; columns = new List <ColumnInfo>(); foreach (var info in tableInfo.tableInfos) { Count += info.Columns.Count; } tableInfo.columnTable = new int[Count]; tableInfo.columnFilter = new int[Count]; int index = 0; for (int i = 0; i < tableInfo.tableInfos.Length; ++i) { var curTableInfo = tableInfo.tableInfos[i]; int refColCount = curTableInfo.Columns.Count; for (int n = 0; n < refColCount; ++n) { tableInfo.columnFilter[index] = n; tableInfo.columnTable[index] = i; ++index; var columnInfo = curTableInfo.Columns[n]; var newColumnInfo = new ColumnInfo(columnInfo.ColumnName, columnInfo.ColumnType) { DefaultValue = columnInfo.DefaultValue }; columns.Add(newColumnInfo); } } }