github.com/rohankumardubey/aresdb@v0.0.2-0.20190517170215-e54e3ca06b9c/query/functor_unittest.cu (about) 1 // Copyright (c) 2017-2018 Uber Technologies, Inc. 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 #include <thrust/host_vector.h> 16 #include <thrust/iterator/zip_iterator.h> 17 #include <thrust/transform.h> 18 #include <thrust/tuple.h> 19 #include <thrust/sort.h> 20 #include <thrust/execution_policy.h> 21 #include <algorithm> 22 #include <iterator> 23 #include <tuple> 24 #include "gtest/gtest.h" 25 #include "query/functor.hpp" 26 #include "query/iterator.hpp" 27 #include "query/unittest_utils.hpp" 28 29 extern uint16_t DAYS_BEFORE_MONTH_HOST[13]; 30 31 namespace ares { 32 33 typedef typename thrust::host_vector<UUIDT>::iterator UUIDIter; 34 typedef typename thrust::host_vector<bool>::iterator BoolIter; 35 typedef typename thrust::host_vector<int>::iterator IntIter; 36 typedef typename thrust::host_vector<int16_t>::iterator Int16Iter; 37 typedef typename thrust::host_vector<uint32_t>::iterator Uint32Iter; 38 39 // cppcheck-suppress * 40 TEST(LogicalFunctorTest, TestBool) { 41 bool values1[5] = {false, false, false, true, true}; 42 bool nulls1[5] = {false, true, true, true, true}; 43 bool values2[5] = {false, false, true, false, true}; 44 bool nulls2[5] = {false, true, true, true, true}; 45 46 // output 47 bool outputValues[5]; 48 thrust::fill(std::begin(outputValues), std::end(outputValues), false); 49 50 bool outputNulls[5]; 51 thrust::fill(std::begin(outputNulls), std::end(outputNulls), false); 52 53 typedef thrust::zip_iterator< 54 thrust::tuple<BoolIter, 55 BoolIter> > InputZipIterator; 56 typedef thrust::zip_iterator<thrust::tuple<BoolIter, 57 BoolIter> > OutputZipIterator; 58 59 InputZipIterator 60 begin1(thrust::make_tuple(std::begin(values1), std::begin(nulls1))); 61 InputZipIterator 62 end1(thrust::make_tuple(std::end(values1), std::end(nulls1))); 63 64 InputZipIterator 65 begin2(thrust::make_tuple(std::begin(values2), std::begin(nulls2))); 66 67 OutputZipIterator outputBegin( 68 thrust::make_tuple(std::begin(outputValues), 69 std::begin(outputNulls))); 70 71 // Test AndFunctor 72 thrust::transform(begin1, end1, begin2, outputBegin, 73 AndFunctor()); 74 75 bool expectedValues[5] = {false, false, false, false, true}; 76 bool expectedNulls[5] = {false, true, true, true, true}; 77 78 EXPECT_TRUE( 79 thrust::equal(std::begin(outputValues), std::end(outputValues), 80 std::begin(expectedValues))); 81 EXPECT_TRUE( 82 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 83 std::begin(expectedNulls))); 84 85 // Test OrFunctor 86 thrust::transform(begin1, end1, begin2, outputBegin, OrFunctor()); 87 88 bool expectedValues2[5] = {false, false, true, true, true}; 89 bool expectedNulls2[5] = {false, true, true, true, true}; 90 91 EXPECT_TRUE( 92 thrust::equal(std::begin(outputValues), std::end(outputValues), 93 std::begin(expectedValues2))); 94 EXPECT_TRUE( 95 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 96 std::begin(expectedNulls2))); 97 98 // Test NotFunctor 99 thrust::transform(begin1, end1, outputBegin, NotFunctor()); 100 101 bool expectedValues3[5] = {false, true, true, false, false}; 102 bool expectedNulls3[5] = {false, true, true, true, true}; 103 EXPECT_TRUE( 104 thrust::equal(std::begin(outputValues), std::end(outputValues), 105 std::begin(expectedValues3))); 106 EXPECT_TRUE( 107 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 108 std::begin(expectedNulls3))); 109 } 110 111 // cppcheck-suppress * 112 TEST(LogicalFunctorTest, TestInt) { 113 int values1[5] = {0, 10, 0, 0, 10}; 114 bool nulls1[5] = {false, true, true, true, true}; 115 116 int values2[5] = {0, 0, 10, 0, 10}; 117 bool nulls2[5] = {false, true, true, true, true}; 118 119 // output 120 bool outputValues[5]; 121 thrust::fill(std::begin(outputValues), std::end(outputValues), false); 122 123 bool outputNulls[5]; 124 thrust::fill(std::begin(outputNulls), std::end(outputNulls), false); 125 126 int *valuesBegin1 = &values1[0]; 127 bool *nullsBegin1 = &nulls1[0]; 128 129 int *valuesBegin2 = &values2[0]; 130 bool *nullsBegin2 = &nulls2[0]; 131 132 typedef thrust::zip_iterator< 133 thrust::tuple<IntIter, BoolIter> > InputZipIterator; 134 typedef thrust::zip_iterator<thrust::tuple<BoolIter, 135 BoolIter> > OutputZipIterator; 136 137 InputZipIterator begin1(thrust::make_tuple(valuesBegin1, nullsBegin1)); 138 InputZipIterator end1( 139 thrust::make_tuple(valuesBegin1 + 5, nullsBegin1 + 5)); 140 141 InputZipIterator begin2(thrust::make_tuple(valuesBegin2, nullsBegin2)); 142 143 OutputZipIterator outputBegin( 144 thrust::make_tuple(std::begin(outputValues), 145 std::begin(outputNulls))); 146 147 thrust::transform(begin1, end1, begin2, outputBegin, AndFunctor()); 148 149 bool expectedValues[5] = {false, false, false, false, true}; 150 bool expectedNulls[5] = {false, true, true, true, true}; 151 EXPECT_TRUE( 152 thrust::equal(std::begin(outputValues), std::end(outputValues), 153 std::begin(expectedValues))); 154 EXPECT_TRUE( 155 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 156 std::begin(expectedNulls))); 157 158 // Test OrFunctor 159 thrust::transform(begin1, end1, begin2, outputBegin, OrFunctor()); 160 161 bool expectedValues2[5] = {false, true, true, false, true}; 162 bool expectedNulls2[5] = {false, true, true, true, true}; 163 164 EXPECT_TRUE( 165 thrust::equal(std::begin(outputValues), std::end(outputValues), 166 std::begin(expectedValues2))); 167 EXPECT_TRUE( 168 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 169 std::begin(expectedNulls2))); 170 171 // Test NotFunctor 172 thrust::transform(begin1, end1, outputBegin, NotFunctor()); 173 174 bool expectedValues3[5] = {false, false, true, true, false}; 175 bool expectedNulls3[5] = {false, true, true, true, true}; 176 EXPECT_TRUE( 177 thrust::equal(std::begin(outputValues), std::end(outputValues), 178 std::begin(expectedValues3))); 179 EXPECT_TRUE( 180 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 181 std::begin(expectedNulls3))); 182 } 183 184 // cppcheck-suppress * 185 TEST(LogicalFunctorTest, TestOrFunctor) { 186 OrFunctor f; 187 thrust::tuple<bool, bool> res = f(thrust::make_tuple(true, true), 188 thrust::make_tuple(true, false)); 189 EXPECT_EQ(thrust::get<0>(res), true); 190 EXPECT_EQ(thrust::get<1>(res), true); 191 192 res = f(thrust::make_tuple(false, true), 193 thrust::make_tuple(true, false)); 194 EXPECT_EQ(thrust::get<0>(res), false); 195 EXPECT_EQ(thrust::get<1>(res), false); 196 197 res = f(thrust::make_tuple(false, true), 198 thrust::make_tuple(false, true)); 199 EXPECT_EQ(thrust::get<0>(res), false); 200 EXPECT_EQ(thrust::get<1>(res), true); 201 } 202 203 // cppcheck-suppress * 204 TEST(ComparisonFunctorTest, TestInt) { 205 int values1[5] = {0, 10, 0, 0, 10}; 206 bool nulls1[5] = {false, true, true, true, true}; 207 208 int values2[5] = {0, 0, 10, 0, 10}; 209 bool nulls2[5] = {false, true, true, true, true}; 210 211 // output 212 bool outputValues[5]; 213 thrust::fill(std::begin(outputValues), std::end(outputValues), false); 214 215 bool outputNulls[5]; 216 thrust::fill(std::begin(outputNulls), std::end(outputNulls), false); 217 218 int *valuesBegin1 = &values1[0]; 219 bool *nullsBegin1 = &nulls1[0]; 220 221 int *valuesBegin2 = &values2[0]; 222 bool *nullsBegin2 = &nulls2[0]; 223 224 typedef thrust::zip_iterator< 225 thrust::tuple<IntIter, BoolIter> > InputZipIterator; 226 typedef thrust::zip_iterator<thrust::tuple<BoolIter, 227 BoolIter> > OutputZipIterator; 228 229 InputZipIterator begin1(thrust::make_tuple(valuesBegin1, nullsBegin1)); 230 InputZipIterator end1( 231 thrust::make_tuple(valuesBegin1 + 5, nullsBegin1 + 5)); 232 233 InputZipIterator begin2(thrust::make_tuple(valuesBegin2, nullsBegin2)); 234 235 OutputZipIterator outputBegin( 236 thrust::make_tuple(std::begin(outputValues), 237 std::begin(outputNulls))); 238 239 // Test EqualFunctor 240 thrust::transform(begin1, end1, begin2, outputBegin, 241 EqualFunctor<int>()); 242 243 bool expectedValues[5] = {false, false, false, true, true}; 244 bool expectedNulls[5] = {false, true, true, true, true}; 245 EXPECT_TRUE( 246 thrust::equal(std::begin(outputValues), std::end(outputValues), 247 std::begin(expectedValues))); 248 EXPECT_TRUE( 249 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 250 std::begin(expectedNulls))); 251 252 // Test NotEqualFunctor 253 thrust::transform(begin1, end1, begin2, outputBegin, 254 NotEqualFunctor<int>()); 255 256 bool expectedValues2[5] = {false, true, true, false, false}; 257 bool expectedNulls2[5] = {false, true, true, true, true}; 258 259 EXPECT_TRUE( 260 thrust::equal(std::begin(outputValues), std::end(outputValues), 261 std::begin(expectedValues2))); 262 EXPECT_TRUE( 263 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 264 std::begin(expectedNulls2))); 265 266 // Test LessThanFunctor 267 thrust::transform(begin1, end1, begin2, outputBegin, 268 LessThanFunctor<int>()); 269 bool expectedValues3[5] = {false, false, true, false, false}; 270 bool expectedNulls3[5] = {false, true, true, true, true}; 271 EXPECT_TRUE( 272 thrust::equal(std::begin(outputValues), std::end(outputValues), 273 std::begin(expectedValues3))); 274 EXPECT_TRUE( 275 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 276 std::begin(expectedNulls3))); 277 278 // Test LessThanOrEqualFunctor 279 thrust::transform(begin1, end1, begin2, outputBegin, 280 LessThanOrEqualFunctor<int>()); 281 282 bool expectedValues4[5] = {false, false, true, true, true}; 283 bool expectedNulls4[5] = {false, true, true, true, true}; 284 EXPECT_TRUE( 285 thrust::equal(std::begin(outputValues), std::end(outputValues), 286 std::begin(expectedValues4))); 287 EXPECT_TRUE( 288 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 289 std::begin(expectedNulls4))); 290 291 // Test GreaterThanFunctor 292 thrust::transform(begin1, end1, begin2, outputBegin, 293 GreaterThanFunctor<int>()); 294 295 bool expectedValues5[5] = {false, true, false, false, false}; 296 bool expectedNulls5[5] = {false, true, true, true, true}; 297 EXPECT_TRUE( 298 thrust::equal(std::begin(outputValues), std::end(outputValues), 299 std::begin(expectedValues5))); 300 EXPECT_TRUE( 301 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 302 std::begin(expectedNulls5))); 303 304 // Test GreaterThanOrEqualFunctor 305 thrust::transform(begin1, end1, begin2, outputBegin, 306 GreaterThanOrEqualFunctor<int>()); 307 308 bool expectedValues6[5] = {false, true, false, true, true}; 309 bool expectedNulls6[5] = {false, true, true, true, true}; 310 EXPECT_TRUE( 311 thrust::equal(std::begin(outputValues), std::end(outputValues), 312 std::begin(expectedValues6))); 313 EXPECT_TRUE( 314 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 315 std::begin(expectedNulls6))); 316 } 317 318 // cppcheck-suppress * 319 TEST(ComparisonFunctorTest, TestUpperCast) { 320 int values1[5] = {0, 10, 0, 0x10, 10}; 321 bool nulls1[5] = {false, true, true, true, true}; 322 323 int16_t values2[5] = {0, 0, 10, 0, 10}; 324 bool nulls2[5] = {false, true, true, true, true}; 325 326 // output 327 bool outputValues[5]; 328 thrust::fill(std::begin(outputValues), std::end(outputValues), false); 329 330 bool outputNulls[5]; 331 thrust::fill(std::begin(outputNulls), std::end(outputNulls), false); 332 333 int *valuesBegin1 = &values1[0]; 334 bool *nullsBegin1 = &nulls1[0]; 335 336 int16_t *valuesBegin2 = &values2[0]; 337 bool *nullsBegin2 = &nulls2[0]; 338 339 typedef thrust::zip_iterator< 340 thrust::tuple<IntIter, BoolIter> > InputZipIterator; 341 typedef thrust::zip_iterator< 342 thrust::tuple<Int16Iter, 343 BoolIter> > InputZipIterator2; 344 typedef thrust::zip_iterator<thrust::tuple<BoolIter, 345 BoolIter> > OutputZipIterator; 346 347 InputZipIterator begin1(thrust::make_tuple(valuesBegin1, nullsBegin1)); 348 InputZipIterator end1( 349 thrust::make_tuple(valuesBegin1 + 5, nullsBegin1 + 5)); 350 351 InputZipIterator2 begin2(thrust::make_tuple(valuesBegin2, nullsBegin2)); 352 353 OutputZipIterator outputBegin( 354 thrust::make_tuple(std::begin(outputValues), 355 std::begin(outputNulls))); 356 357 thrust::transform(begin1, end1, begin2, outputBegin, 358 GreaterThanFunctor<int>()); 359 360 bool expectedValues[5] = {false, true, false, true, false}; 361 bool expectedNulls[5] = {false, true, true, true, true}; 362 EXPECT_TRUE( 363 thrust::equal(std::begin(outputValues), std::end(outputValues), 364 std::begin(expectedValues))); 365 EXPECT_TRUE( 366 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 367 std::begin(expectedNulls))); 368 } 369 370 // cppcheck-suppress * 371 TEST(ArithmeticFunctorTest, TestInt) { 372 int values1[5] = {0, 10, 0, 0, 10}; 373 bool nulls1[5] = {false, true, true, true, true}; 374 375 int values2[5] = {0, 1, 10, 1, 10}; 376 bool nulls2[5] = {false, true, true, true, true}; 377 // output 378 int outputValues[5]; 379 thrust::fill(std::begin(outputValues), std::end(outputValues), 0); 380 381 bool outputNulls[5]; 382 thrust::fill(std::begin(outputNulls), std::end(outputNulls), false); 383 384 int *valuesBegin1 = &values1[0]; 385 bool *nullsBegin1 = &nulls1[0]; 386 387 int *valuesBegin2 = &values2[0]; 388 bool *nullsBegin2 = &nulls2[0]; 389 390 typedef thrust::zip_iterator< 391 thrust::tuple<IntIter, BoolIter> > InputZipIterator; 392 typedef thrust::zip_iterator<thrust::tuple<IntIter, 393 BoolIter> > OutputZipIterator; 394 395 InputZipIterator begin1(thrust::make_tuple(valuesBegin1, nullsBegin1)); 396 InputZipIterator end1( 397 thrust::make_tuple(valuesBegin1 + 5, nullsBegin1 + 5)); 398 399 InputZipIterator begin2(thrust::make_tuple(valuesBegin2, nullsBegin2)); 400 401 OutputZipIterator outputBegin( 402 thrust::make_tuple(std::begin(outputValues), 403 std::begin(outputNulls))); 404 405 // Test PlusFunctor 406 thrust::transform(begin1, end1, begin2, outputBegin, 407 PlusFunctor<int>()); 408 409 int expectedValues[5] = {0, 11, 10, 1, 20}; 410 bool expectedNulls[5] = {false, true, true, true, true}; 411 EXPECT_TRUE( 412 thrust::equal(std::begin(outputValues), std::end(outputValues), 413 std::begin(expectedValues))); 414 EXPECT_TRUE( 415 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 416 std::begin(expectedNulls))); 417 418 // Test MinusFunctor 419 thrust::transform(begin1, end1, begin2, outputBegin, 420 MinusFunctor<int>()); 421 422 int expectedValues2[5] = {0, 9, -10, -1, 0}; 423 bool expectedNulls2[5] = {false, true, true, true, true}; 424 425 EXPECT_TRUE( 426 thrust::equal(std::begin(outputValues), std::end(outputValues), 427 std::begin(expectedValues2))); 428 EXPECT_TRUE( 429 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 430 std::begin(expectedNulls2))); 431 432 // Test MutiplyFunctor 433 thrust::transform(begin1, end1, begin2, outputBegin, 434 MultiplyFunctor<int>()); 435 int expectedValues3[5] = {0, 10, 0, 0, 100}; 436 bool expectedNulls3[5] = {false, true, true, true, true}; 437 EXPECT_TRUE( 438 thrust::equal(std::begin(outputValues), std::end(outputValues), 439 std::begin(expectedValues3))); 440 EXPECT_TRUE( 441 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 442 std::begin(expectedNulls3))); 443 444 // Test DivideFunctor 445 thrust::transform(begin1, end1, begin2, outputBegin, 446 DivideFunctor<int>()); 447 int expectedValues4[5] = {0, 10, 0, 0, 1}; 448 bool expectedNulls4[5] = {false, true, true, true, true}; 449 EXPECT_TRUE( 450 thrust::equal(std::begin(outputValues), std::end(outputValues), 451 std::begin(expectedValues4))); 452 EXPECT_TRUE( 453 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 454 std::begin(expectedNulls4))); 455 456 // Test ModFunctor 457 thrust::transform(begin1, end1, begin2, outputBegin, ModFunctor<int>()); 458 int expectedValues5[5] = {0, 0, 0, 0, 0}; 459 bool expectedNulls5[5] = {false, true, true, true, true}; 460 EXPECT_TRUE( 461 thrust::equal(std::begin(outputValues), std::end(outputValues), 462 std::begin(expectedValues5))); 463 EXPECT_TRUE( 464 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 465 std::begin(expectedNulls5))); 466 467 // Test NegateFunctor 468 thrust::transform(begin1, end1, outputBegin, NegateFunctor<int>()); 469 int expectedValues6[5] = {0, -10, 0, 0, -10}; 470 bool expectedNulls6[5] = {false, true, true, true, true}; 471 EXPECT_TRUE( 472 thrust::equal(std::begin(outputValues), std::end(outputValues), 473 std::begin(expectedValues6))); 474 EXPECT_TRUE( 475 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 476 std::begin(expectedNulls6))); 477 478 // Test FloorFunctor 479 thrust::transform(begin1, end1, begin2, outputBegin, FloorFunctor<int>()); 480 int expectedValues7[5] = {0, 10, 0, 0, 10}; 481 bool expectedNulls7[5] = {false, true, true, true, true}; 482 EXPECT_TRUE( 483 thrust::equal(std::begin(outputValues), std::end(outputValues), 484 std::begin(expectedValues7))); 485 EXPECT_TRUE( 486 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 487 std::begin(expectedNulls7))); 488 } 489 490 // cppcheck-suppress * 491 TEST(BitwiseFunctorTest, TestInt) { 492 int values1[5] = {0, 0xF0, 0x0F, 0x00, 0x00}; 493 bool nulls1[5] = {false, true, true, true, true}; 494 495 int values2[5] = {0, 0x00, 0x0F, 0xF0, 0x00}; 496 bool nulls2[5] = {false, true, true, true, true}; 497 498 // output 499 int outputValues[5]; 500 thrust::fill(std::begin(outputValues), std::end(outputValues), 0); 501 502 bool outputNulls[5]; 503 thrust::fill(std::begin(outputNulls), std::end(outputNulls), false); 504 505 int *valuesBegin1 = &values1[0]; 506 bool *nullsBegin1 = &nulls1[0]; 507 508 int *valuesBegin2 = &values2[0]; 509 bool *nullsBegin2 = &nulls2[0]; 510 511 typedef thrust::zip_iterator< 512 thrust::tuple<IntIter, BoolIter> > InputZipIterator; 513 typedef thrust::zip_iterator<thrust::tuple<IntIter, 514 BoolIter> > OutputZipIterator; 515 516 InputZipIterator begin1(thrust::make_tuple(valuesBegin1, nullsBegin1)); 517 InputZipIterator end1( 518 thrust::make_tuple(valuesBegin1 + 5, nullsBegin1 + 5)); 519 520 InputZipIterator begin2(thrust::make_tuple(valuesBegin2, nullsBegin2)); 521 522 OutputZipIterator outputBegin( 523 thrust::make_tuple(std::begin(outputValues), 524 std::begin(outputNulls))); 525 526 // Test BitwiseAndFunctor 527 thrust::transform(begin1, end1, begin2, outputBegin, 528 BitwiseAndFunctor<int>()); 529 530 int expectedValues[5] = {0, 0x00, 0x0F, 0x00, 0x00}; 531 bool expectedNulls[5] = {false, true, true, true, true}; 532 EXPECT_TRUE( 533 thrust::equal(std::begin(outputValues), std::end(outputValues), 534 std::begin(expectedValues))); 535 EXPECT_TRUE( 536 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 537 std::begin(expectedNulls))); 538 539 // Test BitwiseOrFunctor 540 thrust::transform(begin1, end1, begin2, outputBegin, 541 BitwiseOrFunctor<int>()); 542 543 int expectedValues2[5] = {0, 0xF0, 0x0F, 0xF0, 0x00}; 544 bool expectedNulls2[5] = {false, true, true, true, true}; 545 EXPECT_TRUE( 546 thrust::equal(std::begin(outputValues), std::end(outputValues), 547 std::begin(expectedValues2))); 548 EXPECT_TRUE( 549 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 550 std::begin(expectedNulls2))); 551 552 // Test BitwiseXorFunctor 553 thrust::transform(begin1, end1, begin2, outputBegin, 554 BitwiseXorFunctor<int>()); 555 556 int expectedValues3[5] = {0, 0xF0, 0x00, 0xF0, 0x00}; 557 bool expectedNulls3[5] = {false, true, true, true, true}; 558 EXPECT_TRUE( 559 thrust::equal(std::begin(outputValues), std::end(outputValues), 560 std::begin(expectedValues3))); 561 EXPECT_TRUE( 562 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 563 std::begin(expectedNulls3))); 564 565 // Test BitwiseNotFunctor 566 thrust::transform(begin1, end1, outputBegin, BitwiseNotFunctor<int>()); 567 568 int expectedValues4[5] = {0, static_cast<int>(0xFFFFFF0F), 569 static_cast<int>(0xFFFFFFF0), 570 static_cast<int>(0xFFFFFFFF), 571 static_cast<int>(0xFFFFFFFF)}; 572 bool expectedNulls4[5] = {false, true, true, true, true}; 573 EXPECT_TRUE( 574 thrust::equal(std::begin(outputValues), std::end(outputValues), 575 std::begin(expectedValues4))); 576 EXPECT_TRUE( 577 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 578 std::begin(expectedNulls4))); 579 } 580 581 // cppcheck-suppress * 582 TEST(MiscFunctorTest, TestInt) { 583 int values1[5] = {0, 0, 0, 0, 0}; 584 bool nulls1[5] = {true, true, true, true, false}; 585 586 // output 587 int outputValues[5]; 588 thrust::fill(std::begin(outputValues), std::end(outputValues), 0); 589 590 bool outputNulls[5]; 591 thrust::fill(std::begin(outputNulls), std::end(outputNulls), false); 592 593 int *valuesBegin1 = &values1[0]; 594 bool *nullsBegin1 = &nulls1[0]; 595 596 typedef thrust::zip_iterator< 597 thrust::tuple<IntIter, BoolIter> > InputZipIterator; 598 typedef thrust::zip_iterator<thrust::tuple<IntIter, 599 BoolIter> > OutputZipIterator; 600 601 InputZipIterator begin1(thrust::make_tuple(valuesBegin1, nullsBegin1)); 602 InputZipIterator end1( 603 thrust::make_tuple(valuesBegin1 + 5, nullsBegin1 + 5)); 604 605 OutputZipIterator outputBegin( 606 thrust::make_tuple(std::begin(outputValues), 607 std::begin(outputNulls))); 608 609 // Test IsNullFunctor 610 thrust::transform(begin1, end1, outputBegin, IsNullFunctor()); 611 612 int expectedValues[5] = {0, 0, 0, 0, 1}; 613 bool expectedNulls[5] = {true, true, true, true, true}; 614 EXPECT_TRUE( 615 thrust::equal(std::begin(outputValues), std::end(outputValues), 616 std::begin(expectedValues))); 617 EXPECT_TRUE( 618 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 619 std::begin(expectedNulls))); 620 621 // Test IsNotNullFunctor 622 thrust::transform(begin1, end1, outputBegin, IsNotNullFunctor()); 623 624 int expectedValues2[5] = {1, 1, 1, 1, 0}; 625 bool expectedNulls2[5] = {true, true, true, true, true}; 626 EXPECT_TRUE( 627 thrust::equal(std::begin(outputValues), std::end(outputValues), 628 std::begin(expectedValues2))); 629 EXPECT_TRUE( 630 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 631 std::begin(expectedNulls2))); 632 633 // Test NoopFunctor 634 thrust::transform(begin1, end1, outputBegin, NoopFunctor<int>()); 635 int expectedValues3[5] = {0, 0, 0, 0, 0}; 636 bool expectedNulls3[5] = {true, true, true, true, false}; 637 638 EXPECT_TRUE( 639 thrust::equal(std::begin(outputValues), std::end(outputValues), 640 std::begin(expectedValues3))); 641 EXPECT_TRUE( 642 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 643 std::begin(expectedNulls3))); 644 } 645 646 // cppcheck-suppress * 647 TEST(RemoveFilterTest, CheckRemoveFilter) { 648 uint8_t predicates[5] = {1, 1, 1, 1, 0}; 649 RemoveFilter<thrust::tuple<uint32_t, uint32_t>, uint8_t> f(&predicates[0]); 650 651 EXPECT_FALSE(f(thrust::make_tuple(0, 0))); 652 EXPECT_FALSE(f(thrust::make_tuple(1, 0))); 653 EXPECT_FALSE(f(thrust::make_tuple(2, 0))); 654 EXPECT_FALSE(f(thrust::make_tuple(3, 0))); 655 EXPECT_TRUE(f(thrust::make_tuple(4, 0))); 656 } 657 658 // cppcheck-suppress * 659 TEST(UnaryFunctorTest, CheckUnaryFunctor) { 660 int values1[5] = {0, 0, 0, 0, 0}; 661 bool nulls1[5] = {true, true, true, true, false}; 662 663 // output 664 int outputValues[5]; 665 thrust::fill(std::begin(outputValues), std::end(outputValues), 0); 666 667 bool outputNulls[5]; 668 thrust::fill(std::begin(outputNulls), std::end(outputNulls), false); 669 670 int *valuesBegin1 = &values1[0]; 671 bool *nullsBegin1 = &nulls1[0]; 672 673 typedef thrust::zip_iterator< 674 thrust::tuple<IntIter, BoolIter> > InputZipIterator; 675 typedef thrust::zip_iterator< 676 thrust::tuple<IntIter, BoolIter> > OutputZipIterator; 677 678 InputZipIterator begin1(thrust::make_tuple(valuesBegin1, nullsBegin1)); 679 OutputZipIterator outputBegin( 680 thrust::make_tuple(std::begin(outputValues), 681 std::begin(outputNulls))); 682 683 thrust::transform(begin1, begin1 + 5, outputBegin, 684 UnaryFunctor<int, int>(IsNull)); 685 686 int expectedValues[5] = {0, 0, 0, 0, 1}; 687 bool expectedNulls[5] = {true, true, true, true, true}; 688 EXPECT_TRUE( 689 thrust::equal(std::begin(outputValues), std::end(outputValues), 690 std::begin(expectedValues))); 691 EXPECT_TRUE( 692 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 693 std::begin(expectedNulls))); 694 } 695 696 // cppcheck-suppress * 697 TEST(BinaryFunctorTest, CheckBinaryFunctor) { 698 int values1[5] = {0, 0xF0, 0x0F, 0x00, 0x00}; 699 bool nulls1[5] = {false, true, true, true, true}; 700 701 int values2[5] = {0, 0x00, 0x0F, 0xF0, 0x00}; 702 bool nulls2[5] = {false, true, true, true, true}; 703 704 // output 705 int outputValues[5]; 706 thrust::fill(std::begin(outputValues), std::end(outputValues), 0); 707 708 bool outputNulls[5]; 709 thrust::fill(std::begin(outputNulls), std::end(outputNulls), false); 710 711 int *valuesBegin1 = &values1[0]; 712 bool *nullsBegin1 = &nulls1[0]; 713 714 int *valuesBegin2 = &values2[0]; 715 bool *nullsBegin2 = &nulls2[0]; 716 717 typedef thrust::zip_iterator< 718 thrust::tuple<IntIter, BoolIter> > InputZipIterator; 719 typedef thrust::zip_iterator< 720 thrust::tuple<IntIter, BoolIter> > OutputZipIterator; 721 722 InputZipIterator begin1(thrust::make_tuple(valuesBegin1, nullsBegin1)); 723 InputZipIterator begin2(thrust::make_tuple(valuesBegin2, nullsBegin2)); 724 725 OutputZipIterator outputBegin( 726 thrust::make_tuple(std::begin(outputValues), 727 std::begin(outputNulls))); 728 729 // Test BitwiseAndFunctor 730 thrust::transform(begin1, begin1 + 5, begin2, outputBegin, 731 BinaryFunctor<int, int>(BitwiseAnd)); 732 733 int expectedValues[5] = {0, 0x00, 0x0F, 0x00, 0x00}; 734 bool expectedNulls[5] = {false, true, true, true, true}; 735 EXPECT_TRUE( 736 thrust::equal(std::begin(outputValues), std::end(outputValues), 737 std::begin(expectedValues))); 738 EXPECT_TRUE( 739 thrust::equal(std::begin(outputNulls), std::end(outputNulls), 740 std::begin(expectedNulls))); 741 } 742 743 // cppcheck-suppress * 744 TEST(BinaryPredicateFunctorTest, CheckBinaryTranformFunctor) { 745 int values1[5] = {100, 1, 200, 0, 1}; 746 bool nulls1[5] = {false, true, true, true, true}; 747 748 int values2[5] = {0, 1, 1, 0, 100}; 749 bool nulls2[5] = {false, true, true, true, true}; 750 751 // output 752 bool outputValues[5]; 753 thrust::fill(std::begin(outputValues), std::end(outputValues), 0); 754 755 int *valuesBegin1 = &values1[0]; 756 bool *nullsBegin1 = &nulls1[0]; 757 758 int *valuesBegin2 = &values2[0]; 759 bool *nullsBegin2 = &nulls2[0]; 760 761 typedef thrust::zip_iterator< 762 thrust::tuple<IntIter, BoolIter> > InputZipIterator; 763 typedef thrust::zip_iterator< 764 thrust::tuple<InputZipIterator, 765 InputZipIterator> > ZipOfInputZipIterator; 766 typedef thrust::zip_iterator<thrust::tuple<IntIter, 767 BoolIter> > OutputZipIterator; 768 769 InputZipIterator begin1(thrust::make_tuple(valuesBegin1, nullsBegin1)); 770 InputZipIterator begin2(thrust::make_tuple(valuesBegin2, nullsBegin2)); 771 772 // Test BitwiseAndFunctor 773 thrust::transform(begin1, begin1 + 5, begin2, &outputValues[0], 774 BinaryPredicateFunctor<bool, int>(And)); 775 776 bool expectedValues[5] = {0, 1, 1, 0, 1}; 777 EXPECT_TRUE( 778 thrust::equal(std::begin(outputValues), std::end(outputValues), 779 std::begin(expectedValues))); 780 } 781 782 TEST(HashLookupFunctorTest, CheckHashLookupFunctor) { 783 // hash index created in golang cuckoo_hash_index 784 uint32_t seeds[4] = {2596996162, 4039455774, 2854263694, 1879968118}; 785 uint8_t buckets[312] = { 786 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 787 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 5, 0, 788 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 17, 789 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 0, 0, 790 12, 0, 0, 0, 140, 236, 116, 56, 157, 195, 184, 133, 16, 0, 0, 791 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 6, 0, 792 0, 0, 17, 0, 0, 0, 11, 0, 0, 0, 12, 0, 0, 0, 0, 793 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 794 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0, 0, 9, 0, 0, 795 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 10, 0, 796 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 0, 2, 797 0, 0, 0, 121, 236, 209, 218, 160, 185, 109, 187, 0, 0, 0, 0, 798 8, 0, 0, 0, 15, 0, 0, 0, 9, 0, 0, 0, 1, 0, 0, 799 0, 10, 0, 0, 0, 14, 0, 0, 0, 2, 0, 0, 0, 0, 0, 800 0, 0, 13, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 801 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 802 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 803 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 804 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 13, 0, 0, 0, 7, 805 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 806 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 807 int keyBytes = 4; 808 int numHashes = 4; 809 int numBuckets = 2; 810 811 uint32_t keys[18] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 812 9, 10, 11, 12, 13, 14, 15, 16, 17}; 813 bool nulls[18]; 814 thrust::fill(std::begin(nulls), std::end(nulls), true); 815 bool *nullsBegin = &nulls[0]; 816 817 HashLookupFunctor<uint32_t> lookupFunctor(buckets, seeds, keyBytes, numHashes, 818 numBuckets); 819 RecordID outputValues[18]; 820 typedef typename thrust::host_vector<RecordID>::iterator RecordIDIter; 821 typedef thrust::zip_iterator<thrust::tuple<Uint32Iter, BoolIter> > 822 InputZipIterator; 823 824 InputZipIterator inputBegin(thrust::make_tuple(std::begin(keys), nullsBegin)); 825 thrust::transform(inputBegin, inputBegin + 18, std::begin(outputValues), 826 lookupFunctor); 827 828 for (int i = 0; i < 18; i++) { 829 EXPECT_EQ(outputValues[i].batchID, 0); 830 EXPECT_EQ(outputValues[i].index, i); 831 } 832 } 833 834 // cppcheck-suppress * 835 TEST(ResolveTimeBucketizerTest, CheckTimeSeriesBucketizer) { 836 // works for epoch time. 837 uint32_t ts = get_ts(1970, 1, 1); 838 uint32_t yearStart = resolveTimeBucketizer(ts, YEAR, DAYS_BEFORE_MONTH_HOST); 839 EXPECT_EQ(yearStart, get_ts(1970, 1, 1)); 840 841 uint32_t 842 quarterStart = resolveTimeBucketizer(ts, QUATER, DAYS_BEFORE_MONTH_HOST); 843 EXPECT_EQ(quarterStart, get_ts(1970, 1, 1)); 844 845 uint32_t 846 monthStart = resolveTimeBucketizer(ts, MONTH, DAYS_BEFORE_MONTH_HOST); 847 EXPECT_EQ(monthStart, get_ts(1970, 1, 1)); 848 849 /* 1970-01-31 */ 850 ts = get_ts(1970, 1, 31); 851 yearStart = resolveTimeBucketizer(ts, YEAR, DAYS_BEFORE_MONTH_HOST); 852 EXPECT_EQ(yearStart, get_ts(1970, 1, 1)); 853 854 quarterStart = resolveTimeBucketizer(ts, QUATER, DAYS_BEFORE_MONTH_HOST); 855 EXPECT_EQ(quarterStart, get_ts(1970, 1, 1)); 856 857 monthStart = resolveTimeBucketizer(ts, MONTH, DAYS_BEFORE_MONTH_HOST); 858 EXPECT_EQ(monthStart, get_ts(1970, 1, 1)); 859 860 /* 1970-01-30 */ 861 ts = get_ts(1970, 1, 30); 862 yearStart = resolveTimeBucketizer(ts, YEAR, DAYS_BEFORE_MONTH_HOST); 863 EXPECT_EQ(yearStart, get_ts(1970, 1, 1)); 864 865 quarterStart = resolveTimeBucketizer(ts, QUATER, DAYS_BEFORE_MONTH_HOST); 866 EXPECT_EQ(quarterStart, get_ts(1970, 1, 1)); 867 868 monthStart = resolveTimeBucketizer(ts, MONTH, DAYS_BEFORE_MONTH_HOST); 869 EXPECT_EQ(monthStart, get_ts(1970, 1, 1)); 870 871 /* 1970-02-01 */ 872 ts = get_ts(1970, 2, 1); 873 yearStart = resolveTimeBucketizer(ts, YEAR, DAYS_BEFORE_MONTH_HOST); 874 EXPECT_EQ(yearStart, get_ts(1970, 1, 1)); 875 876 quarterStart = resolveTimeBucketizer(ts, QUATER, DAYS_BEFORE_MONTH_HOST); 877 EXPECT_EQ(quarterStart, get_ts(1970, 1, 1)); 878 879 monthStart = resolveTimeBucketizer(ts, MONTH, DAYS_BEFORE_MONTH_HOST); 880 EXPECT_EQ(monthStart, get_ts(1970, 2, 1)); 881 882 /* 1970-02-28 */ 883 ts = get_ts(1970, 2, 28); 884 yearStart = resolveTimeBucketizer(ts, YEAR, DAYS_BEFORE_MONTH_HOST); 885 EXPECT_EQ(yearStart, get_ts(1970, 1, 1)); 886 887 quarterStart = resolveTimeBucketizer(ts, QUATER, DAYS_BEFORE_MONTH_HOST); 888 EXPECT_EQ(quarterStart, get_ts(1970, 1, 1)); 889 890 monthStart = resolveTimeBucketizer(ts, MONTH, DAYS_BEFORE_MONTH_HOST); 891 EXPECT_EQ(monthStart, get_ts(1970, 2, 1)); 892 893 /* 1970-03-01 */ 894 ts = get_ts(1970, 3, 1); 895 yearStart = resolveTimeBucketizer(ts, YEAR, DAYS_BEFORE_MONTH_HOST); 896 EXPECT_EQ(yearStart, get_ts(1970, 1, 1)); 897 898 quarterStart = resolveTimeBucketizer(ts, QUATER, DAYS_BEFORE_MONTH_HOST); 899 EXPECT_EQ(quarterStart, get_ts(1970, 1, 1)); 900 901 monthStart = resolveTimeBucketizer(ts, MONTH, DAYS_BEFORE_MONTH_HOST); 902 EXPECT_EQ(monthStart, get_ts(1970, 3, 1)); 903 904 /* 1970-04-01 */ 905 ts = get_ts(1970, 4, 1); 906 yearStart = resolveTimeBucketizer(ts, YEAR, DAYS_BEFORE_MONTH_HOST); 907 EXPECT_EQ(yearStart, get_ts(1970, 1, 1)); 908 909 quarterStart = resolveTimeBucketizer(ts, QUATER, DAYS_BEFORE_MONTH_HOST); 910 EXPECT_EQ(quarterStart, get_ts(1970, 4, 1)); 911 912 monthStart = resolveTimeBucketizer(ts, MONTH, DAYS_BEFORE_MONTH_HOST); 913 EXPECT_EQ(monthStart, get_ts(1970, 4, 1)); 914 915 /* 1970-05-01 */ 916 ts = get_ts(1970, 5, 1); 917 yearStart = resolveTimeBucketizer(ts, YEAR, DAYS_BEFORE_MONTH_HOST); 918 EXPECT_EQ(yearStart, get_ts(1970, 1, 1)); 919 920 quarterStart = resolveTimeBucketizer(ts, QUATER, DAYS_BEFORE_MONTH_HOST); 921 EXPECT_EQ(quarterStart, get_ts(1970, 4, 1)); 922 923 monthStart = resolveTimeBucketizer(ts, MONTH, DAYS_BEFORE_MONTH_HOST); 924 EXPECT_EQ(monthStart, get_ts(1970, 5, 1)); 925 926 /* 1970-09-01 */ 927 ts = get_ts(1970, 9, 1); 928 yearStart = resolveTimeBucketizer(ts, YEAR, DAYS_BEFORE_MONTH_HOST); 929 EXPECT_EQ(yearStart, get_ts(1970, 1, 1)); 930 931 quarterStart = resolveTimeBucketizer(ts, QUATER, DAYS_BEFORE_MONTH_HOST); 932 EXPECT_EQ(quarterStart, get_ts(1970, 7, 1)); 933 934 monthStart = resolveTimeBucketizer(ts, MONTH, DAYS_BEFORE_MONTH_HOST); 935 EXPECT_EQ(monthStart, get_ts(1970, 9, 1)); 936 937 /* 1970-12-31 */ 938 ts = get_ts(1970, 12, 31); 939 yearStart = resolveTimeBucketizer(ts, YEAR, DAYS_BEFORE_MONTH_HOST); 940 EXPECT_EQ(yearStart, get_ts(1970, 1, 1)); 941 942 quarterStart = resolveTimeBucketizer(ts, QUATER, DAYS_BEFORE_MONTH_HOST); 943 EXPECT_EQ(quarterStart, get_ts(1970, 10, 1)); 944 945 monthStart = resolveTimeBucketizer(ts, MONTH, DAYS_BEFORE_MONTH_HOST); 946 EXPECT_EQ(monthStart, get_ts(1970, 12, 1)); 947 948 /* 1971-01-01 */ 949 ts = get_ts(1971, 1, 1); 950 yearStart = resolveTimeBucketizer(ts, YEAR, DAYS_BEFORE_MONTH_HOST); 951 EXPECT_EQ(yearStart, get_ts(1971, 1, 1)); 952 953 quarterStart = resolveTimeBucketizer(ts, QUATER, DAYS_BEFORE_MONTH_HOST); 954 EXPECT_EQ(quarterStart, get_ts(1971, 1, 1)); 955 956 monthStart = resolveTimeBucketizer(ts, MONTH, DAYS_BEFORE_MONTH_HOST); 957 EXPECT_EQ(monthStart, get_ts(1971, 1, 1)); 958 959 /* 1971-06-01 */ 960 ts = get_ts(1971, 6, 1); 961 yearStart = resolveTimeBucketizer(ts, YEAR, DAYS_BEFORE_MONTH_HOST); 962 EXPECT_EQ(yearStart, get_ts(1971, 1, 1)); 963 964 quarterStart = resolveTimeBucketizer(ts, QUATER, DAYS_BEFORE_MONTH_HOST); 965 EXPECT_EQ(quarterStart, get_ts(1971, 4, 1)); 966 967 monthStart = resolveTimeBucketizer(ts, MONTH, DAYS_BEFORE_MONTH_HOST); 968 EXPECT_EQ(monthStart, get_ts(1971, 6, 1)); 969 970 // leap year. 971 /* 1972-01-01 */ 972 ts = get_ts(1972, 1, 1); 973 yearStart = resolveTimeBucketizer(ts, YEAR, DAYS_BEFORE_MONTH_HOST); 974 EXPECT_EQ(yearStart, get_ts(1972, 1, 1)); 975 976 quarterStart = resolveTimeBucketizer(ts, QUATER, DAYS_BEFORE_MONTH_HOST); 977 EXPECT_EQ(quarterStart, get_ts(1972, 1, 1)); 978 979 monthStart = resolveTimeBucketizer(ts, MONTH, DAYS_BEFORE_MONTH_HOST); 980 EXPECT_EQ(monthStart, get_ts(1972, 1, 1)); 981 982 /* 1972-02-29 */ 983 ts = get_ts(1972, 2, 29); 984 yearStart = resolveTimeBucketizer(ts, YEAR, DAYS_BEFORE_MONTH_HOST); 985 EXPECT_EQ(yearStart, get_ts(1972, 1, 1)); 986 987 quarterStart = resolveTimeBucketizer(ts, QUATER, DAYS_BEFORE_MONTH_HOST); 988 EXPECT_EQ(quarterStart, get_ts(1972, 1, 1)); 989 990 monthStart = resolveTimeBucketizer(ts, MONTH, DAYS_BEFORE_MONTH_HOST); 991 EXPECT_EQ(monthStart, get_ts(1972, 2, 1)); 992 993 /* 1972-03-01 */ 994 ts = get_ts(1972, 3, 1); 995 yearStart = resolveTimeBucketizer(ts, YEAR, DAYS_BEFORE_MONTH_HOST); 996 EXPECT_EQ(yearStart, get_ts(1972, 1, 1)); 997 998 quarterStart = resolveTimeBucketizer(ts, QUATER, DAYS_BEFORE_MONTH_HOST); 999 EXPECT_EQ(quarterStart, get_ts(1972, 1, 1)); 1000 1001 monthStart = resolveTimeBucketizer(ts, MONTH, DAYS_BEFORE_MONTH_HOST); 1002 EXPECT_EQ(monthStart, get_ts(1972, 3, 1)); 1003 1004 /* 1972-03-31 */ 1005 ts = get_ts(1972, 3, 31); 1006 yearStart = resolveTimeBucketizer(ts, YEAR, DAYS_BEFORE_MONTH_HOST); 1007 EXPECT_EQ(yearStart, get_ts(1972, 1, 1)); 1008 1009 quarterStart = resolveTimeBucketizer(ts, QUATER, DAYS_BEFORE_MONTH_HOST); 1010 EXPECT_EQ(quarterStart, get_ts(1972, 1, 1)); 1011 1012 monthStart = resolveTimeBucketizer(ts, MONTH, DAYS_BEFORE_MONTH_HOST); 1013 EXPECT_EQ(monthStart, get_ts(1972, 3, 1)); 1014 1015 /* 1972-04-01 */ 1016 ts = get_ts(1972, 4, 1); 1017 yearStart = resolveTimeBucketizer(ts, YEAR, DAYS_BEFORE_MONTH_HOST); 1018 EXPECT_EQ(yearStart, get_ts(1972, 1, 1)); 1019 1020 quarterStart = resolveTimeBucketizer(ts, QUATER, DAYS_BEFORE_MONTH_HOST); 1021 EXPECT_EQ(quarterStart, get_ts(1972, 4, 1)); 1022 1023 monthStart = resolveTimeBucketizer(ts, MONTH, DAYS_BEFORE_MONTH_HOST); 1024 EXPECT_EQ(monthStart, get_ts(1972, 4, 1)); 1025 1026 // leap year if year % 400 == 0 1027 /* 2000-03-01 */ 1028 ts = get_ts(2000, 3, 1); 1029 yearStart = resolveTimeBucketizer(ts, YEAR, DAYS_BEFORE_MONTH_HOST); 1030 EXPECT_EQ(yearStart, get_ts(2000, 1, 1)); 1031 1032 quarterStart = resolveTimeBucketizer(ts, QUATER, DAYS_BEFORE_MONTH_HOST); 1033 EXPECT_EQ(quarterStart, get_ts(2000, 1, 1)); 1034 1035 monthStart = resolveTimeBucketizer(ts, MONTH, DAYS_BEFORE_MONTH_HOST); 1036 EXPECT_EQ(monthStart, get_ts(2000, 3, 1)); 1037 1038 /* 2018-06-11 */ 1039 ts = get_ts(2018, 6, 11); 1040 yearStart = resolveTimeBucketizer(ts, YEAR, DAYS_BEFORE_MONTH_HOST); 1041 EXPECT_EQ(yearStart, get_ts(2018, 1, 1)); 1042 1043 quarterStart = resolveTimeBucketizer(ts, QUATER, DAYS_BEFORE_MONTH_HOST); 1044 EXPECT_EQ(quarterStart, get_ts(2018, 4, 1)); 1045 1046 monthStart = resolveTimeBucketizer(ts, MONTH, DAYS_BEFORE_MONTH_HOST); 1047 EXPECT_EQ(monthStart, get_ts(2018, 6, 1)); 1048 } 1049 1050 TEST(ResolveTimeBucketizerTest, CheckRecurringTimeBucketizer) { 1051 // works for epoch time. 1052 uint32_t ts = get_ts(1970, 1, 1); 1053 uint32_t dayOfYear = 1054 resolveTimeBucketizer(ts, DAY_OF_YEAR, DAYS_BEFORE_MONTH_HOST); 1055 EXPECT_EQ(dayOfYear, 0); 1056 1057 uint32_t dayOfMonth = 1058 resolveTimeBucketizer(ts, DAY_OF_MONTH, DAYS_BEFORE_MONTH_HOST); 1059 EXPECT_EQ(dayOfMonth, 0); 1060 1061 uint32_t monthOfYear = 1062 resolveTimeBucketizer(ts, MONTH_OF_YEAR, DAYS_BEFORE_MONTH_HOST); 1063 EXPECT_EQ(monthOfYear, 0); 1064 1065 uint32_t quarterOfMonth = 1066 resolveTimeBucketizer(ts, QUARTER_OF_YEAR, DAYS_BEFORE_MONTH_HOST); 1067 EXPECT_EQ(quarterOfMonth, 0); 1068 1069 ts = get_ts(1972, 2, 29); 1070 dayOfYear = 1071 resolveTimeBucketizer(ts, DAY_OF_YEAR, DAYS_BEFORE_MONTH_HOST); 1072 EXPECT_EQ(dayOfYear, 59); 1073 1074 dayOfMonth = 1075 resolveTimeBucketizer(ts, DAY_OF_MONTH, DAYS_BEFORE_MONTH_HOST); 1076 EXPECT_EQ(dayOfMonth, 28); 1077 1078 monthOfYear = 1079 resolveTimeBucketizer(ts, MONTH_OF_YEAR, DAYS_BEFORE_MONTH_HOST); 1080 EXPECT_EQ(monthOfYear, 1); 1081 1082 quarterOfMonth = 1083 resolveTimeBucketizer(ts, QUARTER_OF_YEAR, DAYS_BEFORE_MONTH_HOST); 1084 EXPECT_EQ(quarterOfMonth, 0); 1085 1086 ts = get_ts(1972, 3, 1); 1087 dayOfYear = 1088 resolveTimeBucketizer(ts, DAY_OF_YEAR, DAYS_BEFORE_MONTH_HOST); 1089 EXPECT_EQ(dayOfYear, 60); 1090 1091 dayOfMonth = 1092 resolveTimeBucketizer(ts, DAY_OF_MONTH, DAYS_BEFORE_MONTH_HOST); 1093 EXPECT_EQ(dayOfMonth, 0); 1094 1095 monthOfYear = 1096 resolveTimeBucketizer(ts, MONTH_OF_YEAR, DAYS_BEFORE_MONTH_HOST); 1097 EXPECT_EQ(monthOfYear, 2); 1098 1099 quarterOfMonth = 1100 resolveTimeBucketizer(ts, QUARTER_OF_YEAR, DAYS_BEFORE_MONTH_HOST); 1101 EXPECT_EQ(quarterOfMonth, 0); 1102 1103 ts = get_ts(2018, 6, 11); 1104 dayOfYear = 1105 resolveTimeBucketizer(ts, DAY_OF_YEAR, DAYS_BEFORE_MONTH_HOST); 1106 EXPECT_EQ(dayOfYear, 161); 1107 1108 dayOfMonth = 1109 resolveTimeBucketizer(ts, DAY_OF_MONTH, DAYS_BEFORE_MONTH_HOST); 1110 EXPECT_EQ(dayOfMonth, 10); 1111 1112 monthOfYear = 1113 resolveTimeBucketizer(ts, MONTH_OF_YEAR, DAYS_BEFORE_MONTH_HOST); 1114 EXPECT_EQ(monthOfYear, 5); 1115 1116 quarterOfMonth = 1117 resolveTimeBucketizer(ts, QUARTER_OF_YEAR, DAYS_BEFORE_MONTH_HOST); 1118 EXPECT_EQ(quarterOfMonth, 1); 1119 } 1120 1121 TEST(getWeekStartTimestamp, CheckWeeklyBucketizer) { 1122 uint32_t ts = get_ts(1970, 1, 3); 1123 uint32_t weekts = getWeekStartTimestamp(ts); 1124 EXPECT_EQ(weekts, 0); 1125 1126 ts = get_ts(1970, 1, 6); 1127 weekts = getWeekStartTimestamp(ts); 1128 EXPECT_EQ(weekts, 345600); 1129 1130 ts = 1533081655; 1131 weekts = getWeekStartTimestamp(ts); 1132 EXPECT_EQ(weekts, 1532908800); 1133 1134 ts = 1534520171; 1135 weekts = getWeekStartTimestamp(ts); 1136 EXPECT_EQ(weekts, 1534118400); 1137 1138 ts = 1528675200; 1139 weekts = getWeekStartTimestamp(ts); 1140 EXPECT_EQ(weekts, 1528675200); 1141 } 1142 1143 TEST(CalculateHLLHashTest, CheckUUIDT) { 1144 UUIDT uuidT = {0x0000483EC1324C38, 0xBE372EB5A01BBB30}; 1145 UUIDT uuidTs[2] = {uuidT, uuidT}; 1146 bool nulls[2] = {true, false}; 1147 uint32_t expectedValues[2] = {14088, 0}; 1148 bool expectedNulls[2] = {true, false}; 1149 uint32_t outputValues[2] = {0}; 1150 bool outputNulls[2] = {0}; 1151 1152 typedef thrust::zip_iterator<thrust::tuple<UUIDIter, BoolIter> > 1153 InputZipIterator; 1154 typedef thrust::zip_iterator<thrust::tuple<Uint32Iter, BoolIter> > 1155 OutputZipIterator; 1156 1157 InputZipIterator inputBegin( 1158 thrust::make_tuple(std::begin(uuidTs), std::begin(nulls))); 1159 OutputZipIterator outputBegin( 1160 thrust::make_tuple(std::begin(outputValues), std::begin(outputNulls))); 1161 1162 thrust::transform(inputBegin, inputBegin + 2, outputBegin, 1163 GetHLLValueFunctor<UUIDT>()); 1164 1165 EXPECT_TRUE(thrust::equal(std::begin(outputValues), std::end(outputValues), 1166 std::begin(expectedValues))); 1167 EXPECT_TRUE(thrust::equal(std::begin(outputNulls), std::end(outputNulls), 1168 std::begin(expectedNulls))); 1169 } 1170 1171 } // namespace ares