Beispiel #1
0
 static void DropMeasureGroupPartitions(MeasureGroup mg)
 {
     //mg.Partitions.Clear();
     while (mg.Partitions.Count > 0)
     {
         mg.Partitions[0].Drop();
     }
     mg.Update();
 }
 /// <summary>
 /// Create cube core measure
 /// </summary>
 /// <param name="sqlHelper"></param>
 /// <param name="asMeta"></param>
 /// <param name="cube"></param>
 public void CREATE_CUBE_CORE_MEASURES(DB_SQLHELPER_BASE sqlHelper
                                       , AS_METADATA asMeta
                                       , Cube cube)
 {
     try
     {
         DataTable coreMeasureSet = asMeta.GET_SSAS_CORE_MEASURES_SET(sqlHelper);
         foreach (DataRow row in coreMeasureSet.Rows)
         {
             String       measureGroupID      = row["measure_group_id"].ToString();
             String       MeasureId           = row["measure_id"].ToString();
             String       MeasureName         = row["measure_name"].ToString();
             String       DSVSchemaName       = row["dsv_schema_name"].ToString();
             String       DisplayFolder       = row["display_folder"].ToString();
             String       FormatString        = row["format_string"].ToString();
             String       MeasureDataType     = row["measure_data_type"].ToString();
             String       DBColumn            = row["db_column"].ToString();
             String       AggregationFunction = row["aggregation_function"].ToString();
             MeasureGroup measureGroup        = cube.MeasureGroups.Find(measureGroupID);
             AS_API.ADD_MEASURE_TO_MEASURE_GROUP(
                 sqlHelper
                 , measureGroup
                 , DSVSchemaName
                 , DBColumn
                 , MeasureName
                 , MeasureId
                 , DisplayFolder
                 , FormatString
                 , AggregationFunction
                 , true
                 , MeasureDataType
                 , MeasureDataType);
             measureGroup.Update();
         }
     }
     catch (Exception ex)
     {
         sqlHelper.ADD_MESSAGE_LOG("Failed to create cube core measures:" + ex.Message.ToString(), MESSAGE_TYPE.MEASURES, MESSAGE_RESULT_TYPE.Error);
         throw (ex);
     }
 }
