Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[c++] SOMAColumn part 1 #3329

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
325d68b
SOMAColumn abstract class definition
XanthosXanthopoulos Nov 18, 2024
3543b40
Remove fmt::format
XanthosXanthopoulos Nov 20, 2024
b4895ca
Remove unneeded methods and member variables
XanthosXanthopoulos Nov 21, 2024
a5811e8
Add helper methods for to and from arrow contructs
XanthosXanthopoulos Nov 21, 2024
722438c
Add concrete class wrapper for TileDB dimension
XanthosXanthopoulos Nov 21, 2024
5b37612
Add concrete class wrapper for TileDB attribute
XanthosXanthopoulos Nov 21, 2024
111e526
Add concrete class wrapper for indexable geometry column
XanthosXanthopoulos Nov 21, 2024
8dff909
Add minimal testing for dimensions
XanthosXanthopoulos Nov 21, 2024
317ef78
Misc fixes
XanthosXanthopoulos Nov 21, 2024
8fe6472
Add read test case
XanthosXanthopoulos Nov 22, 2024
f56099c
Add missing `override`
XanthosXanthopoulos Nov 22, 2024
94c8142
Remove current_domain flag
XanthosXanthopoulos Nov 24, 2024
9def004
Convert float to string before calling std::format
XanthosXanthopoulos Nov 25, 2024
230baf9
Add virtual destructor [skip ci]
XanthosXanthopoulos Nov 25, 2024
f1f767b
Do not export soma column [skip ci]
XanthosXanthopoulos Nov 25, 2024
e1907d5
remove to_string calls [skip ci]
XanthosXanthopoulos Nov 25, 2024
bae31d2
Replace string with string_view
XanthosXanthopoulos Nov 26, 2024
25a5426
Bump min macos version (Remove commit after merging 3361)
XanthosXanthopoulos Nov 26, 2024
a58361a
Replace string_view with string when returning column name, add curre…
XanthosXanthopoulos Dec 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apis/python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def run(self):
CXX_FLAGS.append(f'-Wl,-rpath,{str(tiledb_dir / "lib")}')

if sys.platform == "darwin":
CXX_FLAGS.append("-mmacosx-version-min=11.0")
CXX_FLAGS.append("-mmacosx-version-min=13.3")

