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++] Fix upgrade-soma-joinid-shape for dataframes having non-standard dimensions #3416

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
Binary file not shown.
59 changes: 59 additions & 0 deletions apis/python/tests/test_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,3 +671,62 @@ def _check_ndarray(ndarray, has_shapes, expected_shape):
_check_ndarray(exp.ms["RNA"].obsm["X_pca"], True, (2639, 50))
_check_ndarray(exp.ms["RNA"].obsp["connectivities"], True, (2639, 2639))
_check_ndarray(exp.ms["RNA"].varm["PCs"], True, (1839, 50))


def test_canned_nonstandard_dataframe_upgrade(tmp_path):
uri = tmp_path.as_posix()

tgz = TESTDATA / "nonstandard-dataframe-without-shapes.tgz"

with tarfile.open(tgz) as handle:
handle.extractall(uri)

# ----------------------------------------------------------------
# As of tiledbsoma 1.15 we no longer write dataframes/arrays without
# core current domain (soma domain/shape) so it is crucial that in order
# to test upgrade-shape, we test saved-off data written before 1.15.0.
#
# Here is a dataframe created with tiledbsoma 1.14.5:
# ----------------------------------------------------------------
# import tiledbsoma
# import pyarrow as pa
#
# schema = pa.schema([
# ("soma_joinid", pa.int64()),
# ("mystring", pa.string()),
# ("myint", pa.int32()),
# ("myfloat", pa.float32()),
# ])
#
# data = pa.Table.from_pydict({
# "soma_joinid": [10, 20],
# "mystring": ["hello", "world"],
# "myint": [1330, 1440],
# "myfloat": [4.5, 5.5],
# })
#
# with tiledbsoma.DataFrame.create(
# uri="data-sdf-dom-multi-py",
# schema=schema,
# index_column_names=["soma_joinid", "myint", "mystring"],
# domain=None,
# ) as sdf:
# sdf.write(data)
# ----------------------------------------------------------------

with tiledbsoma.DataFrame.open(uri) as sdf:
assert not sdf.tiledbsoma_has_upgraded_domain
assert sdf.non_empty_domain() == ((10, 20), (1330, 1440), ("hello", "world"))
assert sdf.domain == ((0, 2147483646), (-2147483648, 2147481598), ("", ""))
assert sdf.maxdomain == ((0, 2147483646), (-2147483648, 2147481598), ("", ""))

with tiledbsoma.DataFrame.open(uri, "w") as sdf:
ok, msg = sdf.tiledbsoma_upgrade_soma_joinid_shape(1, check_only=True)

sdf.tiledbsoma_upgrade_soma_joinid_shape(100)

with tiledbsoma.DataFrame.open(uri) as sdf:
assert sdf.tiledbsoma_has_upgraded_domain
assert sdf.non_empty_domain() == ((10, 20), (1330, 1440), ("hello", "world"))
assert sdf.domain == ((0, 99), (-2147483648, 2147481598), ("", ""))
assert sdf.maxdomain == ((0, 2147483646), (-2147483648, 2147481598), ("", ""))
200 changes: 100 additions & 100 deletions libtiledbsoma/src/soma/soma_array.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1039,107 +1039,107 @@ void SOMAArray::_set_soma_joinid_shape_helper(
}
ndrect.set_range<int64_t>(dim_name, 0, newshape - 1);
continue;
}
johnkerl marked this conversation as resolved.
Show resolved Hide resolved

