Skip to content

Commit

Permalink
TileDB 2.0 (#3030)
Browse files Browse the repository at this point in the history
  • Loading branch information
normanb committed Apr 17, 2020
1 parent cdc5343 commit 2a1faea
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 27 deletions.
4 changes: 2 additions & 2 deletions plugins/tiledb/io/TileDBReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ void TileDBReader::localReady()
// read spatial reference
NL::json meta = nullptr;

#if TILEDB_VERSION_MAJOR >= 1 && TILEDB_VERSION_MINOR >= 7
#if TILEDB_VERSION_MAJOR > 1 || TILEDB_VERSION_MINOR >= 7
tiledb_datatype_t v_type = TILEDB_UINT8;
const void* v_r;
uint32_t v_num;
Expand All @@ -310,7 +310,7 @@ void TileDBReader::localReady()
tiledb::VFS::filebuf fbuf(vfs);
std::string metaFName = m_filename + pathSeparator + "pdal.json";

if (vfs.is_dir(m_filename))
if (vfs.is_file(metaFName))
{
auto nBytes = vfs.file_size(metaFName);
tiledb::VFS::filebuf fbuf(vfs);
Expand Down
54 changes: 36 additions & 18 deletions plugins/tiledb/io/TileDBWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,6 @@ void TileDBWriter::ready(pdal::BasePointTable &table)
TILEDB_WRITE));
}

m_query.reset(new tiledb::Query(*m_ctx, *m_array));
m_query->set_layout(TILEDB_UNORDERED);
m_current_idx = 0;
}

Expand All @@ -442,9 +440,9 @@ bool TileDBWriter::processOne(PointRef& point)
for (auto& a : m_attrs)
writeAttributeValue(a, point, m_current_idx);

m_coords.push_back(x);
m_coords.push_back(y);
m_coords.push_back(z);
m_xs.push_back(x);
m_ys.push_back(y);
m_zs.push_back(z);

if (++m_current_idx == m_args->m_cache_size)
{
Expand Down Expand Up @@ -524,7 +522,25 @@ void TileDBWriter::done(PointTableRef table)

bool TileDBWriter::flushCache(size_t size)
{
m_query->set_coordinates(m_coords);
tiledb::Query query(*m_ctx, *m_array);
query.set_layout(TILEDB_UNORDERED);

#if TILEDB_VERSION_MAJOR == 1
// backwards compatibility requires a copy
std::vector<double> coords;

for(unsigned i = 0; i < m_xs.size(); i++)
{
coords.push_back(m_xs[i]);
coords.push_back(m_ys[i]);
coords.push_back(m_zs[i]);
}
query.set_coordinates(coords);
#else
query.set_buffer("X", m_xs);
query.set_buffer("Y", m_ys);
query.set_buffer("Z", m_zs);
#endif

// set tiledb buffers
for (const auto& a : m_attrs)
Expand All @@ -533,43 +549,43 @@ bool TileDBWriter::flushCache(size_t size)
switch (a.m_type)
{
case Dimension::Type::Double:
m_query->set_buffer(a.m_name, reinterpret_cast<double *>(buf),
query.set_buffer(a.m_name, reinterpret_cast<double *>(buf),
size);
break;
case Dimension::Type::Float:
m_query->set_buffer(a.m_name, reinterpret_cast<float *>(buf),
query.set_buffer(a.m_name, reinterpret_cast<float *>(buf),
size);
break;
case Dimension::Type::Signed8:
m_query->set_buffer(a.m_name, reinterpret_cast<int8_t *>(buf),
query.set_buffer(a.m_name, reinterpret_cast<int8_t *>(buf),
size);
break;
case Dimension::Type::Signed16:
m_query->set_buffer(a.m_name, reinterpret_cast<int16_t *>(buf),
query.set_buffer(a.m_name, reinterpret_cast<int16_t *>(buf),
size);
break;
case Dimension::Type::Signed32:
m_query->set_buffer(a.m_name, reinterpret_cast<int32_t *>(buf),
query.set_buffer(a.m_name, reinterpret_cast<int32_t *>(buf),
size);
break;
case Dimension::Type::Signed64:
m_query->set_buffer(a.m_name, reinterpret_cast<int64_t *>(buf),
query.set_buffer(a.m_name, reinterpret_cast<int64_t *>(buf),
size);
break;
case Dimension::Type::Unsigned8:
m_query->set_buffer(a.m_name, reinterpret_cast<uint8_t *>(buf),
query.set_buffer(a.m_name, reinterpret_cast<uint8_t *>(buf),
size);
break;
case Dimension::Type::Unsigned16:
m_query->set_buffer(a.m_name, reinterpret_cast<uint16_t *>(buf),
query.set_buffer(a.m_name, reinterpret_cast<uint16_t *>(buf),
size);
break;
case Dimension::Type::Unsigned32:
m_query->set_buffer(a.m_name, reinterpret_cast<uint32_t *>(buf),
query.set_buffer(a.m_name, reinterpret_cast<uint32_t *>(buf),
size);
break;
case Dimension::Type::Unsigned64:
m_query->set_buffer(a.m_name, reinterpret_cast<uint64_t *>(buf),
query.set_buffer(a.m_name, reinterpret_cast<uint64_t *>(buf),
size);
break;
case Dimension::Type::None:
Expand All @@ -581,7 +597,7 @@ bool TileDBWriter::flushCache(size_t size)
if (m_args->m_stats)
tiledb::Stats::enable();

tiledb::Query::Status status = m_query->submit();
tiledb::Query::Status status = query.submit();

if (m_args->m_stats)
{
Expand All @@ -590,7 +606,9 @@ bool TileDBWriter::flushCache(size_t size)
}

m_current_idx = 0;
m_coords.clear();
m_xs.clear();
m_ys.clear();
m_zs.clear();

if (status == tiledb::Query::Status::FAILED)
return false;
Expand Down
5 changes: 3 additions & 2 deletions plugins/tiledb/io/TileDBWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ class PDAL_DLL TileDBWriter : public Writer, public Streamable
std::unique_ptr<tiledb::Context> m_ctx;
std::unique_ptr<tiledb::ArraySchema> m_schema;
std::unique_ptr<tiledb::Array> m_array;
std::unique_ptr<tiledb::Query> m_query;
std::vector<DimBuffer> m_attrs;
std::vector<double> m_coords;
std::vector<double> m_xs;
std::vector<double> m_ys;
std::vector<double> m_zs;

TileDBWriter(const TileDBWriter&) = delete;
TileDBWriter& operator=(const TileDBWriter&) = delete;
Expand Down
7 changes: 2 additions & 5 deletions plugins/tiledb/test/TileDBReaderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,9 @@ class TileDBReaderTest : public ::testing::Test
c.setInput(reader);
c.prepare(table);
c.execute(table);
// test using a sidecar file
EXPECT_EQ(reader.getSpatialReference(), utm16);
EXPECT_TRUE(reader.getSpatialReference().equals(utm16));
}

#if TILEDB_VERSION_MAJOR >= 1 && TILEDB_VERSION_MINOR >= 7
TEST_F(TileDBReaderTest, spatial_reference)
{
tiledb::Context ctx;
Expand Down Expand Up @@ -233,8 +231,7 @@ class TileDBReaderTest : public ::testing::Test
FixedPointTable table2(100);
rdr.prepare(table2);
rdr.execute(table2);
EXPECT_EQ(rdr.getSpatialReference(), utm16);
EXPECT_TRUE(rdr.getSpatialReference().equals(utm16));
}
#endif
}

0 comments on commit 2a1faea

Please sign in to comment.