Beispiel #3
0
        static void CreateMeasureGroupPartitions(MeasureGroup mg, string query, string slice, DataSource ds, int year, int month_from, int month_to
                                                 , int part_size)
        {
            //mg.Partitions.Clear();

            /*
             * while (mg.Partitions.Count > 0)
             * {
             *      mg.Partitions[0].Drop();
             * }
             */
            string pkey, pname;

            for (int i = month_from; i <= month_to; i++)
            {
                pkey  = String.Format("{0}{1:00}", year, i);
                pname = CreatePartition(mg, pkey, query, slice, ds, part_size);
                logMessageFmt("[{0}]: added partition [{1}].", mg.Name, pname);
            }
            mg.Update();
        }
        /// <summary>
        /// Create measure group
        /// </summary>
        /// <param name="dsv"></param>
        /// <param name="sqlHelper"></param>
        /// <param name="asMeta"></param>
        /// <param name="cube"></param>
        /// <param name="is_rolap"></param>
        /// <param name="measure_group_id"></param>
        public void CREATE_MEASURE_GROUP(DataSourceView dsv
                                         , DB_SQLHELPER_BASE sqlHelper
                                         , AS_METADATA asMeta
                                         , Cube cube
                                         , int is_rolap_cube
                                         , String measure_group_id = null)
        {
            try
            {
                DataTable MGSet         = asMeta.GET_SSAS_MEASURE_GROUPS_SET(sqlHelper, is_rolap_cube);
                String    DSVSchemaName = "";
                foreach (DataRow row in MGSet.Rows)
                {
                    String       measureGroupID     = row["measure_group_id"].ToString();
                    String       measureGroupName   = row["measure_group_name"].ToString();
                    String       DependedFactTable  = row["depended_fact_table"].ToString();
                    String       KeyNotFound_Action = row["key_not_found_action"].ToString();
                    int          is_rolap_mg        = Convert.ToInt16(row["is_rolap_mg"].ToString());
                    MeasureGroup newMG          = AS_API.ADD_MEASURE_GROUP(sqlHelper, cube, measureGroupName, measureGroupID, is_rolap_mg, KeyNotFound_Action);
                    DataTable    dimUsageSet    = asMeta.GET_SSAS_DIM_USAGE_SET(sqlHelper, measureGroupID);
                    DataTable    CoreMeasureSet = asMeta.GET_SSAS_CORE_MEASURES_SET(sqlHelper, measureGroupID);
                    foreach (DataRow measure in CoreMeasureSet.Rows)
                    {
                        measureGroupID   = measure["measure_group_id"].ToString();
                        measureGroupName = measure["measure_group_name"].ToString();
                        String MeasureId       = measure["measure_id"].ToString();
                        String MeasureName     = measure["measure_name"].ToString();
                        String MeasureDataType = measure["measure_data_type"].ToString();
                        String DBColumn        = measure["db_column"].ToString();
                        DSVSchemaName = measure["dsv_schema_name"].ToString();
                        String AggregationFunction = measure["aggregation_function"].ToString();
                        String DisplayFolder       = measure["display_folder"].ToString();
                        String FormatString        = measure["format_string"].ToString();
                        AS_API.ADD_MEASURE_TO_MEASURE_GROUP(
                            sqlHelper,
                            newMG,
                            DSVSchemaName,
                            DBColumn,
                            MeasureName,
                            MeasureId,
                            DisplayFolder,
                            FormatString,
                            AggregationFunction,
                            true,
                            MeasureDataType,
                            MeasureDataType);
                    }
                    foreach (DataRow dimUsage in dimUsageSet.Rows)
                    {
                        String DimUsageType      = dimUsage["dim_usage_type"].ToString();
                        String InternalDimID     = dimUsage["internal_dim_id"].ToString();
                        String InternalDimAttrID = dimUsage["internal_dim_attrid"].ToString();
                        DSVSchemaName = dimUsage["dsv_schema_name"].ToString();
                        String factFKDimColumnName    = dimUsage["fact_fk_dim_column_name"].ToString();
                        String DataType               = dimUsage["fact_fk_dim_column_data_type"].ToString();
                        String DimensionID            = dimUsage["dimension_id"].ToString();
                        String AttributeID            = dimUsage["attribute_id"].ToString();
                        String InternalMeasureGroupID = dimUsage["internal_measure_group_id"].ToString();
                        switch (DimUsageType.ToLower())
                        {
                        case "regular":
                            DataItem factDataItem = AS_API.CREATE_DATA_ITEM(
                                sqlHelper,
                                dsv,
                                DSVSchemaName,
                                factFKDimColumnName,
                                AS_API_HELPER.GET_SSAS_OLEDB_TYPE_BY_NAME(DataType));
                            AS_API.ADD_DIM_USAGE_REGULAR_RELATIONSHIP(
                                sqlHelper,
                                cube,
                                newMG,
                                factDataItem,
                                DimensionID,
                                AttributeID);
                            break;

                        case "reference":
                            AS_API.ADD_DIM_USAGE_REFERENCE_RELATIONSHIP(newMG,
                                                                        DimensionID,
                                                                        AttributeID,
                                                                        InternalDimID,
                                                                        InternalDimAttrID);
                            break;

                        case "manytomany":
                            AS_API.ADD_DIM_USAGE_MANY_RELATIONSHIP(newMG, InternalMeasureGroupID, DimensionID);
                            break;

                        case "fact":
                            AS_API.ADD_DIM_USAGE_FACT_RELATIONSHIP(newMG, InternalDimAttrID, DimensionID);
                            break;

                        default:
                            break;
                        }
                    }
                    AggregationDesign agg_design = CREATE_AGGREGATION_DESIGN(newMG, sqlHelper, asMeta);
                    CREATE_CUBE_PARTITION_FOR_MEASURE_GROUP(sqlHelper, asMeta, cube, is_rolap_cube, newMG, agg_design, is_rolap_mg, DependedFactTable, DSVSchemaName);
                    newMG.Update();
                }
            }
            catch (Exception ex)
            {
                sqlHelper.ADD_MESSAGE_LOG(ex.Message.ToString(), MESSAGE_TYPE.MEASURE_GROUP, MESSAGE_RESULT_TYPE.Error);
                throw (ex);
            }
        }