MCPcopy Create free account
hub / github.com/apache/impala / DatabaseTest

Class DatabaseTest

be/src/service/internal-server-test.cc:124–218  ·  view source on GitHub ↗

Helper class to set up a uniquely named database. Not every test will need its own database, thus an instance of this class must be instantiated in every test that needs its own database. Upon construction, instances of this class create a database consisting of the name_prefix parameter with the current time appended. Upon destruction, instances of this class drop cascade the database that was c

Source from the content-addressed store, hash-verified

122//
123// DO NOT provide a value for record_count that is less than 5.
124class DatabaseTest {
125 public:
126 DatabaseTest(shared_ptr<ImpalaServer> impala_server, const string& name_prefix,
127 const bool create_table = false, const int record_count = 5000) {
128 // See the warning on the category_count_ class member definition.
129 EXPECT_LE(category_count_, 11);
130
131 impala_server_ = move(impala_server);
132 database_name_ = StrCat(name_prefix, "_", GetCurrentTimeMicros());
133 TUniqueId query_id;
134 EXPECT_OK(impala_server_->ExecuteIgnoreResults("impala", StrCat("create database ",
135 database_name_, " comment 'Temporary database created and managed by "
136 "internal-server-test'"), {}, false, &query_id));
137 assertQueryState(query_id, QUERY_STATE_SUCCESS);
138
139 if (create_table) {
140 table_name_ = StrCat(database_name_, ".", "products");
141 EXPECT_OK(impala_server_->ExecuteIgnoreResults("impala", StrCat("create table ",
142 table_name_, "(id INT, name STRING, first_sold TIMESTAMP, "
143 "last_sold TIMESTAMP, price DECIMAL(30, 2)) partitioned by (category INT)"),
144 {}, false, &query_id));
145 assertQueryState(query_id, QUERY_STATE_SUCCESS);
146
147 // Insert some products that have a last_sold time.
148 string sql1 = StrCat("insert into ", table_name_ , "(id,category,name,"
149 "first_sold,last_sold,price) values ");
150
151 const int secs_per_year = 31536000; // Seconds in 1 year.
152 for (int i=0; i<record_count; i+=2) {
153 int cat = (i % category_count_) + 1;
154 double price = cat * .01;
155 // Calculate a first sold offset.
156 uint32_t first_sold = secs_per_year * (cat * cat);
157 // Calculate a last sold offset that is a minimum 1 year after first_sold.
158 uint32_t last_sold = first_sold - (secs_per_year * cat);
159 sql1 += StrCat("(", i, ",", cat, ",'prod_", i,
160 "',seconds_sub(now(),", first_sold, "),seconds_sub(now(),", last_sold,
161 "),cast(", price, " as DECIMAL(30, 2)))");
162
163 if (i < record_count - 2) {
164 sql1 += ",";
165 }
166 }
167
168 EXPECT_OK(impala_server_->ExecuteIgnoreResults("impala", sql1, {},
169 false, &query_id));
170 assertQueryState(query_id, QUERY_STATE_SUCCESS);
171
172 // Insert some products that do not have a last_sold time.
173 string sql2 = StrCat("insert into ", table_name_, "(id, category,name,first_sold,"
174 "price) values ");
175
176 for (int i=1; i<record_count; i+=2) {
177 int cat = (i % category_count_) + 1;
178 double price = cat * .01;
179 // Calculate a sold offset.
180 uint32_t sold = secs_per_year * (cat * cat);
181 sql2 += StrCat("(", i, ",", cat, ",'prod_", i,

Callers 1

TESTFunction · 0.85

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.68