Skip to content

Commit

Permalink
Update schema generation
Browse files Browse the repository at this point in the history
  • Loading branch information
XanthosXanthopoulos committed Jan 29, 2025
1 parent 8f6607e commit db495e1
Showing 1 changed file with 75 additions and 24 deletions.
99 changes: 75 additions & 24 deletions libtiledbsoma/src/utils/arrow_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,7 @@ ArrowAdapter::tiledb_schema_from_arrow_schema(
const ArrowTable& index_column_info,
std::string soma_type,
bool is_sparse,
PlatformConfig platform_config,
const ArrowTable& spatial_column_info) {
PlatformConfig platform_config) {
auto& index_column_array = index_column_info.first;
auto& index_column_schema = index_column_info.second;

Expand Down Expand Up @@ -940,13 +939,12 @@ ArrowAdapter::tiledb_schema_from_arrow_schema(
if (strcmp(child->name, index_column_schema->children[i]->name) ==
0) {
if (strcmp(child->name, SOMA_GEOMETRY_COLUMN_NAME.c_str()) ==
0 &&
spatial_column_info.first.get() != nullptr) {
0) {
columns.push_back(SOMAGeometryColumn::create(
ctx,
child,
spatial_column_info.second.get(),
spatial_column_info.first.get(),
index_column_schema->children[i],
index_column_array->children[i],
soma_type,
type_metadata,
platform_config));
Expand Down Expand Up @@ -1053,23 +1051,28 @@ ArrowAdapter::tiledb_schema_from_arrow_schema(
continue;
}

if (column->name() == SOMA_GEOMETRY_COLUMN_NAME) {
std::vector<std::any> cdslot;
for (int64_t j = 0; j < spatial_column_info.first->n_children;
++j) {
cdslot.push_back(ArrowAdapter::get_table_any_column<2>(
spatial_column_info.first->children[j],
spatial_column_info.second->children[j],
3));
}

column->set_current_domain_slot(ndrect, cdslot);
} else {
column->set_current_domain_slot(
ndrect,
get_table_any_column_by_name<2>(
index_column_info, column->name(), 3));
}
column->set_current_domain_slot(
ndrect,
get_table_any_column_by_name<2>(
index_column_info, column->name(), 3));

// if (column->name() == SOMA_GEOMETRY_COLUMN_NAME) {
// std::vector<std::any> cdslot;
// for (int64_t j = 0; j < spatial_column_info.first->n_children;
// ++j) {
// cdslot.push_back(ArrowAdapter::get_table_any_column<2>(
// spatial_column_info.first->children[j],
// spatial_column_info.second->children[j],
// 3));
// }

// column->set_current_domain_slot(ndrect, cdslot);
// } else {
// column->set_current_domain_slot(
// ndrect,
// get_table_any_column_by_name<2>(
// index_column_info, column->name(), 3));
// }
}
current_domain.set_ndrectangle(ndrect);

Expand Down Expand Up @@ -1121,6 +1124,54 @@ Dimension ArrowAdapter::tiledb_dimension_from_arrow_schema(
return dim;
}

Dimension ArrowAdapter::tiledb_dimension_from_arrow_schema_ext(
std::shared_ptr<Context> ctx,
ArrowSchema* schema,
ArrowArray* array,
std::string soma_type,
std::string_view type_metadata,
std::string prefix,
std::string suffix,
PlatformConfig platform_config) {
if (strcmp(schema->format, "+l") != 0) {
throw TileDBSOMAError(
std::format("[tiledb_dimension_from_arrow_schema_ext] Schema "
"should be of type list."));
}

if (schema->n_children != 1) {
throw TileDBSOMAError(
std::format("[tiledb_dimension_from_arrow_schema_ext] Schema "
"should have exactly 1 child"));
}

auto type = ArrowAdapter::to_tiledb_format(
schema->children[0]->format, type_metadata);

if (ArrowAdapter::arrow_is_var_length_type(schema->format)) {
type = TILEDB_STRING_ASCII;
}

auto col_name = prefix + std::string(schema->name) + suffix;

FilterList filter_list = ArrowAdapter::_create_dim_filter_list(
col_name, platform_config, soma_type, ctx);

if (array->length != 5) {
throw TileDBSOMAError(std::format(
"ArrowAdapter: unexpected length {} != 5 for name "
"'{}'",
array->length,
col_name));
}

const void* buff = array->children[0]->buffers[1];
auto dim = ArrowAdapter::_create_dim(type, col_name, buff, ctx);
dim.set_filter_list(filter_list);

return dim;
}

std::pair<Attribute, std::optional<Enumeration>>
ArrowAdapter::tiledb_attribute_from_arrow_schema(
std::shared_ptr<Context> ctx,
Expand Down Expand Up @@ -1613,7 +1664,7 @@ std::unique_ptr<ArrowSchema> ArrowAdapter::make_arrow_schema(
std::unique_ptr<ArrowSchema> ArrowAdapter::make_arrow_schema_parent(
int num_columns) {
auto arrow_schema = std::make_unique<ArrowSchema>();
arrow_schema->format = "+s"; // structure, i.e. non-leaf node
arrow_schema->format = strdup("+s"); // structure, i.e. non-leaf node
arrow_schema->name = strdup("parent");
arrow_schema->metadata = nullptr;
arrow_schema->flags = 0;
Expand Down

0 comments on commit db495e1

Please sign in to comment.