Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
code
pfabric
Commits
0bb43d0b
Commit
0bb43d0b
authored
Dec 19, 2017
by
Kai-Uwe Sattler
Browse files
more aggregate function added to Python
parent
3d470fed
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/python/PyAggregateState.cpp
View file @
0bb43d0b
...
...
@@ -31,9 +31,36 @@ PyAggregateState::PyAggregateState(const std::vector<int>& cols,
case
AggrFuncType
::
IntSum
:
mAggrFuncs
.
push_back
(
new
AggrSum
<
int
>
());
break
;
case
AggrFuncType
::
DoubleSum
:
mAggrFuncs
.
push_back
(
new
AggrSum
<
double
>
());
break
;
case
AggrFuncType
::
Count
:
mAggrFuncs
.
push_back
(
new
AggrCount
<
int
,
int
>
());
break
;
case
AggrFuncType
::
IntAvg
:
mAggrFuncs
.
push_back
(
new
AggrAvg
<
int
,
int
>
());
break
;
case
AggrFuncType
::
DoubleAvg
:
mAggrFuncs
.
push_back
(
new
AggrAvg
<
double
,
double
>
());
break
;
case
AggrFuncType
::
IntMin
:
mAggrFuncs
.
push_back
(
new
AggrMinMax
<
int
,
std
::
less
<
int
>>
());
break
;
case
AggrFuncType
::
DoubleMin
:
mAggrFuncs
.
push_back
(
new
AggrMinMax
<
double
,
std
::
less
<
double
>>
());
break
;
case
AggrFuncType
::
StringMin
:
mAggrFuncs
.
push_back
(
new
AggrMinMax
<
std
::
string
,
std
::
less
<
std
::
string
>>
());
break
;
case
AggrFuncType
::
IntMax
:
mAggrFuncs
.
push_back
(
new
AggrMinMax
<
int
,
std
::
greater
<
int
>>
());
break
;
case
AggrFuncType
::
DoubleMax
:
mAggrFuncs
.
push_back
(
new
AggrMinMax
<
double
,
std
::
greater
<
double
>>
());
break
;
case
AggrFuncType
::
StringMax
:
mAggrFuncs
.
push_back
(
new
AggrMinMax
<
std
::
string
,
std
::
greater
<
std
::
string
>>
());
break
;
}
}
}
...
...
@@ -55,11 +82,69 @@ void PyAggregateState::iterate(const PyTuplePtr& tp,
aggr
->
iterate
(
val
,
outdated
);
break
;
}
case
AggrFuncType
::
DoubleSum
:
{
AggrSum
<
double
>
*
aggr
=
dynamic_cast
<
AggrSum
<
double
>*>
(
state
->
mAggrFuncs
[
i
]);
double
val
=
bp
::
extract
<
double
>
(
tup
[
i
]);
aggr
->
iterate
(
val
,
outdated
);
break
;
}
case
AggrFuncType
::
Count
:
{
AggrCount
<
int
,
int
>
*
aggr
=
dynamic_cast
<
AggrCount
<
int
,
int
>*>
(
state
->
mAggrFuncs
[
i
]);
aggr
->
iterate
(
1
,
outdated
);
break
;
}
case
AggrFuncType
::
IntAvg
:
{
AggrAvg
<
int
,
int
>
*
aggr
=
dynamic_cast
<
AggrAvg
<
int
,
int
>*>
(
state
->
mAggrFuncs
[
i
]);
aggr
->
iterate
(
1
,
outdated
);
break
;
}
case
AggrFuncType
::
DoubleAvg
:
{
AggrAvg
<
double
,
double
>
*
aggr
=
dynamic_cast
<
AggrAvg
<
double
,
double
>*>
(
state
->
mAggrFuncs
[
i
]);
aggr
->
iterate
(
1
,
outdated
);
break
;
}
case
AggrFuncType
::
IntMin
:
{
AggrMinMax
<
int
,
std
::
less
<
int
>>
*
aggr
=
dynamic_cast
<
AggrMinMax
<
int
,
std
::
less
<
int
>>*>
(
state
->
mAggrFuncs
[
i
]);
int
val
=
bp
::
extract
<
int
>
(
tup
[
i
]);
aggr
->
iterate
(
val
,
outdated
);
break
;
}
case
AggrFuncType
::
DoubleMin
:
{
AggrMinMax
<
double
,
std
::
less
<
double
>>
*
aggr
=
dynamic_cast
<
AggrMinMax
<
double
,
std
::
less
<
double
>>*>
(
state
->
mAggrFuncs
[
i
]);
double
val
=
bp
::
extract
<
double
>
(
tup
[
i
]);
aggr
->
iterate
(
val
,
outdated
);
break
;
}
case
AggrFuncType
::
StringMin
:
{
AggrMinMax
<
std
::
string
,
std
::
less
<
std
::
string
>>
*
aggr
=
dynamic_cast
<
AggrMinMax
<
std
::
string
,
std
::
less
<
std
::
string
>>*>
(
state
->
mAggrFuncs
[
i
]);
std
::
string
val
=
bp
::
extract
<
std
::
string
>
(
tup
[
i
]);
aggr
->
iterate
(
val
,
outdated
);
break
;
}
case
AggrFuncType
::
IntMax
:
{
AggrMinMax
<
int
,
std
::
greater
<
int
>>
*
aggr
=
dynamic_cast
<
AggrMinMax
<
int
,
std
::
greater
<
int
>>*>
(
state
->
mAggrFuncs
[
i
]);
int
val
=
bp
::
extract
<
int
>
(
tup
[
i
]);
aggr
->
iterate
(
val
,
outdated
);
break
;
}
case
AggrFuncType
::
DoubleMax
:
{
AggrMinMax
<
double
,
std
::
greater
<
double
>>
*
aggr
=
dynamic_cast
<
AggrMinMax
<
double
,
std
::
greater
<
double
>>*>
(
state
->
mAggrFuncs
[
i
]);
double
val
=
bp
::
extract
<
double
>
(
tup
[
i
]);
aggr
->
iterate
(
val
,
outdated
);
break
;
}
case
AggrFuncType
::
StringMax
:
{
AggrMinMax
<
std
::
string
,
std
::
greater
<
std
::
string
>>
*
aggr
=
dynamic_cast
<
AggrMinMax
<
std
::
string
,
std
::
greater
<
std
::
string
>>*>
(
state
->
mAggrFuncs
[
i
]);
std
::
string
val
=
bp
::
extract
<
std
::
string
>
(
tup
[
i
]);
aggr
->
iterate
(
val
,
outdated
);
break
;
}
}
}
}
...
...
@@ -73,11 +158,62 @@ PyTuplePtr PyAggregateState::finalize(AggrStatePtr state) {
seq
.
append
(
aggr
->
value
());
break
;
}
case
AggrFuncType
::
DoubleSum
:
{
AggrSum
<
double
>
*
aggr
=
dynamic_cast
<
AggrSum
<
double
>*>
(
state
->
mAggrFuncs
[
i
]);
seq
.
append
(
aggr
->
value
());
break
;
}
case
AggrFuncType
::
Count
:
{
AggrCount
<
int
,
int
>
*
aggr
=
dynamic_cast
<
AggrCount
<
int
,
int
>*>
(
state
->
mAggrFuncs
[
i
]);
seq
.
append
(
aggr
->
value
());
break
;
}
case
AggrFuncType
::
IntAvg
:
{
AggrAvg
<
int
,
int
>
*
aggr
=
dynamic_cast
<
AggrAvg
<
int
,
int
>*>
(
state
->
mAggrFuncs
[
i
]);
seq
.
append
(
aggr
->
value
());
break
;
}
case
AggrFuncType
::
DoubleAvg
:
{
AggrAvg
<
double
,
double
>
*
aggr
=
dynamic_cast
<
AggrAvg
<
double
,
double
>*>
(
state
->
mAggrFuncs
[
i
]);
seq
.
append
(
aggr
->
value
());
break
;
}
case
AggrFuncType
::
IntMin
:
{
AggrMinMax
<
int
,
std
::
less
<
int
>>
*
aggr
=
dynamic_cast
<
AggrMinMax
<
int
,
std
::
less
<
int
>>*>
(
state
->
mAggrFuncs
[
i
]);
seq
.
append
(
aggr
->
value
());
break
;
}
case
AggrFuncType
::
DoubleMin
:
{
AggrMinMax
<
double
,
std
::
less
<
double
>>
*
aggr
=
dynamic_cast
<
AggrMinMax
<
double
,
std
::
less
<
double
>>*>
(
state
->
mAggrFuncs
[
i
]);
seq
.
append
(
aggr
->
value
());
break
;
}
case
AggrFuncType
::
StringMin
:
{
AggrMinMax
<
std
::
string
,
std
::
less
<
std
::
string
>>
*
aggr
=
dynamic_cast
<
AggrMinMax
<
std
::
string
,
std
::
less
<
std
::
string
>>*>
(
state
->
mAggrFuncs
[
i
]);
seq
.
append
(
aggr
->
value
());
break
;
}
case
AggrFuncType
::
IntMax
:
{
AggrMinMax
<
int
,
std
::
greater
<
int
>>
*
aggr
=
dynamic_cast
<
AggrMinMax
<
int
,
std
::
greater
<
int
>>*>
(
state
->
mAggrFuncs
[
i
]);
seq
.
append
(
aggr
->
value
());
break
;
}
case
AggrFuncType
::
DoubleMax
:
{
AggrMinMax
<
double
,
std
::
greater
<
double
>>
*
aggr
=
dynamic_cast
<
AggrMinMax
<
double
,
std
::
greater
<
double
>>*>
(
state
->
mAggrFuncs
[
i
]);
seq
.
append
(
aggr
->
value
());
break
;
}
case
AggrFuncType
::
StringMax
:
{
AggrMinMax
<
std
::
string
,
std
::
greater
<
std
::
string
>>
*
aggr
=
dynamic_cast
<
AggrMinMax
<
std
::
string
,
std
::
greater
<
std
::
string
>>*>
(
state
->
mAggrFuncs
[
i
]);
seq
.
append
(
aggr
->
value
());
break
;
}
}
}
return
makeTuplePtr
(
bp
::
object
(
bp
::
tuple
(
seq
)));
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment