IODA Bundle
TestAggregateFunctions.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 1996-2012 ECMWF.
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  * In applying this licence, ECMWF does not waive the privileges and immunities
7  * granted to it by virtue of its status as an intergovernmental organisation nor
8  * does it submit to any jurisdiction.
9  */
10 
11 /// \file UnitTest.h
12 ///
13 /// @author Piotr Kuchta, ECMWF, Feb 2009
14 
15 #include "eckit/exception/Exceptions.h"
16 #include "eckit/log/Log.h"
17 #include "odc/core/MetaData.h"
18 #include "odc/Select.h"
19 
20 #include "TestCase.h"
21 
22 using namespace std;
23 using namespace eckit;
24 using namespace odc;
25 
26 static void test()
27 {
28  string sql =
29 "SELECT "
30 " count(*),"
31 " count(lat),"
32 " sum(blacklist.fg_depar@body) as sumfg_depar,"
33 " sum((blacklist.fg_depar@body) * (blacklist.fg_depar@body)) as s2umfg_depar,"
34 " min(blacklist.fg_depar@body) as minfg_depar,"
35 " max(blacklist.fg_depar@body) as maxfg_depar, "
36 " sum(biascorr@body) as sumbiascorr,"
37 " sum((biascorr@body) * (biascorr@body)) as s2umbiascorr,"
38 " min(biascorr@body) as minbiascorr,"
39 " max(biascorr@body) as maxbiascorr,"
40 " sum(blacklist.fg_depar@body + biascorr@body) as sumfgdp_unc,"
41 " sum((blacklist.fg_depar@body + biascorr@body) * (blacklist.fg_depar@body + biascorr@body)) as s2umfgdp_unc,"
42 " min(blacklist.fg_depar@body + biascorr@body) as minfgdp_unc,"
43 " max(blacklist.fg_depar@body + biascorr@body) as maxfgdp_unc,\n"
44 
45 "--obstype@hdr as obstype, varno@body as varno, status@body as status, lldegrees(lat@hdr)<=-20 as latbin0, lldegrees(lat@hdr)<=20 AND lldegrees(lat@hdr)>-20 as latbin1, lldegrees(lat@hdr)>20 as latbin2 \n"
46 
47 "FROM \"2000010106.odb\" "
48 
49 "WHERE (biascorr@body is not NULL and biascorr@body <> 0)"
50 " AND not((obstype@hdr == 10 and obschar.codetype@hdr == 250))"
51 " AND (obstype@hdr in (1,4,8,9) or (obstype@hdr == 7 and (obschar.codetype@hdr == 215 or obschar.codetype@hdr == 206)));"
52 ;
53 
54  Log::info() << "Executing: '" << sql << "'" << std::endl;
55 
56  odc::Select oda(sql);
57  odc::Select::iterator it = oda.begin();
58 
59  //Log::info() << "it->columns().size() => " << it->columns().size() << std::endl;
60  ASSERT(it->columns().size() == 14);
61  ASSERT((*it)[0] == 91119); // COUNT(*) == 91119
62  ASSERT((*it)[1] == 91119); // COUNT(lat) == 91119
63 }
64 
65 
66 
67 static void setUp(){}
68 static void tearDown(){}
69 
70 SIMPLE_TEST(AggregateFunctions)
void oda
static void tearDown()
static void test()
static void setUp()
#define SIMPLE_TEST(name)
Definition: TestCase.h:66
const core::MetaData & columns() const
Definition: IteratorProxy.h:94
Definition: ColumnInfo.h:23
Definition: encode.cc:30