Skip to content

Commit ca37f98

Browse files
authored
added parquet support for control networks (#5905)
* added parquet support * checkpoint, more additions * checkpoint * adding deps to meta.yml * added VSI support for image lists * minor changes * added changelog * comments * fixed log * rm frag
1 parent 8fa6d9a commit ca37f98

10 files changed

Lines changed: 861 additions & 20 deletions

File tree

changes/+20260630130235.add.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added Parquet support for control networks

environment.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ dependencies:
3535
- krb5
3636
- libboost >=1.88.0,<1.89
3737
- libgdal >=3.12.2,<4
38+
- libgdal-arrow-parquet >=3.12,<4
3839
- libopencv >=4.12,<5
3940
- libpng >=1.6.34,<1.7
4041
- libprotobuf >=6,<7

environment_arm.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ dependencies:
3333
- jama
3434
- kalasiris
3535
- krb5
36-
- libboost >=1.88.0,<1.89
3736
- libgdal >=3.12.2,<4
37+
- libgdal-arrow-parquet >=3.12,<4
38+
- libboost >=1.88.0,<1.89
3839
- libopencv >=4.12,<5
3940
- libpng >=1.6.34,<1.7
4041
- libprotobuf >=6,<7

isis/src/base/objs/FileList/FileList.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ find files of those names at the top level of this repository. **/
1111
#include "IString.h"
1212
#include <iostream>
1313
#include <fstream>
14+
#include <sstream>
15+
16+
#include "cpl_vsi.h"
1417

1518
using namespace std;
1619
namespace Isis {
@@ -50,6 +53,36 @@ namespace Isis {
5053
* @throws Isis::iException::Io - Cannot open file
5154
*/
5255
void FileList::read(FileName listFile) {
56+
QString path = listFile.toString();
57+
58+
if (path.startsWith("/vsi")) {
59+
VSILFILE *fp = VSIFOpenL(path.toUtf8().constData(), "rb");
60+
if (!fp) {
61+
QString message = Isis::Message::FileOpen(path);
62+
throw IException(IException::Io, message, _FILEINFO_);
63+
}
64+
65+
// Read the entire file in chunks (a cube list can be arbitrarily large,
66+
// so do not assume a fixed buffer size).
67+
std::string contents;
68+
char buffer[65536];
69+
size_t nRead;
70+
while ((nRead = VSIFReadL(buffer, 1, sizeof(buffer), fp)) > 0) {
71+
contents.append(buffer, nRead);
72+
}
73+
VSIFCloseL(fp);
74+
75+
try {
76+
std::istringstream iss(contents);
77+
read(iss);
78+
}
79+
catch (IException &e) {
80+
QString msg = "File [" + path + "] contains no data";
81+
throw IException(IException::User, msg, _FILEINFO_);
82+
}
83+
return;
84+
}
85+
5386
// Open the file
5487
ifstream istm;
5588
istm.open(listFile.toString().toLatin1().data(), std::ios::in);
@@ -156,6 +189,23 @@ namespace Isis {
156189
* @throws Isis::iException::Io File could not be created.
157190
*/
158191
void FileList::write(FileName outputFileList) {
192+
QString path = outputFileList.toString();
193+
194+
if (path.startsWith("/vsi")) {
195+
std::ostringstream oss;
196+
write(oss);
197+
std::string data = oss.str();
198+
199+
VSILFILE *fp = VSIFOpenL(path.toUtf8().constData(), "wb");
200+
if (!fp) {
201+
QString message = Message::FileOpen(path);
202+
throw IException(IException::Io, message, _FILEINFO_);
203+
}
204+
VSIFWriteL(data.data(), 1, data.size(), fp);
205+
VSIFCloseL(fp);
206+
return;
207+
}
208+
159209
// Open the file
160210
ofstream ostm;
161211
ostm.open(outputFileList.toString().toLatin1().data(), std::ios::out);

isis/src/control/objs/ControlNet/ControlNet.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,26 @@ namespace Isis {
310310
void ControlNet::Write(const QString &ptfile, bool pvl) {
311311
ControlNetVersioner versionedWriter(this);
312312

313+
// Check if writing to Parquet format. Strip any VSI query string (e.g.
314+
// "/vsicurl/https://host/net.parquet?list=no") before testing the suffix.
315+
bool isParquet = ptfile.split("?").first().endsWith(".parquet", Qt::CaseInsensitive);
316+
317+
if (isParquet) {
318+
if (pvl) {
319+
QString msg = "Cannot write control network as Pvl to a Parquet file [" + ptfile
320+
+ "]. Parquet (binary) and Pvl output are mutually exclusive.";
321+
throw IException(IException::User, msg, _FILEINFO_);
322+
}
323+
try {
324+
versionedWriter.write(FileName(ptfile));
325+
}
326+
catch (IException &e) {
327+
QString msg = "Failed writing control network to Parquet file [" + ptfile + "]";
328+
throw IException(e, IException::Io, msg, _FILEINFO_);
329+
}
330+
return;
331+
}
332+
313333
if (pvl) {
314334
Pvl network;
315335
try {

0 commit comments

Comments
 (0)