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

Parquet: fix crash when using SetIgnoredFields() + SetSpatialFilter()… #10815

Merged
merged 1 commit into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions autotest/ogr/ogr_parquet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3870,6 +3870,8 @@ def check(lyr):
lyr = ds.GetLayer(0)
lyr.SetIgnoredFields(["foo"])
check(lyr)
lyr.SetSpatialFilter(geom)
assert lyr.GetFeatureCount() == (3 if geom.GetGeometryCount() > 1 else 2)

ds = ogr.Open(filename_to_open)
lyr = ds.GetLayer(0)
Expand Down
113 changes: 58 additions & 55 deletions ogr/ogrsf_frmts/arrow_common/ograrrowlayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3919,62 +3919,65 @@ OGRArrowLayer::SetBatch(const std::shared_ptr<arrow::RecordBatch> &poBatch)
{
const int idx = m_bIgnoredFields ? oIter->second.iArrayIdx
: oIter->second.iArrowCol;
CPLAssert(idx >= 0);
CPLAssert(static_cast<size_t>(idx) < m_poBatchColumns.size());
m_poArrayBBOX = m_poBatchColumns[idx].get();
CPLAssert(m_poArrayBBOX->type_id() == arrow::Type::STRUCT);
const auto castArray =
static_cast<const arrow::StructArray *>(m_poArrayBBOX);
const auto &subArrays = castArray->fields();
CPLAssert(
static_cast<size_t>(oIter->second.iArrowSubfieldXMin) <
subArrays.size());
const auto xminArray =
subArrays[oIter->second.iArrowSubfieldXMin].get();
CPLAssert(
static_cast<size_t>(oIter->second.iArrowSubfieldYMin) <
subArrays.size());
const auto yminArray =
subArrays[oIter->second.iArrowSubfieldYMin].get();
CPLAssert(
static_cast<size_t>(oIter->second.iArrowSubfieldXMax) <
subArrays.size());
const auto xmaxArray =
subArrays[oIter->second.iArrowSubfieldXMax].get();
CPLAssert(
static_cast<size_t>(oIter->second.iArrowSubfieldYMax) <
subArrays.size());
const auto ymaxArray =
subArrays[oIter->second.iArrowSubfieldYMax].get();
if (oIter->second.bIsFloat)
if (idx >= 0)
{
CPLAssert(xminArray->type_id() == arrow::Type::FLOAT);
m_poArrayXMinFloat =
static_cast<const arrow::FloatArray *>(xminArray);
CPLAssert(yminArray->type_id() == arrow::Type::FLOAT);
m_poArrayYMinFloat =
static_cast<const arrow::FloatArray *>(yminArray);
CPLAssert(xmaxArray->type_id() == arrow::Type::FLOAT);
m_poArrayXMaxFloat =
static_cast<const arrow::FloatArray *>(xmaxArray);
CPLAssert(ymaxArray->type_id() == arrow::Type::FLOAT);
m_poArrayYMaxFloat =
static_cast<const arrow::FloatArray *>(ymaxArray);
}
else
{
CPLAssert(xminArray->type_id() == arrow::Type::DOUBLE);
m_poArrayXMinDouble =
static_cast<const arrow::DoubleArray *>(xminArray);
CPLAssert(yminArray->type_id() == arrow::Type::DOUBLE);
m_poArrayYMinDouble =
static_cast<const arrow::DoubleArray *>(yminArray);
CPLAssert(xmaxArray->type_id() == arrow::Type::DOUBLE);
m_poArrayXMaxDouble =
static_cast<const arrow::DoubleArray *>(xmaxArray);
CPLAssert(ymaxArray->type_id() == arrow::Type::DOUBLE);
m_poArrayYMaxDouble =
static_cast<const arrow::DoubleArray *>(ymaxArray);
CPLAssert(static_cast<size_t>(idx) <
m_poBatchColumns.size());
m_poArrayBBOX = m_poBatchColumns[idx].get();
CPLAssert(m_poArrayBBOX->type_id() == arrow::Type::STRUCT);
const auto castArray =
static_cast<const arrow::StructArray *>(m_poArrayBBOX);
const auto &subArrays = castArray->fields();
CPLAssert(
static_cast<size_t>(oIter->second.iArrowSubfieldXMin) <
subArrays.size());
const auto xminArray =
subArrays[oIter->second.iArrowSubfieldXMin].get();
CPLAssert(
static_cast<size_t>(oIter->second.iArrowSubfieldYMin) <
subArrays.size());
const auto yminArray =
subArrays[oIter->second.iArrowSubfieldYMin].get();
CPLAssert(
static_cast<size_t>(oIter->second.iArrowSubfieldXMax) <
subArrays.size());
const auto xmaxArray =
subArrays[oIter->second.iArrowSubfieldXMax].get();
CPLAssert(
static_cast<size_t>(oIter->second.iArrowSubfieldYMax) <
subArrays.size());
const auto ymaxArray =
subArrays[oIter->second.iArrowSubfieldYMax].get();
if (oIter->second.bIsFloat)
{
CPLAssert(xminArray->type_id() == arrow::Type::FLOAT);
m_poArrayXMinFloat =
static_cast<const arrow::FloatArray *>(xminArray);
CPLAssert(yminArray->type_id() == arrow::Type::FLOAT);
m_poArrayYMinFloat =
static_cast<const arrow::FloatArray *>(yminArray);
CPLAssert(xmaxArray->type_id() == arrow::Type::FLOAT);
m_poArrayXMaxFloat =
static_cast<const arrow::FloatArray *>(xmaxArray);
CPLAssert(ymaxArray->type_id() == arrow::Type::FLOAT);
m_poArrayYMaxFloat =
static_cast<const arrow::FloatArray *>(ymaxArray);
}
else
{
CPLAssert(xminArray->type_id() == arrow::Type::DOUBLE);
m_poArrayXMinDouble =
static_cast<const arrow::DoubleArray *>(xminArray);
CPLAssert(yminArray->type_id() == arrow::Type::DOUBLE);
m_poArrayYMinDouble =
static_cast<const arrow::DoubleArray *>(yminArray);
CPLAssert(xmaxArray->type_id() == arrow::Type::DOUBLE);
m_poArrayXMaxDouble =
static_cast<const arrow::DoubleArray *>(xmaxArray);
CPLAssert(ymaxArray->type_id() == arrow::Type::DOUBLE);
m_poArrayYMaxDouble =
static_cast<const arrow::DoubleArray *>(ymaxArray);
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions ogr/ogrsf_frmts/parquet/ogrparquetlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1980,8 +1980,7 @@ OGRErr OGRParquetLayer::SetIgnoredFields(CSLConstList papszFields)
m_oMapGeomFieldIndexToGeomColBBOXParquet.find(i);
if (oIter != m_oMapGeomFieldIndexToGeomColBBOX.end() &&
oIterParquet !=
m_oMapGeomFieldIndexToGeomColBBOXParquet.end() &&
!OGRArrowIsGeoArrowStruct(m_aeGeomEncoding[i]))
m_oMapGeomFieldIndexToGeomColBBOXParquet.end())
{
oIter->second.iArrayIdx = nBatchColumns++;
m_anRequestedParquetColumns.insert(
Expand Down
Loading