7 #include <QProgressDialog>
9 #include <QInputDialog>
10 #include <QListWidget>
14 ui =
new Ui::DialogParquet();
19 connect(
ui->checkBoxDateFormat, &QCheckBox::toggled,
this,
20 [=](
bool checked) { ui->lineEditDateFormat->setEnabled(checked); });
22 connect(
ui->listWidgetSeries, &QListWidget::currentTextChanged,
this,
23 [=](QString text) { ui->buttonBox->setEnabled(!text.isEmpty()); });
25 connect(
ui->listWidgetSeries, &QListWidget::doubleClicked,
this,
26 [=](
const QModelIndex&) { _dialog->accept(); });
28 connect(
ui->radioButtonIndex, &QRadioButton::toggled,
this, [=](
bool checked) {
29 ui->buttonBox->setEnabled(checked);
30 ui->listWidgetSeries->setEnabled(!checked);
35 bool radio_index_checked =
36 settings.value(
"DataLoadParquet::radioIndexChecked",
false).toBool();
37 ui->radioButtonIndex->setChecked(radio_index_checked);
39 bool parse_date_time = settings.value(
"DataLoadParquet::parseDateTime",
false).toBool();
40 ui->checkBoxDateFormat->setChecked(parse_date_time);
42 QString date_format = settings.value(
"DataLoadParquet::dateFromat",
false).toString();
43 if (date_format.isEmpty() ==
false)
45 ui->lineEditDateFormat->setText(date_format);
56 static std::vector<const char*> extensions = {
"parquet" };
62 using parquet::ConvertedType;
72 std::shared_ptr<parquet::FileMetaData> file_metadata =
parquet_reader_->metadata();
73 const auto schema = file_metadata->schema();
74 const size_t num_columns = file_metadata->num_columns();
76 std::vector<parquet::Type::type> column_type;
77 std::vector<parquet::ConvertedType::type> converted_column_type;
78 std::vector<bool> valid_column(num_columns,
true);
80 for (
size_t col = 0; col < num_columns; col++)
82 auto column = schema->Column(col);
83 auto type = column->physical_type();
84 auto converted_type = column->converted_type();
86 column_type.push_back(
type);
87 converted_column_type.push_back(converted_type);
91 type == Type::FLOAT ||
type == Type::DOUBLE);
93 ui->listWidgetSeries->addItem(QString::fromStdString(column->name()));
101 settings.value(
"DataLoadParquet::prevTimestamp", {}).toString();
107 if (items.size() > 0)
109 ui->listWidgetSeries->setCurrentItem(items.front());
115 if (
ret != QDialog::Accepted)
120 QString selected_stamp;
122 if (
ui->radioButtonSelect->isChecked())
124 auto selected =
ui->listWidgetSeries->selectedItems();
125 if (selected.size() == 1)
127 selected_stamp = selected.front()->text();
132 settings.setValue(
"DataLoadParquet::prevTimestamp", selected_stamp);
133 settings.setValue(
"DataLoadParquet::radioIndexChecked",
134 ui->radioButtonIndex->isChecked());
135 settings.setValue(
"DataLoadParquet::parseDateTime",
136 ui->checkBoxDateFormat->isChecked());
137 settings.setValue(
"DataLoadParquet::dateFromat",
ui->lineEditDateFormat->text());
141 int timestamp_column = -1;
143 std::vector<PlotData*> series(num_columns,
nullptr);
145 for (
size_t col = 0; col < num_columns; col++)
147 auto column = schema->Column(col);
148 const std::string&
name = column->name();
149 if (
name == selected_stamp.toStdString())
151 timestamp_column = col;
153 if (valid_column[col])
161 std::vector<double> row_values(num_columns, 0.0);
167 for (
size_t col = 0; col < num_columns; col++)
169 if (!valid_column[col])
173 auto type = column_type[col];
174 auto converted_type = converted_column_type[col];
178 case Type::BOOLEAN: {
181 row_values[col] =
static_cast<double>(tmp);
186 switch (converted_type)
188 case ConvertedType::INT_8: {
191 row_values[col] =
static_cast<double>(tmp);
194 case ConvertedType::INT_16: {
197 row_values[col] =
static_cast<double>(tmp);
200 case ConvertedType::INT_32: {
203 row_values[col] =
static_cast<double>(tmp);
206 case ConvertedType::INT_64: {
209 row_values[col] =
static_cast<double>(tmp);
212 case ConvertedType::UINT_8: {
215 row_values[col] =
static_cast<double>(tmp);
218 case ConvertedType::UINT_16: {
221 row_values[col] =
static_cast<double>(tmp);
224 case ConvertedType::UINT_32: {
227 row_values[col] =
static_cast<double>(tmp);
230 case ConvertedType::UINT_64: {
233 row_values[col] =
static_cast<double>(tmp);
243 row_values[col] =
static_cast<double>(tmp);
249 row_values[col] =
static_cast<double>(tmp);
260 row_values[col] =
static_cast<double>(tmp);
264 os >> row_values[col];
272 os >> parquet::EndRow;
274 double timestamp = timestamp_column >= 0 ? row_values[timestamp_column] : row;
277 for (
size_t col = 0; col < num_columns; col++)
279 if (!valid_column[col])
284 if (valid_column[col])
286 series[col]->pushBack({ timestamp, row_values[col] });
295 QDomElement elem = doc.createElement(
"default");
297 elem.setAttribute(
"radioIndexChecked",
ui->radioButtonIndex->isChecked());
298 elem.setAttribute(
"parseDateTime",
ui->checkBoxDateFormat->isChecked());
299 elem.setAttribute(
"dateFromat",
ui->lineEditDateFormat->text());
301 parent_element.appendChild(elem);
307 QDomElement elem = parent_element.firstChildElement(
"default");
310 if (elem.hasAttribute(
"prevTimestamp"))
314 if (elem.hasAttribute(
"radioIndexChecked"))
316 bool checked = elem.attribute(
"radioIndexChecked").toInt();
317 ui->radioButtonIndex->setChecked(checked);
319 if (elem.hasAttribute(
"parseDateTime"))
321 bool checked = elem.attribute(
"parseDateTime").toInt();
322 ui->checkBoxDateFormat->setChecked(checked);
324 if (elem.hasAttribute(
"dateFromat"))
326 ui->lineEditDateFormat->setText(elem.attribute(
"dateFromat"));