| 124 | class 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, |
| 182 | "',seconds_sub(now(),", sold, "),cast(", price, " as DECIMAL(30, 2)))"); |
| 183 |
nothing calls this directly
no test coverage detected