Skip to content

Commit

Permalink
Remove default constructor argument for FieldInfo.
Browse files Browse the repository at this point in the history
This has caused misuse when refactoring tests and should be avoided.

---
TYPE: NO_HISTORY
DESC: Remove default constructor argument for FieldInfo.
  • Loading branch information
KiterLuc committed Oct 23, 2023
1 parent 595e409 commit 9329c46
Show file tree
Hide file tree
Showing 7 changed files with 295 additions and 119 deletions.
45 changes: 38 additions & 7 deletions test/src/test-cppapi-aggregates.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "tiledb/sm/query/readers/aggregators/min_max_aggregator.h"
#include "tiledb/sm/query/readers/aggregators/sum_aggregator.h"

#include <test/support/src/helper_type.h>
#include <test/support/tdb_catch.h>

using namespace tiledb;
Expand Down Expand Up @@ -1395,7 +1396,11 @@ TEMPLATE_LIST_TEST_CASE_METHOD(
"Mean",
std::make_shared<tiledb::sm::MeanAggregator<T>>(
tiledb::sm::FieldInfo(
"a1", false, CppAggregatesFx<T>::nullable_, 1)));
"a1",
false,
CppAggregatesFx<T>::nullable_,
1,
tdb_type<std::string>())));

CppAggregatesFx<T>::set_ranges_and_condition_if_needed(
array, query, false);
Expand Down Expand Up @@ -1798,7 +1803,8 @@ TEMPLATE_LIST_TEST_CASE_METHOD(
"a1",
false,
CppAggregatesFx<T>::nullable_,
cell_val_num)));
cell_val_num,
tdb_type<std::string>())));

CppAggregatesFx<T>::set_ranges_and_condition_if_needed(
array, query, false);
Expand Down Expand Up @@ -1892,7 +1898,11 @@ TEST_CASE_METHOD(
"NullCount",
std::make_shared<tiledb::sm::NullCountAggregator>(
tiledb::sm::FieldInfo(
"a1", true, nullable_, TILEDB_VAR_NUM)));
"a1",
true,
nullable_,
TILEDB_VAR_NUM,
tdb_type<std::string>())));

set_ranges_and_condition_if_needed(array, query, true);

Expand Down Expand Up @@ -1987,7 +1997,12 @@ TEST_CASE_METHOD(
query.ptr()->query_->add_aggregator_to_default_channel(
"NullCount",
std::make_shared<tiledb::sm::NullCountAggregator>(
tiledb::sm::FieldInfo("a1", true, nullable_, TILEDB_VAR_NUM)));
tiledb::sm::FieldInfo(
"a1",
true,
nullable_,
TILEDB_VAR_NUM,
tdb_type<std::string>())));

// Add another aggregator on the second attribute. We will make the
// first attribute get a var size overflow, which should not impact the
Expand All @@ -1996,7 +2011,12 @@ TEST_CASE_METHOD(
query.ptr()->query_->add_aggregator_to_default_channel(
"NullCount2",
std::make_shared<tiledb::sm::NullCountAggregator>(
tiledb::sm::FieldInfo("a2", true, nullable_, TILEDB_VAR_NUM)));
tiledb::sm::FieldInfo(
"a2",
true,
nullable_,
TILEDB_VAR_NUM,
tdb_type<std::string>())));

set_ranges_and_condition_if_needed(array, query, true);

Expand Down Expand Up @@ -2125,15 +2145,25 @@ TEST_CASE_METHOD(
query.ptr()->query_->add_aggregator_to_default_channel(
"NullCount",
std::make_shared<tiledb::sm::NullCountAggregator>(
tiledb::sm::FieldInfo("a1", true, nullable_, TILEDB_VAR_NUM)));
tiledb::sm::FieldInfo(
"a1",
true,
nullable_,
TILEDB_VAR_NUM,
tdb_type<std::string>())));

// Add another aggregator on the second attribute. We will make this
// attribute get a var size overflow, which should impact the result of
// the first one hence throw an exception.
query.ptr()->query_->add_aggregator_to_default_channel(
"NullCount2",
std::make_shared<tiledb::sm::NullCountAggregator>(
tiledb::sm::FieldInfo("a2", true, nullable_, TILEDB_VAR_NUM)));
tiledb::sm::FieldInfo(
"a2",
true,
nullable_,
TILEDB_VAR_NUM,
tdb_type<std::string>())));

set_ranges_and_condition_if_needed(array, query, true);

