private static Dictionary <string, DataTypeMapping> GetSourceSchema(Partition partition) { var result = new List <MetadataChange>(); if (!(partition.DataSource is ProviderDataSource)) { return(null); } var tds = TypedDataSource.GetFromTabularDs(partition.DataSource as ProviderDataSource); var schemaTable = tds.GetSchemaTable(partition.Query); if (schemaTable == null) { return(null); } var sourceSchema = new Dictionary <string, DataTypeMapping>(StringComparer.InvariantCultureIgnoreCase); foreach (DataRow row in schemaTable.Rows) { var colName = row["ColumnName"].ToString(); var dataType = schemaTable.Columns.Contains("DataTypeName") ? row["DataTypeName"].ToString() : (row["DataType"] as Type).Name; var mappedType = DataTypeMap(dataType); sourceSchema.Add(colName, new DataTypeMapping(dataType, mappedType)); } return(sourceSchema); }
private static Dictionary <string, DataTypeMapping> GetSourceSchema(Partition partition) { var result = new List <MetadataChange>(); if (!(partition.DataSource is ProviderDataSource)) { return(null); } var tds = TypedDataSource.GetFromTabularDs(partition.DataSource as ProviderDataSource); var query = partition.Query; if (partition.CheckFlag(TE_ADDFALSECRITERIA) || partition.Table.CheckFlag(TE_ADDFALSECRITERIA) || (partition.DataSource != null && partition.DataSource.CheckFlag(TE_ADDFALSECRITERIA))) { query = query + " WHERE 1 = 0"; } var schemaTable = tds.GetSchemaTable(query); if (schemaTable == null) { return(null); } var ignoredColumns = new HashSet <string>(); var sourceSchema = new Dictionary <string, DataTypeMapping>(StringComparer.InvariantCultureIgnoreCase); foreach (DataRow row in schemaTable.Rows) { var colName = row["ColumnName"].ToString(); var dataType = schemaTable.Columns.Contains("DataTypeName") ? row["DataTypeName"].ToString() : (row["DataType"] as Type).Name; var mappedType = DataTypeMap(dataType); if (sourceSchema.ContainsKey(colName)) { ignoredColumns.Add(colName); } else { sourceSchema.Add(colName, new DataTypeMapping(dataType, mappedType)); } } if (ignoredColumns.Count > 0) { var plural = ignoredColumns.Count > 1 ? "s" : ""; var columns = string.Join("", ignoredColumns.Select(c => "\r\n\t" + c).ToArray()); var partitionInfo = partition.Table.Partitions.Count > 1 ? $", partition \"{partition.Name}\"" : ""; MessageBox.Show($"The query on table '{partition.Table.Name}'{partitionInfo} specified the following column{plural} more than once:\r\n{columns}", "Repeated columns", MessageBoxButtons.OK, MessageBoxIcon.Information); } return(sourceSchema); }
public static List <MetadataChange> GetChanges(ProviderDataSource dataSource) { var result = new List <MetadataChange>(); var tds = TypedDataSource.GetFromTabularDs(dataSource); foreach (var table in dataSource.Model.Tables.Where(t => t.Partitions[0].DataSource == dataSource)) { result.AddRange(GetChanges(table)); } return(result); }
public static List <MetadataChange> GetChanges(Partition partition) { var result = new List <MetadataChange>(); var table = partition.Table; if (!(partition.DataSource is ProviderDataSource)) { result.Add(new MetadataChange { ModelTable = table, ChangeType = MetadataChangeType.SourceQueryError, SourceQuery = partition.Query }); return(result); } var tds = TypedDataSource.GetFromTabularDs(partition.DataSource as ProviderDataSource); var schemaTable = tds.GetSchemaTable(partition.Query); if (schemaTable == null) { result.Add(new MetadataChange { ModelTable = table, ChangeType = MetadataChangeType.SourceQueryError, SourceQuery = table.Partitions[0].Query }); return(result); } HashSet <Column> matchedColumns = new HashSet <Column>(); foreach (DataRow row in schemaTable.Rows) { var colName = row["ColumnName"].ToString(); var dataType = schemaTable.Columns.Contains("DataTypeName") ? row["DataTypeName"].ToString() : (row["DataType"] as Type).Name; var mappedType = DataTypeMap(dataType); var tCols = table.DataColumns.Where(col => col.SourceColumn.EqualsI(colName) || col.SourceColumn.EqualsI("[" + colName + "]")); if (tCols.Count() == 0) { result.Add(new MetadataChange { ModelTable = table, ChangeType = MetadataChangeType.SourceColumnAdded, SourceColumn = colName, SourceType = mappedType, SourceProviderType = dataType }); } foreach (var tCol in tCols) { matchedColumns.Add(tCol); if (tCol.DataType != mappedType) { result.Add(new MetadataChange { ModelTable = table, ChangeType = MetadataChangeType.DataTypeChange, ModelColumn = tCol, SourceColumn = colName, SourceType = mappedType, SourceProviderType = dataType }); } } } foreach (var col in table.DataColumns.Where(c => !matchedColumns.Contains(c))) { result.Add(new MetadataChange { ModelTable = table, ChangeType = MetadataChangeType.SourceColumnNotFound, ModelColumn = col }); } return(result); }