switch (dim.type()) {
case TILEDB_STRING_ASCII:
case TILEDB_STRING_UTF8:
case TILEDB_CHAR:
case TILEDB_GEOM_WKB:
case TILEDB_GEOM_WKT:
// See comments in soma_array.h.
ndrect.set_range(dim_name, "", "\x7f");
break;

case TILEDB_INT8:
ndrect.set_range<int8_t>(
dim_name,
dim.domain<int8_t>().first,
dim.domain<int8_t>().second);
break;
case TILEDB_BOOL:
case TILEDB_UINT8:
ndrect.set_range<uint8_t>(
dim_name,
dim.domain<uint8_t>().first,
dim.domain<uint8_t>().second);
break;
case TILEDB_INT16:
ndrect.set_range<int16_t>(
dim_name,
dim.domain<int16_t>().first,
dim.domain<int16_t>().second);
break;
case TILEDB_UINT16:
ndrect.set_range<uint16_t>(
dim_name,
dim.domain<uint16_t>().first,
dim.domain<uint16_t>().second);
break;
case TILEDB_INT32:
ndrect.set_range<int32_t>(
dim_name,
dim.domain<int32_t>().first,
dim.domain<int32_t>().second);
break;
case TILEDB_UINT32:
ndrect.set_range<uint32_t>(
dim_name,
dim.domain<uint32_t>().first,
dim.domain<uint32_t>().second);
break;
case TILEDB_INT64:
case TILEDB_DATETIME_YEAR:
case TILEDB_DATETIME_MONTH:
case TILEDB_DATETIME_WEEK:
case TILEDB_DATETIME_DAY:
case TILEDB_DATETIME_HR:
case TILEDB_DATETIME_MIN:
case TILEDB_DATETIME_SEC:
case TILEDB_DATETIME_MS:
case TILEDB_DATETIME_US:
case TILEDB_DATETIME_NS:
case TILEDB_DATETIME_PS:
case TILEDB_DATETIME_FS:
case TILEDB_DATETIME_AS:
case TILEDB_TIME_HR:
case TILEDB_TIME_MIN:
case TILEDB_TIME_SEC:
case TILEDB_TIME_MS:
case TILEDB_TIME_US:
case TILEDB_TIME_NS:
case TILEDB_TIME_PS:
case TILEDB_TIME_FS:
case TILEDB_TIME_AS:
ndrect.set_range<int64_t>(
dim_name,
dim.domain<int64_t>().first,
dim.domain<int64_t>().second);
break;
case TILEDB_UINT64:
ndrect.set_range<uint64_t>(
dim_name,
dim.domain<int64_t>().first,
dim.domain<int64_t>().second);
break;
case TILEDB_FLOAT32:
ndrect.set_range<float>(
dim_name,
dim.domain<float>().first,
dim.domain<float>().second);
break;
case TILEDB_FLOAT64:
ndrect.set_range<double>(
dim_name,
dim.domain<double>().first,
dim.domain<double>().second);
break;
default:
throw TileDBSOMAError(std::format(
"{}: internal error: unhandled type {} for {}.",
function_name_for_messages,
tiledb::impl::type_to_str(dim.type()),
dim_name));
}
switch (dim.type()) {
case TILEDB_STRING_ASCII:
case TILEDB_STRING_UTF8:
case TILEDB_CHAR:
case TILEDB_GEOM_WKB:
case TILEDB_GEOM_WKT:
// See comments in soma_array.h.
ndrect.set_range(dim_name, "", "\x7f");
break;

case TILEDB_INT8:
ndrect.set_range<int8_t>(
dim_name,
dim.domain<int8_t>().first,
dim.domain<int8_t>().second);
break;
case TILEDB_BOOL:
case TILEDB_UINT8:
ndrect.set_range<uint8_t>(
dim_name,
dim.domain<uint8_t>().first,
dim.domain<uint8_t>().second);
break;
case TILEDB_INT16:
ndrect.set_range<int16_t>(
dim_name,
dim.domain<int16_t>().first,
dim.domain<int16_t>().second);
break;
case TILEDB_UINT16:
ndrect.set_range<uint16_t>(
dim_name,
dim.domain<uint16_t>().first,
dim.domain<uint16_t>().second);
break;
case TILEDB_INT32:
ndrect.set_range<int32_t>(
dim_name,
dim.domain<int32_t>().first,
dim.domain<int32_t>().second);
break;
case TILEDB_UINT32:
ndrect.set_range<uint32_t>(
dim_name,
dim.domain<uint32_t>().first,
dim.domain<uint32_t>().second);
break;
case TILEDB_INT64:
case TILEDB_DATETIME_YEAR:
case TILEDB_DATETIME_MONTH:
case TILEDB_DATETIME_WEEK:
case TILEDB_DATETIME_DAY:
case TILEDB_DATETIME_HR:
case TILEDB_DATETIME_MIN:
case TILEDB_DATETIME_SEC:
case TILEDB_DATETIME_MS:
case TILEDB_DATETIME_US:
case TILEDB_DATETIME_NS:
case TILEDB_DATETIME_PS:
case TILEDB_DATETIME_FS:
case TILEDB_DATETIME_AS:
case TILEDB_TIME_HR:
case TILEDB_TIME_MIN:
case TILEDB_TIME_SEC:
case TILEDB_TIME_MS:
case TILEDB_TIME_US:
case TILEDB_TIME_NS:
case TILEDB_TIME_PS:
case TILEDB_TIME_FS:
case TILEDB_TIME_AS:
ndrect.set_range<int64_t>(
dim_name,
dim.domain<int64_t>().first,
dim.domain<int64_t>().second);
break;
case TILEDB_UINT64:
ndrect.set_range<uint64_t>(
dim_name,
dim.domain<int64_t>().first,
dim.domain<int64_t>().second);
break;
case TILEDB_FLOAT32:
ndrect.set_range<float>(
dim_name,
dim.domain<float>().first,
dim.domain<float>().second);
break;
case TILEDB_FLOAT64:
ndrect.set_range<double>(
dim_name,
dim.domain<double>().first,
dim.domain<double>().second);
break;
default:
throw TileDBSOMAError(std::format(
"{}: internal error: unhandled type {} for {}.",
function_name_for_messages,
tiledb::impl::type_to_str(dim.type()),
dim_name));
}
}

Expand Down