Expand Down Expand Up @@ -2198,6 +2228,7 @@ TEMPLATE_LIST_TEST_CASE_METHOD(
for (tiledb_layout_t layout : CppAggregatesFx<T>::layout_values_) {
CppAggregatesFx<T>::layout_ = layout;
Query query(CppAggregatesFx<T>::ctx_, array, TILEDB_READ);

// Add a count aggregator to the query. We add both sum and count as
// they are processed separately in the dense case.
QueryChannel default_channel =
Expand Down
129 changes: 129 additions & 0 deletions test/support/src/helper_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/**
* @file type.h
*
* @section LICENSE
*
* The MIT License
*
* @copyright Copyright (c) 2023 TileDB, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @section DESCRIPTION
*
* This defines TileDB datatypes.
*/

#ifndef TILEDB_TEST_TYPE_H
#define TILEDB_TEST_TYPE_H

namespace tiledb::test {

using Datatype = tiledb::sm::Datatype;

/**
* Convert a type into a tiledb::sm::Datatype. The default for all copyable
* types is char.
*/
template <typename T>
struct type_to_tiledb {
using type = char;
static const Datatype tiledb_type = Datatype::STRING_ASCII;
};

template <>
struct type_to_tiledb<std::byte> {
using type = std::byte;
static const Datatype tiledb_type = Datatype::BLOB;
};

template <>
struct type_to_tiledb<bool> {
using type = bool;
static const Datatype tiledb_type = Datatype::BOOL;
};

template <>
struct type_to_tiledb<int8_t> {
using type = int8_t;
static const Datatype tiledb_type = Datatype::INT8;
};

template <>
struct type_to_tiledb<uint8_t> {
using type = uint8_t;
static const Datatype tiledb_type = Datatype::UINT8;
};

template <>
struct type_to_tiledb<int16_t> {
using type = int16_t;
static const Datatype tiledb_type = Datatype::INT16;
};

template <>
struct type_to_tiledb<uint16_t> {
using type = uint16_t;
static const Datatype tiledb_type = Datatype::UINT16;
};

template <>
struct type_to_tiledb<int32_t> {
using type = int32_t;
static const Datatype tiledb_type = Datatype::INT32;
};

template <>
struct type_to_tiledb<uint32_t> {
using type = uint32_t;
static const Datatype tiledb_type = Datatype::UINT32;
};

template <>
struct type_to_tiledb<int64_t> {
using type = int64_t;
static const Datatype tiledb_type = Datatype::INT64;
};

template <>
struct type_to_tiledb<uint64_t> {
using type = uint64_t;
static const Datatype tiledb_type = Datatype::UINT64;
};

template <>
struct type_to_tiledb<float> {
using type = float;
static const Datatype tiledb_type = Datatype::FLOAT32;
};

template <>
struct type_to_tiledb<double> {
using type = double;
static const Datatype tiledb_type = Datatype::FLOAT64;
};

template <typename T>
Datatype tdb_type() {
return type_to_tiledb<T>::tiledb_type;
}

} // namespace tiledb::test

#endif // TILEDB_TEST_TYPE_H
2 changes: 1 addition & 1 deletion tiledb/sm/query/readers/aggregators/field_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class FieldInfo {
const bool var_sized,
const bool is_nullable,
const unsigned cell_val_num,
const Datatype type = Datatype::UINT8)
const Datatype type)
: name_(name)
, var_sized_(var_sized)
, is_nullable_(is_nullable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
#include "tiledb/sm/query/readers/aggregators/sum_type.h"
#include "tiledb/sm/query/readers/aggregators/validity_policies.h"

#include <test/support/src/helper_type.h>
#include <test/support/tdb_catch.h>

using namespace tiledb::sm;
using namespace tiledb::test;

const uint64_t num_cells = 10 * 1024 * 1024;

Expand Down Expand Up @@ -156,7 +158,7 @@ void run_bench() {
<< ", Segmented: " << (segmented ? "true" : "false")) {
BENCHMARK("Bench") {
AggregateWithCount<T, AggregateT, PolicyT, ValidityPolicyT> aggregator(
FieldInfo("a1", var_sized, nullable, 1));
FieldInfo("a1", var_sized, nullable, 1, tdb_type<T>()));
for (uint64_t s = 0; s < num_cells; s += increment) {
AggregateBuffer input_data{
s,
Expand Down
Loading

0 comments on commit 9329c46

Please sign in to comment.