首页 文章

日志文件和Power Pivot - 将DATETIME分成不同的列?

提问于
浏览
0

我正在将一些IIS日志导入Power Pivot以使用以下方法进行一些分析:

LogParser.exe "
SELECT 
EXTRACT_TOKEN(LogFileName, 5, '\\') As LogFile,
LogRow,
to_localtime(to_timestamp(date,time)) as LOG_DTTM,
cs-UserName as ClientUserName,
cs-Method,cs-Uri-Stem as UriStem,
cs-Uri-Query as UriQuery,
sc-Status as Status,
sc-SubStatus as SubStatus,
time-Taken as ElapsedTimeMS,
c-Ip As ClientIP,
s-ComputerName as ComputerName,
s-Ip as ServerIP,
s-Port as Port,
sc-Win32-Status as Win32Status,
cs(User-Agent) as UserAgent 
    INTO IIS_LOG_PROD_STAGING 
FROM somefile.log" -o:SQL -oConnString:"Driver=SQL Server;Server=MY_SERVER_NAME; Database=MY_DATABASE_NAME;Trusted_Connection=yes" -createTable:ON -e:10 -transactionRowCount:-1

......我的问题是: Should I be splitting up the discrete parts of my DateTime columns into seperate columns at the database storage level, or should that be left to calculated columns in the PowerPivot model?

Marco Russo似乎建议至少将DATE拆分为一个单独的列:
http://sqlblog.com/blogs/marco_russo/archive/2011/09/01/separate-date-and-time-in-powerpivot-and-bism-tabular.aspx

PowerPivot仍将列作为DateTime读取,但小时/分钟/秒消失,唯一值的数量减少到数据中不同天数 . 当然,使用Calendar表更容易加入!

这似乎有道理 . 但是,如果我知道我想要在HourOfDay,DayOfWeek,DayOfMonth等级别进行分析,那么我是否应该将它们分成单独的数据库列?

1 回答

  • 3

    我强烈建议您创建一个日期表和一个时间表来进行此类分析 . date table将帮助计算星期几,日期等 . 它允许您通过简单的连接轻松进行日期计算和分类 . 时间维度将按小时分组 . 我倾向于在我的数据库中创建这些表,并将它们从SQL Server中导入我的Power Pivot模型 . 我的一般想法是行级计算在较低级别(SQL数据库)中比在Power Pivot模型中更有效地完成 . 它们可以在两者中完成,因此位置取决于您以及服务器和运行Power Pivot模型的计算机上可用的内存和CPU数量 . 由于Power Pivot在个人笔记本电脑上打开而我无法控制,我喜欢在SQL Server中进行大量计算 . 我看到你标记了Power Query . 有scripts available to create a date dimension in Power Query,不需要SQL Server中的表 . 我还没有在Power Query中 Build 时间维度,但here's a good SQL Server script . 日期表位于日期级别 . 时间表下降到秒,允许您轻松地按分钟,小时等滚动时间 .

    这是链接的日期表:

    CREATE TABLE [dbo].[DimDate] (
        [DateKey] [int] NOT NULL
        ,[Date] [datetime] NOT NULL
        ,[Day] [char](10) NULL
        ,[DayOfWeek] [smallint] NULL
        ,[DayOfMonth] [smallint] NULL
        ,[DayOfYear] [smallint] NULL
        ,[PreviousDay] [datetime] NULL
        ,[NextDay] [datetime] NULL
        ,[WeekOfYear] [smallint] NULL
        ,[Month] [char](10) NULL
        ,[MonthOfYear] [smallint] NULL
        ,[QuarterOfYear] [smallint] NULL
        ,[Year] [int] NULL
        );
    

    这是时间表:

    create table time_of_day 
    ( 
         time_of_day_key smallint primary key, 
         hour_of_day_24 tinyint,                --0-23, military/European time 
         hour_of_day_12 tinyint,                --1-12, repeating for AM/PM, for us American types 
         am_pm char(2),                         --AM/PM 
         minute_of_hour tinyint,                --the minute of the hour, reset at the top of each hour. 0-59 
         half_hour tinyint,                     --1 or 2, if it is the first or second half of the hour 
         half_hour_of_day tinyint,              --1-24, incremented at the top of each half hour for the entire day 
         quarter_hour tinyint,                  --1-4, for each quarter hour 
         quarter_hour_of_day tinyint,           --1-48, incremented at the tope of each half hour for the entire day 
         string_representation_24 char(5),      --military/European textual representation 
         string_representation_12 char(5)       --12 hour clock representation sans AM/PM 
    )
    

    即使您没有真正创建维度模型,这些表也可能有所帮助 .

相关问题