예제 #1
0
 protected override void OnExecute()
 {
     foreach (var ap in context.HPartitioningDesignData.AttributesPartitioning)
     {
         var attribute = ap.Key;
         context.HPartitioningDesignData.Environments.Clear();
         var partitioning = new HPartitioningDefinition(attribute.Relation);
         partitioning.PartitioningAttributes.Add(ap.Value);
         context.HPartitioningDesignData.Environments.Add(new VirtualHPartitioningEnvironment(partitioning));
     }
     foreach (var relationAttributesPartitionings in context.HPartitioningDesignData.AttributesPartitioning.GroupBy(x => x.Key.Relation))
     {
         var relation = relationAttributesPartitionings.Key;
         foreach (var attributesPartitioningsByType in relationAttributesPartitionings.GroupBy(x => x.Value.GetType()))
         {
             var attributePartitionings = new ElementSet <HPartitioningAttributeDefinition>(attributesPartitioningsByType.Select(x => x.Value));
             if (attributePartitionings.Count >= 2)
             {
                 var combinations = new Combinations <HPartitioningAttributeDefinition>(attributePartitionings, 2);
                 foreach (var combination in combinations)
                 {
                     var partitioning = new HPartitioningDefinition(relation);
                     partitioning.PartitioningAttributes.AddRange(combination);
                     context.HPartitioningDesignData.Environments.Add(new VirtualHPartitioningEnvironment(partitioning));
                 }
             }
         }
     }
 }
        public VirtualHPartitioningDefinition Generate(HPartitioningDefinition hPartitioningDefinition)
        {
            var result = new VirtualHPartitioningDefinition();

            result.PartitionStatements = new HashSet <string>();
            var relation = hPartitioningDefinition.Relation;

            if (hPartitioningDefinition.PartitioningAttributes.First() is RangeHPartitioningAttributeDefinition)
            {
                var partitioningAttributes = hPartitioningDefinition.PartitioningAttributes.Cast <RangeHPartitioningAttributeDefinition>();
                result.PartitioningStatement = String.Format("PARTITION BY RANGE ({0})", String.Join(",", partitioningAttributes.Select(x => x.Attribute.Name)));
                GenerateRange(partitioningAttributes, new List <RangeHPartitionAttributeDefinition>(), relation, ref result);
            }
            else if (hPartitioningDefinition.PartitioningAttributes.First() is HashHPartitioningAttributeDefinition)
            {
                var partitioningAttributes = hPartitioningDefinition.PartitioningAttributes.Cast <HashHPartitioningAttributeDefinition>();
                result.PartitioningStatement = String.Format("PARTITION BY HASH ({0})", String.Join(",", partitioningAttributes.Select(x => x.Attribute.Name)));
                int partitionCounts = partitioningAttributes.Sum(x => x.Modulus);
                for (int i = 0; i < partitionCounts; i++)
                {
                    result.PartitionStatements.Add(String.Format("PARTITION OF {0}.{1} FOR VALUES WITH (MODULUS {2}, REMAINDER {3})",
                                                                 relation.SchemaName, relation.Name, partitionCounts, i
                                                                 )
                                                   );
                }
            }
            result.SchemaName   = hPartitioningDefinition.Relation.SchemaName;
            result.RelationName = hPartitioningDefinition.Relation.Name;
            return(result);
        }
예제 #3
0
 public VirtualHPartitioningEnvironment(HPartitioningDefinition partitioning)
 {
     Partitioning = partitioning;
 }