Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
2dot5
ClickHouse
提交
0652f9da
C
ClickHouse
项目概览
2dot5
/
ClickHouse
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
ClickHouse
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
0652f9da
编写于
8月 31, 2012
作者:
A
Alexey Milovidov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dbms: development [#CONV-2944].
上级
ec8c0b21
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
92 addition
and
25 deletion
+92
-25
dbms/include/DB/Functions/FunctionsDateTime.h
dbms/include/DB/Functions/FunctionsDateTime.h
+75
-12
dbms/include/DB/IO/WriteHelpers.h
dbms/include/DB/IO/WriteHelpers.h
+2
-2
dbms/src/Functions/FunctionsLibrary.cpp
dbms/src/Functions/FunctionsLibrary.cpp
+4
-0
dbms/src/Storages/StorageMergeTree.cpp
dbms/src/Storages/StorageMergeTree.cpp
+9
-9
libs/libmysqlxx/include/mysqlxx/DateTime.h
libs/libmysqlxx/include/mysqlxx/DateTime.h
+2
-2
未找到文件。
dbms/include/DB/Functions/FunctionsDateTime.h
浏览文件 @
0652f9da
...
...
@@ -13,17 +13,18 @@ namespace DB
/** Функции работы с датой и временем.
*
* toYear, toMonth, toDayOfMonth, toDayOfWeek, toHour, toMinute, toSecond,
* toMonday, toStartOfMonth,
* toMonday, toStartOfMonth,
toStartOfYear, toStartOfMinute, toStartOfHour
* toTime,
* TODO: makeDate, makeDateTime, now, toStartOfMinute, toStartOfHour, toStartOfYear
* now
* TODO: makeDate, makeDateTime
*
* (toDate - расположена в файле FunctionsConversion.h)
*
* Возвращаемые типы:
* toYear -> UInt16
* toMonth, toDayOfMonth, toDayOfWeek, toHour, toMinute, toSecond -> UInt8
* toMonday, toStartOfMonth -> Date
* to
Time
-> DateTime
* toMonday, toStartOfMonth
, toStartOfYear
-> Date
* to
StartOfMinute, toStartOfHour, toTime, now
-> DateTime
*/
struct
ToYearImpl
...
...
@@ -61,7 +62,7 @@ struct ToHourImpl
struct
ToMinuteImpl
{
static
inline
UInt8
execute
(
UInt32
t
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
return
date_lut
.
toMinute
(
t
);
}
static
inline
UInt8
execute
(
UInt32
t
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
return
date_lut
.
toMinute
Inaccurate
(
t
);
}
static
inline
UInt8
execute
(
UInt16
d
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
throw
Exception
(
"Illegal type Date of argument for function toMinute"
,
ErrorCodes
::
ILLEGAL_TYPE_OF_ARGUMENT
);
...
...
@@ -70,7 +71,7 @@ struct ToMinuteImpl
struct
ToSecondImpl
{
static
inline
UInt8
execute
(
UInt32
t
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
return
date_lut
.
toSecond
(
t
);
}
static
inline
UInt8
execute
(
UInt32
t
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
return
date_lut
.
toSecond
Inaccurate
(
t
);
}
static
inline
UInt8
execute
(
UInt16
d
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
throw
Exception
(
"Illegal type Date of argument for function toSecond"
,
ErrorCodes
::
ILLEGAL_TYPE_OF_ARGUMENT
);
...
...
@@ -79,16 +80,23 @@ struct ToSecondImpl
struct
ToMondayImpl
{
static
inline
UInt
32
execute
(
UInt32
t
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
return
date_lut
.
toWeek
(
t
);
}
static
inline
UInt
32
execute
(
UInt16
d
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
return
date_lut
.
to
Week
(
Yandex
::
DayNum_t
(
d
));
}
static
inline
UInt
16
execute
(
UInt32
t
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
return
date_lut
.
toFirstDayNumOfWeek
(
date_lut
.
toDayNum
(
t
)
);
}
static
inline
UInt
16
execute
(
UInt16
d
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
return
date_lut
.
toFirstDayNumOf
Week
(
Yandex
::
DayNum_t
(
d
));
}
};
struct
ToStartOfMonthImpl
{
static
inline
UInt
32
execute
(
UInt32
t
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
return
date_lut
.
toFirstDayOfMonth
(
t
);
}
static
inline
UInt
32
execute
(
UInt16
d
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
return
date_lut
.
toFirstDay
OfMonth
(
Yandex
::
DayNum_t
(
d
));
}
static
inline
UInt
16
execute
(
UInt32
t
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
return
date_lut
.
toFirstDayNumOfMonth
(
date_lut
.
toDayNum
(
t
)
);
}
static
inline
UInt
16
execute
(
UInt16
d
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
return
date_lut
.
toFirstDayNum
OfMonth
(
Yandex
::
DayNum_t
(
d
));
}
};
struct
ToStartOfYearImpl
{
static
inline
UInt16
execute
(
UInt32
t
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
return
date_lut
.
toFirstDayNumOfYear
(
date_lut
.
toDayNum
(
t
));
}
static
inline
UInt16
execute
(
UInt16
d
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
return
date_lut
.
toFirstDayNumOfYear
(
Yandex
::
DayNum_t
(
d
));
}
};
struct
ToTimeImpl
{
/// При переводе во время, дату будем приравнивать к 1970-01-02.
...
...
@@ -99,6 +107,24 @@ struct ToTimeImpl
}
};
struct
ToStartOfMinuteImpl
{
static
inline
UInt32
execute
(
UInt32
t
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
return
date_lut
.
toStartOfMinute
(
t
);
}
static
inline
UInt32
execute
(
UInt16
d
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
throw
Exception
(
"Illegal type Date of argument for function toStartOfMinute"
,
ErrorCodes
::
ILLEGAL_TYPE_OF_ARGUMENT
);
}
};
struct
ToStartOfHourImpl
{
static
inline
UInt32
execute
(
UInt32
t
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
return
date_lut
.
toStartOfHour
(
t
);
}
static
inline
UInt32
execute
(
UInt16
d
,
Yandex
::
DateLUTSingleton
&
date_lut
)
{
throw
Exception
(
"Illegal type Date of argument for function toStartOfHour"
,
ErrorCodes
::
ILLEGAL_TYPE_OF_ARGUMENT
);
}
};
template
<
typename
FromType
,
typename
ToType
,
typename
Transform
,
typename
Name
>
struct
DateTimeTransformImpl
...
...
@@ -169,6 +195,37 @@ public:
};
/// Получить текущее время. (Оно - константа, вычисляется один раз за весь запрос.)
class
FunctionNow
:
public
IFunction
{
public:
/// Получить имя функции.
String
getName
()
const
{
return
"now"
;
}
/// Получить тип результата по типам аргументов. Если функция неприменима для данных аргументов - кинуть исключение.
DataTypePtr
getReturnType
(
const
DataTypes
&
arguments
)
const
{
if
(
arguments
.
size
()
!=
0
)
throw
Exception
(
"Number of arguments for function "
+
getName
()
+
" doesn't match: passed "
+
Poco
::
NumberFormatter
::
format
(
arguments
.
size
())
+
", should be 0."
,
ErrorCodes
::
NUMBER_OF_ARGUMENTS_DOESNT_MATCH
);
return
new
DataTypeDateTime
;
}
/// Выполнить функцию над блоком.
void
execute
(
Block
&
block
,
const
ColumnNumbers
&
arguments
,
size_t
result
)
{
block
.
getByPosition
(
result
).
column
=
new
ColumnConstUInt32
(
block
.
getByPosition
(
0
).
column
->
size
(),
time
(
0
));
}
};
struct
NameToYear
{
static
const
char
*
get
()
{
return
"toYear"
;
}
};
struct
NameToMonth
{
static
const
char
*
get
()
{
return
"toMonth"
;
}
};
struct
NameToDayOfMonth
{
static
const
char
*
get
()
{
return
"toDayOfMonth"
;
}
};
...
...
@@ -178,6 +235,9 @@ struct NameToMinute { static const char * get() { return "toMinute"; } };
struct
NameToSecond
{
static
const
char
*
get
()
{
return
"toSecond"
;
}
};
struct
NameToMonday
{
static
const
char
*
get
()
{
return
"toMonday"
;
}
};
struct
NameToStartOfMonth
{
static
const
char
*
get
()
{
return
"toStartOfMonth"
;
}
};
struct
NameToStartOfYear
{
static
const
char
*
get
()
{
return
"toStartOfYear"
;
}
};
struct
NameToStartOfMinute
{
static
const
char
*
get
()
{
return
"toStartOfMinute"
;
}
};
struct
NameToStartOfHour
{
static
const
char
*
get
()
{
return
"toStartOfHour"
;
}
};
struct
NameToTime
{
static
const
char
*
get
()
{
return
"toTime"
;
}
};
typedef
FunctionDateOrDateTimeToSomething
<
DataTypeUInt16
,
ToYearImpl
,
NameToYear
>
FunctionToYear
;
...
...
@@ -187,8 +247,11 @@ typedef FunctionDateOrDateTimeToSomething<DataTypeUInt8, ToDayOfWeekImpl, NameT
typedef
FunctionDateOrDateTimeToSomething
<
DataTypeUInt8
,
ToHourImpl
,
NameToHour
>
FunctionToHour
;
typedef
FunctionDateOrDateTimeToSomething
<
DataTypeUInt8
,
ToMinuteImpl
,
NameToMinute
>
FunctionToMinute
;
typedef
FunctionDateOrDateTimeToSomething
<
DataTypeUInt8
,
ToSecondImpl
,
NameToSecond
>
FunctionToSecond
;
typedef
FunctionDateOrDateTimeToSomething
<
DataTypeDateTime
,
ToMondayImpl
,
NameToMonday
>
FunctionToMonday
;
typedef
FunctionDateOrDateTimeToSomething
<
DataTypeDateTime
,
ToStartOfMonthImpl
,
NameToStartOfMonth
>
FunctionToStartOfMonth
;
typedef
FunctionDateOrDateTimeToSomething
<
DataTypeDate
,
ToMondayImpl
,
NameToMonday
>
FunctionToMonday
;
typedef
FunctionDateOrDateTimeToSomething
<
DataTypeDate
,
ToStartOfMonthImpl
,
NameToStartOfMonth
>
FunctionToStartOfMonth
;
typedef
FunctionDateOrDateTimeToSomething
<
DataTypeDate
,
ToStartOfYearImpl
,
NameToStartOfYear
>
FunctionToStartOfYear
;
typedef
FunctionDateOrDateTimeToSomething
<
DataTypeDateTime
,
ToStartOfMinuteImpl
,
NameToStartOfMinute
>
FunctionToStartOfMinute
;
typedef
FunctionDateOrDateTimeToSomething
<
DataTypeDateTime
,
ToStartOfHourImpl
,
NameToStartOfHour
>
FunctionToStartOfHour
;
typedef
FunctionDateOrDateTimeToSomething
<
DataTypeDateTime
,
ToTimeImpl
,
NameToTime
>
FunctionToTime
;
}
dbms/include/DB/IO/WriteHelpers.h
浏览文件 @
0652f9da
...
...
@@ -309,8 +309,8 @@ inline void writeDateTimeText(time_t datetime, WriteBuffer & buf)
s
[
9
]
+=
values
.
day_of_month
%
10
;
UInt8
hour
=
date_lut
.
toHourInaccurate
(
datetime
);
UInt8
minute
=
date_lut
.
toMinute
(
datetime
);
UInt8
second
=
date_lut
.
toSecond
(
datetime
);
UInt8
minute
=
date_lut
.
toMinute
Inaccurate
(
datetime
);
UInt8
second
=
date_lut
.
toSecond
Inaccurate
(
datetime
);
s
[
11
]
+=
hour
/
10
;
s
[
12
]
+=
hour
%
10
;
...
...
dbms/src/Functions/FunctionsLibrary.cpp
浏览文件 @
0652f9da
...
...
@@ -83,7 +83,11 @@ namespace FunctionsLibrary
(
"toSecond"
,
new
FunctionToSecond
)
(
"toMonday"
,
new
FunctionToMonday
)
(
"toStartOfMonth"
,
new
FunctionToStartOfMonth
)
(
"toStartOfYear"
,
new
FunctionToStartOfYear
)
(
"toStartOfMinute"
,
new
FunctionToStartOfMinute
)
(
"toStartOfHour"
,
new
FunctionToStartOfHour
)
(
"toTime"
,
new
FunctionToTime
)
(
"now"
,
new
FunctionNow
)
(
"position"
,
new
FunctionPosition
)
(
"positionUTF8"
,
new
FunctionPositionUTF8
)
...
...
dbms/src/Storages/StorageMergeTree.cpp
浏览文件 @
0652f9da
...
...
@@ -80,8 +80,8 @@ public:
typedef
std
::
map
<
UInt16
,
BlockWithDateInterval
>
BlocksByMonth
;
BlocksByMonth
blocks_by_month
;
UInt16
min_month
=
date_lut
.
toFirstDayOfMonth
(
Yandex
::
DayNum_t
(
min_date
));
UInt16
max_month
=
date_lut
.
toFirstDayOfMonth
(
Yandex
::
DayNum_t
(
max_date
));
UInt16
min_month
=
date_lut
.
toFirstDay
Num
OfMonth
(
Yandex
::
DayNum_t
(
min_date
));
UInt16
max_month
=
date_lut
.
toFirstDay
Num
OfMonth
(
Yandex
::
DayNum_t
(
max_date
));
/// Типичный случай - когда месяц один (ничего разделять не нужно).
if
(
min_month
==
max_month
)
...
...
@@ -90,7 +90,7 @@ public:
{
for
(
size_t
i
=
0
;
i
<
rows
;
++
i
)
{
UInt16
month
=
date_lut
.
toFirstDayOfMonth
(
Yandex
::
DayNum_t
(
dates
[
i
]));
UInt16
month
=
date_lut
.
toFirstDay
Num
OfMonth
(
Yandex
::
DayNum_t
(
dates
[
i
]));
BlockWithDateInterval
&
block_for_month
=
blocks_by_month
[
month
];
if
(
!
block_for_month
.
block
)
...
...
@@ -210,8 +210,8 @@ private:
new_data_part
->
name
=
part_name
;
new_data_part
->
size
=
rows
/
storage
.
index_granularity
;
new_data_part
->
modification_time
=
time
(
0
);
new_data_part
->
left_month
=
date_lut
.
toFirstDayOfMonth
(
new_data_part
->
left_date
);
new_data_part
->
right_month
=
date_lut
.
toFirstDayOfMonth
(
new_data_part
->
right_date
);
new_data_part
->
left_month
=
date_lut
.
toFirstDay
Num
OfMonth
(
new_data_part
->
left_date
);
new_data_part
->
right_month
=
date_lut
.
toFirstDay
Num
OfMonth
(
new_data_part
->
right_date
);
storage
.
data_parts
.
insert
(
new_data_part
);
storage
.
all_data_parts
.
insert
(
new_data_part
);
...
...
@@ -1094,8 +1094,8 @@ void StorageMergeTree::loadDataParts()
part
->
modification_time
=
it
->
getLastModified
().
epochTime
();
part
->
left_month
=
date_lut
.
toFirstDayOfMonth
(
part
->
left_date
);
part
->
right_month
=
date_lut
.
toFirstDayOfMonth
(
part
->
right_date
);
part
->
left_month
=
date_lut
.
toFirstDay
Num
OfMonth
(
part
->
left_date
);
part
->
right_month
=
date_lut
.
toFirstDay
Num
OfMonth
(
part
->
right_date
);
data_parts
.
insert
(
part
);
}
...
...
@@ -1367,8 +1367,8 @@ void StorageMergeTree::mergeParts(DataPartPtr left, DataPartPtr right)
new_data_part
->
name
=
getPartName
(
new_data_part
->
left_date
,
new_data_part
->
right_date
,
new_data_part
->
left
,
new_data_part
->
right
,
new_data_part
->
level
);
new_data_part
->
size
=
left
->
size
+
right
->
size
;
new_data_part
->
left_month
=
date_lut
.
toFirstDayOfMonth
(
new_data_part
->
left_date
);
new_data_part
->
right_month
=
date_lut
.
toFirstDayOfMonth
(
new_data_part
->
right_date
);
new_data_part
->
left_month
=
date_lut
.
toFirstDay
Num
OfMonth
(
new_data_part
->
left_date
);
new_data_part
->
right_month
=
date_lut
.
toFirstDay
Num
OfMonth
(
new_data_part
->
right_date
);
/** Читаем из левого и правого куска, сливаем и пишем в новый.
* Попутно вычисляем выражение для сортировки.
...
...
libs/libmysqlxx/include/mysqlxx/DateTime.h
浏览文件 @
0652f9da
...
...
@@ -50,8 +50,8 @@ private:
m_month
=
values
.
month
;
m_day
=
values
.
day_of_month
;
m_hour
=
date_lut
.
toHourInaccurate
(
time
);
m_minute
=
date_lut
.
toMinute
(
time
);
m_second
=
date_lut
.
toSecond
(
time
);
m_minute
=
date_lut
.
toMinute
Inaccurate
(
time
);
m_second
=
date_lut
.
toSecond
Inaccurate
(
time
);
}
void
init
(
const
char
*
s
,
size_t
length
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录