private void ReplacePartitionsFromDestination(JObject sourceModel, TOM.TableCollection sourceModelTables, TOM.Model destinationModel, DeploymentOptions options) { if (sourceModel["tables"] is JArray tables) { foreach (var table in tables) { var tableName = table["name"].Value <string>(); if (destinationModel.Tables.Contains(tableName)) { // Use destination partitions only if both source and destination tables are imported: if (!(sourceModelTables[tableName].IsImported() && destinationModel.Tables[tableName].IsImported())) { continue; } var t = destinationModel.Tables[tableName]; // If destination partition is not a policyrange if (!options.DeployPartitions || (options.SkipRefreshPolicyPartitions && t.GetSourceType() == TOM.PartitionSourceType.PolicyRange)) { // Retain existing partitions on destination: var partitions = new JArray(); table["partitions"] = partitions; foreach (var pt in t.Partitions) { partitions.Add(JObject.Parse(TOM.JsonSerializer.SerializeObject(pt))); } } } } } }
public static CreateDatasetRequest GetDataset( string datasetName, TabModel.TableCollection tables, TabModel.RelationshipCollection relationships, Action <TabModel.Measure> unsupportedMeasureAction, Action <TabModel.Relationship> unsupportedRelationshipAction ) { List <TabModel.Measure> allMeasures = tables.SelectMany(t => t.Measures).Select(m => m).ToList(); if (!CheckUnsupportedMeasures(allMeasures, out List <TabModel.Measure> unsupportedMeasures, out List <TabModel.Measure> supportedMeasures)) { // Diagnostic - list of unsupported measures foreach (var m in unsupportedMeasures) { unsupportedMeasureAction?.Invoke(m); } } var datasetSchema = new CreateDatasetRequest { Name = datasetName, Tables = new List <Table>(), Relationships = new List <Relationship>() }; foreach (var t in tables) { datasetSchema.Tables.Add(GetTable(t, unsupportedMeasures)); } foreach (var r in relationships) { bool addedRelationship = false; if ((r is TabModel.SingleColumnRelationship sr) && sr.IsActive && (sr.FromCardinality != sr.ToCardinality)) { if (r != null) { var pushRelationship = new Relationship { Name = sr.Name, FromTable = sr.FromTable.Name, FromColumn = sr.FromColumn.Name, ToTable = sr.ToTable.Name, ToColumn = sr.ToColumn.Name, CrossFilteringBehavior = r.CrossFilteringBehavior == TabModel.CrossFilteringBehavior.OneDirection ? CrossFilteringBehavior.OneDirection : r.CrossFilteringBehavior == TabModel.CrossFilteringBehavior.BothDirections ? CrossFilteringBehavior.BothDirections : r.CrossFilteringBehavior == TabModel.CrossFilteringBehavior.Automatic ? CrossFilteringBehavior.Automatic : null }; datasetSchema.Relationships.Add(pushRelationship); addedRelationship = true; } } if (!addedRelationship) { unsupportedRelationshipAction?.Invoke(r); } } return(datasetSchema); }