if os.name == "posix" and sys.platform != "darwin":
LIB_DIRS.append(str(tiledbsoma_dir / "lib" / "x86_64-linux-gnu"))
Expand Down
8 changes: 8 additions & 0 deletions libtiledbsoma/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ add_library(TILEDB_SOMA_OBJECTS OBJECT
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_array.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_group.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_object.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_column.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_attribute.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_dimension.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_geometry_column.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_collection.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_experiment.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_measurement.cc
Expand Down Expand Up @@ -206,6 +210,10 @@ install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/soma/column_buffer.h
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_array.h
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_group.h
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_column.h
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_attribute.h
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_dimension.h
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_geometry_column.h
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_collection.h
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_dataframe.h
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_dense_ndarray.h
Expand Down
14 changes: 14 additions & 0 deletions libtiledbsoma/src/soma/enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,18 @@ enum class ResultOrder { automatic = 0, rowmajor, colmajor };
/** Defines whether the SOMAGroup URI is absolute or relative */
enum class URIType { automatic = 0, absolute, relative };

typedef enum {
SOMA_COLUMN_DIMENSION = 0,
SOMA_COLUMN_ATTRIBUTE = 1,
SOMA_COLUMN_GEOMETRY = 2
} soma_column_datatype_t;

// This enables some code deduplication between core domain, core current
// domain, and core non-empty domain.
enum class Domainish {
kind_core_domain = 0,
kind_core_current_domain = 1,
kind_non_empty_domain = 2
};

#endif // SOMA_ENUMS
8 changes: 0 additions & 8 deletions libtiledbsoma/src/soma/soma_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,6 @@ using namespace tiledb;

using StatusAndReason = std::pair<bool, std::string>;

// This enables some code deduplication between core domain, core current
// domain, and core non-empty domain.
enum class Domainish {
kind_core_domain = 0,
kind_core_current_domain = 1,
kind_non_empty_domain = 2
};

class SOMAArray : public SOMAObject {
public:
friend class ManagedQuery;
Expand Down
95 changes: 95 additions & 0 deletions libtiledbsoma/src/soma/soma_attribute.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include "soma_attribute.h"

namespace tiledbsoma {
std::shared_ptr<SOMAAttribute> SOMAAttribute::create(
std::shared_ptr<Context> ctx,
ArrowSchema* schema,
std::string_view type_metadata,
PlatformConfig platform_config) {
auto attribute = ArrowAdapter::tiledb_attribute_from_arrow_schema(
ctx, schema, type_metadata, platform_config);

return std::make_shared<SOMAAttribute>(
SOMAAttribute(attribute.first, attribute.second));
}

void SOMAAttribute::_set_dim_points(
const std::unique_ptr<ManagedQuery>&,
const SOMAContext&,
const std::any&) const {
throw TileDBSOMAError(std::format(
"[SOMAAttribute][_set_dim_points] Column with name {} is not an index "
"column",
name()));
}

void SOMAAttribute::_set_dim_ranges(
const std::unique_ptr<ManagedQuery>&,
const SOMAContext&,
const std::any&) const {
throw TileDBSOMAError(std::format(
"[SOMAAttribute][_set_dim_ranges] Column with name {} is not an index "
"column",
name()));
}

void SOMAAttribute::_set_current_domain_slot(
NDRectangle&, std::span<const std::any>) const {
throw TileDBSOMAError(std::format(
"[SOMAAttribute][_set_current_domain_slot] Column with name {} is not "
"an index column",
name()));
}

std::pair<bool, std::string> SOMAAttribute::_can_set_current_domain_slot(
std::optional<NDRectangle>&, std::span<const std::any>) const {
throw TileDBSOMAError(std::format(
"[SOMAAttribute][_set_current_domain_slot] Column with name {} is not "
"an index column",
name()));
};

std::any SOMAAttribute::_core_domain_slot() const {
throw TileDBSOMAError(std::format(
"[SOMAAttribute][_core_domain_slot] Column with name {} is not an "
"index column",
name()));
}

std::any SOMAAttribute::_non_empty_domain_slot(Array&) const {
throw TileDBSOMAError(std::format(
"[SOMAAttribute][_non_empty_domain_slot] Column with name {} is not an "
"index column",
name()));
}

std::any SOMAAttribute::_core_current_domain_slot(
const SOMAContext&, Array&) const {
throw TileDBSOMAError(std::format(
"[SOMAAttribute][_core_current_domain_slot] Column with name {} is not "
"an index column",
name()));
}

std::any SOMAAttribute::_core_current_domain_slot(NDRectangle&) const {
throw TileDBSOMAError(std::format(
"[SOMAAttribute][_core_current_domain_slot] Column with name {} is not "
"an index column",
name()));
}

ArrowArray* SOMAAttribute::arrow_domain_slot(
const SOMAContext&, Array&, enum Domainish) const {
throw TileDBSOMAError(std::format(
"[SOMAAttribute][arrow_domain_slot] Column with name {} is not an "
"index column",
name()));
}

ArrowSchema* SOMAAttribute::arrow_schema_slot(
const SOMAContext& ctx, Array& array) {
return ArrowAdapter::arrow_schema_from_tiledb_attribute(
attribute, *ctx.tiledb_ctx(), array)
.release();
}
} // namespace tiledbsoma
119 changes: 119 additions & 0 deletions libtiledbsoma/src/soma/soma_attribute.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
#ifndef SOMA_ATTRIBUTE_H
#define SOMA_ATTRIBUTE_H

#include <algorithm>
#include <vector>

#include <tiledb/tiledb>
#include "soma_column.h"

namespace tiledbsoma {
using namespace tiledb;

class SOMAAttribute : public virtual SOMAColumn {
public:
/**
* Create a ``SOMAAttribute`` shared pointer from an arrow schema
*/
static std::shared_ptr<SOMAAttribute> create(
std::shared_ptr<Context> ctx,
ArrowSchema* schema,
std::string_view type_metadata,
PlatformConfig platform_config);

SOMAAttribute(
Attribute attribute,
std::optional<Enumeration> enumeration = std::nullopt)
: attribute(attribute)
, enumeration(enumeration) {
}

virtual inline std::string name() const override {
return attribute.name();
}

virtual inline bool isIndexColumn() const override {
return false;
}

virtual inline void select_columns(
const std::unique_ptr<ManagedQuery>& query,
bool if_not_empty = false) const override {
query->select_columns(std::vector({attribute.name()}), if_not_empty);
};

virtual inline soma_column_datatype_t type() const override {
return soma_column_datatype_t::SOMA_COLUMN_ATTRIBUTE;
}

virtual inline std::optional<tiledb_datatype_t> domain_type()
const override {
return std::nullopt;
}

virtual inline std::optional<tiledb_datatype_t> data_type() const override {
return attribute.type();
}

virtual inline std::optional<std::vector<Dimension>> tiledb_dimensions()
override {
return std::nullopt;
}

virtual inline std::optional<std::vector<Attribute>> tiledb_attributes()
override {
return std::vector({attribute});
}

virtual inline std::optional<std::vector<Enumeration>> tiledb_enumerations()
override {
if (!enumeration.has_value()) {
return std::nullopt;
}

return std::vector({enumeration.value()});
}

virtual ArrowArray* arrow_domain_slot(
const SOMAContext& ctx,
Array& array,
enum Domainish kind) const override;

virtual ArrowSchema* arrow_schema_slot(
const SOMAContext& ctx, Array& array) override;

private:
virtual void _set_dim_points(
const std::unique_ptr<ManagedQuery>& query,
const SOMAContext& ctx,
const std::any& points) const override;

virtual void _set_dim_ranges(
const std::unique_ptr<ManagedQuery>& query,
const SOMAContext& ctx,
const std::any& ranges) const override;

virtual void _set_current_domain_slot(
NDRectangle& rectangle,
std::span<const std::any> domain) const override;

virtual std::pair<bool, std::string> _can_set_current_domain_slot(
std::optional<NDRectangle>& rectangle,
std::span<const std::any> new_domain) const override;

virtual std::any _core_domain_slot() const override;

virtual std::any _non_empty_domain_slot(Array& array) const override;

virtual std::any _core_current_domain_slot(
const SOMAContext& ctx, Array& array) const override;

virtual std::any _core_current_domain_slot(
NDRectangle& ndrect) const override;

Attribute attribute;
std::optional<Enumeration> enumeration;
};
} // namespace tiledbsoma

#endif
62 changes: 62 additions & 0 deletions libtiledbsoma/src/soma/soma_column.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* @file soma_column.cc
*
* @section LICENSE
*
* The MIT License
*
* @copyright Copyright (c) 2024 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 file defines the SOMAColumn class.
*/

#include "soma_column.h"

namespace tiledbsoma {

template <>
std::pair<std::string, std::string> SOMAColumn::core_domain_slot<std::string>()
const {
return std::pair<std::string, std::string>("", "");
}

template <>
std::pair<std::string, std::string>
SOMAColumn::core_current_domain_slot<std::string>(
const SOMAContext& ctx, Array& array) const {
try {
std::pair<std::string, std::string>
current_domain = std::any_cast<std::pair<std::string, std::string>>(
_core_current_domain_slot(ctx, array));

if (current_domain.first == "" && (current_domain.second == "\x7f" ||
current_domain.second == "\xff")) {
return std::pair<std::string, std::string>("", "");
}

return current_domain;
} catch (const std::exception& e) {
throw TileDBSOMAError(e.what());
}
}
} // namespace tiledbsoma
Loading