Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
data-provider-test.cc
Go to the documentation of this file.
1 // Copyright (c) 2012 Cloudera, Inc. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 
16 #include <stdlib.h>
17 #include <stdio.h>
18 #include <iostream>
19 
21 #include "util/cpu-info.h"
22 #include "runtime/mem-pool.h"
23 #include "runtime/mem-tracker.h"
24 #include "runtime/string-value.h"
25 
26 #include "common/names.h"
27 
28 using namespace impala;
29 
30 // This test will generate 20 rows of data, in all the types supported by the
31 // data provider.
32 int main(int argc, char **argv) {
33 
34  string min_std_str("a");
35  string max_std_str("zzzzzz");
36 
37  StringValue min_str(const_cast<char*>(min_std_str.c_str()), min_std_str.size());
38  StringValue max_str(const_cast<char*>(max_std_str.c_str()), max_std_str.size());
39 
40  vector<DataProvider::ColDesc> cols;
41  cols.push_back(DataProvider::ColDesc::Create<bool>(false, true));
42  cols.push_back(DataProvider::ColDesc::Create<bool>(
43  false, true, DataProvider::SEQUENTIAL));
44  cols.push_back(DataProvider::ColDesc::Create<int8_t>(0, 8));
45  cols.push_back(DataProvider::ColDesc::Create<int8_t>(0, 8, DataProvider::SEQUENTIAL));
46  cols.push_back(DataProvider::ColDesc::Create<int16_t>(8, 16));
47  cols.push_back(DataProvider::ColDesc::Create<int32_t>(16, 32));
48  cols.push_back(DataProvider::ColDesc::Create<int64_t>(32, 64));
49  cols.push_back(DataProvider::ColDesc::Create<float>(-1, 1));
50  cols.push_back(DataProvider::ColDesc::Create<float>(0, 5, DataProvider::SEQUENTIAL));
51  cols.push_back(DataProvider::ColDesc::Create<double>(200, 300));
52  cols.push_back(DataProvider::ColDesc::Create<StringValue>(min_str, max_str));
53 
55  RuntimeProfile profile(&obj_pool, "DataGenTest");
56 
58  MemPool pool(&tracker);
59  DataProvider provider(&pool, &profile);
60  provider.Reset(20, 2, cols);
61  int rows;
62  void* data;
63 
64  cout << "Row size: " << provider.row_size() << endl;
65 
66  while ( (data = provider.NextBatch(&rows)) != NULL) {
67  provider.Print(&cout, reinterpret_cast<char*>(data), rows);
68  }
69 
70  profile.PrettyPrint(&cout);
71 
72  cout << endl << "Done." << endl;
73  return 0;
74 }
void Reset(int num_rows, int batch_size, const std::vector< ColDesc > &columns)
MemTracker tracker
void * NextBatch(int *rows_returned)
See data-provider-test.cc on how to use this.
Definition: data-provider.h:33
ObjectPool * obj_pool()
Returns a local object pool.
Definition: coordinator.h:263
int main(int argc, char **argv)
ObjectPool pool
This class is thread-safe.
Definition: mem-tracker.h:61
void PrettyPrint(std::ostream *s, const std::string &prefix="") const
int row_size() const
The size of a row (tuple size)
void Print(std::ostream *, char *data, int num_rows) const
Print the row data in csv format.